@malloydata/malloy 0.0.2 → 0.0.4
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 +12 -11
- package/dist/dialect/duckdb.d.ts +1 -1
- package/dist/dialect/postgres.d.ts +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/lang/ast/ast-expr.d.ts +0 -1
- package/dist/lang/field-space.d.ts +9 -7
- package/dist/lang/lib/Malloy/MalloyLexer.d.ts +108 -106
- package/dist/lang/lib/Malloy/MalloyLexer.js +1019 -1006
- package/dist/lang/lib/Malloy/MalloyParser.d.ts +581 -590
- package/dist/lang/lib/Malloy/MalloyParser.js +1141 -1202
- package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +2015 -0
- package/dist/lang/lib/Malloy/MalloyParserListener.js +4 -0
- package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +1269 -0
- package/dist/lang/lib/Malloy/MalloyParserVisitor.js +4 -0
- package/dist/lang/parse-to-ast.d.ts +3 -4
- package/dist/lang/parse-to-ast.js +1 -1
- package/dist/lang/parse-tree-walkers/document-completion-walker.js +2 -0
- package/dist/lang/parse-tree-walkers/explore-query-walker.d.ts +2 -2
- package/dist/malloy.d.ts +1 -1
- package/dist/md5.d.ts +1 -0
- package/dist/md5.js +30 -0
- package/dist/model/malloy_types.d.ts +3 -1
- package/package.json +9 -14
- package/dist/connection_utils.js +0 -56
- package/dist/dialect/dialect-map.d.ts +0 -3
- package/dist/dialect/dialect-map.js +0 -33
- package/dist/dialect/dialect.js +0 -77
- package/dist/dialect/dialect_map.js +0 -35
- package/dist/dialect/duckdb.js +0 -349
- package/dist/dialect/index.js +0 -27
- package/dist/dialect/postgres.js +0 -308
- package/dist/dialect/standardsql.js +0 -361
- package/dist/index.js +0 -47
- package/dist/lang/ast/apply-expr.js +0 -231
- package/dist/lang/ast/ast-expr.js +0 -1051
- package/dist/lang/ast/ast-main.js +0 -2086
- package/dist/lang/ast/ast-time-expr.js +0 -549
- package/dist/lang/ast/ast-types.js +0 -215
- package/dist/lang/ast/index.js +0 -34
- package/dist/lang/ast/time-utils.js +0 -94
- package/dist/lang/field-space.js +0 -629
- package/dist/lang/field-utils.js +0 -33
- package/dist/lang/index.js +0 -22
- package/dist/lang/parse-log.js +0 -41
- package/dist/lang/reference-list.js +0 -80
- package/dist/lang/space-field.js +0 -346
- package/dist/lang/test/document-help-context-walker.spec.js +0 -45
- package/dist/lang/test/document-symbol-walker.spec.js +0 -100
- package/dist/lang/test/field-symbols.spec.js +0 -172
- package/dist/lang/test/parse.spec.js +0 -1936
- package/dist/lang/test/test-translator.js +0 -334
- package/dist/lang/zone.js +0 -97
- package/dist/malloy.js +0 -2354
- package/dist/model/index.js +0 -34
- package/dist/model/malloy-query.d.ts +0 -313
- package/dist/model/malloy-query.js +0 -2603
- package/dist/model/malloy-types.d.ts +0 -404
- package/dist/model/malloy-types.js +0 -242
- package/dist/model/malloy_query.js +0 -2996
- package/dist/model/malloy_types.js +0 -283
- package/dist/model/sql-block.d.ts +0 -11
- package/dist/model/sql-block.js +0 -38
- package/dist/model/sql_block.js +0 -41
- package/dist/model/utils.js +0 -84
- package/dist/runtime-types.d.ts +0 -116
- package/dist/runtime-types.js +0 -40
- package/dist/runtime_types.js +0 -15
|
@@ -1,215 +0,0 @@
|
|
|
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
|
package/dist/lang/ast/index.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
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
|
|
@@ -1,94 +0,0 @@
|
|
|
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.timeLiteral = 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
|
-
function timeLiteral(literalStr, timeType, tz) {
|
|
84
|
-
const fragment = {
|
|
85
|
-
type: "dialect",
|
|
86
|
-
function: "timeLiteral",
|
|
87
|
-
literal: literalStr,
|
|
88
|
-
literalType: timeType,
|
|
89
|
-
timezone: tz,
|
|
90
|
-
};
|
|
91
|
-
return [fragment];
|
|
92
|
-
}
|
|
93
|
-
exports.timeLiteral = timeLiteral;
|
|
94
|
-
//# sourceMappingURL=time-utils.js.map
|