@malloydata/malloy 0.0.138-dev240331204754 → 0.0.138-dev240401131656

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.
@@ -77,7 +77,7 @@ class TrinoDialect extends dialect_1.Dialect {
77
77
  this.supportsQualify = true;
78
78
  this.supportsSafeCast = true;
79
79
  this.supportsNesting = true;
80
- this.cantPartitionWindowFunctionsOnExpressions = true;
80
+ this.cantPartitionWindowFunctionsOnExpressions = false;
81
81
  this.orderByClause = 'output_name';
82
82
  // TODO(figutierrez): update.
83
83
  this.keywords = `
@@ -248,19 +248,20 @@ class TrinoDialect extends dialect_1.Dialect {
248
248
  // BigQuery will allocate more resources if we use a CROSS JOIN so we do that instead.
249
249
  //
250
250
  sqlUnnestAlias(source, alias, fieldList, needDistinctKey, isArray, _isInNestedPipeline) {
251
+ const fieldsNames = fieldList.map(f => this.sqlMaybeQuoteIdentifier(f.sqlOutputName));
251
252
  if (isArray) {
252
253
  if (needDistinctKey) {
253
- return `LEFT JOIN UNNEST(ARRAY(( SELECT AS STRUCT row_number() over() as __row_id, value FROM UNNEST(${source}) value))) as ${alias}`;
254
+ return `,UNNEST(ARRAY(( SELECT AS STRUCT row_number() over() as __row_id, value FROM UNNEST(${source}) value))) as ${alias}`;
254
255
  }
255
256
  else {
256
- return `LEFT JOIN UNNEST(ARRAY((SELECT AS STRUCT value FROM unnest(${source}) value))) as ${alias}`;
257
+ return `,UNNEST(ARRAY((SELECT AS STRUCT value FROM unnest(${source}) value))) as ${alias}`;
257
258
  }
258
259
  }
259
260
  else if (needDistinctKey) {
260
- return `LEFT JOIN UNNEST(ARRAY(( SELECT AS STRUCT row_number() over() as __row_id, * FROM UNNEST(${source})))) as ${alias}`;
261
+ return `,UNNEST(zip_with(a, SEQUENCE(1,cardinality(a)), (r,__row_id) -> (r, __row_id))) as ${alias}_outer(${alias},__row_id)`;
261
262
  }
262
263
  else {
263
- return `LEFT JOIN UNNEST(${source}) as ${alias}`;
264
+ return `,UNNEST(${source}) as ${alias}(${fieldsNames.join(', ')})`;
264
265
  }
265
266
  }
266
267
  sqlSumDistinctHashedKey(sqlDistinctKey) {
@@ -271,9 +272,13 @@ class TrinoDialect extends dialect_1.Dialect {
271
272
  return `(${upperPart} + ${lowerPart}) * ${precisionShiftMultiplier}`;
272
273
  }
273
274
  sqlGenerateUUID() {
274
- return 'GENERATE_UUID()';
275
+ return 'UUID()';
275
276
  }
276
277
  sqlFieldReference(alias, fieldName, _fieldType, _isNested, _isArray) {
278
+ // LTNOTE: hack, in duckdb we can't have structs as tables so we kind of simulate it.
279
+ if (fieldName === '__row_id') {
280
+ return `${alias}_outer.__row_id`;
281
+ }
277
282
  return `${alias}.${fieldName}`;
278
283
  }
279
284
  sqlUnnestPipelineHead(isSingleton, sourceSQLExpression) {
@@ -304,12 +309,7 @@ ${(0, utils_1.indent)(sql)}
304
309
  return `(SELECT AS STRUCT ${alias}.*)`;
305
310
  }
306
311
  sqlMaybeQuoteIdentifier(identifier) {
307
- // return this.keywords.indexOf(identifier.toUpperCase()) > 0
308
- // ? '`' + identifier + '`'
309
- // : identifier;
310
- return identifier;
311
- // TODO: may need to escape;
312
- //return `"${identifier}"`;
312
+ return '"' + identifier + '"';
313
313
  }
314
314
  sqlNow() {
315
315
  return (0, malloy_types_1.mkExpr) `CURRENT_TIMESTAMP()`;
@@ -374,7 +374,7 @@ ${(0, utils_1.indent)(sql)}
374
374
  return cast.expr;
375
375
  }
376
376
  sqlRegexpMatch(expr, regexp) {
377
- return (0, malloy_types_1.mkExpr) `REGEXP_CONTAINS(${expr}, ${regexp})`;
377
+ return (0, malloy_types_1.mkExpr) `REGEXP_LIKE(${expr}, ${regexp})`;
378
378
  }
379
379
  sqlLiteralTime(qi, timeString, type, timezone) {
380
380
  if (type === 'date') {
@@ -2105,7 +2105,7 @@ class QueryQuery extends QueryField {
2105
2105
  o.push(`${fi.fieldUsage.resultIndex} ${f.dir || 'ASC'}`);
2106
2106
  }
2107
2107
  else if (this.parent.dialect.orderByClause === 'output_name') {
2108
- o.push(`${f.field}${f.dir || 'ASC'}`);
2108
+ o.push(`${this.parent.dialect.sqlMaybeQuoteIdentifier(f.field)} ${f.dir || 'ASC'}`);
2109
2109
  }
2110
2110
  }
2111
2111
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.138-dev240331204754",
3
+ "version": "0.0.138-dev240401131656",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",