From ec2f8956b4ecb7a9078b37c637386ca65242b2ee Mon Sep 17 00:00:00 2001 From: Alexander Petric Date: Thu, 2 Jan 2025 14:48:51 -0500 Subject: [PATCH] snowflake resource picker to show both snowflake + snowflake_oauth --- .../src/lib/components/ResourcePicker.svelte | 17 ++++++++---- .../src/lib/components/TestConnection.svelte | 5 ++++ .../apps/components/display/dbtable/utils.ts | 27 ++++++++++++++++++- .../apps/editor/component/components.ts | 3 ++- .../inputEditor/StaticInputEditor.svelte | 2 +- frontend/src/lib/components/apps/inputType.ts | 2 ++ 6 files changed, 48 insertions(+), 8 deletions(-) diff --git a/frontend/src/lib/components/ResourcePicker.svelte b/frontend/src/lib/components/ResourcePicker.svelte index 4942ec3014271..41e81c4127d71 100644 --- a/frontend/src/lib/components/ResourcePicker.svelte +++ b/frontend/src/lib/components/ResourcePicker.svelte @@ -47,12 +47,19 @@ async function loadResources(resourceType: string | undefined) { loading = true try { - const nc = ( - await ResourceService.listResource({ - workspace: $workspaceStore!, - resourceType - }) + const resourceTypesToQuery = + resourceType === 'snowflake' ? ['snowflake', 'snowflake_oauth'] : [resourceType] + + const resources = await Promise.all( + resourceTypesToQuery.map((rt) => + ResourceService.listResource({ + workspace: $workspaceStore!, + resourceType: rt + }) + ) ) + const nc = resources + .flat() .filter((x) => x.resource_type != 'state' && x.resource_type != 'cache') .map((x) => ({ value: x.path, diff --git a/frontend/src/lib/components/TestConnection.svelte b/frontend/src/lib/components/TestConnection.svelte index 99e9717ad151f..3569fc070f6ee 100644 --- a/frontend/src/lib/components/TestConnection.svelte +++ b/frontend/src/lib/components/TestConnection.svelte @@ -40,6 +40,11 @@ lang: 'snowflake', argName: 'database' }, + snowflake_oauth: { + code: `select 1`, + lang: 'snowflake', + argName: 'database' + }, ms_sql_server: { code: `SELECT 1`, lang: 'mssql', diff --git a/frontend/src/lib/components/apps/components/display/dbtable/utils.ts b/frontend/src/lib/components/apps/components/display/dbtable/utils.ts index 53a3ce9001896..2eca9ffd5c7af 100644 --- a/frontend/src/lib/components/apps/components/display/dbtable/utils.ts +++ b/frontend/src/lib/components/apps/components/display/dbtable/utils.ts @@ -137,7 +137,7 @@ ORDER BY ORDINAL_POSITION; ` - } else if (resourceType === 'snowflake') { + } else if (resourceType === 'snowflake' || resourceType === 'snowflake_oauth') { code = ` select COLUMN_NAME as field, DATA_TYPE as DataType, @@ -380,6 +380,30 @@ return schema }, argName: 'database' }, + snowflake_oauth: { + code: `select TABLE_SCHEMA, TABLE_NAME, DATA_TYPE, COLUMN_NAME, COLUMN_DEFAULT, IS_NULLABLE from information_schema.columns where table_schema != 'INFORMATION_SCHEMA'`, + lang: 'snowflake', + processingFn: (rows) => { + const schema = {} + for (const row of rows) { + if (!(row.TABLE_SCHEMA in schema)) { + schema[row.TABLE_SCHEMA] = {} + } + if (!(row.TABLE_NAME in schema[row.TABLE_SCHEMA])) { + schema[row.TABLE_SCHEMA][row.TABLE_NAME] = {} + } + schema[row.TABLE_SCHEMA][row.TABLE_NAME][row.COLUMN_NAME] = { + type: row.DATA_TYPE, + required: row.IS_NULLABLE === 'YES' + } + if (row.COLUMN_DEFAULT !== null) { + schema[row.TABLE_SCHEMA][row.TABLE_NAME][row.COLUMN_NAME]['default'] = row.COLUMN_DEFAULT + } + } + return schema + }, + argName: 'database' + }, ms_sql_server: { argName: 'database', code: `select TABLE_SCHEMA, TABLE_NAME, DATA_TYPE, COLUMN_NAME, COLUMN_DEFAULT from information_schema.columns where table_schema != 'sys'`, @@ -560,6 +584,7 @@ export function getLanguageByResourceType(name: string): Preview['language'] { mysql: 'mysql', ms_sql_server: 'mssql', snowflake: 'snowflake', + snowflake_oauth: 'snowflake', bigquery: 'bigquery' } return language[name] diff --git a/frontend/src/lib/components/apps/editor/component/components.ts b/frontend/src/lib/components/apps/editor/component/components.ts index bc45095c05ba4..df833f15284d3 100644 --- a/frontend/src/lib/components/apps/editor/component/components.ts +++ b/frontend/src/lib/components/apps/editor/component/components.ts @@ -3713,7 +3713,8 @@ See date-fns format for more information. By default, it is 'dd.MM.yyyy HH:mm' mysql: 'MySQL', ms_sql_server: 'MS SQL Server', snowflake: 'Snowflake', - bigquery: 'BigQuery' + bigquery: 'BigQuery', + snowflake_oauth: 'Snowflake OAuth' }, configuration: { postgresql: { diff --git a/frontend/src/lib/components/apps/editor/settingsPanel/inputEditor/StaticInputEditor.svelte b/frontend/src/lib/components/apps/editor/settingsPanel/inputEditor/StaticInputEditor.svelte index d234f5880beac..3137b6d229701 100644 --- a/frontend/src/lib/components/apps/editor/settingsPanel/inputEditor/StaticInputEditor.svelte +++ b/frontend/src/lib/components/apps/editor/settingsPanel/inputEditor/StaticInputEditor.svelte @@ -73,7 +73,7 @@ {:else if fieldType === 'tab-select'} - {:else if fieldType === 'resource' && subFieldType && ['mysql', 'postgres', 'ms_sql_server', 'snowflake', 'bigquery'].includes(subFieldType)} + {:else if fieldType === 'resource' && subFieldType && ['mysql', 'postgres', 'ms_sql_server', 'snowflake', 'snowflake_oauth', 'bigquery'].includes(subFieldType)} { diff --git a/frontend/src/lib/components/apps/inputType.ts b/frontend/src/lib/components/apps/inputType.ts index a62f9e6f59a3d..e31a33c78f28a 100644 --- a/frontend/src/lib/components/apps/inputType.ts +++ b/frontend/src/lib/components/apps/inputType.ts @@ -38,6 +38,7 @@ export type InputType = | 'mysql' | 'ms_sql_server' | 'snowflake' + | 'snowflake_oauth' | 'bigquery' | 'app-path' @@ -224,6 +225,7 @@ export type AppInput = | AppInputSpec<'resource', string, 'mysql'> | AppInputSpec<'resource', string, 'ms_sql_server'> | AppInputSpec<'resource', string, 'snowflake'> + | AppInputSpec<'resource', string, 'snowflake_oauth'> | AppInputSpec<'resource', string, 'bigquery'> | AppInputSpec<'array', object[], 'number-tuple'> | AppInputSpec<'app-path', string>