Skip to content
Closed
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
6 changes: 6 additions & 0 deletions docs/pages/product/configuration/data-sources/snowflake.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ redirect_from:
- [The region][snowflake-docs-regions] for the [Snowflake][snowflake] warehouse
- The username/password for the [Snowflake][snowflake] account

## Snowflake quoted identifiers

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

## Setup

<WarningBox>
Expand Down
33 changes: 33 additions & 0 deletions packages/cubejs-backend-shared/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,39 @@ const variables: Record<string, (...args: any) => any> = {
]
),

/**
* Snowflake case sensitivity for identifiers (like database columns).
*/
snowflakeQuotedIdentIgnoreCase: ({
dataSource
}: {
dataSource: string,
}) => {
const val = process.env[
keyByDataSource(
'CUBEJS_DB_SNOWFLAKE_QUOTED_IDENTIFIERS_IGNORE_CASE',
dataSource,
)
];
if (val) {
if (val.toLocaleLowerCase() === 'true') {
return true;
} else if (val.toLowerCase() === 'false') {
return false;
} else {
throw new TypeError(
`The ${
keyByDataSource(
'CUBEJS_DB_SNOWFLAKE_QUOTED_IDENTIFIERS_IGNORE_CASE',
dataSource,
)
} must be either 'true' or 'false'.`
);
}
} else {
return true;
}
},
/** ****************************************************************
* Presto Driver *
***************************************************************** */
Expand Down
10 changes: 9 additions & 1 deletion packages/cubejs-snowflake-driver/src/SnowflakeDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
resultPrefetch?: number,
exportBucket?: SnowflakeDriverExportBucket,
executionTimeout?: number,
caseSensitiveIdentifiers?: boolean,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
caseSensitiveIdentifiers?: boolean,
identIgnoreCase?: boolean,

application: string,
readOnly?: boolean,

Expand Down Expand Up @@ -213,6 +214,7 @@
'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 @@ -279,6 +281,7 @@
exportBucket: this.getExportBucket(dataSource),
resultPrefetch: 1,
executionTimeout: getEnv('dbQueryTimeout', { dataSource }),
ignoreCase: getEnv('snowflakeQuotedIdentIgnoreCase', { dataSource }),

Check failure on line 284 in packages/cubejs-snowflake-driver/src/SnowflakeDriver.ts

View workflow job for this annotation

GitHub Actions / unit (20.x, 3.11)

Type '{ host: any; account: any; username: any; password: any; region: any; warehouse: any; role: any; clientSessionKeepAlive: any; database: any; authenticator: any; oauthTokenPath: any; token?: string | undefined; ... 13 more ...; ignoreCase: any; }' is not assignable to type 'SnowflakeDriverOptions'.

Check failure on line 284 in packages/cubejs-snowflake-driver/src/SnowflakeDriver.ts

View workflow job for this annotation

GitHub Actions / unit (22.x, 3.11)

Type '{ host: any; account: any; username: any; password: any; region: any; warehouse: any; role: any; clientSessionKeepAlive: any; database: any; authenticator: any; oauthTokenPath: any; token?: string | undefined; ... 13 more ...; ignoreCase: any; }' is not assignable to type 'SnowflakeDriverOptions'.

Check failure on line 284 in packages/cubejs-snowflake-driver/src/SnowflakeDriver.ts

View workflow job for this annotation

GitHub Actions / integration-cubestore (20.x)

Type '{ host: any; account: any; username: any; password: any; region: any; warehouse: any; role: any; clientSessionKeepAlive: any; database: any; authenticator: any; oauthTokenPath: any; token?: string | undefined; ... 13 more ...; ignoreCase: any; }' is not assignable to type 'SnowflakeDriverOptions'.

Check failure on line 284 in packages/cubejs-snowflake-driver/src/SnowflakeDriver.ts

View workflow job for this annotation

GitHub Actions / integration-smoke (20.x, 3.11)

Type '{ host: any; account: any; username: any; password: any; region: any; warehouse: any; role: any; clientSessionKeepAlive: any; database: any; authenticator: any; oauthTokenPath: any; token?: string | undefined; ... 13 more ...; ignoreCase: any; }' is not assignable to type 'SnowflakeDriverOptions'.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here you set ignoreCase, while SnowflakeDriverOptions type has caseSensitiveIdentifiers?: boolean

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ignoreCase: getEnv('snowflakeQuotedIdentIgnoreCase', { dataSource }),
identIgnoreCase: getEnv('snowflakeQuotedIdentIgnoreCase', { dataSource }),

exportBucketCsvEscapeSymbol: getEnv('dbExportBucketCsvEscapeSymbol', { dataSource }),
application: 'CubeDev_Cube',
...config
Expand Down Expand Up @@ -450,7 +453,12 @@

await this.execute(connection, 'ALTER SESSION SET TIMEZONE = \'UTC\'', [], false);
await this.execute(connection, `ALTER SESSION SET STATEMENT_TIMEOUT_IN_SECONDS = ${this.config.executionTimeout}`, [], false);


// We only want to ignore the case if someone sets the value to false explicitly since the default assumption
// is that casing matters
if (!this.ignoreCase) {

Check failure on line 459 in packages/cubejs-snowflake-driver/src/SnowflakeDriver.ts

View workflow job for this annotation

GitHub Actions / unit (20.x, 3.11)

Property 'ignoreCase' does not exist on type 'SnowflakeDriver'.

Check failure on line 459 in packages/cubejs-snowflake-driver/src/SnowflakeDriver.ts

View workflow job for this annotation

GitHub Actions / unit (22.x, 3.11)

Property 'ignoreCase' does not exist on type 'SnowflakeDriver'.

Check failure on line 459 in packages/cubejs-snowflake-driver/src/SnowflakeDriver.ts

View workflow job for this annotation

GitHub Actions / integration-cubestore (20.x)

Property 'ignoreCase' does not exist on type 'SnowflakeDriver'.

Check failure on line 459 in packages/cubejs-snowflake-driver/src/SnowflakeDriver.ts

View workflow job for this annotation

GitHub Actions / integration-smoke (20.x, 3.11)

Property 'ignoreCase' does not exist on type 'SnowflakeDriver'.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!this.ignoreCase) {
if (!this.identIgnoreCase) {

await this.execute(connection, 'ALTER SESSION SET QUOTED_IDENTIFIERS_IGNORE_CASE = FALSE', [], false);
}
return connection;
} catch (e) {
this.connection = null;
Expand Down
Loading