Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 5 additions & 2 deletions packages/cubejs-bigquery-driver/src/BigQueryDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,12 @@ export class BigQueryDriver extends BaseDriver implements DriverInterface {
}
}

/**
* Returns the configurable driver options
* Note: It returns the unprefixed option names.
* In case of using multisources options need to be prefixed manually.
*/
public static driverEnvVariables() {
// TODO (buntarb): check how this method can/must be used with split
// names by the data source.
return [
'CUBEJS_DB_BQ_PROJECT_ID',
'CUBEJS_DB_BQ_KEY_FILE',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ class ElasticSearchDriver extends BaseDriver {
}
}

/**
* Returns the configurable driver options
* Note: It returns the unprefixed option names.
* In case of using multisources options need to be prefixed manually.
*/
static driverEnvVariables() {
// TODO (buntarb): check how this method can/must be used with split
// names by the data source.
return [
'CUBEJS_DB_URL',
'CUBEJS_DB_ELASTIC_QUERY_FORMAT',
Expand Down
7 changes: 5 additions & 2 deletions packages/cubejs-ksql-driver/src/KsqlDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,12 @@ export class KsqlDriver extends BaseDriver implements DriverInterface {
return `\`${identifier}\``;
}

/**
* Returns the configurable driver options
* Note: It returns the unprefixed option names.
* In case of using multisources options need to be prefixed manually.
*/
public static driverEnvVariables() {
// TODO (buntarb): check how this method can/must be used with split
// names by the data source.
return [
'CUBEJS_DB_URL',
'CUBEJS_DB_USER',
Expand Down
20 changes: 14 additions & 6 deletions packages/cubejs-mssql-driver/driver/MSSqlDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,19 @@ class MSSqlDriver extends BaseDriver {
this.initialConnectPromise = this.connectionPool.connect();
}

/**
* Returns the configurable driver options
* Note: It returns the unprefixed option names.
* In case of using multisources options need to be prefixed manually.
*/
static driverEnvVariables() {
// TODO (buntarb): check how this method can/must be used with split
// names by the data source.
return [
'CUBEJS_DB_HOST', 'CUBEJS_DB_NAME', 'CUBEJS_DB_PORT', 'CUBEJS_DB_USER', 'CUBEJS_DB_PASS', 'CUBEJS_DB_DOMAIN'
'CUBEJS_DB_HOST',
'CUBEJS_DB_NAME',
'CUBEJS_DB_PORT',
'CUBEJS_DB_USER',
'CUBEJS_DB_PASS',
'CUBEJS_DB_DOMAIN',
];
}

Expand All @@ -97,8 +105,8 @@ class MSSqlDriver extends BaseDriver {
/**
* Executes query in streaming mode.
*
* @param {string} query
* @param {Array} values
* @param {string} query
* @param {Array} values
* @param {{ highWaterMark: number? }} options
* @return {Promise<StreamTableDataWithTypes>}
*/
Expand Down Expand Up @@ -151,7 +159,7 @@ class MSSqlDriver extends BaseDriver {
* scale: number?,
* precision: number?
* }
* }} fields
* }} fields
*/
mapFields(fields) {
return Object.keys(fields).map((field) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/cubejs-mysql-driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@cubejs-backend/base-driver": "1.2.24",
"@cubejs-backend/shared": "1.2.24",
"@types/mysql": "^2.15.21",
"generic-pool": "^3.6.0",
"generic-pool": "^3.8.2",
"mysql": "^2.18.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/cubejs-snowflake-driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@cubejs-backend/base-driver": "1.2.24",
"@cubejs-backend/shared": "1.2.24",
"date-fns-timezone": "^0.1.4",
"snowflake-sdk": "^1.13.1"
"snowflake-sdk": "^2.0.3"
},
"license": "Apache-2.0",
"publishConfig": {
Expand Down
77 changes: 32 additions & 45 deletions packages/cubejs-snowflake-driver/src/SnowflakeDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,28 @@
* @fileoverview The `SnowflakeDriver` and related types declaration.
*/

import {
getEnv,
assertDataSource,
} from '@cubejs-backend/shared';
import { assertDataSource, getEnv, } from '@cubejs-backend/shared';
import snowflake, { Column, Connection, RowStatement } from 'snowflake-sdk';
import {
BaseDriver,
DownloadQueryResultsOptions,
DownloadQueryResultsResult,
DownloadTableCSVData,
DownloadTableMemoryData,
DriverCapabilities,
DriverInterface,
GenericDataBaseType,
TableStructure,
UnloadOptions,
StreamOptions,
StreamTableDataWithTypes,
DownloadTableMemoryData,
DownloadQueryResultsResult,
DownloadQueryResultsOptions,
DriverCapabilities,
TableStructure,
UnloadOptions,
} from '@cubejs-backend/base-driver';
import { formatToTimeZone } from 'date-fns-timezone';
import fs from 'fs/promises';
import { HydrationMap, HydrationStream } from './HydrationStream';

// eslint-disable-next-line import/order
const util = require('snowflake-sdk/lib/util');

const SUPPORTED_BUCKET_TYPES = ['s3', 'gcs', 'azure'];

// TODO Remove when https://github.com/snowflakedb/snowflake-connector-nodejs/pull/158 is resolved
util.construct_hostname = (region: any, account: any) => {
let host;
if (region === 'us-west-2') {
region = null;
}
if (account.indexOf('.') > 0) {
account = account.substring(0, account.indexOf('.'));
}
if (region) {
host = `${account}.${region}.snowflakecomputing.com`;
} else {
host = `${account}.snowflakecomputing.com`;
}
return host;
};

type HydrationConfiguration = {
types: string[], toValue: (column: Column) => ((value: any) => any) | null
};
Expand Down Expand Up @@ -104,11 +81,21 @@ const hydrators: HydrationConfiguration[] = [
}
);
},
},
{
types: ['object'], // Workaround for HLL_SNOWFLAKE
toValue: () => (value) => {
if (!value) {
return null;
}

return JSON.stringify(value);
},
}
];

