From 05491a44eecc5efff53b429206777f3f9b9b1b53 Mon Sep 17 00:00:00 2001 From: Michael Toy <66150587+mtoy-googly-moogly@users.noreply.github.com> Date: Wed, 27 Nov 2024 11:08:16 -0800 Subject: [PATCH] more cleanup --- .../src/snowflake_connection.ts | 6 ++-- .../malloy/src/dialect/snowflake/snowflake.ts | 2 -- .../src/databases/all/compound-atomic.spec.ts | 30 +++++++++---------- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/packages/malloy-db-snowflake/src/snowflake_connection.ts b/packages/malloy-db-snowflake/src/snowflake_connection.ts index d6cabd6b4..a412ace8c 100644 --- a/packages/malloy-db-snowflake/src/snowflake_connection.ts +++ b/packages/malloy-db-snowflake/src/snowflake_connection.ts @@ -133,9 +133,9 @@ class SnowObject extends SnowField { 'SNOWFLAKE SCHEMA PARSER ERROR: Walk through undefined' ); } else { - if (field) { - // mtoy todo Variant record value - } else { + // If we get multiple type for a field, ignore them, should + // which will do until we support viarant data + if (!field) { this.fieldMap.set( path.name, SnowField.make(path.name, fieldType, this.dialect) diff --git a/packages/malloy/src/dialect/snowflake/snowflake.ts b/packages/malloy/src/dialect/snowflake/snowflake.ts index 97296ad8b..980dd9438 100644 --- a/packages/malloy/src/dialect/snowflake/snowflake.ts +++ b/packages/malloy/src/dialect/snowflake/snowflake.ts @@ -200,10 +200,8 @@ export class SnowflakeDialect extends Dialect { isArray: boolean, _isInNestedPipeline: boolean ): string { - // mtoy todo would like to NOT do this const as = this.sqlMaybeQuoteIdentifier(alias); if (isArray) { - const as = this.sqlMaybeQuoteIdentifier(alias); return `,LATERAL FLATTEN(INPUT => ${source}) AS ${alias}_1, LATERAL (SELECT ${alias}_1.INDEX, object_construct('value', ${alias}_1.value) as value ) as ${as}`; } else { // have to have a non empty row or it treats it like an inner join :barf-emoji: diff --git a/test/src/databases/all/compound-atomic.spec.ts b/test/src/databases/all/compound-atomic.spec.ts index c2b46f076..f38d09096 100644 --- a/test/src/databases/all/compound-atomic.spec.ts +++ b/test/src/databases/all/compound-atomic.spec.ts @@ -35,18 +35,6 @@ describe.each(runtimes.runtimeList)( const literal = num.toString(); return {node: 'numberLiteral', literal, sql: literal}; } - // this is just a standin for "unknown function" - const arrayLen = { - 'duckdb': 'LEN', - 'duckdb_wasm': 'LEN', - 'motherduck': 'LEN', - 'bigquery': 'ARRAY_LENGTH', - 'postgres': 'ARRAY_LENGTH', - 'presto': 'CARDINALITY', - 'trino': 'CARDINALITY', - 'mysql': 'JSON_LENGTH', - 'snowflake': 'ARRAY_SIZE', - }; const empty = `${databaseName}.sql("SELECT 0 as z")`; function arraySelectVal(...val: Number[]): string { const literal: ArrayLiteralNode = { @@ -125,9 +113,21 @@ describe.each(runtimes.runtimeList)( evensObj.map(n => ({n})) ); }); - test('array can be passed to functions', async () => { - const fn = arrayLen[databaseName]; - expect(fn).toBeDefined(); + test('array can be passed to !function', async () => { + // Used as a standin for "unknown function user might call" + const nameOfArrayLenFunction = { + 'duckdb': 'LEN', + 'standardsql': 'ARRAY_LENGTH', + 'postgres': 'ARRAY_LENGTH', + 'presto': 'CARDINALITY', + 'trino': 'CARDINALITY', + 'mysql': 'JSON_LENGTH', + 'snowflake': 'ARRAY_SIZE', + }; + const dialect = runtime.dialect.name; + const missing = `Dialect '${dialect}' missing array length function in nameOfArrayLenFunction`; + const fn = nameOfArrayLenFunction[dialect] ?? missing; + expect(fn).not.toEqual(missing); await expect( `run: ${evens}->{ select: nby2 is ${fn}!number(evens); } ` ).malloyResultMatches(runtime, {nby2: evensObj.length});