Skip to content

Commit 2b38bea

Browse files
committed
dev
1 parent a714bd8 commit 2b38bea

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

packages/cubejs-backend-shared/src/env.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,6 +1625,26 @@ const variables: Record<string, (...args: any) => any> = {
16251625
return false;
16261626
}
16271627
},
1628+
1629+
snowflakeExecutionProcedure: ({
1630+
dataSource
1631+
}: {
1632+
dataSource: string,
1633+
}) => (
1634+
process.env[
1635+
keyByDataSource('CUBEJS_DB_SNOWFLAKE_EXECUTION_PROCEDURE', dataSource)
1636+
]
1637+
),
1638+
1639+
snowflakeInformationSchemaProcedure: ({
1640+
dataSource
1641+
}: {
1642+
dataSource: string,
1643+
}) => (
1644+
process.env[
1645+
keyByDataSource('CUBEJS_DB_SNOWFLAKE_INFORMATION_SCHEMA_PROCEDURE', dataSource)
1646+
]
1647+
),
16281648
/** ****************************************************************
16291649
* Presto Driver *
16301650
***************************************************************** */

packages/cubejs-snowflake-driver/src/SnowflakeDriver.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ interface SnowflakeDriverOptions {
163163
executionTimeout?: number,
164164
identIgnoreCase?: boolean,
165165
application: string,
166+
snowflakeExecutionProcedure?: string,
167+
snowflakeInformationSchemaProcedure?: string,
166168
readOnly?: boolean,
167169

168170
/**
@@ -208,6 +210,8 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
208210
'CUBEJS_DB_SNOWFLAKE_PRIVATE_KEY_PATH',
209211
'CUBEJS_DB_SNOWFLAKE_PRIVATE_KEY_PASS',
210212
'CUBEJS_DB_SNOWFLAKE_QUOTED_IDENTIFIERS_IGNORE_CASE',
213+
'CUBEJS_DB_SNOWFLAKE_EXECUTION_PROCEDURE',
214+
'CUBEJS_DB_SNOWFLAKE_INFORMATION_SCHEMA_PROCEDURE',
211215
];
212216
}
213217

@@ -296,6 +300,8 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
296300
identIgnoreCase: getEnv('snowflakeQuotedIdentIgnoreCase', { dataSource }),
297301
exportBucketCsvEscapeSymbol: getEnv('dbExportBucketCsvEscapeSymbol', { dataSource }),
298302
application: 'CubeDev_Cube',
303+
snowflakeExecutionProcedure: getEnv('snowflakeExecutionProcedure', { dataSource }),
304+
snowflakeInformationSchemaProcedure: getEnv('snowflakeInformationSchemaProcedure', { dataSource }),
299305
...config
300306
};
301307
}
@@ -879,6 +885,24 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
879885
values?: unknown[],
880886
rehydrate: boolean = true
881887
): Promise<R> {
888+
if (
889+
this.config.snowflakeExecutionProcedure &&
890+
query.toUpperCase().startsWith('SELECT')
891+
) {
892+
const escapedQuery = query.replace(/'/g, "\\'");
893+
const serializedBinds = `ARRAY_CONSTRUCT(${(values ?? [])
894+
.map((v) =>
895+
typeof v === 'string'
896+
? `'${String(v).replace(/'/g, "''")}'`
897+
: v === null || v === undefined
898+
? "NULL"
899+
: v
900+
)
901+
.join(", ")})`;
902+
903+
query = `CALL ${this.config.snowflakeExecutionProcedure}('${escapedQuery}', ${serializedBinds})`;
904+
}
905+
882906
return new Promise((resolve, reject) => connection.execute({
883907
sqlText: query,
884908
binds: <string[] | undefined>values,
@@ -908,6 +932,15 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
908932
}
909933

910934
public informationSchemaQuery() {
935+
if (this.config.snowflakeInformationSchemaProcedure) {
936+
return `
937+
SELECT COLUMN_NAME as "column_name",
938+
TABLE_NAME as "table_name",
939+
TABLE_SCHEMA as "table_schema",
940+
DATA_TYPE as "data_type"
941+
FROM TABLE(${this.config.snowflakeInformationSchemaProcedure}())`;
942+
}
943+
911944
return `
912945
SELECT COLUMNS.COLUMN_NAME as "column_name",
913946
COLUMNS.TABLE_NAME as "table_name",

0 commit comments

Comments
 (0)