@malloydata/malloy 0.0.1
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/README.md +39 -0
- package/dist/connection_utils.d.ts +1 -0
- package/dist/connection_utils.js +56 -0
- package/dist/dialect/dialect-map.d.ts +3 -0
- package/dist/dialect/dialect-map.js +33 -0
- package/dist/dialect/dialect.d.ts +64 -0
- package/dist/dialect/dialect.js +64 -0
- package/dist/dialect/dialect_map.d.ts +3 -0
- package/dist/dialect/dialect_map.js +35 -0
- package/dist/dialect/duckdb.d.ts +49 -0
- package/dist/dialect/duckdb.js +349 -0
- package/dist/dialect/index.d.ts +6 -0
- package/dist/dialect/index.js +27 -0
- package/dist/dialect/postgres.d.ts +49 -0
- package/dist/dialect/postgres.js +308 -0
- package/dist/dialect/standardsql.d.ts +46 -0
- package/dist/dialect/standardsql.js +361 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +47 -0
- package/dist/lang/ast/apply-expr.d.ts +16 -0
- package/dist/lang/ast/apply-expr.js +215 -0
- package/dist/lang/ast/ast-expr.d.ts +291 -0
- package/dist/lang/ast/ast-expr.js +1056 -0
- package/dist/lang/ast/ast-main.d.ts +480 -0
- package/dist/lang/ast/ast-main.js +2096 -0
- package/dist/lang/ast/ast-time-expr.d.ts +109 -0
- package/dist/lang/ast/ast-time-expr.js +550 -0
- package/dist/lang/ast/ast-types.d.ts +83 -0
- package/dist/lang/ast/ast-types.js +215 -0
- package/dist/lang/ast/index.d.ts +5 -0
- package/dist/lang/ast/index.js +34 -0
- package/dist/lang/ast/time-utils.d.ts +8 -0
- package/dist/lang/ast/time-utils.js +83 -0
- package/dist/lang/field-space.d.ts +157 -0
- package/dist/lang/field-space.js +651 -0
- package/dist/lang/field-utils.d.ts +5 -0
- package/dist/lang/field-utils.js +33 -0
- package/dist/lang/index.d.ts +9 -0
- package/dist/lang/index.js +22 -0
- package/dist/lang/lib/Malloy/MalloyLexer.d.ts +156 -0
- package/dist/lang/lib/Malloy/MalloyLexer.js +1163 -0
- package/dist/lang/lib/Malloy/MalloyListener.d.ts +2026 -0
- package/dist/lang/lib/Malloy/MalloyListener.js +4 -0
- package/dist/lang/lib/Malloy/MalloyParser.d.ts +1920 -0
- package/dist/lang/lib/Malloy/MalloyParser.js +11790 -0
- package/dist/lang/lib/Malloy/MalloyVisitor.d.ts +1276 -0
- package/dist/lang/lib/Malloy/MalloyVisitor.js +4 -0
- package/dist/lang/parse-log.d.ts +27 -0
- package/dist/lang/parse-log.js +41 -0
- package/dist/lang/parse-malloy.d.ts +245 -0
- package/dist/lang/parse-malloy.js +729 -0
- package/dist/lang/parse-to-ast.d.ts +156 -0
- package/dist/lang/parse-to-ast.js +945 -0
- package/dist/lang/parse-tree-walkers/document-completion-walker.d.ts +10 -0
- package/dist/lang/parse-tree-walkers/document-completion-walker.js +136 -0
- package/dist/lang/parse-tree-walkers/document-help-context-walker.d.ts +9 -0
- package/dist/lang/parse-tree-walkers/document-help-context-walker.js +97 -0
- package/dist/lang/parse-tree-walkers/document-highlight-walker.d.ts +83 -0
- package/dist/lang/parse-tree-walkers/document-highlight-walker.js +375 -0
- package/dist/lang/parse-tree-walkers/document-symbol-walker.d.ts +11 -0
- package/dist/lang/parse-tree-walkers/document-symbol-walker.js +172 -0
- package/dist/lang/parse-tree-walkers/explore-query-walker.d.ts +34 -0
- package/dist/lang/parse-tree-walkers/explore-query-walker.js +64 -0
- package/dist/lang/parse-tree-walkers/find-external-references.d.ts +11 -0
- package/dist/lang/parse-tree-walkers/find-external-references.js +51 -0
- package/dist/lang/reference-list.d.ts +10 -0
- package/dist/lang/reference-list.js +80 -0
- package/dist/lang/space-field.d.ts +119 -0
- package/dist/lang/space-field.js +339 -0
- package/dist/lang/test/document-help-context-walker.spec.d.ts +1 -0
- package/dist/lang/test/document-help-context-walker.spec.js +45 -0
- package/dist/lang/test/document-symbol-walker.spec.d.ts +1 -0
- package/dist/lang/test/document-symbol-walker.spec.js +100 -0
- package/dist/lang/test/field-symbols.spec.d.ts +1 -0
- package/dist/lang/test/field-symbols.spec.js +172 -0
- package/dist/lang/test/parse.spec.d.ts +12 -0
- package/dist/lang/test/parse.spec.js +1936 -0
- package/dist/lang/test/test-translator.d.ts +38 -0
- package/dist/lang/test/test-translator.js +334 -0
- package/dist/lang/zone.d.ts +57 -0
- package/dist/lang/zone.js +97 -0
- package/dist/malloy.d.ts +1134 -0
- package/dist/malloy.js +2354 -0
- package/dist/model/index.d.ts +2 -0
- package/dist/model/index.js +34 -0
- package/dist/model/malloy-query.d.ts +313 -0
- package/dist/model/malloy-query.js +2603 -0
- package/dist/model/malloy-types.d.ts +404 -0
- package/dist/model/malloy-types.js +242 -0
- package/dist/model/malloy_query.d.ts +353 -0
- package/dist/model/malloy_query.js +2990 -0
- package/dist/model/malloy_types.d.ts +502 -0
- package/dist/model/malloy_types.js +283 -0
- package/dist/model/sql-block.d.ts +11 -0
- package/dist/model/sql-block.js +38 -0
- package/dist/model/sql_block.d.ts +11 -0
- package/dist/model/sql_block.js +41 -0
- package/dist/model/utils.d.ts +21 -0
- package/dist/model/utils.js +84 -0
- package/dist/runtime-types.d.ts +116 -0
- package/dist/runtime-types.js +40 -0
- package/dist/runtime_types.d.ts +119 -0
- package/dist/runtime_types.js +15 -0
- package/package.json +36 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { AtomicFieldType, Fragment, TimestampUnit, Expr, TimeFieldType } 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
|
+
aggregate: boolean;
|
|
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;
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2021 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* This program is free software; you can redistribute it and/or
|
|
6
|
+
* modify it under the terms of the GNU General Public License
|
|
7
|
+
* version 2 as published by the Free Software Foundation.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU General Public License for more details.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.isEquality = exports.isComparison = exports.timestampOffset = exports.dateOffset = exports.compose = exports.compressExpr = exports.errorFor = exports.isGranularResult = exports.FT = exports.isExpressionValueType = void 0;
|
|
16
|
+
const malloy_types_1 = require("../../model/malloy_types");
|
|
17
|
+
function isExpressionValueType(fv) {
|
|
18
|
+
return ((0, malloy_types_1.isAtomicFieldType)(fv) ||
|
|
19
|
+
["null", "unknown", "duration", "regular expression"].includes(fv));
|
|
20
|
+
}
|
|
21
|
+
exports.isExpressionValueType = isExpressionValueType;
|
|
22
|
+
/**
|
|
23
|
+
* Collects functions which operate on fragtype compatible objects
|
|
24
|
+
*/
|
|
25
|
+
class FT {
|
|
26
|
+
/**
|
|
27
|
+
* Checks if a given type is in a list
|
|
28
|
+
* @param check The type to check (can be undefined)
|
|
29
|
+
* @param from List of types which are OK
|
|
30
|
+
*/
|
|
31
|
+
static in(check, from) {
|
|
32
|
+
if (check) {
|
|
33
|
+
const found = from.find((okType) => FT.eq(okType, check));
|
|
34
|
+
return found !== undefined;
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Checks if a possibly undefined candidate matches a type
|
|
40
|
+
* @param good The real type
|
|
41
|
+
* @param checkThis The possibly undefined candidate
|
|
42
|
+
*/
|
|
43
|
+
static eq(good, checkThis) {
|
|
44
|
+
return (checkThis !== undefined &&
|
|
45
|
+
good.dataType === checkThis.dataType &&
|
|
46
|
+
good.aggregate === checkThis.aggregate);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Checks if the base types, ignoring aggregate, are equal
|
|
50
|
+
* @param left Left type
|
|
51
|
+
* @param right Right type
|
|
52
|
+
* @param nullOk True if a NULL is an acceptable match
|
|
53
|
+
*/
|
|
54
|
+
static typeEq(left, right, nullOk = false) {
|
|
55
|
+
const maybeEq = left.dataType === right.dataType;
|
|
56
|
+
const nullEq = nullOk && (left.dataType === "null" || right.dataType === "null");
|
|
57
|
+
return maybeEq || nullEq;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
*
|
|
61
|
+
* For error messages, returns a comma seperated list of readable names
|
|
62
|
+
* for a list of types.
|
|
63
|
+
* @param types List of type or objects with types
|
|
64
|
+
*/
|
|
65
|
+
static inspect(...types) {
|
|
66
|
+
const strings = types.map((type) => {
|
|
67
|
+
if (type) {
|
|
68
|
+
let inspected = type.dataType;
|
|
69
|
+
if (type.aggregate) {
|
|
70
|
+
inspected = `aggregate ${inspected}`;
|
|
71
|
+
}
|
|
72
|
+
return inspected;
|
|
73
|
+
}
|
|
74
|
+
return "undefined";
|
|
75
|
+
});
|
|
76
|
+
return strings.join(",");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.FT = FT;
|
|
80
|
+
FT.nullT = mkFragType("null");
|
|
81
|
+
FT.numberT = mkFragType("number");
|
|
82
|
+
FT.stringT = mkFragType("string");
|
|
83
|
+
FT.dateT = mkFragType("date");
|
|
84
|
+
FT.timestampT = mkFragType("timestamp");
|
|
85
|
+
FT.boolT = mkFragType("boolean");
|
|
86
|
+
FT.anyAtomicT = [
|
|
87
|
+
FT.numberT,
|
|
88
|
+
FT.stringT,
|
|
89
|
+
FT.dateT,
|
|
90
|
+
FT.timestampT,
|
|
91
|
+
FT.boolT,
|
|
92
|
+
];
|
|
93
|
+
function mkFragType(dType) {
|
|
94
|
+
return { dataType: dType, aggregate: false };
|
|
95
|
+
}
|
|
96
|
+
function isGranularResult(v) {
|
|
97
|
+
if (v.dataType !== "date" && v.dataType !== "timestamp") {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
return v.timeframe !== undefined;
|
|
101
|
+
}
|
|
102
|
+
exports.isGranularResult = isGranularResult;
|
|
103
|
+
/**
|
|
104
|
+
* When a translation hits an error, log and return one of these as a value.
|
|
105
|
+
* This will allow the rest of the translation walk to complete. The
|
|
106
|
+
* generated SQL will have a reference to an impossible variable name
|
|
107
|
+
* with the reason embedded in it.
|
|
108
|
+
* @param reason very short phrase, only read by implementers
|
|
109
|
+
* @returns Fragment[] which a debugging humnan will regognize
|
|
110
|
+
*/
|
|
111
|
+
function errorFor(reason) {
|
|
112
|
+
return {
|
|
113
|
+
dataType: "unknown",
|
|
114
|
+
aggregate: false,
|
|
115
|
+
value: [`_ERROR_${reason.replace(/ /g, "_")}`],
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
exports.errorFor = errorFor;
|
|
119
|
+
/**
|
|
120
|
+
* If the passed expresion is not a single term, wrap it in parens
|
|
121
|
+
* @param f expression fragment
|
|
122
|
+
*/
|
|
123
|
+
function term(f) {
|
|
124
|
+
if (f.length > 1) {
|
|
125
|
+
return ["(", ...f, ")"];
|
|
126
|
+
}
|
|
127
|
+
if (f.length === 0) {
|
|
128
|
+
// Trying to compose a binary expresion with an entity that has no value
|
|
129
|
+
// this should at least cause the generated SQL to error, but likely
|
|
130
|
+
// there has already been a semantic error reported.
|
|
131
|
+
return ["__MISSING_VALUE__"];
|
|
132
|
+
}
|
|
133
|
+
return f;
|
|
134
|
+
}
|
|
135
|
+
function compressExpr(expr) {
|
|
136
|
+
// compress all adjacent strings
|
|
137
|
+
const compressValue = [];
|
|
138
|
+
let buildString;
|
|
139
|
+
for (const fragment of expr.flat()) {
|
|
140
|
+
if (typeof fragment === "string") {
|
|
141
|
+
buildString = buildString ? buildString + fragment : fragment;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
if (buildString) {
|
|
145
|
+
compressValue.push(buildString);
|
|
146
|
+
buildString = undefined;
|
|
147
|
+
}
|
|
148
|
+
compressValue.push(fragment);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (buildString) {
|
|
152
|
+
compressValue.push(buildString);
|
|
153
|
+
}
|
|
154
|
+
return compressValue;
|
|
155
|
+
}
|
|
156
|
+
exports.compressExpr = compressExpr;
|
|
157
|
+
/**
|
|
158
|
+
* Compose a binary expression. Tries to write them safely and concisely
|
|
159
|
+
* @param left
|
|
160
|
+
* @param op
|
|
161
|
+
* @param right
|
|
162
|
+
* @returns Fragment list of the composed expression
|
|
163
|
+
*/
|
|
164
|
+
function compose(left, op, right) {
|
|
165
|
+
const opAlpha = op.match(/^[A-Za-z]/);
|
|
166
|
+
const leftSpace = left.length === 1 && opAlpha ? " " : "";
|
|
167
|
+
const rightSpace = right.length === 1 && opAlpha ? " " : "";
|
|
168
|
+
const newOp = leftSpace + op + rightSpace;
|
|
169
|
+
return [...term(left), newOp, ...term(right)];
|
|
170
|
+
}
|
|
171
|
+
exports.compose = compose;
|
|
172
|
+
function dateOffset(from, op, n, timeframe) {
|
|
173
|
+
const add = op === "+" ? "_ADD" : "_SUB";
|
|
174
|
+
const units = timeframe.toUpperCase();
|
|
175
|
+
return compressExpr([
|
|
176
|
+
`DATE${add}(`,
|
|
177
|
+
...from,
|
|
178
|
+
`,INTERVAL `,
|
|
179
|
+
...n,
|
|
180
|
+
` ${units})`,
|
|
181
|
+
]);
|
|
182
|
+
}
|
|
183
|
+
exports.dateOffset = dateOffset;
|
|
184
|
+
function timestampOffset(from, op, n, timeframe, fromNotTimestamp = false) {
|
|
185
|
+
const useDatetime = ["week", "month", "quarter", "year"].includes(timeframe);
|
|
186
|
+
const add = op === "+" ? "_ADD" : "_SUB";
|
|
187
|
+
const units = timeframe.toUpperCase();
|
|
188
|
+
if (useDatetime) {
|
|
189
|
+
return [
|
|
190
|
+
`TIMESTAMP(DATETIME${add}(DATETIME(`,
|
|
191
|
+
...from,
|
|
192
|
+
`),INTERVAL `,
|
|
193
|
+
...n,
|
|
194
|
+
` ${units}))`,
|
|
195
|
+
];
|
|
196
|
+
}
|
|
197
|
+
const typeFrom = fromNotTimestamp ? ["TIMESTAMP(", ...from, ")"] : from;
|
|
198
|
+
return compressExpr([
|
|
199
|
+
`TIMESTAMP${add}(`,
|
|
200
|
+
...typeFrom,
|
|
201
|
+
`,INTERVAL `,
|
|
202
|
+
...n,
|
|
203
|
+
` ${units})`,
|
|
204
|
+
]);
|
|
205
|
+
}
|
|
206
|
+
exports.timestampOffset = timestampOffset;
|
|
207
|
+
function isComparison(s) {
|
|
208
|
+
return ["~", "!~", "<", "<=", "=", ">", ">=", "!="].includes(s);
|
|
209
|
+
}
|
|
210
|
+
exports.isComparison = isComparison;
|
|
211
|
+
function isEquality(s) {
|
|
212
|
+
return ["~", "!~", "=", "!="].includes(s);
|
|
213
|
+
}
|
|
214
|
+
exports.isEquality = isEquality;
|
|
215
|
+
//# sourceMappingURL=ast-types.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2021 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* This program is free software; you can redistribute it and/or
|
|
6
|
+
* modify it under the terms of the GNU General Public License
|
|
7
|
+
* version 2 as published by the Free Software Foundation.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU General Public License for more details.
|
|
13
|
+
*/
|
|
14
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
17
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
18
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
19
|
+
}
|
|
20
|
+
Object.defineProperty(o, k2, desc);
|
|
21
|
+
}) : (function(o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
}));
|
|
25
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
__exportStar(require("./ast-types"), exports);
|
|
30
|
+
__exportStar(require("./ast-main"), exports);
|
|
31
|
+
__exportStar(require("./ast-expr"), exports);
|
|
32
|
+
__exportStar(require("./ast-time-expr"), exports);
|
|
33
|
+
__exportStar(require("./time-utils"), exports);
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { TimestampUnit, Expr, TimeFieldType, AtomicFieldType } from "../../model/malloy_types";
|
|
2
|
+
import { GranularResult, TimeResult } from "./ast-types";
|
|
3
|
+
export declare function timeOffset(timeType: TimeFieldType, from: Expr, op: "+" | "-", n: Expr, timeframe: TimestampUnit): Expr;
|
|
4
|
+
export declare function castTo(castType: AtomicFieldType, from: Expr, safe?: boolean): Expr;
|
|
5
|
+
export declare function castTimestampToDate(from: Expr, safe?: boolean): Expr;
|
|
6
|
+
export declare function castDateToTimestamp(from: Expr, safe?: boolean): Expr;
|
|
7
|
+
export declare function resolution(timeframe: string): TimeFieldType;
|
|
8
|
+
export declare function timeResult(t: TimeResult, tt: TimestampUnit | undefined): TimeResult | GranularResult;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2021 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* This program is free software; you can redistribute it and/or
|
|
6
|
+
* modify it under the terms of the GNU General Public License
|
|
7
|
+
* version 2 as published by the Free Software Foundation.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU General Public License for more details.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.timeResult = exports.resolution = exports.castDateToTimestamp = exports.castTimestampToDate = exports.castTo = exports.timeOffset = void 0;
|
|
16
|
+
function timeOffset(timeType, from, op, n, timeframe) {
|
|
17
|
+
return [
|
|
18
|
+
{
|
|
19
|
+
type: "dialect",
|
|
20
|
+
function: "delta",
|
|
21
|
+
base: { valueType: timeType, value: from },
|
|
22
|
+
op,
|
|
23
|
+
delta: n,
|
|
24
|
+
units: timeframe,
|
|
25
|
+
},
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
exports.timeOffset = timeOffset;
|
|
29
|
+
function castTo(castType, from, safe = false) {
|
|
30
|
+
const cast = {
|
|
31
|
+
type: "dialect",
|
|
32
|
+
function: "cast",
|
|
33
|
+
dstType: castType,
|
|
34
|
+
expr: from,
|
|
35
|
+
safe,
|
|
36
|
+
};
|
|
37
|
+
return [cast];
|
|
38
|
+
}
|
|
39
|
+
exports.castTo = castTo;
|
|
40
|
+
function castTimestampToDate(from, safe = false) {
|
|
41
|
+
const cast = {
|
|
42
|
+
type: "dialect",
|
|
43
|
+
function: "cast",
|
|
44
|
+
dstType: "date",
|
|
45
|
+
srcType: "timestamp",
|
|
46
|
+
expr: from,
|
|
47
|
+
safe,
|
|
48
|
+
};
|
|
49
|
+
return [cast];
|
|
50
|
+
}
|
|
51
|
+
exports.castTimestampToDate = castTimestampToDate;
|
|
52
|
+
function castDateToTimestamp(from, safe = false) {
|
|
53
|
+
const cast = {
|
|
54
|
+
type: "dialect",
|
|
55
|
+
function: "cast",
|
|
56
|
+
dstType: "timestamp",
|
|
57
|
+
srcType: "date",
|
|
58
|
+
expr: from,
|
|
59
|
+
safe,
|
|
60
|
+
};
|
|
61
|
+
return [cast];
|
|
62
|
+
}
|
|
63
|
+
exports.castDateToTimestamp = castDateToTimestamp;
|
|
64
|
+
function resolution(timeframe) {
|
|
65
|
+
switch (timeframe) {
|
|
66
|
+
case "hour":
|
|
67
|
+
case "minute":
|
|
68
|
+
case "second":
|
|
69
|
+
case "microsecond":
|
|
70
|
+
case "millisecond":
|
|
71
|
+
return "timestamp";
|
|
72
|
+
}
|
|
73
|
+
return "date";
|
|
74
|
+
}
|
|
75
|
+
exports.resolution = resolution;
|
|
76
|
+
function timeResult(t, tt) {
|
|
77
|
+
if (tt) {
|
|
78
|
+
return { ...t, timeframe: tt };
|
|
79
|
+
}
|
|
80
|
+
return t;
|
|
81
|
+
}
|
|
82
|
+
exports.timeResult = timeResult;
|
|
83
|
+
//# sourceMappingURL=time-utils.js.map
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { Dialect } from "../dialect";
|
|
2
|
+
import * as model from "../model/malloy_types";
|
|
3
|
+
import { ExploreField, FieldListEdit, FieldDeclaration, WildcardFieldReference, Join, FieldName, HasParameter, FieldCollectionMember, QueryItem, MalloyElement, FieldReference } from "./ast";
|
|
4
|
+
import { SpaceField, SpaceEntry } from "./space-field";
|
|
5
|
+
interface LookupFound {
|
|
6
|
+
found: SpaceEntry;
|
|
7
|
+
error: undefined;
|
|
8
|
+
}
|
|
9
|
+
interface LookupError {
|
|
10
|
+
error: string;
|
|
11
|
+
found: undefined;
|
|
12
|
+
}
|
|
13
|
+
export declare type LookupResult = LookupFound | LookupError;
|
|
14
|
+
/**
|
|
15
|
+
* A FieldSpace is a hierarchy of namespaces, where the leaf nodes
|
|
16
|
+
* are fields. A FieldSpace can lookup fields, and generate a StructDef
|
|
17
|
+
*/
|
|
18
|
+
export interface FieldSpace {
|
|
19
|
+
type: "fieldSpace";
|
|
20
|
+
structDef(): model.StructDef;
|
|
21
|
+
emptyStructDef(): model.StructDef;
|
|
22
|
+
lookup(symbol: FieldName[]): LookupResult;
|
|
23
|
+
getDialect(): Dialect;
|
|
24
|
+
whenComplete: (step: () => void) => void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The father of all FieldSpaces is a wrapper for a StructDef.
|
|
28
|
+
*/
|
|
29
|
+
export declare class StaticSpace implements FieldSpace {
|
|
30
|
+
readonly type = "fieldSpace";
|
|
31
|
+
private memoMap?;
|
|
32
|
+
protected fromStruct: model.StructDef;
|
|
33
|
+
constructor(sourceStructDef: model.StructDef);
|
|
34
|
+
whenComplete(step: () => void): void;
|
|
35
|
+
getDialect(): Dialect;
|
|
36
|
+
fromFieldDef(from: model.FieldDef): SpaceField;
|
|
37
|
+
private get map();
|
|
38
|
+
protected dropEntries(): void;
|
|
39
|
+
protected dropEntry(name: string): void;
|
|
40
|
+
protected entry(name: string): SpaceEntry | undefined;
|
|
41
|
+
protected setEntry(name: string, value: SpaceEntry): void;
|
|
42
|
+
protected entries(): [string, SpaceEntry][];
|
|
43
|
+
structDef(): model.StructDef;
|
|
44
|
+
emptyStructDef(): model.StructDef;
|
|
45
|
+
lookup(path: FieldName[]): LookupResult;
|
|
46
|
+
}
|
|
47
|
+
export declare type SourceSpec = model.StructDef | FieldSpace;
|
|
48
|
+
/**
|
|
49
|
+
* Based on how things are constructed, the starting field space
|
|
50
|
+
* can either be another field space or an existing structdef.
|
|
51
|
+
* Using a SourceSpace allows a class to accept either one
|
|
52
|
+
* and use either version at some future time.
|
|
53
|
+
*/
|
|
54
|
+
declare class SourceSpace {
|
|
55
|
+
readonly sourceSpec: SourceSpec;
|
|
56
|
+
private spaceSpec;
|
|
57
|
+
private asFS?;
|
|
58
|
+
private asStruct?;
|
|
59
|
+
constructor(sourceSpec: SourceSpec);
|
|
60
|
+
get structDef(): model.StructDef;
|
|
61
|
+
get fieldSpace(): FieldSpace;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A FieldSpace which may undergo modification
|
|
65
|
+
*/
|
|
66
|
+
export declare class DynamicSpace extends StaticSpace {
|
|
67
|
+
protected final: model.StructDef | undefined;
|
|
68
|
+
protected source: SourceSpace;
|
|
69
|
+
outputFS?: QuerySpace;
|
|
70
|
+
completions: (() => void)[];
|
|
71
|
+
private complete;
|
|
72
|
+
constructor(extending: SourceSpec);
|
|
73
|
+
/**
|
|
74
|
+
* Factory for DynamicSpace when there are accept/except edits
|
|
75
|
+
* @param from A structdef which seeds this space
|
|
76
|
+
* @param choose A accept/except edit of the "from" fields
|
|
77
|
+
*/
|
|
78
|
+
static filteredFrom(from: model.StructDef, choose?: FieldListEdit): DynamicSpace;
|
|
79
|
+
whenComplete(finalizeStep: () => void): void;
|
|
80
|
+
isComplete(): void;
|
|
81
|
+
protected setEntry(name: string, value: SpaceEntry): void;
|
|
82
|
+
addParameters(params: HasParameter[]): DynamicSpace;
|
|
83
|
+
newEntry(name: string, astEl: MalloyElement, entry: SpaceEntry): void;
|
|
84
|
+
addField(...defs: ExploreField[]): void;
|
|
85
|
+
addFieldDef(fd: model.FieldDef): void;
|
|
86
|
+
structDef(): model.StructDef;
|
|
87
|
+
}
|
|
88
|
+
declare type QuerySegType = "reduce" | "project" | "index";
|
|
89
|
+
/**
|
|
90
|
+
* A namespace for Query operations. The have an input and an
|
|
91
|
+
* output set of fields.
|
|
92
|
+
*/
|
|
93
|
+
export declare abstract class QueryOperationSpace extends DynamicSpace {
|
|
94
|
+
abstract segType: QuerySegType;
|
|
95
|
+
astEl?: MalloyElement | undefined;
|
|
96
|
+
readonly queryInput: SourceSpace;
|
|
97
|
+
nestParent?: QuerySpace;
|
|
98
|
+
constructor(input: SourceSpec);
|
|
99
|
+
inputFS(): FieldSpace;
|
|
100
|
+
structDef(): model.StructDef;
|
|
101
|
+
abstract getPipeSegment(refineFrom: model.PipeSegment | undefined): model.PipeSegment;
|
|
102
|
+
addMembers(members: FieldCollectionMember[]): void;
|
|
103
|
+
addReference(ref: FieldReference): void;
|
|
104
|
+
addWild(wild: WildcardFieldReference): void;
|
|
105
|
+
log(s: string): void;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Reduce and project queries use a "QuerySpace"
|
|
109
|
+
*/
|
|
110
|
+
export declare abstract class QuerySpace extends QueryOperationSpace {
|
|
111
|
+
extendedInput?: DynamicSpace;
|
|
112
|
+
extendedFields: string[];
|
|
113
|
+
extendSource(extendField: Join | FieldDeclaration): void;
|
|
114
|
+
inputFS(): FieldSpace;
|
|
115
|
+
qfs(): FSPair;
|
|
116
|
+
checkUngroup(fn: FieldName, isExclude: boolean): void;
|
|
117
|
+
private extendInto;
|
|
118
|
+
getPipeSegment(refineFrom: model.QuerySegment | undefined): model.QuerySegment;
|
|
119
|
+
addQueryItems(...qiList: QueryItem[]): void;
|
|
120
|
+
canContain(_qd: model.QueryFieldDef): boolean;
|
|
121
|
+
protected queryFieldDefs(): model.QueryFieldDef[];
|
|
122
|
+
}
|
|
123
|
+
export declare class ReduceFieldSpace extends QuerySpace {
|
|
124
|
+
segType: QuerySegType;
|
|
125
|
+
}
|
|
126
|
+
export declare class ProjectFieldSpace extends QuerySpace {
|
|
127
|
+
segType: QuerySegType;
|
|
128
|
+
canContain(qd: model.QueryFieldDef): boolean;
|
|
129
|
+
}
|
|
130
|
+
export declare class IndexFieldSpace extends QueryOperationSpace {
|
|
131
|
+
segType: QuerySegType;
|
|
132
|
+
fieldList: Set<string>;
|
|
133
|
+
addReference(ref: FieldReference): void;
|
|
134
|
+
addWild(wild: WildcardFieldReference): void;
|
|
135
|
+
getPipeSegment(refineIndex?: model.PipeSegment): model.IndexSegment;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Used to detect references to fields in the statement which defines them
|
|
139
|
+
*/
|
|
140
|
+
export declare class DefSpace implements FieldSpace {
|
|
141
|
+
readonly realFS: FieldSpace;
|
|
142
|
+
readonly circular: FieldDeclaration;
|
|
143
|
+
readonly type = "fieldSpace";
|
|
144
|
+
foundCircle: boolean;
|
|
145
|
+
constructor(realFS: FieldSpace, circular: FieldDeclaration);
|
|
146
|
+
structDef(): model.StructDef;
|
|
147
|
+
emptyStructDef(): model.StructDef;
|
|
148
|
+
lookup(symbol: FieldName[]): LookupResult;
|
|
149
|
+
getDialect(): Dialect;
|
|
150
|
+
whenComplete(step: () => void): void;
|
|
151
|
+
}
|
|
152
|
+
export interface FSPair {
|
|
153
|
+
in: FieldSpace;
|
|
154
|
+
out: FieldSpace;
|
|
155
|
+
}
|
|
156
|
+
export declare function fsPair(inFS: FieldSpace, outFS?: FieldSpace): FSPair;
|
|
157
|
+
export {};
|