@malloydata/malloy 0.0.144 → 0.0.145

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.
@@ -325,12 +325,11 @@ ${(0, utils_1.indent)(sql)}
325
325
  if (sqlTime.valueType === 'timestamp') {
326
326
  const tz = qtz(qi);
327
327
  if (tz) {
328
- const civilSource = (0, malloy_types_1.mkExpr) `CAST(${truncThis} AS TIMESTAMPTZ AT TIME ZONE '${tz}')`;
329
- let civilTrunc = (0, malloy_types_1.mkExpr) `DATE_TRUNC('${units}', ${civilSource})`;
328
+ const civilSource = (0, malloy_types_1.mkExpr) `AT_TIMEZONE(${truncThis},'${tz}')`;
329
+ const civilTrunc = (0, malloy_types_1.mkExpr) `DATE_TRUNC('${units}', ${civilSource})`;
330
330
  // MTOY todo ... only need to do this if this is a date ...
331
- civilTrunc = (0, malloy_types_1.mkExpr) `CAST(${civilTrunc}, TIMESTAMP)`;
332
- const truncTsTz = (0, malloy_types_1.mkExpr) `${civilTrunc} AT TIME ZONE '${tz}'`;
333
- return (0, malloy_types_1.mkExpr) `CAST((${truncTsTz}),TIMESTAMP)`;
331
+ return (0, malloy_types_1.mkExpr) `AT_TIMEZONE(${civilTrunc},'${tz}')`;
332
+ // return mkExpr`CAST((${truncTsTz}),TIMESTAMP)`;
334
333
  }
335
334
  }
336
335
  let result = (0, malloy_types_1.mkExpr) `DATE_TRUNC('${units}', ${truncThis})`;
@@ -345,7 +344,7 @@ ${(0, utils_1.indent)(sql)}
345
344
  if (from.valueType === 'timestamp') {
346
345
  const tz = qtz(qi);
347
346
  if (tz) {
348
- extractFrom = (0, malloy_types_1.mkExpr) `CAST(${extractFrom}, TIMESTAMPTZ AT TIME ZONE '${tz}')`;
347
+ extractFrom = (0, malloy_types_1.mkExpr) `at_timezone(${extractFrom},'${tz}')`;
349
348
  }
350
349
  }
351
350
  const extracted = (0, malloy_types_1.mkExpr) `EXTRACT(${pgUnits} FROM ${extractFrom})`;
@@ -366,14 +365,14 @@ ${(0, utils_1.indent)(sql)}
366
365
  return (0, malloy_types_1.mkExpr) `DATE_ADD('${timeframe}', ${n}, ${expr.value})`;
367
366
  }
368
367
  sqlCast(qi, cast) {
369
- const op = `${cast.srcType}::${cast.dstType}`;
368
+ const op = `${cast.srcType}=>${cast.dstType}`;
370
369
  const tz = qtz(qi);
371
- if (op === 'timestamp::date' && tz) {
372
- const tstz = (0, malloy_types_1.mkExpr) `CAST(${cast.expr} as TIMESTAMPTZ)`;
370
+ if (op === 'timestamp=>date' && tz) {
371
+ const tstz = (0, malloy_types_1.mkExpr) `CAST(${cast.expr} as TIMESTAMP)`;
373
372
  return (0, malloy_types_1.mkExpr) `CAST((${tstz}) AT TIME ZONE '${tz}' AS DATE)`;
374
373
  }
375
- else if (op === 'date::timestamp' && tz) {
376
- return (0, malloy_types_1.mkExpr) `CAST(CAST(${cast.expr}), TIMESTAMP AT TIME ZONE '${tz}') AS TIMESTAMP)`;
374
+ else if (op === 'date=>timestamp' && tz) {
375
+ return (0, malloy_types_1.mkExpr) `CAST(CONCAT(CAST(CAST(${cast.expr} AS TIMESTAMP) AS VARCHAR), ' ${tz}') AS TIMESTAMP WITH TIME ZONE)`;
377
376
  }
378
377
  if (cast.srcType !== cast.dstType) {
379
378
  const dstType = typeof cast.dstType === 'string'
@@ -393,7 +392,7 @@ ${(0, utils_1.indent)(sql)}
393
392
  }
394
393
  const tz = timezone || qtz(qi);
395
394
  if (tz) {
396
- return `TIMESTAMPTZ '${timeString} ${tz}'::TIMESTAMP`;
395
+ return `TIMESTAMP '${timeString} ${tz}'`;
397
396
  }
398
397
  return `TIMESTAMP '${timeString}'`;
399
398
  }
@@ -696,7 +696,11 @@ class QueryField extends QueryNode {
696
696
  between = `ROWS BETWEEN ${preceding} PRECEDING AND ${following} FOLLOWING`;
697
697
  }
698
698
  const funcSQL = this.generateExpressionFromExpr(resultStruct, context, expr, state);
699
- return `${funcSQL} OVER(${partitionBy} ${orderBy} ${between})`;
699
+ let retExpr = `${funcSQL} OVER(${partitionBy} ${orderBy} ${between})`;
700
+ if (isComplex) {
701
+ retExpr = `CASE WHEN group_set=${resultStruct.groupSet} THEN ${retExpr} END`;
702
+ }
703
+ return retExpr;
700
704
  }
701
705
  generateExpressionFromExpr(resultSet, context, e, state = new GenerateState()) {
702
706
  let s = '';
@@ -12,3 +12,4 @@ export declare function databasesFromEnvironmentOr(defaultDatabases: string[]):
12
12
  * return a tuple if jest.describe.skip and the dialects to be tested
13
13
  */
14
14
  export declare function describeIfDatabaseAvailable(acceptableDatabases: string[]): [jest.Describe, string[]];
15
+ export declare function brokenIn(dialectName: string, connectionName: string): boolean;
@@ -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.describeIfDatabaseAvailable = exports.databasesFromEnvironmentOr = void 0;
25
+ exports.brokenIn = exports.describeIfDatabaseAvailable = exports.databasesFromEnvironmentOr = void 0;
26
26
  /**
27
27
  * Accepts databases in env, either via comma-separated dialect list
28
28
  * (MALLOY_DATABASES=) or a single database (MALLOY_DATABASE=). returns either
@@ -57,4 +57,8 @@ function describeIfDatabaseAvailable(acceptableDatabases) {
57
57
  return overlap.length > 0 ? [describe, overlap] : [describeSkip, overlap];
58
58
  }
59
59
  exports.describeIfDatabaseAvailable = describeIfDatabaseAvailable;
60
+ function brokenIn(dialectName, connectionName) {
61
+ return dialectName === connectionName;
62
+ }
63
+ exports.brokenIn = brokenIn;
60
64
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.144",
3
+ "version": "0.0.145",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",