@malloydata/malloy 0.0.143-dev240417161322 → 0.0.143-dev240418162623

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.
@@ -9,6 +9,8 @@ export declare class SnowflakeDialect extends Dialect {
9
9
  hasFinalStage: boolean;
10
10
  divisionIsInteger: boolean;
11
11
  supportsSumDistinctFunction: boolean;
12
+ supportsSafeCast: boolean;
13
+ supportsNesting: boolean;
12
14
  defaultSampling: {
13
15
  rows: number;
14
16
  };
@@ -17,10 +19,8 @@ export declare class SnowflakeDialect extends Dialect {
17
19
  supportUnnestArrayAgg: boolean;
18
20
  supportsAggDistinct: boolean;
19
21
  supportsCTEinCoorelatedSubQueries: boolean;
20
- supportsSafeCast: boolean;
21
22
  dontUnionIndex: boolean;
22
23
  supportsQualify: boolean;
23
- supportsNesting: boolean;
24
24
  supportsPipelinesInViews: boolean;
25
25
  quoteTablePath(tablePath: string): string;
26
26
  sqlGroupSetTable(groupSetCount: number): string;
@@ -81,6 +81,8 @@ class SnowflakeDialect extends dialect_1.Dialect {
81
81
  this.hasFinalStage = false;
82
82
  this.divisionIsInteger = false;
83
83
  this.supportsSumDistinctFunction = false;
84
+ this.supportsSafeCast = true;
85
+ this.supportsNesting = true;
84
86
  this.defaultSampling = { rows: 50000 };
85
87
  this.globalFunctions = functions_1.SNOWFLAKE_FUNCTIONS;
86
88
  // NOTE: safely setting all these to false for now
@@ -89,10 +91,8 @@ class SnowflakeDialect extends dialect_1.Dialect {
89
91
  this.supportUnnestArrayAgg = false;
90
92
  this.supportsAggDistinct = false;
91
93
  this.supportsCTEinCoorelatedSubQueries = false;
92
- this.supportsSafeCast = false;
93
94
  this.dontUnionIndex = false;
94
95
  this.supportsQualify = false;
95
- this.supportsNesting = true;
96
96
  this.supportsPipelinesInViews = false;
97
97
  }
98
98
  // don't mess with the table pathing.
@@ -268,10 +268,12 @@ ${(0, utils_1.indent)(sql)}
268
268
  if (cast.srcType === cast.dstType) {
269
269
  return cast.expr;
270
270
  }
271
- if (cast.safe) {
271
+ if (cast.safe && typeof cast.srcType !== 'string') {
272
272
  // safe cast is only supported for a few combinations of src -> dst types
273
273
  // so we will not support it in the general case
274
- throw new Error("Snowflake dialect doesn't support safe cast for a few types");
274
+ // see: https://docs.snowflake.com/en/sql-reference/functions/try_cast
275
+ throw new Error(`Snowflake dialect doesn't support safe cast for a few types:
276
+ refer to: https://docs.snowflake.com/en/sql-reference/functions/try_cast`);
275
277
  }
276
278
  const tz = (0, dialect_1.qtz)(qi);
277
279
  // casting timestamps and dates
@@ -289,7 +291,8 @@ ${(0, utils_1.indent)(sql)}
289
291
  const dstType = typeof cast.dstType === 'string'
290
292
  ? this.malloyTypeToSQLType({ type: cast.dstType })
291
293
  : cast.dstType.raw;
292
- return (0, malloy_types_1.mkExpr) `CAST(${cast.expr} AS ${dstType})`;
294
+ const castFunc = cast.safe ? 'TRY_CAST' : 'CAST';
295
+ return (0, malloy_types_1.mkExpr) `${castFunc}(${cast.expr} AS ${dstType})`;
293
296
  }
294
297
  sqlLiteralTime(qi, timeString, type, timezone) {
295
298
  const tz = (0, dialect_1.qtz)(qi);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.143-dev240417161322",
3
+ "version": "0.0.143-dev240418162623",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",