From 7d480f837c7b0016287b2484429fb328499937d9 Mon Sep 17 00:00:00 2001 From: Michael Toy <66150587+mtoy-googly-moogly@users.noreply.github.com> Date: Wed, 11 Dec 2024 08:03:00 -1000 Subject: [PATCH] add a test for reading nested array schema --- .../src/databases/all/compound-atomic.spec.ts | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/src/databases/all/compound-atomic.spec.ts b/test/src/databases/all/compound-atomic.spec.ts index 6fd6123e3..7e6aa6520 100644 --- a/test/src/databases/all/compound-atomic.spec.ts +++ b/test/src/databases/all/compound-atomic.spec.ts @@ -14,6 +14,7 @@ import { ArrayTypeDef, FieldDef, Expr, + SQLSourceDef, } from '@malloydata/malloy'; const runtimes = new RuntimeList(databasesFromEnvironmentOr(allDatabases)); @@ -198,6 +199,44 @@ describe.each(runtimes.runtimeList)( } } ); + test.when(supportsNestedArrays && canReadCompoundSchema)( + 'Can read schema for array of arrays', + async () => { + // a lot of work to make [[1],[2]] on all dialects + const aLit: ArrayLiteralNode = { + node: 'arrayLiteral', + typeDef: {type: 'array', elementTypeDef: {type: 'number'}}, + kids: {values: []}, + }; + const aOne = {...aLit}; + aOne.kids.values[0] = {node: 'numberLiteral', literal: '1', sql: '1'}; + aOne.sql = runtime.dialect.sqlLiteralArray(aOne); + const aTwo = {...aLit, sql: '2'}; + aTwo.kids.values[0] = {node: 'numberLiteral', literal: '2', sql: '2'}; + aTwo.sql = runtime.dialect.sqlLiteralArray(aTwo); + const aoa: ArrayLiteralNode = { + node: 'arrayLiteral', + typeDef: {type: 'array', elementTypeDef: aLit.typeDef}, + kids: {values: [aOne, aTwo]}, + }; + const sql_aoa = runtime.dialect.sqlLiteralArray(aoa); + const asStruct: SQLSourceDef = { + name: 'select_with_aoa', + type: 'sql_select', + connection: conName, + dialect: runtime.dialect.name, + selectStr: `SELECT ${sql_aoa} AS aoa`, + fields: [], + }; + const ret = await runtime.connection.fetchSchemaForSQLStruct( + asStruct, + {} + ); + expect(ret.structDef).toBeDefined(); + const aoa_ent = ret.structDef!.fields[0]; + expect(aoa_ent).toMatchObject(aoa.typeDef); + } + ); test.when(supportsNestedArrays)('bare array of array', async () => { await expect(` run: ${empty} -> { select: aoa is [[1,2]] }