Skip to content

Commit

Permalink
records can be selected
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoy-googly-moogly committed Nov 7, 2024
1 parent 2f23f1d commit e3793a2
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 42 deletions.
9 changes: 5 additions & 4 deletions packages/malloy/src/model/malloy_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
);
}
}
Expand Down Expand Up @@ -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();
Expand Down
38 changes: 0 additions & 38 deletions test/src/databases/all/arrays.spec.ts

This file was deleted.

57 changes: 57 additions & 0 deletions test/src/databases/all/composite-atomic.spec.ts
Original file line number Diff line number Diff line change
@@ -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,
});
});
});
}
);

0 comments on commit e3793a2

Please sign in to comment.