Skip to content

Commit

Permalink
add a test for reading nested array schema
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoy-googly-moogly committed Dec 11, 2024
1 parent 39ec720 commit 7d480f8
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/src/databases/all/compound-atomic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ArrayTypeDef,
FieldDef,
Expr,
SQLSourceDef,
} from '@malloydata/malloy';

const runtimes = new RuntimeList(databasesFromEnvironmentOr(allDatabases));
Expand Down Expand Up @@ -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]] }
Expand Down

0 comments on commit 7d480f8

Please sign in to comment.