in ingestion/batch/index.js [208:259]
async function createTransformJob(config, query) {
console.log(`Configuration for runTransform: ${JSON.stringify(config)}`);
// process.env.GCP_PROJECT is currently used by unit tests
// This var is not supported in cloud function node.js 10 + environments
// https://cloud.google.com/functions/docs/env-var#nodejs_10_and_subsequent_runtimes
let projectId = null;
if (!process.env.GCP_PROJECT) {
const gcpMetadata = require('gcp-metadata');
const isAvailable = await gcpMetadata.isAvailable();
if (isAvailable === true) {
projectId = await gcpMetadata.project('project-id');
console.log(`Project Id is: ${projectId}`); // ...Project ID of the running instance
} else {
console.log('gcpMetadata is unavailable, unable to determine projectId');
throw new Error('Unable to determine GCP Project Id');
}
} else {
projectId = process.env.GCP_PROJECT;
}
let options = {
destinationTable: {
projectId: projectId,
datasetId: config.datasetId,
tableId: config.destinationTableId
},
createDisposition: "CREATE_IF_NEEDED",
writeDisposition: (config.truncate)
? "WRITE_TRUNCATE"
: "WRITE_APPEND",
query: query,
jobPrefix: `${cfg.pathPrefix}_`,
timePartitioning: {
type: 'DAY'
}
};
if (config.metadata && config.metadata.location) {
options.location = config.metadata.location;
}
console.log(`BigQuery options: ${JSON.stringify(options)}`);
try {
return bigqueryUtil.createQueryJob(options);
}
catch (exception) {
console.error(`Exception encountered running transform: ${getExceptionString(exception)}`);
logException(exception);
throw (exception);
}
}