@malloydata/malloy 0.0.32-dev230505153727 → 0.0.32-dev230506192652

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.
@@ -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): string;
29
29
  sqlSumDistinctHashedKey(_sqlDistinctKey: string): string;
30
30
  sqlGenerateUUID(): string;
31
31
  sqlDateToString(sqlDateExp: string): string;
@@ -129,11 +129,11 @@ class DuckDBDialect extends dialect_1.Dialect {
129
129
  this.stringTypeName = 'VARCHAR';
130
130
  this.divisionIsInteger = true;
131
131
  this.supportsSumDistinctFunction = true;
132
- this.unnestWithNumbers = true;
132
+ this.unnestWithNumbers = false;
133
133
  this.defaultSampling = { rows: 50000 };
134
134
  this.supportUnnestArrayAgg = true;
135
135
  this.supportsCTEinCoorelatedSubQueries = true;
136
- this.dontUnionIndex = false;
136
+ this.dontUnionIndex = true;
137
137
  this.supportsQualify = true;
138
138
  this.functionInfo = {
139
139
  concat: { returnType: 'string' },
@@ -183,13 +183,27 @@ class DuckDBDialect extends dialect_1.Dialect {
183
183
  .join(', ');
184
184
  return `COALESCE(FIRST({${fields}}) FILTER(WHERE group_set=${groupSet}), {${nullValues}})`;
185
185
  }
186
- sqlUnnestAlias(source, alias, _fieldList, _needDistinctKey) {
187
- return `LEFT JOIN (select UNNEST(generate_series(1,
188
- 100000, --
189
- -- (SELECT genres_length FROM movies limit 1),
190
- 1)) as __row_id) as ${alias} ON ${alias}.__row_id <= array_length(${source})`;
191
- // When DuckDB supports lateral joins...
192
- //return `,(select UNNEST(generate_series(1, length(${source}),1))) as ${alias}(__row_id)`;
186
+ // sqlUnnestAlias(
187
+ // source: string,
188
+ // alias: string,
189
+ // _fieldList: DialectFieldList,
190
+ // _needDistinctKey: boolean
191
+ // ): string {
192
+ // return `LEFT JOIN (select UNNEST(generate_series(1,
193
+ // 100000, --
194
+ // -- (SELECT genres_length FROM movies limit 1),
195
+ // 1)) as __row_id) as ${alias} ON ${alias}.__row_id <= array_length(${source})`;
196
+ // // When DuckDB supports lateral joins...
197
+ // //return `,(select UNNEST(generate_series(1, length(${source}),1))) as ${alias}(__row_id)`;
198
+ // }
199
+ sqlUnnestAlias(source, alias, _fieldList, needDistinctKey) {
200
+ //Simulate left joins by guarenteeing there is at least one row.
201
+ if (!needDistinctKey) {
202
+ return `LEFT JOIN LATERAL (SELECT UNNEST(${source}), 1 as ignoreme) as ${alias}_outer(${alias},ignoreme) ON ${alias}_outer.ignoreme=1`;
203
+ }
204
+ else {
205
+ return `LEFT JOIN LATERAL (SELECT UNNEST(GENERATE_SERIES(1, length(${source}),1)) as __row_id, UNNEST(${source}), 1 as ignoreme) as ${alias}_outer(__row_id, ${alias},ignoreme) ON ${alias}_outer.ignoreme=1`;
206
+ }
193
207
  }
194
208
  sqlSumDistinctHashedKey(_sqlDistinctKey) {
195
209
  return 'uses sumDistinctFunction, should not be called';
@@ -201,7 +215,11 @@ class DuckDBDialect extends dialect_1.Dialect {
201
215
  return `(${sqlDateExp})::date::varchar`;
202
216
  }
203
217
  sqlFieldReference(alias, fieldName, _fieldType, _isNested, isArray) {
204
- if (isArray) {
218
+ // LTNOTE: hack, in duckdb we can't have structs as tables so we kind of simulate it.
219
+ if (fieldName === '__row_id') {
220
+ return `${alias}_outer.__row_id`;
221
+ }
222
+ else if (isArray) {
205
223
  return alias;
206
224
  }
207
225
  else {
@@ -1328,6 +1328,7 @@ class QueryQuery extends QueryField {
1328
1328
  else if ((0, malloy_types_1.isFilterFragment)(expr)) {
1329
1329
  for (const filterCond of expr.filterList) {
1330
1330
  this.addDependantExpr(resultStruct, context, filterCond.expression, joinStack);
1331
+ this.addDependantExpr(resultStruct, context, expr.e, joinStack);
1331
1332
  }
1332
1333
  }
1333
1334
  else if ((0, malloy_types_1.isDialectFragment)(expr)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.32-dev230505153727",
3
+ "version": "0.0.32-dev230506192652",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",