const SnowflakeToGenericType: Record<string, GenericDataBaseType> = {
// It's a limitation for now, because anyway we dont work with JSON objects in Cube Store.
// It's a limitation for now, because anyway we don't work with JSON objects in Cube Store.
object: 'HLL_SNOWFLAKE',
number: 'decimal',
timestamp_ntz: 'timestamp'
Expand Down Expand Up @@ -198,9 +185,12 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
return 8;
}

/**
* Returns the configurable driver options
* Note: It returns the unprefixed option names.
* In case of using multisources options need to be prefixed manually.
*/
public static driverEnvVariables() {
// TODO (buntarb): check how this method can/must be used with split
// names by the data source.
return [
'CUBEJS_DB_NAME',
'CUBEJS_DB_USER',
Expand All @@ -211,9 +201,11 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
'CUBEJS_DB_SNOWFLAKE_ROLE',
'CUBEJS_DB_SNOWFLAKE_CLIENT_SESSION_KEEP_ALIVE',
'CUBEJS_DB_SNOWFLAKE_AUTHENTICATOR',
'CUBEJS_DB_SNOWFLAKE_OAUTH_TOKEN_PATH',
'CUBEJS_DB_SNOWFLAKE_HOST',
'CUBEJS_DB_SNOWFLAKE_PRIVATE_KEY',
'CUBEJS_DB_SNOWFLAKE_PRIVATE_KEY_PATH',
'CUBEJS_DB_SNOWFLAKE_PRIVATE_KEY_PASS',
'CUBEJS_DB_SNOWFLAKE_OAUTH_TOKEN_PATH',
'CUBEJS_DB_SNOWFLAKE_QUOTED_IDENTIFIERS_IGNORE_CASE',
];
}
Expand Down Expand Up @@ -257,10 +249,7 @@ 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
});
snowflake.configure({ logLevel: 'OFF' });

this.config = {
readOnly: false,
Expand Down Expand Up @@ -416,9 +405,7 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
this.config.token = await this.readOAuthToken();
}

const connection = snowflake.createConnection(this.config);

return connection;
return snowflake.createConnection(this.config);
}

/**
Expand Down Expand Up @@ -475,8 +462,8 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
}
}

// eslint-disable-next-line no-return-assign
return this.connection = this.initConnection();
this.connection = this.initConnection();
return this.connection;
}

/**
Expand Down Expand Up @@ -758,7 +745,7 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
const hydrationMap = this.generateHydrationMap(stmt.getColumns());
const types: {name: string, type: string}[] =
this.getTypes(stmt);
if (rows && rows.length && Object.keys(hydrationMap).length) {
if (rows?.length && Object.keys(hydrationMap).length) {
for (const row of rows) {
for (const [field, toValue] of Object.entries(hydrationMap)) {
if (row.hasOwnProperty(field)) {
Expand Down Expand Up @@ -922,6 +909,6 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {

public async getTablesQuery(schemaName: string) {
const tables = await super.getTablesQuery(schemaName.toUpperCase());
return tables.map(t => ({ table_name: t.TABLE_NAME && t.TABLE_NAME.toLowerCase() }));
return tables.map(t => ({ table_name: t.TABLE_NAME?.toLowerCase() }));
}
}
Loading
Loading