Skip to content

Commit

Permalink
Snowflake (patch) prevent engine crash (#379)
Browse files Browse the repository at this point in the history
* Snowflake (path) prevent engine crash

* Refactor SnowflakeDB to handle asynchronous query execution and improve error handling

* update snowflake to enable async queries
  • Loading branch information
jirihofman authored Feb 17, 2025
1 parent 16847ac commit 3a6610b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
5 changes: 4 additions & 1 deletion src/appmixer/snowflake/bundle.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "appmixer.snowflake",
"version": "1.1.12",
"version": "1.1.13",
"changelog": {
"1.0.0": [
"Initial version"
Expand Down Expand Up @@ -46,6 +46,9 @@
],
"1.1.12": [
"Update snowflake-sdk dependency to v1.11.0."
],
"1.1.13": [
"Fixed an issue when invalid query could cause the engine to crash."
]
}
}
35 changes: 21 additions & 14 deletions src/appmixer/snowflake/common.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// 'use strict';
const snowflake = require('snowflake-sdk');
const { promisify } = require('util');

Expand All @@ -12,23 +11,31 @@ class SnowflakeDB {
await promisify(connection.connect).bind(connection)();
return connection;
}
async runQuery(context, sql) {

const connection = await this.getConnection(context);
const executedQuery = connection.execute({
sqlText: sql
async getRows(auth, statement) {

const connection = await this.getConnection(auth);
const promise = await new Promise((resolve, reject) => {
connection.execute({
sqlText: statement.sqlText,
asyncExec: true,
complete: async function(err, stmt, rows) {
let queryId = stmt.getQueryId();
try {
const results = await connection.getResultsFromQueryId({ queryId });
resolve(results);
} catch (error) {
// We can't throw Snoflake error directly, because it will terminate the node process.
reject(error.message);
}
}
});
});
return executedQuery;
}
async getRows(context, statement) {

const connection = await this.getConnection(context);
const executedStatement = connection.execute(statement);
return executedStatement.streamRows();
return promise.streamRows();
}
async collectRows(context, statement) {
async collectRows(auth, statement) {

const rowStream = await this.getRows(context, statement);
const rowStream = await this.getRows(auth, statement);
const rows = [];
for await (const row of rowStream) {
rows.push(row);
Expand Down
2 changes: 1 addition & 1 deletion src/appmixer/snowflake/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"version": "0.0.1",
"dependencies": {
"csv-stringify": "6.2.3",
"snowflake-sdk": "1.11.0"
"snowflake-sdk": "2.0.2"
}
}

0 comments on commit 3a6610b

Please sign in to comment.