@malloydata/malloy 0.0.312 → 0.0.313
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.
|
@@ -231,10 +231,10 @@ class MySQLDialect extends dialect_1.Dialect {
|
|
|
231
231
|
}
|
|
232
232
|
sqlSumDistinct(key, value, funcName) {
|
|
233
233
|
const sqlDistinctKey = `CONCAT(${key}, '')`;
|
|
234
|
-
const upperPart = `CAST(CONV(SUBSTRING(MD5(${sqlDistinctKey}), 1, 16), 16, 10) AS DECIMAL(
|
|
235
|
-
const lowerPart = `CAST(CONV(SUBSTRING(MD5(${sqlDistinctKey}), 16, 8), 16, 10) AS DECIMAL(
|
|
234
|
+
const upperPart = `CAST(CONV(SUBSTRING(MD5(${sqlDistinctKey}), 1, 16), 16, 10) AS DECIMAL(55, 10)) * 4294967296`;
|
|
235
|
+
const lowerPart = `CAST(CONV(SUBSTRING(MD5(${sqlDistinctKey}), 16, 8), 16, 10) AS DECIMAL(55, 10))`;
|
|
236
236
|
const hashkey = `(${upperPart} + ${lowerPart})`;
|
|
237
|
-
const v = `COALESCE(${value},0)`;
|
|
237
|
+
const v = `CAST(COALESCE(${value},0) as DECIMAL(55, 10))`;
|
|
238
238
|
const sqlSum = `(SUM(DISTINCT ${hashkey} + ${v}) - SUM(DISTINCT ${hashkey}))`;
|
|
239
239
|
if (funcName === 'SUM') {
|
|
240
240
|
return sqlSum;
|
|
@@ -212,14 +212,14 @@ function exprToSQL(resultSet, context, exprToTranslate, state = new utils_1.Gene
|
|
|
212
212
|
case 'compositeField':
|
|
213
213
|
return '{COMPOSITE_FIELD}';
|
|
214
214
|
case 'filterMatch':
|
|
215
|
-
return generateAppliedFilter(context, expr);
|
|
215
|
+
return generateAppliedFilter(context, expr, qi);
|
|
216
216
|
case 'filterLiteral':
|
|
217
217
|
return 'INTERNAL ERROR FILTER EXPRESSION VALUE SHOULD NOT BE USED';
|
|
218
218
|
default:
|
|
219
219
|
throw new Error(`Internal Error: Unknown expression node '${expr.node}' ${JSON.stringify(expr, undefined, 2)}`);
|
|
220
220
|
}
|
|
221
221
|
}
|
|
222
|
-
function generateAppliedFilter(context, filterMatchExpr) {
|
|
222
|
+
function generateAppliedFilter(context, filterMatchExpr, qi) {
|
|
223
223
|
var _a;
|
|
224
224
|
let filterExpr = filterMatchExpr.kids.filterExpr;
|
|
225
225
|
while (filterExpr.node === '()') {
|
|
@@ -261,7 +261,7 @@ function generateAppliedFilter(context, filterMatchExpr) {
|
|
|
261
261
|
if (fParse.log.length > 0) {
|
|
262
262
|
throw new Error(`Filter expression parse error: ${fParse.log[0]}`);
|
|
263
263
|
}
|
|
264
|
-
return filter_compilers_1.FilterCompilers.compile(filterMatchExpr.dataType, fParse.parsed, filterMatchExpr.kids.expr.sql || '', context.dialect);
|
|
264
|
+
return filter_compilers_1.FilterCompilers.compile(filterMatchExpr.dataType, fParse.parsed, filterMatchExpr.kids.expr.sql || '', context.dialect, qi);
|
|
265
265
|
}
|
|
266
266
|
// Helper functions for generateFunctionCallExpression
|
|
267
267
|
function getParameterMap(overload, numArgs) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { BooleanFilter, FilterExpression, NumberFilter, StringFilter, TemporalFilter } from '@malloydata/malloy-filter';
|
|
2
|
-
import type { Dialect } from '../dialect';
|
|
2
|
+
import type { Dialect, QueryInfo } from '../dialect';
|
|
3
3
|
export declare const FilterCompilers: {
|
|
4
|
-
compile(t: string, c: FilterExpression | null, x: string, d: Dialect): string;
|
|
4
|
+
compile(t: string, c: FilterExpression | null, x: string, d: Dialect, qi?: QueryInfo): string;
|
|
5
5
|
numberCompile(nc: NumberFilter, x: string, d: Dialect): string;
|
|
6
6
|
booleanCompile(bc: BooleanFilter, x: string, _d: Dialect): string;
|
|
7
7
|
stringCompile(sc: StringFilter, x: string, d: Dialect): string;
|
|
8
|
-
temporalCompile(tc: TemporalFilter, x: string, d: Dialect, t: "date" | "timestamp"): string;
|
|
8
|
+
temporalCompile(tc: TemporalFilter, x: string, d: Dialect, t: "date" | "timestamp", qi?: QueryInfo): string;
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
11
|
* I felt like there was enough "helpful functions needed to make everything
|
|
@@ -17,7 +17,8 @@ export declare class TemporalFilterCompiler {
|
|
|
17
17
|
readonly expr: string;
|
|
18
18
|
readonly timetype: 'timestamp' | 'date';
|
|
19
19
|
readonly d: Dialect;
|
|
20
|
-
|
|
20
|
+
readonly qi: QueryInfo;
|
|
21
|
+
constructor(expr: string, dialect: Dialect, timetype?: 'timestamp' | 'date', queryInfo?: QueryInfo);
|
|
21
22
|
time(timeSQL: string): string;
|
|
22
23
|
compile(tc: TemporalFilter): string;
|
|
23
24
|
private expandLiteral;
|
|
@@ -37,7 +37,7 @@ function unlike(disLiked, x) {
|
|
|
37
37
|
* XXXXFilterCompiler.compile() will move to XXXFilterExpression.compile()
|
|
38
38
|
*/
|
|
39
39
|
exports.FilterCompilers = {
|
|
40
|
-
compile(t, c, x, d) {
|
|
40
|
+
compile(t, c, x, d, qi = {}) {
|
|
41
41
|
if (c === null) {
|
|
42
42
|
return 'true';
|
|
43
43
|
}
|
|
@@ -51,7 +51,7 @@ exports.FilterCompilers = {
|
|
|
51
51
|
return exports.FilterCompilers.booleanCompile(c, x, d);
|
|
52
52
|
}
|
|
53
53
|
else if ((t === 'date' || t === 'timestamp') && (0, malloy_filter_1.isTemporalFilter)(c)) {
|
|
54
|
-
return exports.FilterCompilers.temporalCompile(c, x, d, t);
|
|
54
|
+
return exports.FilterCompilers.temporalCompile(c, x, d, t, qi);
|
|
55
55
|
}
|
|
56
56
|
throw new Error('INTERNAL ERROR: No filter compiler for ' + t);
|
|
57
57
|
},
|
|
@@ -251,8 +251,8 @@ exports.FilterCompilers = {
|
|
|
251
251
|
}
|
|
252
252
|
},
|
|
253
253
|
// mtoy todo figure out what to do about dates
|
|
254
|
-
temporalCompile(tc, x, d, t) {
|
|
255
|
-
const c = new TemporalFilterCompiler(x, d, t);
|
|
254
|
+
temporalCompile(tc, x, d, t, qi = {}) {
|
|
255
|
+
const c = new TemporalFilterCompiler(x, d, t, qi);
|
|
256
256
|
return c.compile(tc);
|
|
257
257
|
},
|
|
258
258
|
};
|
|
@@ -269,10 +269,11 @@ const fTimestamp = `${fMinute}:ss`;
|
|
|
269
269
|
* a dialect as an argument?
|
|
270
270
|
*/
|
|
271
271
|
class TemporalFilterCompiler {
|
|
272
|
-
constructor(expr, dialect, timetype = 'timestamp') {
|
|
272
|
+
constructor(expr, dialect, timetype = 'timestamp', queryInfo = {}) {
|
|
273
273
|
this.expr = expr;
|
|
274
274
|
this.timetype = timetype;
|
|
275
275
|
this.d = dialect;
|
|
276
|
+
this.qi = queryInfo;
|
|
276
277
|
}
|
|
277
278
|
time(timeSQL) {
|
|
278
279
|
if (this.timetype === 'timestamp') {
|
|
@@ -430,7 +431,10 @@ class TemporalFilterCompiler {
|
|
|
430
431
|
typeDef: { type: 'timestamp' },
|
|
431
432
|
literal,
|
|
432
433
|
};
|
|
433
|
-
|
|
434
|
+
if (this.qi.queryTimezone) {
|
|
435
|
+
literalNode.timezone = this.qi.queryTimezone;
|
|
436
|
+
}
|
|
437
|
+
return { ...literalNode, sql: this.d.sqlLiteralTime(this.qi, literalNode) };
|
|
434
438
|
}
|
|
435
439
|
nowExpr() {
|
|
436
440
|
return {
|
|
@@ -460,7 +464,7 @@ class TemporalFilterCompiler {
|
|
|
460
464
|
e: (0, malloy_types_1.mkTemporal)(e, 'timestamp'),
|
|
461
465
|
units: 'day_of_week',
|
|
462
466
|
};
|
|
463
|
-
return { ...t, sql: this.d.sqlTimeExtractExpr(
|
|
467
|
+
return { ...t, sql: this.d.sqlTimeExtractExpr(this.qi, t) };
|
|
464
468
|
}
|
|
465
469
|
nowDot(units) {
|
|
466
470
|
const nowTruncExpr = {
|
|
@@ -468,7 +472,7 @@ class TemporalFilterCompiler {
|
|
|
468
472
|
e: this.nowExpr(),
|
|
469
473
|
units,
|
|
470
474
|
};
|
|
471
|
-
return { ...nowTruncExpr, sql: this.d.sqlTruncExpr(
|
|
475
|
+
return { ...nowTruncExpr, sql: this.d.sqlTruncExpr(this.qi, nowTruncExpr) };
|
|
472
476
|
}
|
|
473
477
|
thisUnit(units) {
|
|
474
478
|
const thisUnit = this.nowDot(units);
|
|
@@ -562,17 +566,24 @@ class TemporalFilterCompiler {
|
|
|
562
566
|
const destDayZeroBased = destDay - 1;
|
|
563
567
|
// dow is 1-7, convert to 0-6 for the arithmetic
|
|
564
568
|
const dowZeroBased = `(${dow.sql}-1)`;
|
|
565
|
-
let
|
|
569
|
+
let beginOffset;
|
|
570
|
+
let endOffset;
|
|
571
|
+
// "dayname" and "last dayname" both refer to the most recent,
|
|
572
|
+
// already complete day of that name. So if today is Sunday,
|
|
573
|
+
// "next sunday" is "today", and "last sunday" is 7 days ago.
|
|
566
574
|
if (direction === 'next') {
|
|
567
|
-
// Days forward: ((destDay -
|
|
568
|
-
|
|
575
|
+
// Days forward: ((destDay - currentDay + 6) % 7) + 1
|
|
576
|
+
beginOffset = `${this.mod7(`${destDayZeroBased}-${dowZeroBased}+6`)}+1`;
|
|
577
|
+
endOffset = `${this.mod7(`${destDayZeroBased}-${dowZeroBased}+6`)}+2`;
|
|
569
578
|
}
|
|
570
579
|
else {
|
|
571
|
-
// Days back: ((
|
|
572
|
-
|
|
580
|
+
// Days back: ((currentDay - destDay + 6) % 7) + 1
|
|
581
|
+
beginOffset = `${this.mod7(`${dowZeroBased}-${destDayZeroBased}+6`)}+1`;
|
|
582
|
+
// End offset is one day less (closer to today)
|
|
583
|
+
endOffset = `${this.mod7(`${dowZeroBased}-${destDayZeroBased}+6`)}`;
|
|
573
584
|
}
|
|
574
|
-
const begin = this.delta(todayBegin, direction === 'next' ? '+' : '-',
|
|
575
|
-
const end = this.delta(
|
|
585
|
+
const begin = this.delta(todayBegin, direction === 'next' ? '+' : '-', beginOffset, 'day');
|
|
586
|
+
const end = this.delta(todayBegin, direction === 'next' ? '+' : '-', endOffset, 'day');
|
|
576
587
|
return { begin, end: end.sql };
|
|
577
588
|
}
|
|
578
589
|
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const MALLOY_VERSION = "0.0.
|
|
1
|
+
export declare const MALLOY_VERSION = "0.0.313";
|
package/dist/version.js
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MALLOY_VERSION = void 0;
|
|
4
4
|
// generated with 'generate-version-file' script; do not edit manually
|
|
5
|
-
exports.MALLOY_VERSION = '0.0.
|
|
5
|
+
exports.MALLOY_VERSION = '0.0.313';
|
|
6
6
|
//# sourceMappingURL=version.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/malloy",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.313",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/index.js",
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
"generate-version-file": "VERSION=$(npm pkg get version --workspaces=false | tr -d \\\")\necho \"// generated with 'generate-version-file' script; do not edit manually\\nexport const MALLOY_VERSION = '$VERSION';\" > src/version.ts"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@malloydata/malloy-filter": "0.0.
|
|
45
|
-
"@malloydata/malloy-interfaces": "0.0.
|
|
46
|
-
"@malloydata/malloy-tag": "0.0.
|
|
44
|
+
"@malloydata/malloy-filter": "0.0.313",
|
|
45
|
+
"@malloydata/malloy-interfaces": "0.0.313",
|
|
46
|
+
"@malloydata/malloy-tag": "0.0.313",
|
|
47
47
|
"antlr4ts": "^0.5.0-alpha.4",
|
|
48
48
|
"assert": "^2.0.0",
|
|
49
49
|
"jaro-winkler": "^0.2.8",
|