Skip to content

Commit 2c5054b

Browse files
Fixes case sensitivity for snowflake to be default and env driven
Adds env var for the snowflake driver to enable or disable the case sensitivity and if not set will default to case insensitive
1 parent c0d6ccc commit 2c5054b

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

docs/pages/product/configuration/data-sources/snowflake.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ redirect_from:
1212
- [The region][snowflake-docs-regions] for the [Snowflake][snowflake] warehouse
1313
- The username/password for the [Snowflake][snowflake] account
1414

15+
## Snowflake quoted identifiers
16+
17+
Due to an issue in snowflakes opinion about quoted identifers we set a session value to override
18+
snowflake defaults for users that have set an account value for: QUOTED_IDENTIFIERS_IGNORE_CASE
19+
you can learn more about this here: https://docs.snowflake.com/en/sql-reference/identifiers-syntax#double-quoted-identifiers
20+
1521
## Setup
1622

1723
<WarningBox>

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,6 +1478,39 @@ const variables: Record<string, (...args: any) => any> = {
14781478
]
14791479
),
14801480

1481+
/**
1482+
* Snowflake case sensitivity for identifiers (like database columns).
1483+
*/
1484+
snowflakeQuotedIdentIgnoreCase: ({
1485+
dataSource
1486+
}: {
1487+
dataSource: string,
1488+
}) => {
1489+
const val = process.env[
1490+
keyByDataSource(
1491+
'CUBEJS_DB_SNOWFLAKE_QUOTED_IDENTIFIERS_IGNORE_CASE',
1492+
dataSource,
1493+
)
1494+
];
1495+
if (val) {
1496+
if (val.toLocaleLowerCase() === 'true') {
1497+
return true;
1498+
} else if (val.toLowerCase() === 'false') {
1499+
return false;
1500+
} else {
1501+
throw new TypeError(
1502+
`The ${
1503+
keyByDataSource(
1504+
'CUBEJS_DB_SNOWFLAKE_QUOTED_IDENTIFIERS_IGNORE_CASE',
1505+
dataSource,
1506+
)
1507+
} must be either 'true' or 'false'.`
1508+
);
1509+
}
1510+
} else {
1511+
return true;
1512+
}
1513+
},
14811514
/** ****************************************************************
14821515
* Presto Driver *
14831516
***************************************************************** */

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ interface SnowflakeDriverOptions {
173173
resultPrefetch?: number,
174174
exportBucket?: SnowflakeDriverExportBucket,
175175
executionTimeout?: number,
176+
caseSensitiveIdentifiers?: boolean,
176177
application: string,
177178
readOnly?: boolean,
178179

@@ -213,6 +214,7 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
213214
'CUBEJS_DB_SNOWFLAKE_PRIVATE_KEY_PATH',
214215
'CUBEJS_DB_SNOWFLAKE_PRIVATE_KEY_PASS',
215216
'CUBEJS_DB_SNOWFLAKE_OAUTH_TOKEN_PATH',
217+
'CUBEJS_DB_SNOWFLAKE_QUOTED_IDENTIFIRS_IGNORE_CASE',
216218
];
217219
}
218220

@@ -279,6 +281,7 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
279281
exportBucket: this.getExportBucket(dataSource),
280282
resultPrefetch: 1,
281283
executionTimeout: getEnv('dbQueryTimeout', { dataSource }),
284+
ignoreCase: getEnv('snowflakeQuotedIdentIgnoreCase', { dataSource }),
282285
exportBucketCsvEscapeSymbol: getEnv('dbExportBucketCsvEscapeSymbol', { dataSource }),
283286
application: 'CubeDev_Cube',
284287
...config
@@ -450,8 +453,9 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
450453

451454
await this.execute(connection, 'ALTER SESSION SET TIMEZONE = \'UTC\'', [], false);
452455
await this.execute(connection, `ALTER SESSION SET STATEMENT_TIMEOUT_IN_SECONDS = ${this.config.executionTimeout}`, [], false);
453-
await this.execute(connection, 'ALTER SESSION SET QUOTED_IDENTIFIRS_IGNORE_CASE = FALSE', [], false);
454-
456+
if (this.ignoreCase) {
457+
await this.execute(connection, 'ALTER SESSION SET QUOTED_IDENTIFIERS_IGNORE_CASE = FALSE', [], false);
458+
}
455459
return connection;
456460
} catch (e) {
457461
this.connection = null;

0 commit comments

Comments
 (0)