From e3793a27b8702b0923fc7a4e54d8adec1381f619 Mon Sep 17 00:00:00 2001 From: Michael Toy <66150587+mtoy-googly-moogly@users.noreply.github.com> Date: Thu, 7 Nov 2024 12:40:38 -0800 Subject: [PATCH] records can be selected --- packages/malloy/src/model/malloy_query.ts | 9 +-- test/src/databases/all/arrays.spec.ts | 38 ------------- .../databases/all/composite-atomic.spec.ts | 57 +++++++++++++++++++ 3 files changed, 62 insertions(+), 42 deletions(-) delete mode 100644 test/src/databases/all/arrays.spec.ts create mode 100644 test/src/databases/all/composite-atomic.spec.ts diff --git a/packages/malloy/src/model/malloy_query.ts b/packages/malloy/src/model/malloy_query.ts index f066de385..53e4463bb 100644 --- a/packages/malloy/src/model/malloy_query.ts +++ b/packages/malloy/src/model/malloy_query.ts @@ -3060,7 +3060,7 @@ class QueryQuery extends QueryField { const sqlName = this.parent.dialect.sqlMaybeQuoteIdentifier(name); if (fi.fieldUsage.type === 'result') { fields.push( - ` ${fi.f.generateExpression(this.rootResult)} as ${sqlName}` + ` ${fi.f.generateExpression(this.rootResult)} aS ${sqlName}` ); } } @@ -4181,9 +4181,10 @@ class QueryFieldStruct extends QueryField { * but maybe it isn't, it doesn't fix the problem I am working on ... */ - getIdentifier() { - return this.queryStruct.getIdentifier(); - } + // mtoy todo review with lloyd if any of these are needed + // getIdentifier() { + // return this.queryStruct.getIdentifier(); + // } getJoinableParent() { return this.queryStruct.getJoinableParent(); diff --git a/test/src/databases/all/arrays.spec.ts b/test/src/databases/all/arrays.spec.ts deleted file mode 100644 index f56cc9ea4..000000000 --- a/test/src/databases/all/arrays.spec.ts +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -import {RuntimeList, allDatabases} from '../../runtimes'; -import {databasesFromEnvironmentOr} from '../../util'; -import '../../util/db-jest-matchers'; - -const runtimes = new RuntimeList(databasesFromEnvironmentOr(allDatabases)); - -describe.each(runtimes.runtimeList)('arrays %s', (databaseName, runtime) => { - const evens = 'duckdb.sql("SELECT [2,4] as evens")'; - test('array literal', async () => { - await expect(` - # test.debug - run: duckdb.sql("SELECT 1 AS row") -> { select: odds is [1,3] } - `).malloyResultMatches(runtime, {odds: [1, 3]}); - }); - test('array-un-nest', async () => { - await expect(` - run: ${evens}->{ select: n is evens.each } - `).malloyResultMatches(runtime, [{n: 2}, {n: 4}]); - }); - test('array columns can be passed to functions', async () => { - await expect( - `run: ${evens}->{ select: two is len!number(evens); } ` - ).malloyResultMatches(runtime, {two: 2}); - }); - test('array columns can be selected', async () => { - await expect(`run: ${evens}->{ select: evens }`).malloyResultMatches( - runtime, - {evens: [2, 4]} - ); - }); -}); diff --git a/test/src/databases/all/composite-atomic.spec.ts b/test/src/databases/all/composite-atomic.spec.ts new file mode 100644 index 000000000..dfcfa9072 --- /dev/null +++ b/test/src/databases/all/composite-atomic.spec.ts @@ -0,0 +1,57 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import {RuntimeList, allDatabases} from '../../runtimes'; +import {databasesFromEnvironmentOr} from '../../util'; +import '../../util/db-jest-matchers'; + +const runtimes = new RuntimeList(databasesFromEnvironmentOr(allDatabases)); + +describe.each(runtimes.runtimeList)( + 'composite fields %s', + (databaseName, runtime) => { + describe('simple arrays', () => { + const evens = 'duckdb.sql("SELECT [2,4] as evens")'; + test('array literal', async () => { + await expect(` + # test.debug + run: duckdb.sql("SELECT 1 AS row") -> { select: odds is [1,3] } + `).malloyResultMatches(runtime, {odds: [1, 3]}); + }); + test('array-un-nest', async () => { + await expect(` + run: ${evens}->{ select: n is evens.each } + `).malloyResultMatches(runtime, [{n: 2}, {n: 4}]); + }); + test('array columns can be passed to functions', async () => { + await expect( + `run: ${evens}->{ select: two is len!number(evens); } ` + ).malloyResultMatches(runtime, {two: 2}); + }); + test('array columns can be selected', async () => { + await expect(`run: ${evens}->{ select: evens }`).malloyResultMatches( + runtime, + {evens: [2, 4]} + ); + }); + }); + describe('record', () => { + const record = 'duckdb.sql("SELECT {s: 0, m: 1, l:2, xl: 3} as record")'; + test('record can be selected', async () => { + await expect( + ` + run: ${record} -> { select: record }` + ).malloyResultMatches(runtime, { + 'record/s': 0, + 'record/m': 1, + 'record/l': 2, + 'record/xl': 3, + }); + }); + }); + } +);