Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace better-eval with vm #536

Merged
merged 54 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
3211f5d
Replace better-eval with vm
sfc-gh-ext-simba-lf Jun 14, 2023
23fc95d
issue366 - Add test case for variant column type
sfc-gh-ext-simba-lf Jun 14, 2023
752e5ee
Merge branch 'master' into blockingIssue
sfc-gh-ext-simba-lf Jun 14, 2023
49be617
issue 366 - Remove 'vm' from package.json as it's already part of node
sfc-gh-ext-simba-lf Jun 15, 2023
d6caa0a
issue 366 - Rename test
sfc-gh-ext-simba-lf Jun 15, 2023
48362b1
issue 366 - Make array const
sfc-gh-ext-simba-lf Jun 15, 2023
73d1184
issue 366 - Wrapped lines in else clause
sfc-gh-ext-simba-lf Jun 15, 2023
6e5ea30
issue 366 - Put variant test in its own describe and placed create/dr…
sfc-gh-ext-simba-lf Jun 15, 2023
a4116fe
issue 366 - Put variant test in its own describe and placed create/dr…
sfc-gh-ext-simba-lf Jun 15, 2023
6b48461
issue 366 - Put variant test in its own describe and placed create/dr…
sfc-gh-ext-simba-lf Jun 15, 2023
7648167
issue 366 - Put variant test in its own describe and placed create/dr…
sfc-gh-ext-simba-lf Jun 15, 2023
a386231
issue 366 - Put variant test in its own describe and placed create/dr…
sfc-gh-ext-simba-lf Jun 15, 2023
45d6ac7
issue 366 - Put variant test in its own describe and placed create/dr…
sfc-gh-ext-simba-lf Jun 15, 2023
9909b2b
issue 366 - Temp revert wrapping test in describe
sfc-gh-ext-simba-lf Jun 15, 2023
f17bd1d
issue 366 - Temp revert else clause
sfc-gh-ext-simba-lf Jun 15, 2023
8cb7cbe
issue 366 - Temp revert const array
sfc-gh-ext-simba-lf Jun 15, 2023
7e490c8
issue 366 - Temp revert name change
sfc-gh-ext-simba-lf Jun 15, 2023
2fe6098
issue 366 - Temp revert remove vm
sfc-gh-ext-simba-lf Jun 15, 2023
ae4f82b
issue 366 - Remove vm
sfc-gh-ext-simba-lf Jun 15, 2023
32828b1
issue 366 - Rename test
sfc-gh-ext-simba-lf Jun 15, 2023
a2c7f7a
issue 366 - Make array const
sfc-gh-ext-simba-lf Jun 15, 2023
18b1307
issue 366 - Wrap in else clause
sfc-gh-ext-simba-lf Jun 15, 2023
78d351f
issue 366 - Wrap variant test in its own describe
sfc-gh-ext-simba-lf Jun 15, 2023
3307632
Merge branch 'master' into blockingIssue
sfc-gh-ext-simba-lf Jun 15, 2023
0b4ed6a
Require async used by the variant test
sfc-gh-ext-simba-lf Jun 15, 2023
57e1fae
Parse JSON one row at a time
sfc-gh-ext-simba-lf Jun 16, 2023
698da7f
Merge branch 'master' into blockingIssue
sfc-gh-ext-simba-lf Jun 19, 2023
94a0dc0
Merge branch 'master' into blockingIssue
sfc-gh-ext-simba-lf Jun 20, 2023
13182d7
Merge branch 'master' into blockingIssue
sfc-gh-ext-simba-lf Jun 21, 2023
f3f148f
issue 366 - Add option to configure json/xml parser
sfc-gh-ext-simba-lf Jun 21, 2023
907e70d
issue 366 - Fix typo from logLevel
sfc-gh-ext-simba-lf Jun 21, 2023
293bf49
issue 366 - Add test case for xml data type
sfc-gh-ext-simba-lf Jun 21, 2023
6e25381
issue 366 - Add tests for snowflake.configure options
sfc-gh-ext-simba-lf Jun 21, 2023
59617fc
issue 366 - Fix ocsp variable
sfc-gh-ext-simba-lf Jun 22, 2023
205aefd
Return to default configuration after test
sfc-gh-ext-simba-lf Jun 22, 2023
57156f1
Return to default configuration after test
sfc-gh-ext-simba-lf Jun 22, 2023
bc05b67
issue 366 - nit newline
sfc-gh-ext-simba-lf Jun 22, 2023
5c14ff6
Run lint on new test file
sfc-gh-ext-simba-lf Jun 22, 2023
7c3337c
Move required up
sfc-gh-ext-simba-lf Jun 22, 2023
abc37de
issue 366 - Keep old behaviour of xml parser
sfc-gh-ext-simba-lf Jun 22, 2023
8d38f0d
issue 366 - Log and throw error in the default xml parser
sfc-gh-ext-simba-lf Jun 22, 2023
f2e4fb3
issue 366 - Add expected signature for setting a custom parser
sfc-gh-ext-simba-lf Jun 22, 2023
e041119
issue 366 - Make new variables const
sfc-gh-ext-simba-lf Jun 22, 2023
e2b3676
Wrap variant test cases in their own describe
sfc-gh-ext-simba-lf Jun 22, 2023
29e122a
issue 366 - Wrap the configure test cases in their own describe
sfc-gh-ext-simba-lf Jun 22, 2023
a1041ae
issue 366 - Refactor calling the test cases
sfc-gh-ext-simba-lf Jun 22, 2023
dd16337
issue 366 - Fixed the custom xml parser in the test case
sfc-gh-ext-simba-lf Jun 22, 2023
122949e
issue 366 - Create test with custom parser
sfc-gh-ext-simba-lf Jun 23, 2023
bdef7ef
issue 366 - Move require up
sfc-gh-ext-simba-lf Jun 23, 2023
687064a
issue 366 - Add logging and throw for both JSON/XML parser errors
sfc-gh-ext-simba-lf Jun 27, 2023
32bdf40
Merge branch 'master' into blockingIssue
sfc-gh-ext-simba-lf Jun 27, 2023
c53bc3b
Merge branch 'master' into blockingIssue
sfc-gh-ext-simba-lf Jun 27, 2023
edec59c
Merge branch 'master' into blockingIssue
sfc-gh-ext-simba-lf Jun 28, 2023
4733e29
Merge branch 'master' into blockingIssue
sfc-gh-ext-simba-lf Jun 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/connection/result/column.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ var SfTimestamp = require('./sf_timestamp');
var SqlTypes = require('./data_types').SqlTypes;
var bigInt = require('big-integer');
var { XMLParser, XMLValidator } = require("fast-xml-parser");
var betterEval = require("better-eval");
const vm = require('vm');

