Skip to content

Commit

Permalink
feat(snowflake-driver): Upgrade snowflake-sdk to 1.13.1 (fix Node.js …
Browse files Browse the repository at this point in the history
…20+ crash) (#8713)

This upgrade is required to fix a compatibility issue for Snowflake SDK and Node.js 20+. 

References:

- snowflakedb/snowflake-connector-nodejs#588
- snowflakedb/snowflake-connector-nodejs#703
  • Loading branch information
ovr authored Sep 16, 2024
1 parent 26a8fec commit 84bc8de
Show file tree
Hide file tree
Showing 5 changed files with 13,467 additions and 6,353 deletions.
3 changes: 1 addition & 2 deletions packages/cubejs-snowflake-driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@cubejs-backend/shared": "^0.36.0",
"@google-cloud/storage": "^5.8.5",
"date-fns-timezone": "^0.1.4",
"snowflake-sdk": "^1.8.0"
"snowflake-sdk": "^1.13.1"
},
"license": "Apache-2.0",
"publishConfig": {
Expand All @@ -40,7 +40,6 @@
},
"devDependencies": {
"@cubejs-backend/linter": "^0.36.0",
"@types/snowflake-sdk": "^1.6.8",
"typescript": "~5.2.2"
}
}
12 changes: 8 additions & 4 deletions packages/cubejs-snowflake-driver/src/SnowflakeDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
getEnv,
assertDataSource,
} from '@cubejs-backend/shared';
import snowflake, { Column, Connection, Statement } from 'snowflake-sdk';
import snowflake, { Column, Connection, RowStatement } from 'snowflake-sdk';
import {
BaseDriver,
DownloadTableCSVData,
Expand All @@ -22,7 +22,6 @@ import {
DownloadQueryResultsResult,
DownloadQueryResultsOptions,
DriverCapabilities,
QueryTablesResult,
} from '@cubejs-backend/base-driver';
import { formatToTimeZone } from 'date-fns-timezone';
import { Storage } from '@google-cloud/storage';
Expand Down Expand Up @@ -228,6 +227,11 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
privateKey += '\n';
}

snowflake.configure({
// TODO: Remove after release of https://github.com/snowflakedb/snowflake-connector-nodejs/pull/912
logLevel: 'OFF' as any
});

this.config = {
readOnly: false,
account: getEnv('snowflakeAccount', { dataSource }),
Expand Down Expand Up @@ -700,7 +704,7 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
_options: StreamOptions,
): Promise<StreamTableDataWithTypes> {
const connection = await this.getConnection();
const stmt = await new Promise<Statement>((resolve, reject) => connection.execute({
const stmt = await new Promise<RowStatement>((resolve, reject) => connection.execute({
sqlText: query,
binds: <string[] | undefined>values,
fetchAsString: [
Expand Down Expand Up @@ -742,7 +746,7 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
};
}

private getTypes(stmt: Statement) {
private getTypes(stmt: RowStatement) {
return stmt.getColumns().map((column) => {
const type = {
name: column.getName().toLowerCase(),
Expand Down
5 changes: 4 additions & 1 deletion packages/cubejs-testing-drivers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@
"testMatch": [
"<rootDir>/dist/test/**/*.(test|spec).(ts|js)"
],
"snapshotResolver": "<rootDir>/test/snapshotResolver.js"
"snapshotResolver": "<rootDir>/test/snapshotResolver.js",
"moduleNameMapper": {
"^axios$": "axios/dist/node/axios.cjs"
}
},
"eslintConfig": {
"extends": "../cubejs-linter"
Expand Down
Loading

0 comments on commit 84bc8de

Please sign in to comment.