@malloydata/malloy 0.0.43-dev230622192152 → 0.0.43

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.
@@ -35,6 +35,7 @@ export declare abstract class Dialect {
35
35
  abstract supportsCTEinCoorelatedSubQueries: boolean;
36
36
  abstract dontUnionIndex: boolean;
37
37
  abstract supportsQualify: boolean;
38
+ abstract supportsSafeCast: boolean;
38
39
  abstract getGlobalFunctionDef(name: string): DialectFunctionOverloadDef[] | undefined;
39
40
  abstract quoteTablePath(tablePath: string): string;
40
41
  abstract sqlGroupSetTable(groupSetCount: number): string;
@@ -17,6 +17,7 @@ export declare class DuckDBDialect extends Dialect {
17
17
  supportsCTEinCoorelatedSubQueries: boolean;
18
18
  dontUnionIndex: boolean;
19
19
  supportsQualify: boolean;
20
+ supportsSafeCast: boolean;
20
21
  get udfPrefix(): string;
21
22
  quoteTablePath(tableName: string): string;
22
23
  sqlGroupSetTable(groupSetCount: number): string;
@@ -53,6 +53,7 @@ class DuckDBDialect extends dialect_1.Dialect {
53
53
  this.supportsCTEinCoorelatedSubQueries = true;
54
54
  this.dontUnionIndex = true;
55
55
  this.supportsQualify = true;
56
+ this.supportsSafeCast = true;
56
57
  }
57
58
  // hack until they support temporary macros.
58
59
  get udfPrefix() {
@@ -260,8 +261,10 @@ class DuckDBDialect extends dialect_1.Dialect {
260
261
  else if (op === 'date::timestamp' && tz) {
261
262
  return (0, malloy_types_1.mkExpr) `CAST((${cast.expr})::TIMESTAMP AT TIME ZONE '${tz}' AS TIMESTAMP)`;
262
263
  }
263
- if (cast.dstType !== cast.srcType) {
264
- return (0, malloy_types_1.mkExpr) `CAST(${cast.expr} AS ${castTo})`;
264
+ if (cast.srcType !== cast.dstType) {
265
+ const dstType = castMap[cast.dstType] || cast.dstType;
266
+ const castFunc = cast.safe ? 'TRY_CAST' : 'CAST';
267
+ return (0, malloy_types_1.mkExpr) `${castFunc}(${cast.expr} AS ${dstType})`;
265
268
  }
266
269
  return cast.expr;
267
270
  }
@@ -16,6 +16,7 @@ export declare class PostgresDialect extends Dialect {
16
16
  supportUnnestArrayAgg: boolean;
17
17
  supportsAggDistinct: boolean;
18
18
  supportsCTEinCoorelatedSubQueries: boolean;
19
+ supportsSafeCast: boolean;
19
20
  dontUnionIndex: boolean;
20
21
  supportsQualify: boolean;
21
22
  globalFunctions: import("../functions/function_map").FunctionMap;
@@ -66,6 +66,7 @@ class PostgresDialect extends dialect_1.Dialect {
66
66
  this.supportUnnestArrayAgg = true;
67
67
  this.supportsAggDistinct = true;
68
68
  this.supportsCTEinCoorelatedSubQueries = true;
69
+ this.supportsSafeCast = false;
69
70
  this.dontUnionIndex = false;
70
71
  this.supportsQualify = false;
71
72
  this.globalFunctions = functions_1.POSTGRES_FUNCTIONS;
@@ -274,8 +275,13 @@ class PostgresDialect extends dialect_1.Dialect {
274
275
  else if (op === 'date::timestamp' && tz) {
275
276
  return (0, malloy_types_1.mkExpr) `CAST((${cast.expr})::TIMESTAMP AT TIME ZONE '${tz}' AS TIMESTAMP)`;
276
277
  }
277
- if (cast.dstType !== cast.srcType) {
278
- return (0, malloy_types_1.mkExpr) `CAST(${cast.expr} AS ${castTo})`;
278
+ if (cast.srcType !== cast.dstType) {
279
+ const dstType = castMap[cast.dstType] || cast.dstType;
280
+ if (cast.safe) {
281
+ throw new Error("Postgres dialect doesn't support Safe Cast");
282
+ }
283
+ const castFunc = 'CAST';
284
+ return (0, malloy_types_1.mkExpr) `${castFunc}(${cast.expr} AS ${dstType})`;
279
285
  }
280
286
  return cast.expr;
281
287
  }
@@ -18,6 +18,7 @@ export declare class StandardSQLDialect extends Dialect {
18
18
  supportsCTEinCoorelatedSubQueries: boolean;
19
19
  dontUnionIndex: boolean;
20
20
  supportsQualify: boolean;
21
+ supportsSafeCast: boolean;
21
22
  quoteTablePath(tablePath: string): string;
22
23
  sqlGroupSetTable(groupSetCount: number): string;
23
24
  sqlAnyValue(groupSet: number, fieldName: string): string;
@@ -74,6 +74,7 @@ class StandardSQLDialect extends dialect_1.Dialect {
74
74
  this.supportsCTEinCoorelatedSubQueries = false;
75
75
  this.dontUnionIndex = true; // bigquery can't use a sample table more than once in a query.
76
76
  this.supportsQualify = true;
77
+ this.supportsSafeCast = true;
77
78
  this.keywords = `
78
79
  ALL
79
80
  AND
@@ -103,49 +103,50 @@ export declare class MalloyLexer extends Lexer {
103
103
  static readonly OCURLY = 98;
104
104
  static readonly CCURLY = 99;
105
105
  static readonly DOUBLECOLON = 100;
106
- static readonly EXCLAM = 101;
107
- static readonly COLON = 102;
108
- static readonly COMMA = 103;
109
- static readonly DOT = 104;
110
- static readonly LT = 105;
111
- static readonly GT = 106;
112
- static readonly EQ = 107;
113
- static readonly NE = 108;
114
- static readonly LTE = 109;
115
- static readonly GTE = 110;
116
- static readonly PLUS = 111;
117
- static readonly MINUS = 112;
118
- static readonly STAR = 113;
119
- static readonly STARSTAR = 114;
120
- static readonly SLASH = 115;
121
- static readonly BAR = 116;
122
- static readonly SEMI = 117;
123
- static readonly NOT_MATCH = 118;
124
- static readonly MATCH = 119;
125
- static readonly PERCENT = 120;
126
- static readonly DOUBLE_QMARK = 121;
127
- static readonly QMARK = 122;
128
- static readonly LITERAL_TIMESTAMP = 123;
129
- static readonly LITERAL_HOUR = 124;
130
- static readonly LITERAL_DAY = 125;
131
- static readonly LITERAL_QUARTER = 126;
132
- static readonly LITERAL_MONTH = 127;
133
- static readonly LITERAL_WEEK = 128;
134
- static readonly LITERAL_YEAR = 129;
135
- static readonly IDENTIFIER = 130;
136
- static readonly PERCENT_LITERAL = 131;
137
- static readonly INTEGER_LITERAL = 132;
138
- static readonly NUMERIC_LITERAL = 133;
139
- static readonly OBJECT_NAME_LITERAL = 134;
140
- static readonly BLOCK_COMMENT = 135;
141
- static readonly COMMENT_TO_EOL = 136;
142
- static readonly WHITE_SPACE = 137;
143
- static readonly SQL_BEGIN = 138;
144
- static readonly CLOSE_CODE = 139;
145
- static readonly UNWATED_CHARS_TRAILING_NUMBERS = 140;
146
- static readonly UNEXPECTED_CHAR = 141;
147
- static readonly OPEN_CODE = 142;
148
- static readonly SQL_END = 143;
106
+ static readonly TRIPLECOLON = 101;
107
+ static readonly EXCLAM = 102;
108
+ static readonly COLON = 103;
109
+ static readonly COMMA = 104;
110
+ static readonly DOT = 105;
111
+ static readonly LT = 106;
112
+ static readonly GT = 107;
113
+ static readonly EQ = 108;
114
+ static readonly NE = 109;
115
+ static readonly LTE = 110;
116
+ static readonly GTE = 111;
117
+ static readonly PLUS = 112;
118
+ static readonly MINUS = 113;
119
+ static readonly STAR = 114;
120
+ static readonly STARSTAR = 115;
121
+ static readonly SLASH = 116;
122
+ static readonly BAR = 117;
123
+ static readonly SEMI = 118;
124
+ static readonly NOT_MATCH = 119;
125
+ static readonly MATCH = 120;
126
+ static readonly PERCENT = 121;
127
+ static readonly DOUBLE_QMARK = 122;
128
+ static readonly QMARK = 123;
129
+ static readonly LITERAL_TIMESTAMP = 124;
130
+ static readonly LITERAL_HOUR = 125;
131
+ static readonly LITERAL_DAY = 126;
132
+ static readonly LITERAL_QUARTER = 127;
133
+ static readonly LITERAL_MONTH = 128;
134
+ static readonly LITERAL_WEEK = 129;
135
+ static readonly LITERAL_YEAR = 130;
136
+ static readonly IDENTIFIER = 131;
137
+ static readonly PERCENT_LITERAL = 132;
138
+ static readonly INTEGER_LITERAL = 133;
139
+ static readonly NUMERIC_LITERAL = 134;
140
+ static readonly OBJECT_NAME_LITERAL = 135;
141
+ static readonly BLOCK_COMMENT = 136;
142
+ static readonly COMMENT_TO_EOL = 137;
143
+ static readonly WHITE_SPACE = 138;
144
+ static readonly SQL_BEGIN = 139;
145
+ static readonly CLOSE_CODE = 140;
146
+ static readonly UNWATED_CHARS_TRAILING_NUMBERS = 141;
147
+ static readonly UNEXPECTED_CHAR = 142;
148
+ static readonly OPEN_CODE = 143;
149
+ static readonly SQL_END = 144;
149
150
  static readonly SQL_MODE = 1;
150
151
  static readonly channelNames: string[];
151
152
  static readonly modeNames: string[];