var NULL_UPPERCASE = 'NULL';
const VM_CONTEXT = vm.createContext(); // create a new context so VM does not have to make a new one for each conversion

/**
* Creates a new Column.
Expand Down Expand Up @@ -552,7 +553,8 @@ function convertRawVariant(rawColumnValue, column, context)
{
try
{
ret = betterEval("(" + rawColumnValue + ")");
// run code on a different scope
ret = vm.runInContext("(" + rawColumnValue + ")", VM_CONTEXT);
sfc-gh-ext-simba-lf marked this conversation as resolved.
Show resolved Hide resolved
}
catch (parseError)
{
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"async": "^3.2.3",
"aws-sdk": "^2.878.0",
"axios": "^0.27.2",
"better-eval": "^1.3.0",
"big-integer": "^1.6.43",
"bignumber.js": "^2.4.0",
"binascii": "0.0.2",
Expand Down
144 changes: 144 additions & 0 deletions test/integration/testLargeResultSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright (c) 2015-2019 Snowflake Computing Inc. All rights reserved.
*/
const assert = require('assert');
const async = require('async');
const testUtil = require('./testUtil');

const sourceRowCount = 10000;
Expand Down Expand Up @@ -105,4 +106,147 @@ 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';

before(async () =>
{
await testUtil.executeCmdAsync(connection, createTableWithVariant);
await testUtil.executeCmdAsync(connection, createTempTable);
});

after(async () =>
{
await testUtil.executeCmdAsync(connection, dropTableWithVariant);
await testUtil.executeCmdAsync(connection, dropTempTable);
});

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 arrJSON = [];
for (let i = 0; i < sourceRowCount; i++)
{
const sampleJSON = {
"root":
{
"key":
[
{
"key1": i,
"key2": "value2",
"key3": "value3",
"key4": "value4",
"key5":
{
"key":
[
{ "key1": "value1", "key2": "value2" },
{ "key1": "value1", "key2": "value2" },
{ "key1": "value1", "key2": "value2" },
{ "key1": "value1", "key2": "value2" }
]
},
"key6":
[
{ "key1": "value1", "key": "value" },
{ "key1": "value1", "key": "value" },
{ "key1": "value1", "key": "value" },
{ "key1": "value1", "key": "value" },
{ "key1": "value1", "key": "value" },
{ "key1": "value1", "key": "value" },
{ "key1": "value1", "key": "value" }
]
},
]
}
};
arrJSON.push([JSON.stringify(sampleJSON)]);
}

async.series([
function (callback)
{
connection.execute({
sqlText: insertTemp,
binds: arrJSON,
complete: function (err, stmt)
{
if (err)
{
callback(err);
}
else
{
try
{
assert.strictEqual(stmt.getNumUpdatedRows(), sourceRowCount);
callback();
}
catch (err)
{
callback(err);
}
}
}
});
},
function (callback)
{
connection.execute({
sqlText: insertVariant,
complete: (err) => callback(err)
})
},
function (callback)
{
connection.execute({
sqlText: selectVariant,
streamResult: true,
complete: function (err, stmt)
{
if (err)
{
callback(err);
}
else
{
var stream = stmt.streamRows();
var rowCount = 0;
stream.on('data', function ()
{
rowCount++;
});
stream.on('error', function (err)
{
callback(err);
});
stream.on('end', function ()
{
try
{
assert.strictEqual(rowCount, sourceRowCount);
callback();
}
catch (err)
{
callback(err);
}
});
}
}
});
}],
done
);
});
});
});