Skip to content

Commit

Permalink
fix join problem with arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoy-googly-moogly committed Nov 6, 2024
1 parent fcb9cb3 commit 2f23f1d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
14 changes: 8 additions & 6 deletions packages/malloy/src/model/malloy_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1915,12 +1915,14 @@ class FieldInstanceResult implements FieldInstance {

findJoins(query: QueryQuery) {
for (const dim of this.fields()) {
this.addStructToJoin(
dim.f.getJoinableParent(),
query,
dim.f.uniqueKeyPossibleUse(),
[]
);
if (!(dim.f instanceof QueryFieldStruct)) {
this.addStructToJoin(
dim.f.getJoinableParent(),
query,
dim.f.uniqueKeyPossibleUse(),
[]
);
}
}
for (const s of this.structs()) {
s.findJoins(query);
Expand Down
25 changes: 15 additions & 10 deletions test/src/databases/all/arrays.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,27 @@ import '../../util/db-jest-matchers';
const runtimes = new RuntimeList(databasesFromEnvironmentOr(allDatabases));

describe.each(runtimes.runtimeList)('arrays %s', (databaseName, runtime) => {
const head = `${databaseName}.sql("select null")`;
const digits = `${head} -> {select: digits is [1,2]}`;
const evens = 'duckdb.sql("SELECT [2,4] as evens")';
test('array literal', async () => {
await expect(`run: ${digits}`).malloyResultMatches(runtime, {
digits: [1, 2],
});
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 () => {
expect(`run: ${digits}->{ select: n is digits.each }`).malloyResultMatches(
runtime,
[{n: 1}, {n: 2}]
);
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: ${digits}->{ select: two is len!number(digits); } `
`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]}
);
});
});

0 comments on commit 2f23f1d

Please sign in to comment.