Skip to content

Commit

Permalink
feat: Retail Tutorials. If create BQ table is requested, check if it …
Browse files Browse the repository at this point in the history
…exists and remove before creation (#157)

* Update setup-cleanup.js

* fix: change BQ table creation logic

Co-authored-by: Karl Weinmeister <11586922+kweinmeister@users.noreply.github.com>
Co-authored-by: tkarasyova <tkarasyova@griddynamics.com>
  • Loading branch information
3 people authored Apr 8, 2022
1 parent c20eab5 commit 5f6e987
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 61 deletions.
35 changes: 17 additions & 18 deletions retail/interactive-tutorials/setup/setup-cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,26 +231,25 @@ const isTableExist = async (datasetId, tableId) => {

const createBqTable = async (datasetId, tableId, schemaFile) => {
if (await isTableExist(datasetId, tableId)) {
console.log(`Table ${tableId} already exists`);
return false;
} else {
const schemaFileData = fs.readFileSync(schemaFile);
const schema = JSON.parse(schemaFileData);

const bigquery = new BigQuery();
const options = {
schema: schema,
location: 'US',
};
console.log(`Table ${tableId} exists and will be removed`);
await deleteBqTable(datasetId, tableId);
}
console.log(`Table name ${tableId} is unique for the dataset ${datasetId}`);
//Create a new table in the dataset
const schemaFileData = fs.readFileSync(schemaFile);
const schema = JSON.parse(schemaFileData);
const bigquery = new BigQuery();
const options = {
schema: schema,
location: 'US',
};

//Create a new table in the dataset
const [table] = await bigquery
.dataset(datasetId)
.createTable(tableId, options);
const [table] = await bigquery
.dataset(datasetId)
.createTable(tableId, options);

console.log(`Table ${table.id} created.`);
return true;
}
console.log(`Table ${table.id} created.`);
return true;
};

const deleteBqTable = async (datasetId, tableId) => {
Expand Down
43 changes: 0 additions & 43 deletions retail/interactive-tutorials/test/get-products-list.test.js

This file was deleted.

0 comments on commit 5f6e987

Please sign in to comment.