@malloydata/malloy 0.0.37-dev230525224620 → 0.0.37-dev230526070709
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dialect/dialect.d.ts +1 -1
- package/dist/dialect/duckdb.d.ts +1 -1
- package/dist/dialect/duckdb.js +12 -3
- package/dist/dialect/postgres.d.ts +1 -1
- package/dist/dialect/postgres.js +1 -1
- package/dist/dialect/standardsql.d.ts +1 -1
- package/dist/dialect/standardsql.js +1 -1
- package/dist/model/malloy_query.d.ts +1 -0
- package/dist/model/malloy_query.js +6 -1
- package/package.json +1 -1
|
@@ -49,7 +49,7 @@ export declare abstract class Dialect {
|
|
|
49
49
|
abstract sqlAnyValueTurtle(groupSet: number, fieldList: DialectFieldList): string;
|
|
50
50
|
abstract sqlAnyValueLastTurtle(name: string, groupSet: number, sqlName: string): string;
|
|
51
51
|
abstract sqlCoaleseMeasuresInline(groupSet: number, fieldList: DialectFieldList): string;
|
|
52
|
-
abstract sqlUnnestAlias(source: string, alias: string, fieldList: DialectFieldList, needDistinctKey: boolean, isArray: boolean): string;
|
|
52
|
+
abstract sqlUnnestAlias(source: string, alias: string, fieldList: DialectFieldList, needDistinctKey: boolean, isArray: boolean, isInNestedPipeline: boolean): string;
|
|
53
53
|
abstract sqlSumDistinctHashedKey(sqlDistinctKey: string): string;
|
|
54
54
|
abstract sqlGenerateUUID(): string;
|
|
55
55
|
abstract sqlFieldReference(alias: string, fieldName: string, fieldType: string, isNested: boolean, isArray: boolean): string;
|
package/dist/dialect/duckdb.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export declare class DuckDBDialect extends Dialect {
|
|
|
25
25
|
sqlAnyValueTurtle(groupSet: number, fieldList: DialectFieldList): string;
|
|
26
26
|
sqlAnyValueLastTurtle(name: string, groupSet: number, sqlName: string): string;
|
|
27
27
|
sqlCoaleseMeasuresInline(groupSet: number, fieldList: DialectFieldList): string;
|
|
28
|
-
sqlUnnestAlias(source: string, alias: string, _fieldList: DialectFieldList, needDistinctKey: boolean): string;
|
|
28
|
+
sqlUnnestAlias(source: string, alias: string, _fieldList: DialectFieldList, needDistinctKey: boolean, _isArray: boolean, isInNestedPipeline: boolean): string;
|
|
29
29
|
sqlSumDistinctHashedKey(_sqlDistinctKey: string): string;
|
|
30
30
|
sqlGenerateUUID(): string;
|
|
31
31
|
sqlDateToString(sqlDateExp: string): string;
|
package/dist/dialect/duckdb.js
CHANGED
|
@@ -45,7 +45,7 @@ class DuckDBDialect extends dialect_1.Dialect {
|
|
|
45
45
|
this.stringTypeName = 'VARCHAR';
|
|
46
46
|
this.divisionIsInteger = true;
|
|
47
47
|
this.supportsSumDistinctFunction = true;
|
|
48
|
-
this.unnestWithNumbers =
|
|
48
|
+
this.unnestWithNumbers = true;
|
|
49
49
|
this.defaultSampling = { rows: 50000 };
|
|
50
50
|
this.supportUnnestArrayAgg = true;
|
|
51
51
|
this.supportsCTEinCoorelatedSubQueries = true;
|
|
@@ -112,7 +112,16 @@ class DuckDBDialect extends dialect_1.Dialect {
|
|
|
112
112
|
// // When DuckDB supports lateral joins...
|
|
113
113
|
// //return `,(select UNNEST(generate_series(1, length(${source}),1))) as ${alias}(__row_id)`;
|
|
114
114
|
// }
|
|
115
|
-
sqlUnnestAlias(source, alias, _fieldList, needDistinctKey) {
|
|
115
|
+
sqlUnnestAlias(source, alias, _fieldList, needDistinctKey, _isArray, isInNestedPipeline) {
|
|
116
|
+
if (this.unnestWithNumbers) {
|
|
117
|
+
// Duckdb can't unnest in a coorelated subquery at the moment so we hack it.
|
|
118
|
+
const arrayLen = isInNestedPipeline
|
|
119
|
+
? '100000'
|
|
120
|
+
: `array_length(${source})`;
|
|
121
|
+
return `LEFT JOIN (select UNNEST(generate_series(1,
|
|
122
|
+
${arrayLen},
|
|
123
|
+
1)) as __row_id) as ${alias} ON ${alias}.__row_id <= array_length(${source})`;
|
|
124
|
+
}
|
|
116
125
|
//Simulate left joins by guarenteeing there is at least one row.
|
|
117
126
|
if (!needDistinctKey) {
|
|
118
127
|
return `LEFT JOIN LATERAL (SELECT UNNEST(${source}), 1 as ignoreme) as ${alias}_outer(${alias},ignoreme) ON ${alias}_outer.ignoreme=1`;
|
|
@@ -132,7 +141,7 @@ class DuckDBDialect extends dialect_1.Dialect {
|
|
|
132
141
|
}
|
|
133
142
|
sqlFieldReference(alias, fieldName, _fieldType, _isNested, isArray) {
|
|
134
143
|
// LTNOTE: hack, in duckdb we can't have structs as tables so we kind of simulate it.
|
|
135
|
-
if (fieldName === '__row_id') {
|
|
144
|
+
if (!this.unnestWithNumbers && fieldName === '__row_id') {
|
|
136
145
|
return `${alias}_outer.__row_id`;
|
|
137
146
|
}
|
|
138
147
|
else if (isArray) {
|
|
@@ -25,7 +25,7 @@ export declare class PostgresDialect extends Dialect {
|
|
|
25
25
|
sqlAnyValueTurtle(groupSet: number, fieldList: DialectFieldList): string;
|
|
26
26
|
sqlAnyValueLastTurtle(name: string, groupSet: number, sqlName: string): string;
|
|
27
27
|
sqlCoaleseMeasuresInline(groupSet: number, fieldList: DialectFieldList): string;
|
|
28
|
-
sqlUnnestAlias(source: string, alias: string, fieldList: DialectFieldList, needDistinctKey: boolean, isArray: boolean): string;
|
|
28
|
+
sqlUnnestAlias(source: string, alias: string, fieldList: DialectFieldList, needDistinctKey: boolean, isArray: boolean, _isInNestedPipeline: boolean): string;
|
|
29
29
|
sqlSumDistinctHashedKey(sqlDistinctKey: string): string;
|
|
30
30
|
sqlGenerateUUID(): string;
|
|
31
31
|
sqlFieldReference(alias: string, fieldName: string, fieldType: string, isNested: boolean, _isArray: boolean): string;
|
package/dist/dialect/postgres.js
CHANGED
|
@@ -144,7 +144,7 @@ class PostgresDialect extends dialect_1.Dialect {
|
|
|
144
144
|
// return `UNNEST(${source}) as ${alias}(${fields.join(", ")})`;
|
|
145
145
|
// }
|
|
146
146
|
// }
|
|
147
|
-
sqlUnnestAlias(source, alias, fieldList, needDistinctKey, isArray) {
|
|
147
|
+
sqlUnnestAlias(source, alias, fieldList, needDistinctKey, isArray, _isInNestedPipeline) {
|
|
148
148
|
if (isArray) {
|
|
149
149
|
if (needDistinctKey) {
|
|
150
150
|
return `LEFT JOIN UNNEST(ARRAY((SELECT jsonb_build_object('__row_id', row_number() over (), 'value', v) FROM UNNEST(${source}) as v))) as ${alias} ON true`;
|
|
@@ -24,7 +24,7 @@ export declare class StandardSQLDialect extends Dialect {
|
|
|
24
24
|
sqlAnyValueTurtle(groupSet: number, fieldList: DialectFieldList): string;
|
|
25
25
|
sqlAnyValueLastTurtle(name: string, groupSet: number, sqlName: string): string;
|
|
26
26
|
sqlCoaleseMeasuresInline(groupSet: number, fieldList: DialectFieldList): string;
|
|
27
|
-
sqlUnnestAlias(source: string, alias: string, fieldList: DialectFieldList, needDistinctKey: boolean, isArray: boolean): string;
|
|
27
|
+
sqlUnnestAlias(source: string, alias: string, fieldList: DialectFieldList, needDistinctKey: boolean, isArray: boolean, _isInNestedPipeline: boolean): string;
|
|
28
28
|
sqlSumDistinctHashedKey(sqlDistinctKey: string): string;
|
|
29
29
|
sqlGenerateUUID(): string;
|
|
30
30
|
sqlFieldReference(alias: string, fieldName: string, _fieldType: string, _isNested: boolean, _isArray: boolean): string;
|
|
@@ -221,7 +221,7 @@ class StandardSQLDialect extends dialect_1.Dialect {
|
|
|
221
221
|
//
|
|
222
222
|
// BigQuery will allocate more resources if we use a CROSS JOIN so we do that instead.
|
|
223
223
|
//
|
|
224
|
-
sqlUnnestAlias(source, alias, fieldList, needDistinctKey, isArray) {
|
|
224
|
+
sqlUnnestAlias(source, alias, fieldList, needDistinctKey, isArray, _isInNestedPipeline) {
|
|
225
225
|
if (isArray) {
|
|
226
226
|
if (needDistinctKey) {
|
|
227
227
|
return `LEFT JOIN UNNEST(ARRAY(( SELECT AS STRUCT row_number() over() as __row_id, value FROM UNNEST(${source}) value))) as ${alias}`;
|
|
@@ -223,6 +223,7 @@ declare class QueryQuery extends QueryField {
|
|
|
223
223
|
stageWriter: StageWriter | undefined;
|
|
224
224
|
constructor(fieldDef: TurtleDef, parent: QueryStruct, stageWriter: StageWriter | undefined);
|
|
225
225
|
static makeQuery(fieldDef: TurtleDef, parentStruct: QueryStruct, stageWriter?: StageWriter | undefined): QueryQuery;
|
|
226
|
+
inNestedPipeline(): boolean;
|
|
226
227
|
getFieldList(): QueryFieldDef[];
|
|
227
228
|
expandField(f: QueryFieldDef): {
|
|
228
229
|
as: any;
|
|
@@ -1163,6 +1163,10 @@ class QueryQuery extends QueryField {
|
|
|
1163
1163
|
return new QueryQueryIndex(flatTurtleDef, parent, stageWriter);
|
|
1164
1164
|
}
|
|
1165
1165
|
}
|
|
1166
|
+
inNestedPipeline() {
|
|
1167
|
+
return (this.parent.fieldDef.structSource.type === 'sql' &&
|
|
1168
|
+
this.parent.fieldDef.structSource.method === 'nested');
|
|
1169
|
+
}
|
|
1166
1170
|
getFieldList() {
|
|
1167
1171
|
switch (this.firstSegment.type) {
|
|
1168
1172
|
// case "index":
|
|
@@ -1718,7 +1722,8 @@ class QueryQuery extends QueryField {
|
|
|
1718
1722
|
const fieldExpression = this.parent.dialect.sqlFieldReference(qs.parent.getSQLIdentifier(), structRelationship.field, 'struct', qs.parent.fieldDef.structRelationship.type === 'nested', this.parent.fieldDef.structRelationship.type === 'nested' &&
|
|
1719
1723
|
this.parent.fieldDef.structRelationship.isArray);
|
|
1720
1724
|
// we need to generate primary key. If parent has a primary key combine
|
|
1721
|
-
|
|
1725
|
+
// console.log(ji.alias, fieldExpression, this.inNestedPipeline());
|
|
1726
|
+
s += `${this.parent.dialect.sqlUnnestAlias(fieldExpression, ji.alias, ji.getDialectFieldList(), ji.makeUniqueKey, structRelationship.isArray, this.inNestedPipeline())}\n`;
|
|
1722
1727
|
}
|
|
1723
1728
|
else if (structRelationship.type === 'inline') {
|
|
1724
1729
|
throw new Error('Internal Error: inline structs should never appear in join trees');
|