@malloydata/malloy 0.0.149-dev240706223116 → 0.0.150-dev240714131913

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.
@@ -57,6 +57,7 @@ export declare abstract class Dialect {
57
57
  supportsComplexFilteredSources: boolean;
58
58
  supportsTempTables: boolean;
59
59
  hasModOperator: boolean;
60
+ supportsLeftJoinUnnest: boolean;
60
61
  abstract getGlobalFunctionDef(name: string): DialectFunctionOverloadDef[] | undefined;
61
62
  abstract quoteTablePath(tablePath: string): string;
62
63
  abstract sqlGroupSetTable(groupSetCount: number): string;
@@ -79,6 +79,8 @@ class Dialect {
79
79
  // can create temp tables
80
80
  this.supportsTempTables = true;
81
81
  this.hasModOperator = true;
82
+ // can LEFT JOIN UNNEST
83
+ this.supportsLeftJoinUnnest = true;
82
84
  }
83
85
  sqlFinalStage(_lastStageName, _fields) {
84
86
  throw new Error('Dialect has no final Stage but called Anyway');
@@ -46,6 +46,7 @@ registerDialect(new standardsql_1.StandardSQLDialect());
46
46
  registerDialect(new duckdb_1.DuckDBDialect());
47
47
  registerDialect(new snowflake_1.SnowflakeDialect());
48
48
  registerDialect(new trino_1.TrinoDialect());
49
+ registerDialect(new trino_1.PrestoDialect());
49
50
  function paramsEqual(a, b) {
50
51
  return (a.params.length === b.params.length &&
51
52
  a.params.every((param, i) => {
@@ -29,8 +29,8 @@ function fnLog() {
29
29
  const base = (0, util_1.makeParam)('base', (0, util_1.anyExprType)('number'));
30
30
  return [
31
31
  (0, util_1.overload)((0, util_1.minScalar)('number'), [value.param, base.param],
32
- // Snowflake take base first, then value
33
- (0, util_1.sql) `LOG(${base.arg},${value.arg})`),
32
+ // Trino has it but Presto doesn't
33
+ (0, util_1.sql) `(LN(${value.arg}) / LN(${base.arg}))`),
34
34
  ];
35
35
  }
36
36
  exports.fnLog = fnLog;
@@ -36,7 +36,7 @@ export declare class TrinoDialect extends Dialect {
36
36
  sqlAnyValueTurtle(groupSet: number, fieldList: DialectFieldList): string;
37
37
  sqlAnyValueLastTurtle(name: string, groupSet: number, sqlName: string): string;
38
38
  sqlCoaleseMeasuresInline(groupSet: number, fieldList: DialectFieldList): string;
39
- sqlUnnestAlias(source: string, alias: string, fieldList: DialectFieldList, needDistinctKey: boolean, isArray: boolean, _isInNestedPipeline: boolean): string;
39
+ sqlUnnestAlias(source: string, alias: string, _fieldList: DialectFieldList, needDistinctKey: boolean, isArray: boolean, _isInNestedPipeline: boolean): string;
40
40
  sqlSumDistinctHashedKey(sqlDistinctKey: string): string;
41
41
  sqlGenerateUUID(): string;
42
42
  sqlFieldReference(alias: string, fieldName: string, _fieldType: string, _isNested: boolean, _isArray: boolean): string;
@@ -67,3 +67,10 @@ export declare class TrinoDialect extends Dialect {
67
67
  sqlStringAggDistinct(distinctKey: string, valueSQL: string, separatorSQL: string): string;
68
68
  validateTypeName(sqlType: string): boolean;
69
69
  }
70
+ export declare class PrestoDialect extends TrinoDialect {
71
+ name: string;
72
+ supportsPipelinesInViews: boolean;
73
+ supportsLeftJoinUnnest: boolean;
74
+ sqlGenerateUUID(): string;
75
+ sqlUnnestAlias(source: string, alias: string, _fieldList: DialectFieldList, needDistinctKey: boolean, isArray: boolean, _isInNestedPipeline: boolean): string;
76
+ }
@@ -22,7 +22,7 @@
22
22
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  */
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.TrinoDialect = void 0;
25
+ exports.PrestoDialect = exports.TrinoDialect = void 0;
26
26
  const utils_1 = require("../../model/utils");
27
27
  const malloy_types_1 = require("../../model/malloy_types");
28
28
  const functions_1 = require("./functions");
@@ -246,21 +246,21 @@ class TrinoDialect extends dialect_1.Dialect {
246
246
  //
247
247
  // BigQuery will allocate more resources if we use a CROSS JOIN so we do that instead.
248
248
  //
249
- sqlUnnestAlias(source, alias, fieldList, needDistinctKey, isArray, _isInNestedPipeline) {
250
- const fieldsNames = fieldList.map(f => this.sqlMaybeQuoteIdentifier(f.sqlOutputName));
249
+ sqlUnnestAlias(source, alias, _fieldList, needDistinctKey, isArray, _isInNestedPipeline) {
251
250
  if (isArray) {
252
251
  if (needDistinctKey) {
253
- return `LEFT JOIN UNNEST(zip(${source}, SEQUENCE(1,cardinality(${source})))) as words_0(value,__row_id_from_${alias}) ON TRUE`;
252
+ // return `LEFT JOIN UNNEST(transform(${source}, x -> ROW(x) )) WITH ORDINALIITY as words_0(value,__row_id_from_${alias}) ON TRUE`;
253
+ return `LEFT JOIN UNNEST(zip_with(${source},array[],(r,ignore) -> (r, ignore))) WITH ORDINALITY as ${alias}(value, ignore,__row_id_from_${alias}) ON TRUE`;
254
254
  }
255
255
  else {
256
- return `LEFT JOIN UNNEST(transform(${source}, x -> ROW(x) )) as ${alias}(value) ON TRUE`;
256
+ return `LEFT JOIN UNNEST(zip_with(${source},array[],(r,ignore) -> (r, ignore))) as ${alias}(value, ignore) ON TRUE`;
257
257
  }
258
258
  }
259
259
  else if (needDistinctKey) {
260
- return `LEFT JOIN UNNEST(zip_with(${source}, SEQUENCE(1,cardinality(${source})), (r,__row_id) -> (r, __row_id))) as ${alias}_outer(${alias},__row_id_from_${alias}) ON TRUE`;
260
+ return `LEFT JOIN UNNEST(zip_with(${source},array[],(r,ignore) -> (r, ignore))) WITH ORDINALITY as ${alias}_outer(${alias}, ignore,__row_id_from_${alias}) ON TRUE`;
261
261
  }
262
262
  else {
263
- return `LEFT JOIN UNNEST(${source}) as ${alias}(${fieldsNames.join(', ')}) ON TRUE`;
263
+ return `LEFT JOIN UNNEST(zip_with(${source},array[],(r,ignore) -> (r, ignore)))as ${alias}_outer(${alias},ignore) ON TRUE`;
264
264
  }
265
265
  }
266
266
  sqlSumDistinctHashedKey(sqlDistinctKey) {
@@ -494,4 +494,33 @@ ${(0, utils_1.indent)(sql)}
494
494
  }
495
495
  }
496
496
  exports.TrinoDialect = TrinoDialect;
497
+ class PrestoDialect extends TrinoDialect {
498
+ constructor() {
499
+ super(...arguments);
500
+ this.name = 'presto';
501
+ this.supportsPipelinesInViews = false; // what a drag...
502
+ this.supportsLeftJoinUnnest = false; // we need to fix this....
503
+ }
504
+ sqlGenerateUUID() {
505
+ return 'CAST(UUID() AS VARCHAR)';
506
+ }
507
+ sqlUnnestAlias(source, alias, _fieldList, needDistinctKey, isArray, _isInNestedPipeline) {
508
+ if (isArray) {
509
+ if (needDistinctKey) {
510
+ // return `LEFT JOIN UNNEST(transform(${source}, x -> ROW(x) )) WITH ORDINALIITY as words_0(value,__row_id_from_${alias}) ON TRUE`;
511
+ return `CROSS JOIN UNNEST(zip_with(${source},array[],(r,ignore) -> (r, ignore))) WITH ORDINALITY as ${alias}(value, ignore,__row_id_from_${alias})`;
512
+ }
513
+ else {
514
+ return `CROSS JOIN UNNEST(zip_with(${source},array[],(r,ignore) -> (r, ignore))) as ${alias}(value, ignore)`;
515
+ }
516
+ }
517
+ else if (needDistinctKey) {
518
+ return `CROSS JOIN UNNEST(zip_with(${source},array[],(r,ignore) -> (r, ignore))) WITH ORDINALITY as ${alias}_outer(${alias}, ignore,__row_id_from_${alias})`;
519
+ }
520
+ else {
521
+ return `CROSS JOIN UNNEST(zip_with(${source},array[],(r,ignore) -> (r, ignore)))as ${alias}_outer(${alias},ignore)`;
522
+ }
523
+ }
524
+ }
525
+ exports.PrestoDialect = PrestoDialect;
497
526
  //# sourceMappingURL=trino.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.149-dev240706223116",
3
+ "version": "0.0.150-dev240714131913",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",