Skip to content

Commit

Permalink
snowflake resource picker to show both snowflake + snowflake_oauth (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
alpetric authored Jan 3, 2025
1 parent 0ee7c9e commit c999788
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 8 deletions.
17 changes: 12 additions & 5 deletions frontend/src/lib/components/ResourcePicker.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/lib/components/TestConnection.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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'`,
Expand Down Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<IconSelectInput bind:value={componentInput.value} />
{:else if fieldType === 'tab-select'}
<TabSelectInput bind:componentInput />
{: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)}
<ResourcePicker
initialValue={componentInput.value?.split('$res:')?.[1] || ''}
on:change={(e) => {
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib/components/apps/inputType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export type InputType =
| 'mysql'
| 'ms_sql_server'
| 'snowflake'
| 'snowflake_oauth'
| 'bigquery'
| 'app-path'

Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit c999788

Please sign in to comment.