Skip to content

Commit d906e0e

Browse files
committed
Merge branch 'fix-case-statement' of github.com:artemishealth/cube into artemishealth-fix-case-statement
2 parents 5fb81cc + 29bc2fc commit d906e0e

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
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
@@ -1491,6 +1491,39 @@ const variables: Record<string, (...args: any) => any> = {
14911491
]
14921492
),
14931493

1494+
/**
1495+
* Snowflake case sensitivity for identifiers (like database columns).
1496+
*/
1497+
snowflakeQuotedIdentIgnoreCase: ({
1498+
dataSource
1499+
}: {
1500+
dataSource: string,
1501+
}) => {
1502+
const val = process.env[
1503+
keyByDataSource(
1504+
'CUBEJS_DB_SNOWFLAKE_QUOTED_IDENTIFIERS_IGNORE_CASE',
1505+
dataSource,
1506+
)
1507+
];
1508+
if (val) {
1509+
if (val.toLocaleLowerCase() === 'true') {
1510+
return true;
1511+
} else if (val.toLowerCase() === 'false') {
1512+
return false;
1513+
} else {
1514+
throw new TypeError(
1515+
`The ${
1516+
keyByDataSource(
1517+
'CUBEJS_DB_SNOWFLAKE_QUOTED_IDENTIFIERS_IGNORE_CASE',
1518+
dataSource,
1519+
)
1520+
} must be either 'true' or 'false'.`
1521+
);
1522+
}
1523+
} else {
1524+
return true;
1525+
}
1526+
},
14941527
/** ****************************************************************
14951528
* Presto Driver *
14961529
***************************************************************** */

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

Lines changed: 9 additions & 1 deletion
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_IDENTIFIERS_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,7 +453,12 @@ 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-
456+
457+
// We only want to ignore the case if someone sets the value to false explicitly since the default assumption
458+
// is that casing matters
459+
if (!this.ignoreCase) {
460+
await this.execute(connection, 'ALTER SESSION SET QUOTED_IDENTIFIERS_IGNORE_CASE = FALSE', [], false);
461+
}
454462
return connection;
455463
} catch (e) {
456464
this.connection = null;

0 commit comments

Comments
 (0)