@malloydata/malloy 0.0.138-dev240404154020 → 0.0.138-dev240404193102

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.
@@ -91,6 +91,7 @@ export declare abstract class Dialect {
91
91
  sqlSampleTable(tableSQL: string, sample: Sampling | undefined): string;
92
92
  sqlOrderBy(orderTerms: string[]): string;
93
93
  sqlTzStr(qi: QueryInfo): string;
94
+ sqlMakeUnnestKey(key: string, rowKey: string): string;
94
95
  abstract sqlTypeToMalloyType(sqlType: string): FieldAtomicTypeDef | undefined;
95
96
  abstract malloyTypeToSQLType(malloyType: FieldAtomicTypeDef): string;
96
97
  abstract validateTypeName(sqlType: string): boolean;
@@ -145,6 +145,9 @@ class Dialect {
145
145
  sqlTzStr(qi) {
146
146
  return `"${qi.queryTimezone}"`;
147
147
  }
148
+ sqlMakeUnnestKey(key, rowKey) {
149
+ return this.concat(key, "'x'", rowKey);
150
+ }
148
151
  }
149
152
  exports.Dialect = Dialect;
150
153
  //# sourceMappingURL=dialect.js.map
@@ -59,5 +59,6 @@ export declare class TrinoDialect extends Dialect {
59
59
  sqlTypeToMalloyType(_sqlType: string): FieldAtomicTypeDef | undefined;
60
60
  castToString(expression: string): string;
61
61
  concat(...values: string[]): string;
62
+ sqlMakeUnnestKey(key: string, rowKey: string): string;
62
63
  validateTypeName(sqlType: string): boolean;
63
64
  }
@@ -248,14 +248,14 @@ class TrinoDialect extends dialect_1.Dialect {
248
248
  const fieldsNames = fieldList.map(f => this.sqlMaybeQuoteIdentifier(f.sqlOutputName));
249
249
  if (isArray) {
250
250
  if (needDistinctKey) {
251
- return `,UNNEST(ARRAY(( SELECT AS STRUCT row_number() over() as __row_id, value FROM UNNEST(${source}) value))) as ${alias}`;
251
+ return `,UNNEST(zip(${source}, SEQUENCE(1,cardinality(${source})))) as words_0(value,__row_id_from_${alias})`;
252
252
  }
253
253
  else {
254
- return `,UNNEST(ARRAY((SELECT AS STRUCT value FROM unnest(${source}) value))) as ${alias}`;
254
+ return `,UNNEST(transform(${source}, x -> ROW(x) )) as ${alias}(value)`;
255
255
  }
256
256
  }
257
257
  else if (needDistinctKey) {
258
- return `,UNNEST(zip_with(a, SEQUENCE(1,cardinality(a)), (r,__row_id) -> (r, __row_id))) as ${alias}_outer(${alias},__row_id)`;
258
+ return `,UNNEST(zip_with(a, SEQUENCE(1,cardinality(a)), (r,__row_id) -> (r, __row_id))) as ${alias}_outer(${alias},__row_id_from_${alias})`;
259
259
  }
260
260
  else {
261
261
  return `,UNNEST(${source}) as ${alias}(${fieldsNames.join(', ')})`;
@@ -274,7 +274,7 @@ class TrinoDialect extends dialect_1.Dialect {
274
274
  sqlFieldReference(alias, fieldName, _fieldType, _isNested, _isArray) {
275
275
  // LTNOTE: hack, in duckdb we can't have structs as tables so we kind of simulate it.
276
276
  if (fieldName === '__row_id') {
277
- return `${alias}_outer.__row_id`;
277
+ return `__row_id_from_${alias}`;
278
278
  }
279
279
  return `${alias}.${fieldName}`;
280
280
  }
@@ -469,6 +469,9 @@ ${(0, utils_1.indent)(sql)}
469
469
  concat(...values) {
470
470
  return values.join(' || ');
471
471
  }
472
+ sqlMakeUnnestKey(key, rowKey) {
473
+ return `CAST(${key} as VARCHAR) || 'x' || CAST(${rowKey} as VARCHAR)`;
474
+ }
472
475
  validateTypeName(sqlType) {
473
476
  // Letters: BIGINT
474
477
  // Numbers: INT8
@@ -905,8 +905,8 @@ class QueryFieldDistinctKey extends QueryAtomicField {
905
905
  }
906
906
  else if (this.parent.fieldDef.structSource.type === 'nested') {
907
907
  const parentKey = (_a = this.parent.parent) === null || _a === void 0 ? void 0 : _a.getDistinctKey().generateExpression(resultSet);
908
- return this.parent.dialect.concat(parentKey || '', // shouldn't have to do this...
909
- "'x'", this.parent.dialect.sqlFieldReference(this.parent.getIdentifier(), '__row_id', 'string', true, false));
908
+ return this.parent.dialect.sqlMakeUnnestKey(parentKey || '', // shouldn't have to do this...
909
+ this.parent.dialect.sqlFieldReference(this.parent.getIdentifier(), '__row_id', 'string', true, false));
910
910
  }
911
911
  else {
912
912
  // return this.parent.getIdentifier() + "." + "__distinct_key";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.138-dev240404154020",
3
+ "version": "0.0.138-dev240404193102",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",