@malloydata/malloy 0.0.22-dev230126015148 → 0.0.22-dev230206094309
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.
- package/package.json +2 -2
- package/dist/connection_utils.d.ts +0 -1
- package/dist/connection_utils.js +0 -66
- package/dist/dialect/dialect.d.ts +0 -66
- package/dist/dialect/dialect.js +0 -85
- package/dist/dialect/dialect_map.d.ts +0 -3
- package/dist/dialect/dialect_map.js +0 -45
- package/dist/dialect/duckdb.d.ts +0 -52
- package/dist/dialect/duckdb.js +0 -364
- package/dist/dialect/index.d.ts +0 -6
- package/dist/dialect/index.js +0 -37
- package/dist/dialect/postgres.d.ts +0 -52
- package/dist/dialect/postgres.js +0 -330
- package/dist/dialect/standardsql.d.ts +0 -49
- package/dist/dialect/standardsql.js +0 -381
- package/dist/index.d.ts +0 -10
- package/dist/index.js +0 -59
- package/dist/lang/ast/apply-expr.d.ts +0 -3
- package/dist/lang/ast/apply-expr.js +0 -34
- package/dist/lang/ast/ast-expr.d.ts +0 -206
- package/dist/lang/ast/ast-expr.js +0 -781
- package/dist/lang/ast/ast-main.d.ts +0 -915
- package/dist/lang/ast/ast-main.js +0 -3672
- package/dist/lang/ast/ast-time-expr.d.ts +0 -69
- package/dist/lang/ast/ast-time-expr.js +0 -389
- package/dist/lang/ast/ast-types.d.ts +0 -83
- package/dist/lang/ast/ast-types.js +0 -225
- package/dist/lang/ast/index.d.ts +0 -5
- package/dist/lang/ast/index.js +0 -44
- package/dist/lang/ast/time-utils.d.ts +0 -9
- package/dist/lang/ast/time-utils.js +0 -104
- package/dist/lang/field-utils.d.ts +0 -5
- package/dist/lang/field-utils.js +0 -43
- package/dist/lang/index.d.ts +0 -9
- package/dist/lang/index.js +0 -32
- package/dist/lang/lib/Malloy/MalloyLexer.d.ts +0 -165
- package/dist/lang/lib/Malloy/MalloyLexer.js +0 -1232
- package/dist/lang/lib/Malloy/MalloyParser.d.ts +0 -1947
- package/dist/lang/lib/Malloy/MalloyParser.js +0 -11909
- package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +0 -2022
- package/dist/lang/lib/Malloy/MalloyParserListener.js +0 -4
- package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +0 -1274
- package/dist/lang/lib/Malloy/MalloyParserVisitor.js +0 -4
- package/dist/lang/parse-log.d.ts +0 -27
- package/dist/lang/parse-log.js +0 -51
- package/dist/lang/parse-malloy.d.ts +0 -236
- package/dist/lang/parse-malloy.js +0 -746
- package/dist/lang/parse-to-ast.d.ts +0 -155
- package/dist/lang/parse-to-ast.js +0 -990
- package/dist/lang/parse-tree-walkers/document-completion-walker.d.ts +0 -10
- package/dist/lang/parse-tree-walkers/document-completion-walker.js +0 -148
- package/dist/lang/parse-tree-walkers/document-help-context-walker.d.ts +0 -9
- package/dist/lang/parse-tree-walkers/document-help-context-walker.js +0 -107
- package/dist/lang/parse-tree-walkers/document-highlight-walker.d.ts +0 -83
- package/dist/lang/parse-tree-walkers/document-highlight-walker.js +0 -385
- package/dist/lang/parse-tree-walkers/document-symbol-walker.d.ts +0 -11
- package/dist/lang/parse-tree-walkers/document-symbol-walker.js +0 -182
- package/dist/lang/parse-tree-walkers/explore-query-walker.d.ts +0 -34
- package/dist/lang/parse-tree-walkers/explore-query-walker.js +0 -74
- package/dist/lang/parse-tree-walkers/find-external-references.d.ts +0 -11
- package/dist/lang/parse-tree-walkers/find-external-references.js +0 -61
- package/dist/lang/reference-list.d.ts +0 -10
- package/dist/lang/reference-list.js +0 -90
- package/dist/lang/space-field.d.ts +0 -17
- package/dist/lang/space-field.js +0 -127
- package/dist/lang/test/document-help-context-walker.spec.d.ts +0 -1
- package/dist/lang/test/document-help-context-walker.spec.js +0 -55
- package/dist/lang/test/document-symbol-walker.spec.d.ts +0 -1
- package/dist/lang/test/document-symbol-walker.spec.js +0 -110
- package/dist/lang/test/field-symbols.spec.d.ts +0 -1
- package/dist/lang/test/field-symbols.spec.js +0 -180
- package/dist/lang/test/parse.spec.d.ts +0 -14
- package/dist/lang/test/parse.spec.js +0 -2134
- package/dist/lang/test/test-translator.d.ts +0 -38
- package/dist/lang/test/test-translator.js +0 -344
- package/dist/lang/zone.d.ts +0 -57
- package/dist/lang/zone.js +0 -107
- package/dist/malloy.d.ts +0 -1146
- package/dist/malloy.js +0 -2413
- package/dist/model/index.d.ts +0 -2
- package/dist/model/index.js +0 -45
- package/dist/model/malloy_query.d.ts +0 -351
- package/dist/model/malloy_query.js +0 -3174
- package/dist/model/malloy_types.d.ts +0 -551
- package/dist/model/malloy_types.js +0 -378
- package/dist/model/sql_block.d.ts +0 -7
- package/dist/model/sql_block.js +0 -56
- package/dist/model/utils.d.ts +0 -22
- package/dist/model/utils.js +0 -102
- package/dist/run_sql_options.d.ts +0 -3
- package/dist/run_sql_options.js +0 -25
- package/dist/runtime_types.d.ts +0 -105
- package/dist/runtime_types.js +0 -25
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { TimestampUnit, ExtractUnit, TimeFieldType } from "../../model/malloy_types";
|
|
2
|
-
import { Comparison, ExprValue } from "./ast-types";
|
|
3
|
-
import { ExpressionDef, FieldSpace, MalloyElement } from "./ast-main";
|
|
4
|
-
export declare class Timeframe extends MalloyElement {
|
|
5
|
-
elementType: string;
|
|
6
|
-
readonly text: TimestampUnit;
|
|
7
|
-
constructor(timeframeName: string);
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* GranularTime made from a literal. Funky because it doesn't know if it
|
|
11
|
-
* is a date or a timestamp in many cases until it is applied.
|
|
12
|
-
*/
|
|
13
|
-
export declare class GranularLiteral extends ExpressionDef {
|
|
14
|
-
readonly moment: string;
|
|
15
|
-
readonly until: string;
|
|
16
|
-
readonly units: TimestampUnit;
|
|
17
|
-
elementType: string;
|
|
18
|
-
timeType?: TimeFieldType;
|
|
19
|
-
constructor(moment: string, until: string, units: TimestampUnit);
|
|
20
|
-
granular(): boolean;
|
|
21
|
-
static parse(possibleLiteral: string): GranularLiteral | undefined;
|
|
22
|
-
apply(fs: FieldSpace, op: string, left: ExpressionDef): ExprValue;
|
|
23
|
-
getExpression(_fs: FieldSpace): ExprValue;
|
|
24
|
-
}
|
|
25
|
-
export declare class ExprNow extends ExpressionDef {
|
|
26
|
-
elementType: string;
|
|
27
|
-
getExpression(_fs: FieldSpace): ExprValue;
|
|
28
|
-
}
|
|
29
|
-
export declare class PartialCompare extends ExpressionDef {
|
|
30
|
-
readonly op: Comparison;
|
|
31
|
-
readonly right: ExpressionDef;
|
|
32
|
-
elementType: string;
|
|
33
|
-
constructor(op: Comparison, right: ExpressionDef);
|
|
34
|
-
granular(): boolean;
|
|
35
|
-
apply(fs: FieldSpace, op: string, expr: ExpressionDef): ExprValue;
|
|
36
|
-
requestExpression(_fs: FieldSpace): ExprValue | undefined;
|
|
37
|
-
getExpression(_fs: FieldSpace): ExprValue;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* TODO: This is sort of a hand clone of the "Range" class, they should
|
|
41
|
-
* be siblings of a common abstract classs.
|
|
42
|
-
*/
|
|
43
|
-
export declare class ForRange extends ExpressionDef {
|
|
44
|
-
readonly from: ExpressionDef;
|
|
45
|
-
readonly duration: ExpressionDef;
|
|
46
|
-
readonly timeframe: Timeframe;
|
|
47
|
-
elementType: string;
|
|
48
|
-
legalChildTypes: import("./ast-types").FragType[];
|
|
49
|
-
constructor(from: ExpressionDef, duration: ExpressionDef, timeframe: Timeframe);
|
|
50
|
-
apply(fs: FieldSpace, op: string, expr: ExpressionDef): ExprValue;
|
|
51
|
-
requestExpression(_fs: FieldSpace): ExprValue | undefined;
|
|
52
|
-
getExpression(_fs: FieldSpace): ExprValue;
|
|
53
|
-
}
|
|
54
|
-
export declare class ExprTimeExtract extends ExpressionDef {
|
|
55
|
-
readonly extractText: string;
|
|
56
|
-
readonly args: ExpressionDef[];
|
|
57
|
-
elementType: string;
|
|
58
|
-
static pluralMap: Record<string, ExtractUnit>;
|
|
59
|
-
static extractor(funcName: string): ExtractUnit | undefined;
|
|
60
|
-
constructor(extractText: string, args: ExpressionDef[]);
|
|
61
|
-
getExpression(fs: FieldSpace): ExprValue;
|
|
62
|
-
}
|
|
63
|
-
export declare class ExprFunc extends ExpressionDef {
|
|
64
|
-
readonly name: string;
|
|
65
|
-
readonly args: ExpressionDef[];
|
|
66
|
-
elementType: string;
|
|
67
|
-
constructor(name: string, args: ExpressionDef[]);
|
|
68
|
-
getExpression(fs: FieldSpace): ExprValue;
|
|
69
|
-
}
|
|
@@ -1,389 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright 2023 Google LLC
|
|
4
|
-
*
|
|
5
|
-
* Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
-
* a copy of this software and associated documentation files
|
|
7
|
-
* (the "Software"), to deal in the Software without restriction,
|
|
8
|
-
* including without limitation the rights to use, copy, modify, merge,
|
|
9
|
-
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
10
|
-
* and to permit persons to whom the Software is furnished to do so,
|
|
11
|
-
* subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be
|
|
14
|
-
* included in all copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
-
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
-
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
-
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
-
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
-
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
-
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.ExprFunc = exports.ExprTimeExtract = exports.ForRange = exports.PartialCompare = exports.ExprNow = exports.GranularLiteral = exports.Timeframe = void 0;
|
|
26
|
-
const luxon_1 = require("luxon");
|
|
27
|
-
const malloy_types_1 = require("../../model/malloy_types");
|
|
28
|
-
const ast_types_1 = require("./ast-types");
|
|
29
|
-
const time_utils_1 = require("./time-utils");
|
|
30
|
-
const ast_main_1 = require("./ast-main");
|
|
31
|
-
class Timeframe extends ast_main_1.MalloyElement {
|
|
32
|
-
constructor(timeframeName) {
|
|
33
|
-
super();
|
|
34
|
-
this.elementType = "timeframe";
|
|
35
|
-
let tf = timeframeName.toLowerCase();
|
|
36
|
-
if (tf.endsWith("s")) {
|
|
37
|
-
tf = tf.slice(0, -1);
|
|
38
|
-
}
|
|
39
|
-
this.text = (0, malloy_types_1.isTimestampUnit)(tf) ? tf : "second";
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
exports.Timeframe = Timeframe;
|
|
43
|
-
/**
|
|
44
|
-
* GranularTime made from a literal. Funky because it doesn't know if it
|
|
45
|
-
* is a date or a timestamp in many cases until it is applied.
|
|
46
|
-
*/
|
|
47
|
-
class GranularLiteral extends ast_main_1.ExpressionDef {
|
|
48
|
-
constructor(moment, until, units) {
|
|
49
|
-
super();
|
|
50
|
-
this.moment = moment;
|
|
51
|
-
this.until = until;
|
|
52
|
-
this.units = units;
|
|
53
|
-
this.elementType = "timeLiteral";
|
|
54
|
-
}
|
|
55
|
-
granular() {
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
static parse(possibleLiteral) {
|
|
59
|
-
const s = possibleLiteral.slice(1);
|
|
60
|
-
const fYear = "yyyy";
|
|
61
|
-
const fMonth = `${fYear}-LL`;
|
|
62
|
-
const fDay = `${fMonth}-dd`;
|
|
63
|
-
const fMinute = `${fDay} HH:mm`;
|
|
64
|
-
const fSecond = `${fMinute}:ss`;
|
|
65
|
-
const tss = luxon_1.DateTime.fromFormat(s, fSecond);
|
|
66
|
-
if (tss.isValid) {
|
|
67
|
-
const nextSecond = tss.plus({ second: 1 }).toFormat(fSecond);
|
|
68
|
-
const tsLit = new GranularLiteral(s, nextSecond, "second");
|
|
69
|
-
tsLit.timeType = "timestamp";
|
|
70
|
-
return tsLit;
|
|
71
|
-
}
|
|
72
|
-
const tsm = luxon_1.DateTime.fromFormat(s, fMinute);
|
|
73
|
-
if (tsm.isValid) {
|
|
74
|
-
// working around a weird bigquery bug ...
|
|
75
|
-
const thisMin = s + ":00";
|
|
76
|
-
const nextMinute = tsm.plus({ minute: 1 }).toFormat(fMinute) + ":00";
|
|
77
|
-
const tsLit = new GranularLiteral(thisMin, nextMinute, "minute");
|
|
78
|
-
tsLit.timeType = "timestamp";
|
|
79
|
-
return tsLit;
|
|
80
|
-
}
|
|
81
|
-
const quarter = s.match(/(\d{4})-[qQ](\d)$/);
|
|
82
|
-
if (quarter) {
|
|
83
|
-
const qplus = Number.parseInt(quarter[2]) - 1;
|
|
84
|
-
let qstart = luxon_1.DateTime.fromFormat(quarter[1], "yyyy");
|
|
85
|
-
if (qplus > 0) {
|
|
86
|
-
qstart = qstart.plus({ quarters: qplus });
|
|
87
|
-
}
|
|
88
|
-
const qend = qstart.plus({ quarter: 1 });
|
|
89
|
-
return new GranularLiteral(`${qstart.toFormat(fDay)}`, `${qend.toFormat(fDay)}`, "quarter");
|
|
90
|
-
}
|
|
91
|
-
const yyyymmdd = luxon_1.DateTime.fromFormat(s, fDay);
|
|
92
|
-
if (yyyymmdd.isValid) {
|
|
93
|
-
const next = yyyymmdd.plus({ days: 1 });
|
|
94
|
-
return new GranularLiteral(`${yyyymmdd.toFormat(fDay)}`, `${next.toFormat(fDay)}`, "day");
|
|
95
|
-
}
|
|
96
|
-
const yyyymm = luxon_1.DateTime.fromFormat(s, fMonth);
|
|
97
|
-
if (yyyymm.isValid) {
|
|
98
|
-
const next = yyyymm.plus({ months: 1 });
|
|
99
|
-
return new GranularLiteral(`${yyyymm.toFormat(fDay)}`, `${next.toFormat(fDay)}`, "month");
|
|
100
|
-
}
|
|
101
|
-
const yyyy = luxon_1.DateTime.fromFormat(s, fYear);
|
|
102
|
-
if (yyyy.isValid) {
|
|
103
|
-
const year = yyyy.toFormat(`yyyy-01-01`);
|
|
104
|
-
const nextYear = yyyy.plus({ year: 1 }).toFormat(`yyyy-01-01`);
|
|
105
|
-
return new GranularLiteral(year, nextYear, "year");
|
|
106
|
-
}
|
|
107
|
-
if (s.startsWith("WK")) {
|
|
108
|
-
const yyyymmdd = luxon_1.DateTime.fromFormat(s.slice(2), fDay);
|
|
109
|
-
if (yyyymmdd.isValid) {
|
|
110
|
-
// wonky because luxon uses monday weeks and bigquery uses sunday weeks
|
|
111
|
-
let sunday = yyyymmdd;
|
|
112
|
-
if (yyyymmdd.weekday !== 7) {
|
|
113
|
-
sunday = yyyymmdd.startOf("week").minus({ day: 1 });
|
|
114
|
-
}
|
|
115
|
-
const next = sunday.plus({ days: 7 });
|
|
116
|
-
return new GranularLiteral(`${sunday.toFormat(fDay)}`, `${next.toFormat(fDay)}`, "week");
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return undefined;
|
|
120
|
-
}
|
|
121
|
-
apply(fs, op, left) {
|
|
122
|
-
const lhs = left.getExpression(fs);
|
|
123
|
-
if ((0, malloy_types_1.isTimeFieldType)(lhs.dataType)) {
|
|
124
|
-
let rangeType = "timestamp";
|
|
125
|
-
if (lhs.dataType === "date" && !this.timeType) {
|
|
126
|
-
rangeType = "date";
|
|
127
|
-
}
|
|
128
|
-
const range = new ast_main_1.Range(new ast_main_1.ExprTime(rangeType, (0, time_utils_1.timeLiteral)(this.moment, rangeType, "UTC")), new ast_main_1.ExprTime(rangeType, (0, time_utils_1.timeLiteral)(this.until, rangeType, "UTC")));
|
|
129
|
-
return range.apply(fs, op, left);
|
|
130
|
-
}
|
|
131
|
-
return super.apply(fs, op, left);
|
|
132
|
-
}
|
|
133
|
-
getExpression(_fs) {
|
|
134
|
-
const dataType = this.timeType || "date";
|
|
135
|
-
const value = {
|
|
136
|
-
dataType,
|
|
137
|
-
expressionType: "scalar",
|
|
138
|
-
value: (0, time_utils_1.timeLiteral)(this.moment, dataType, "UTC"),
|
|
139
|
-
};
|
|
140
|
-
// Literals with date resolution can be used as timestamps or dates,
|
|
141
|
-
// this is the third attempt to make that work. It still feels like
|
|
142
|
-
// there should be a better way to make this happen, but the point
|
|
143
|
-
// at which the data is needed, the handle is gone to the ExpressionDef
|
|
144
|
-
// which would allow a method call into this class. I think the second
|
|
145
|
-
// if clause is redundant (see "parse" above, but I'm paranoid)
|
|
146
|
-
if (dataType == "date" && (0, malloy_types_1.isDateUnit)(this.units)) {
|
|
147
|
-
value.alsoTimestamp = true;
|
|
148
|
-
}
|
|
149
|
-
if (this.units != "second") {
|
|
150
|
-
return {
|
|
151
|
-
...value,
|
|
152
|
-
timeframe: this.units,
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
return value;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
exports.GranularLiteral = GranularLiteral;
|
|
159
|
-
class ExprNow extends ast_main_1.ExpressionDef {
|
|
160
|
-
constructor() {
|
|
161
|
-
super(...arguments);
|
|
162
|
-
this.elementType = "timestamp";
|
|
163
|
-
}
|
|
164
|
-
getExpression(_fs) {
|
|
165
|
-
return {
|
|
166
|
-
dataType: "timestamp",
|
|
167
|
-
expressionType: "scalar",
|
|
168
|
-
value: [
|
|
169
|
-
{
|
|
170
|
-
type: "dialect",
|
|
171
|
-
function: "now",
|
|
172
|
-
},
|
|
173
|
-
],
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
exports.ExprNow = ExprNow;
|
|
178
|
-
class PartialCompare extends ast_main_1.ExpressionDef {
|
|
179
|
-
constructor(op, right) {
|
|
180
|
-
super({ right });
|
|
181
|
-
this.op = op;
|
|
182
|
-
this.right = right;
|
|
183
|
-
this.elementType = "<=> a";
|
|
184
|
-
}
|
|
185
|
-
granular() {
|
|
186
|
-
return this.right.granular();
|
|
187
|
-
}
|
|
188
|
-
apply(fs, op, expr) {
|
|
189
|
-
return this.right.apply(fs, this.op, expr);
|
|
190
|
-
}
|
|
191
|
-
requestExpression(_fs) {
|
|
192
|
-
return undefined;
|
|
193
|
-
}
|
|
194
|
-
getExpression(_fs) {
|
|
195
|
-
this.log(`Partial comparison does not have a value`);
|
|
196
|
-
return (0, ast_types_1.errorFor)("no value for partial compare");
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
exports.PartialCompare = PartialCompare;
|
|
200
|
-
/**
|
|
201
|
-
* TODO: This is sort of a hand clone of the "Range" class, they should
|
|
202
|
-
* be siblings of a common abstract classs.
|
|
203
|
-
*/
|
|
204
|
-
class ForRange extends ast_main_1.ExpressionDef {
|
|
205
|
-
constructor(from, duration, timeframe) {
|
|
206
|
-
super({ from, duration, timeframe });
|
|
207
|
-
this.from = from;
|
|
208
|
-
this.duration = duration;
|
|
209
|
-
this.timeframe = timeframe;
|
|
210
|
-
this.elementType = "forRange";
|
|
211
|
-
this.legalChildTypes = [ast_types_1.FT.timestampT, ast_types_1.FT.dateT];
|
|
212
|
-
}
|
|
213
|
-
apply(fs, op, expr) {
|
|
214
|
-
const startV = this.from.getExpression(fs);
|
|
215
|
-
const checkV = expr.getExpression(fs);
|
|
216
|
-
if (!this.typeCheck(expr, checkV)) {
|
|
217
|
-
return (0, ast_types_1.errorFor)("no time for range");
|
|
218
|
-
}
|
|
219
|
-
const nV = this.duration.getExpression(fs);
|
|
220
|
-
if (nV.dataType !== "number") {
|
|
221
|
-
this.log(`FOR duration count must be a number, not '${nV.dataType}'`);
|
|
222
|
-
return (0, ast_types_1.errorFor)("FOR not number");
|
|
223
|
-
}
|
|
224
|
-
const units = this.timeframe.text;
|
|
225
|
-
// If the duration resolution is smaller than date, we have
|
|
226
|
-
// to do the computaion with timestamps.
|
|
227
|
-
const durationRes = (0, time_utils_1.resolution)(units);
|
|
228
|
-
let rangeType = durationRes;
|
|
229
|
-
// Next, if the beginning of the range is a timestamp, then we
|
|
230
|
-
// also have to do the computation as a timestamp
|
|
231
|
-
if (startV.dataType === "timestamp") {
|
|
232
|
-
rangeType = "timestamp";
|
|
233
|
-
}
|
|
234
|
-
// everything is dates, do date math
|
|
235
|
-
if (checkV.dataType === "date" && rangeType === "date") {
|
|
236
|
-
const rangeStart = this.from;
|
|
237
|
-
const rangeEndV = (0, time_utils_1.timeOffset)("date", startV.value, "+", nV.value, units);
|
|
238
|
-
const rangeEnd = new ast_main_1.ExprTime("date", rangeEndV);
|
|
239
|
-
return new ast_main_1.Range(rangeStart, rangeEnd).apply(fs, op, expr);
|
|
240
|
-
}
|
|
241
|
-
// Now it doesn't matter if the range is a date or a timestamp,
|
|
242
|
-
// the comparison will be in timestamp space,
|
|
243
|
-
const applyTo = ast_main_1.ExprTime.fromValue("timestamp", checkV);
|
|
244
|
-
let rangeStart = this.from;
|
|
245
|
-
let from = startV.value;
|
|
246
|
-
if (startV.dataType === "date") {
|
|
247
|
-
// Time literals with timestamp units can also be used as timestamps;
|
|
248
|
-
const alreadyTs = (0, ast_types_1.isGranularResult)(startV) && startV.alsoTimestamp;
|
|
249
|
-
if (!alreadyTs) {
|
|
250
|
-
// ... not a literal, need a cast
|
|
251
|
-
from = (0, time_utils_1.castDateToTimestamp)(from);
|
|
252
|
-
}
|
|
253
|
-
rangeStart = new ast_main_1.ExprTime("timestamp", from, startV.expressionType);
|
|
254
|
-
}
|
|
255
|
-
const to = (0, time_utils_1.timeOffset)("timestamp", from, "+", nV.value, units);
|
|
256
|
-
const rangeEnd = new ast_main_1.ExprTime("timestamp", to, startV.expressionType);
|
|
257
|
-
return new ast_main_1.Range(rangeStart, rangeEnd).apply(fs, op, applyTo);
|
|
258
|
-
}
|
|
259
|
-
requestExpression(_fs) {
|
|
260
|
-
return undefined;
|
|
261
|
-
}
|
|
262
|
-
getExpression(_fs) {
|
|
263
|
-
this.log("A Range is not a value");
|
|
264
|
-
return (0, ast_types_1.errorFor)("range has no value");
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
exports.ForRange = ForRange;
|
|
268
|
-
class ExprTimeExtract extends ast_main_1.ExpressionDef {
|
|
269
|
-
constructor(extractText, args) {
|
|
270
|
-
super({ args });
|
|
271
|
-
this.extractText = extractText;
|
|
272
|
-
this.args = args;
|
|
273
|
-
this.elementType = "timeExtract";
|
|
274
|
-
}
|
|
275
|
-
static extractor(funcName) {
|
|
276
|
-
const mappedName = ExprTimeExtract.pluralMap[funcName];
|
|
277
|
-
if (mappedName) {
|
|
278
|
-
return mappedName;
|
|
279
|
-
}
|
|
280
|
-
if ((0, malloy_types_1.isExtractUnit)(funcName)) {
|
|
281
|
-
return funcName;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
getExpression(fs) {
|
|
285
|
-
const extractTo = ExprTimeExtract.extractor(this.extractText);
|
|
286
|
-
if (extractTo) {
|
|
287
|
-
if (this.args.length !== 1) {
|
|
288
|
-
this.log(`Extraction function ${extractTo} requires one argument`);
|
|
289
|
-
return (0, ast_types_1.errorFor)(`{this.name} arg count`);
|
|
290
|
-
}
|
|
291
|
-
const from = this.args[0];
|
|
292
|
-
if (from instanceof ast_main_1.Range) {
|
|
293
|
-
const first = from.first.getExpression(fs);
|
|
294
|
-
const last = from.last.getExpression(fs);
|
|
295
|
-
if (!(0, malloy_types_1.isTimeFieldType)(first.dataType)) {
|
|
296
|
-
from.first.log(`Can't extract ${extractTo} from '${first.dataType}'`);
|
|
297
|
-
return (0, ast_types_1.errorFor)(`${extractTo} bad type ${first.dataType}`);
|
|
298
|
-
}
|
|
299
|
-
if (!(0, malloy_types_1.isTimeFieldType)(last.dataType)) {
|
|
300
|
-
from.last.log(`Cannot extract ${extractTo} from '${last.dataType}'`);
|
|
301
|
-
return (0, ast_types_1.errorFor)(`${extractTo} bad type ${last.dataType}`);
|
|
302
|
-
}
|
|
303
|
-
if (!(0, malloy_types_1.isTimestampUnit)(extractTo)) {
|
|
304
|
-
this.log(`Cannot extract ${extractTo} from a range`);
|
|
305
|
-
return (0, ast_types_1.errorFor)(`${extractTo} bad extraction`);
|
|
306
|
-
}
|
|
307
|
-
return {
|
|
308
|
-
dataType: "number",
|
|
309
|
-
expressionType: (0, malloy_types_1.maxExpressionType)(first.expressionType, last.expressionType),
|
|
310
|
-
value: [
|
|
311
|
-
{
|
|
312
|
-
type: "dialect",
|
|
313
|
-
function: "timeDiff",
|
|
314
|
-
units: extractTo,
|
|
315
|
-
left: { valueType: first.dataType, value: first.value },
|
|
316
|
-
right: { valueType: last.dataType, value: last.value },
|
|
317
|
-
},
|
|
318
|
-
],
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
else {
|
|
322
|
-
const argV = from.getExpression(fs);
|
|
323
|
-
if ((0, malloy_types_1.isTimeFieldType)(argV.dataType)) {
|
|
324
|
-
return {
|
|
325
|
-
dataType: "number",
|
|
326
|
-
expressionType: argV.expressionType,
|
|
327
|
-
value: [
|
|
328
|
-
{
|
|
329
|
-
type: "dialect",
|
|
330
|
-
function: "extract",
|
|
331
|
-
expr: { value: argV.value, valueType: argV.dataType },
|
|
332
|
-
units: extractTo,
|
|
333
|
-
},
|
|
334
|
-
],
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
this.log(`${this.extractText}() requires time type, not '${argV.dataType}'`);
|
|
338
|
-
return (0, ast_types_1.errorFor)(`${this.extractText} bad type ${argV.dataType}`);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
throw this.internalError(`Illegal extraction unit '${this.extractText}'`);
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
exports.ExprTimeExtract = ExprTimeExtract;
|
|
345
|
-
ExprTimeExtract.pluralMap = {
|
|
346
|
-
years: "year",
|
|
347
|
-
quarters: "quarter",
|
|
348
|
-
months: "month",
|
|
349
|
-
weeks: "week",
|
|
350
|
-
days: "day",
|
|
351
|
-
hours: "hour",
|
|
352
|
-
minutes: "minute",
|
|
353
|
-
seconds: "second",
|
|
354
|
-
};
|
|
355
|
-
class ExprFunc extends ast_main_1.ExpressionDef {
|
|
356
|
-
constructor(name, args) {
|
|
357
|
-
super({ args });
|
|
358
|
-
this.name = name;
|
|
359
|
-
this.args = args;
|
|
360
|
-
this.elementType = "function call()";
|
|
361
|
-
}
|
|
362
|
-
getExpression(fs) {
|
|
363
|
-
var _a, _b, _c;
|
|
364
|
-
let expressionType = "scalar";
|
|
365
|
-
let collectType;
|
|
366
|
-
const funcCall = [`${this.name}(`];
|
|
367
|
-
for (const fexpr of this.args) {
|
|
368
|
-
const expr = fexpr.getExpression(fs);
|
|
369
|
-
expressionType = (0, malloy_types_1.maxExpressionType)(expressionType, expr.expressionType);
|
|
370
|
-
if (collectType) {
|
|
371
|
-
funcCall.push(",");
|
|
372
|
-
}
|
|
373
|
-
else {
|
|
374
|
-
collectType = expr.dataType;
|
|
375
|
-
}
|
|
376
|
-
funcCall.push(...expr.value);
|
|
377
|
-
}
|
|
378
|
-
funcCall.push(")");
|
|
379
|
-
const dialect = fs.dialectObj();
|
|
380
|
-
const dataType = (_c = (_b = (_a = dialect === null || dialect === void 0 ? void 0 : dialect.getFunctionInfo(this.name)) === null || _a === void 0 ? void 0 : _a.returnType) !== null && _b !== void 0 ? _b : collectType) !== null && _c !== void 0 ? _c : "number";
|
|
381
|
-
return {
|
|
382
|
-
dataType: dataType,
|
|
383
|
-
expressionType,
|
|
384
|
-
value: (0, ast_types_1.compressExpr)(funcCall),
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
exports.ExprFunc = ExprFunc;
|
|
389
|
-
//# sourceMappingURL=ast-time-expr.js.map
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { AtomicFieldType, Fragment, TimestampUnit, Expr, TimeFieldType, ExpressionType } from "../../model/malloy_types";
|
|
2
|
-
export declare type ExpressionValueType = AtomicFieldType | "null" | "unknown" | "duration" | "regular expression";
|
|
3
|
-
export declare function isExpressionValueType(fv: FieldValueType): fv is ExpressionValueType;
|
|
4
|
-
export declare type StageFieldType = "turtle";
|
|
5
|
-
export declare type FieldValueType = ExpressionValueType | StageFieldType | "struct";
|
|
6
|
-
export interface FragType {
|
|
7
|
-
dataType: FieldValueType;
|
|
8
|
-
expressionType: ExpressionType;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Collects functions which operate on fragtype compatible objects
|
|
12
|
-
*/
|
|
13
|
-
export declare class FT {
|
|
14
|
-
/**
|
|
15
|
-
* Checks if a given type is in a list
|
|
16
|
-
* @param check The type to check (can be undefined)
|
|
17
|
-
* @param from List of types which are OK
|
|
18
|
-
*/
|
|
19
|
-
static in(check: FragType | undefined, from: FragType[]): boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Checks if a possibly undefined candidate matches a type
|
|
22
|
-
* @param good The real type
|
|
23
|
-
* @param checkThis The possibly undefined candidate
|
|
24
|
-
*/
|
|
25
|
-
static eq(good: FragType, checkThis: FragType | undefined): boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Checks if the base types, ignoring aggregate, are equal
|
|
28
|
-
* @param left Left type
|
|
29
|
-
* @param right Right type
|
|
30
|
-
* @param nullOk True if a NULL is an acceptable match
|
|
31
|
-
*/
|
|
32
|
-
static typeEq(left: FragType, right: FragType, nullOk?: boolean): boolean;
|
|
33
|
-
/**
|
|
34
|
-
*
|
|
35
|
-
* For error messages, returns a comma seperated list of readable names
|
|
36
|
-
* for a list of types.
|
|
37
|
-
* @param types List of type or objects with types
|
|
38
|
-
*/
|
|
39
|
-
static inspect(...types: (FragType | undefined)[]): string;
|
|
40
|
-
static nullT: FragType;
|
|
41
|
-
static numberT: FragType;
|
|
42
|
-
static stringT: FragType;
|
|
43
|
-
static dateT: FragType;
|
|
44
|
-
static timestampT: FragType;
|
|
45
|
-
static boolT: FragType;
|
|
46
|
-
static anyAtomicT: FragType[];
|
|
47
|
-
}
|
|
48
|
-
export declare type ExprValue = ExprResult | GranularResult;
|
|
49
|
-
export interface ExprResult extends FragType {
|
|
50
|
-
value: Fragment[];
|
|
51
|
-
}
|
|
52
|
-
export interface TimeResult extends ExprResult {
|
|
53
|
-
dataType: TimeFieldType;
|
|
54
|
-
alsoTimestamp?: true;
|
|
55
|
-
}
|
|
56
|
-
export interface GranularResult extends TimeResult {
|
|
57
|
-
timeframe: TimestampUnit;
|
|
58
|
-
}
|
|
59
|
-
export declare function isGranularResult(v: ExprValue): v is GranularResult;
|
|
60
|
-
/**
|
|
61
|
-
* When a translation hits an error, log and return one of these as a value.
|
|
62
|
-
* This will allow the rest of the translation walk to complete. The
|
|
63
|
-
* generated SQL will have a reference to an impossible variable name
|
|
64
|
-
* with the reason embedded in it.
|
|
65
|
-
* @param reason very short phrase, only read by implementers
|
|
66
|
-
* @returns Fragment[] which a debugging humnan will regognize
|
|
67
|
-
*/
|
|
68
|
-
export declare function errorFor(reason: string): ExprValue;
|
|
69
|
-
export declare function compressExpr(expr: Expr): Expr;
|
|
70
|
-
/**
|
|
71
|
-
* Compose a binary expression. Tries to write them safely and concisely
|
|
72
|
-
* @param left
|
|
73
|
-
* @param op
|
|
74
|
-
* @param right
|
|
75
|
-
* @returns Fragment list of the composed expression
|
|
76
|
-
*/
|
|
77
|
-
export declare function compose(left: Fragment[], op: string, right: Fragment[]): Fragment[];
|
|
78
|
-
export declare function dateOffset(from: Fragment[], op: "+" | "-", n: Fragment[], timeframe: TimestampUnit): Fragment[];
|
|
79
|
-
export declare function timestampOffset(from: Fragment[], op: "+" | "-", n: Fragment[], timeframe: TimestampUnit, fromNotTimestamp?: boolean): Fragment[];
|
|
80
|
-
export declare type Comparison = "~" | "!~" | "<" | "<=" | "=" | ">" | ">=" | "!=";
|
|
81
|
-
export declare function isComparison(s: string): s is Comparison;
|
|
82
|
-
export declare type Equality = "~" | "!~" | "=" | "!=";
|
|
83
|
-
export declare function isEquality(s: string): s is Equality;
|