Skip to content

Commit

Permalink
skip nested arrays in bigquery
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoy-googly-moogly committed Nov 14, 2024
1 parent 43a30c1 commit f603354
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
21 changes: 14 additions & 7 deletions packages/malloy/src/model/malloy_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2958,21 +2958,28 @@ class QueryQuery extends QueryField {
if (qs.parent === undefined || ji.parent === undefined) {
throw new Error('Internal Error, nested structure with no parent.');
}
// mtoy todo i think there should be a better way to decide if
// a parent name should be expanded, but for now we only expand
// expression values parent names on top level joins, believing
// all lower levels will be in the name space from the top level
const topLevelJoin = ji.parent.parent === undefined;
// Compute the field expression being passed the un-nest. It is made
// up of a parent name, and a child name, either of which could
// be expressions, not references
let fieldExpression: string;

// mtoy todo dont like the way parent name expansion is decided
// If this is a top level join with an expression value, then
// we may have to replace the name with the expression. There is a
// test where a top level join with an expression has a join inside
// of it, and in that case, we don't need to expand the name
// of the parent join when making the child join, because it would have been done
// at a higher level, only I am not 100% confident that is correct
const shouldExpandExpressionParent = ji.parent.parent === undefined;
if (hasExpression(qsDef)) {
// There are two interesting cases here. One is that this array object
// itself is an expression
// itself is an expression. We don't need the parent name, we just do
// => arrayValue is the fieldExpression
fieldExpression = this.exprToSQL(this.rootResult, qs.parent, qsDef.e);
} else if (
isJoined(qs.parent.structDef) &&
hasExpression(qs.parent.structDef) &&
topLevelJoin
shouldExpandExpressionParent
) {
// Ok, this is an array object, with a name, inside some parent.
//
Expand Down
5 changes: 3 additions & 2 deletions test/src/databases/all/compound-atomic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const runtimes = new RuntimeList(databasesFromEnvironmentOr(allDatabases));
describe.each(runtimes.runtimeList)(
'compound atomic datatypes %s',
(databaseName, runtime) => {
const supportsNestedArrays = !['bigquery'].includes(databaseName);
function literalNum(num: Number): Expr {
const literal = num.toString();
return {node: 'numberLiteral', literal, sql: literal};
Expand Down Expand Up @@ -167,12 +168,12 @@ describe.each(runtimes.runtimeList)(
{roll: 8, rolls: 1},
]);
});
test('bare array of array', async () => {
test.when(supportsNestedArrays)('bare array of array', async () => {
await expect(`
run: ${empty} -> { select: aoa is [[1,2]] }
`).malloyResultMatches(runtime, {aoa: [[1, 2]]});
});
test('each.each array of array', async () => {
test.when(supportsNestedArrays)('each.each array of array', async () => {
await expect(`
run: ${empty} extend { dimension: aoa is [[1,2]] }
-> { select: aoa.each.each }
Expand Down

0 comments on commit f603354

Please sign in to comment.