Skip to content

Commit

Permalink
SNOW-930831: Add randomization to the table name in put/get test
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pmotacki committed Oct 5, 2023
1 parent 40f370c commit 7afdb2f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
19 changes: 11 additions & 8 deletions test/integration/testLargeResultSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const assert = require('assert');
const async = require('async');
const testUtil = require('./testUtil');
const { configureLogger } = require('../configureLogger');
const {randomizeName} = require('./testUtil');

describe('Large result Set Tests', function ()
{
Expand Down Expand Up @@ -110,10 +111,12 @@ describe('Large result Set Tests', function ()

describe('Large Result Set Tests For Variant Column Type', function ()
{
const createTempTable = 'create or replace table testVariantTemp(value string)';
const createTableWithVariant = 'create or replace table testVariantTable(colA variant)';
const dropTableWithVariant = 'drop table if exists testVariantTable';
const dropTempTable = 'drop table if exists testVariantTemp';
const testVariantTemp = randomizeName('testVariantTemp');
const testVariantTable = randomizeName('testVariantTable');
const createTempTable = `create or replace table ${testVariantTemp} (value string)`;
const createTableWithVariant = `create or replace table ${testVariantTable} (colA variant)`;
const dropTableWithVariant = `drop table if exists ${testVariantTable}`;
const dropTempTable = `drop table if exists ${testVariantTemp} `;

before(async () =>
{
Expand All @@ -129,9 +132,9 @@ describe('Large result Set Tests', function ()

it('testSelectOnVariantColumnForLargeResultSets', function (done)
{
const insertTemp = 'insert into testVariantTemp values (?)';
const insertVariant = 'insert into testVariantTable select parse_json(value) from testVariantTemp';
const selectVariant = 'select * from testVariantTable';
const insertTemp = `insert into ${testVariantTemp} values (?)`;
const insertVariant = `insert into ${testVariantTable} select parse_json(value) from ${testVariantTemp}`;
const selectVariant = `select * from ${testVariantTable}`;

const arrJSON = [];
for (let i = 0; i < sourceRowCount; i++)
Expand Down Expand Up @@ -254,7 +257,7 @@ describe('Large result Set Tests', function ()

describe('SNOW-743920:Large result set with ~35 chunks', function () {
let connection;
const tableName = 'test_table';
const tableName = randomizeName('test_table');
const sourceRowCount = 251002;
const generatedRowSize = 350;
const createTable = `create or replace table ${tableName} (data string)`;
Expand Down
10 changes: 8 additions & 2 deletions test/integration/testPutGet.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ const tmp = require('tmp');
const os = require('os');
const path = require('path');
const zlib = require('zlib');
const {randomizeName} = require("./testUtil");

const DATABASE_NAME = connOption.valid.database;
const SCHEMA_NAME = connOption.valid.schema;
const TEMP_TABLE_NAME = 'TEMP_TABLE';

const SKIPPED = 'SKIPPED';
const UPLOADED = 'UPLOADED';
Expand Down Expand Up @@ -75,6 +75,7 @@ describe('PUT GET test', function () {

let connection;
let tmpFile;
const TEMP_TABLE_NAME = randomizeName('TEMP_TABLE');
const createTable = `create or replace table ${TEMP_TABLE_NAME} (${COL1} STRING, ${COL2} STRING, ${COL3} STRING)`;
const truncateTable = `truncate table if exists ${TEMP_TABLE_NAME}`;
const copyInto = `COPY INTO ${TEMP_TABLE_NAME}`;
Expand Down Expand Up @@ -292,6 +293,7 @@ describe('PUT GET overwrite test', function () {
this.retries(3); // this test suit are considered as flaky test

let connection;
const TEMP_TABLE_NAME = randomizeName('TEMP_TABLE');
const createTable = `create or replace table ${TEMP_TABLE_NAME} (${COL1} STRING, ${COL2} STRING, ${COL3} STRING)`;
const removeFile = `REMOVE @${DATABASE_NAME}.${SCHEMA_NAME}.%${TEMP_TABLE_NAME}`;
const dropTable = `DROP TABLE IF EXISTS ${TEMP_TABLE_NAME}`;
Expand Down Expand Up @@ -477,8 +479,8 @@ describe('PUT GET test with GCS_USE_DOWNSCOPED_CREDENTIAL', function () {
this.retries(3); // this test suit are considered as flaky test

let connection;

let tmpFile;
const TEMP_TABLE_NAME = randomizeName('TEMP_TABLE');
const createTable = `create or replace table ${TEMP_TABLE_NAME} (${COL1} STRING, ${COL2} STRING, ${COL3} STRING)`;
const copyInto = `COPY INTO ${TEMP_TABLE_NAME}`;
const removeFile = `REMOVE @${DATABASE_NAME}.${SCHEMA_NAME}.%${TEMP_TABLE_NAME}`;
Expand Down Expand Up @@ -649,6 +651,7 @@ describe('PUT GET test with GCS_USE_DOWNSCOPED_CREDENTIAL', function () {
describe('PUT GET test with multiple files', function () {
let connection;
let tmpDir;
const TEMP_TABLE_NAME = randomizeName('TEMP_TABLE');
const stage = `@${DATABASE_NAME}.${SCHEMA_NAME}.%${TEMP_TABLE_NAME}`;
const removeFile = `REMOVE ${stage}`;
let tmpFiles; // FileSyncObject[]
Expand Down Expand Up @@ -862,6 +865,7 @@ describe('PUT GET test with multiple files', function () {

describe('PUT GET test without compress', function () {
let connection;
const TEMP_TABLE_NAME = randomizeName('TEMP_TABLE');
const stage = `@${DATABASE_NAME}.${SCHEMA_NAME}.%${TEMP_TABLE_NAME}`;
const createTable = `create or replace table ${TEMP_TABLE_NAME} (${COL1} STRING, ${COL2} STRING, ${COL3} STRING)`;
const removeFile = `REMOVE ${stage}`;
Expand Down Expand Up @@ -959,6 +963,7 @@ describe('PUT GET test without compress', function () {

describe('PUT GET test with different size', function () {
let connection;
const TEMP_TABLE_NAME = randomizeName('TEMP_TABLE');
const stage = `@${DATABASE_NAME}.${SCHEMA_NAME}.%${TEMP_TABLE_NAME}`;
const createTable = `create or replace table ${TEMP_TABLE_NAME} (${COL1} STRING, ${COL2} STRING, ${COL3} STRING)`;
const removeFile = `REMOVE ${stage}`;
Expand Down Expand Up @@ -1092,6 +1097,7 @@ describe('PUT GET test with different size', function () {

describe('PUT GET test with error', function () {
let connection;
const TEMP_TABLE_NAME = randomizeName('TEMP_TABLE');
const stage = `@${DATABASE_NAME}.${SCHEMA_NAME}.%${TEMP_TABLE_NAME}`;
const stage_not_exist = `@${DATABASE_NAME}.${SCHEMA_NAME}.%NONEXISTTABLE`;
const createTable = `create or replace table ${TEMP_TABLE_NAME} (${COL1} STRING, ${COL2} STRING, ${COL3} STRING)`;
Expand Down
12 changes: 7 additions & 5 deletions test/integration/testPutSmallFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ var os = require('os');
var path = require('path');
var testUtil = require('./testUtil');
const connOption = require('./connectionOptions');
const {randomizeName} = require('./testUtil');

const DATABASE_NAME = connOption.valid.database;
const SCHEMA_NAME = connOption.valid.schema;
const WAREHOUSE_NAME = connOption.valid.warehouse;
const TABLE = randomizeName('TESTTBL');

var connection;
var files = new Array();
Expand All @@ -20,7 +22,7 @@ function uploadFiles(callback, index = 0)
{
if(index < files.length)
{
var putQuery = `PUT file://${files[index]} @${DATABASE_NAME}.${SCHEMA_NAME}.%TESTTBL`;
var putQuery = `PUT file://${files[index]} @${DATABASE_NAME}.${SCHEMA_NAME}.%${TABLE}`;
var insertStmt = connection.execute({
sqlText: putQuery,
complete: function (err, stmt) {
Expand All @@ -46,10 +48,10 @@ describe('Test Put Small Files', function ()
{
this.timeout(100000);
var useWH = `use warehouse ${WAREHOUSE_NAME}`;
var createTable = `create or replace table ${DATABASE_NAME}.${SCHEMA_NAME}.TESTTBL(colA string, colB number, colC date, colD time, colE TIMESTAMP_NTZ, colF TIMESTAMP_TZ)`;
var copytInto = `copy into ${DATABASE_NAME}.${SCHEMA_NAME}.TESTTBL`;
var select1row = `select * from ${DATABASE_NAME}.${SCHEMA_NAME}.TESTTBL where colB = 3`;
var selectAll = `select count(*) AS NUM from ${DATABASE_NAME}.${SCHEMA_NAME}.TESTTBL`;
var createTable = `create or replace table ${DATABASE_NAME}.${SCHEMA_NAME}.${TABLE}(colA string, colB number, colC date, colD time, colE TIMESTAMP_NTZ, colF TIMESTAMP_TZ)`;
var copytInto = `copy into ${DATABASE_NAME}.${SCHEMA_NAME}.${TABLE}`;
var select1row = `select * from ${DATABASE_NAME}.${SCHEMA_NAME}.${TABLE} where colB = 3`;
var selectAll = `select count(*) AS NUM from ${DATABASE_NAME}.${SCHEMA_NAME}.${TABLE}`;
var count = 5000;

before(function (done)
Expand Down
12 changes: 12 additions & 0 deletions test/integration/testUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const snowflake = require('./../../lib/snowflake');
const connOptions = require('./connectionOptions');
const assert = require('assert');
const fs = require('fs');
const crypto = require('crypto');

module.exports.createConnection = function (validConnectionOptionsOverride = {}) {
return snowflake.createConnection({
Expand Down Expand Up @@ -244,3 +245,14 @@ module.exports.deleteFolderSyncIgnoringErrors = function (directory) {
console.warn(`Cannot delete folder ${directory}: ${JSON.stringify(e)}`);
}
};

/**
* @param name string
*/
module.exports.randomizeName = function (name) {
if (name === null || name.trim() === '') {
throw new Error('Name must be non empty string');
}
const randomString = crypto.randomBytes(4).toString('hex');
return name.concat(randomString);
};

0 comments on commit 7afdb2f

Please sign in to comment.