@malloydata/malloy 0.0.3 → 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/dist/lang/ast/ast-expr.d.ts +0 -1
- package/dist/lang/ast/ast-main.d.ts +2 -2
- package/package.json +1 -1
- package/dist/connection_utils.js +0 -56
- package/dist/dialect/dialect.js +0 -77
- package/dist/dialect/dialect_map.js +0 -35
- package/dist/dialect/duckdb.js +0 -347
- package/dist/dialect/index.js +0 -27
- package/dist/dialect/postgres.js +0 -315
- package/dist/dialect/standardsql.js +0 -362
- package/dist/index.js +0 -47
- package/dist/lang/ast/apply-expr.js +0 -231
- package/dist/lang/ast/ast-expr.js +0 -1041
- package/dist/lang/ast/ast-main.js +0 -2087
- 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 -631
- 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 -1951
- package/dist/lang/test/test-translator.js +0 -334
- package/dist/lang/zone.js +0 -97
- package/dist/malloy.js +0 -2360
- package/dist/model/index.js +0 -34
- package/dist/model/malloy_query.js +0 -2994
- package/dist/model/malloy_types.js +0 -283
- package/dist/model/sql_block.js +0 -41
- package/dist/model/utils.js +0 -84
- package/dist/runtime_types.js +0 -15
package/dist/index.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright 2022 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.toAsyncGenerator = exports.DataWriter = exports.JSONWriter = exports.CSVWriter = exports.QueryMaterializer = exports.parseTableURI = exports.Result = exports.TimestampTimeframe = exports.DateTimeframe = exports.SourceRelationship = exports.JoinRelationship = exports.MalloyError = exports.FixedConnectionMap = exports.InMemoryURLReader = exports.EmptyURLReader = exports.SingleConnectionRuntime = exports.ConnectionRuntime = exports.AtomicFieldType = exports.Runtime = exports.Malloy = exports.MalloyTranslator = exports.HighlightType = exports.isFilteredAliasedName = exports.Segment = void 0;
|
|
16
|
-
var model_1 = require("./model");
|
|
17
|
-
// Used in Composer Demo
|
|
18
|
-
Object.defineProperty(exports, "Segment", { enumerable: true, get: function () { return model_1.Segment; } });
|
|
19
|
-
Object.defineProperty(exports, "isFilteredAliasedName", { enumerable: true, get: function () { return model_1.isFilteredAliasedName; } });
|
|
20
|
-
var lang_1 = require("./lang");
|
|
21
|
-
// Neede for VSCode extension
|
|
22
|
-
Object.defineProperty(exports, "HighlightType", { enumerable: true, get: function () { return lang_1.HighlightType; } });
|
|
23
|
-
// Needed for tests only
|
|
24
|
-
Object.defineProperty(exports, "MalloyTranslator", { enumerable: true, get: function () { return lang_1.MalloyTranslator; } });
|
|
25
|
-
var malloy_1 = require("./malloy");
|
|
26
|
-
Object.defineProperty(exports, "Malloy", { enumerable: true, get: function () { return malloy_1.Malloy; } });
|
|
27
|
-
Object.defineProperty(exports, "Runtime", { enumerable: true, get: function () { return malloy_1.Runtime; } });
|
|
28
|
-
Object.defineProperty(exports, "AtomicFieldType", { enumerable: true, get: function () { return malloy_1.AtomicFieldType; } });
|
|
29
|
-
Object.defineProperty(exports, "ConnectionRuntime", { enumerable: true, get: function () { return malloy_1.ConnectionRuntime; } });
|
|
30
|
-
Object.defineProperty(exports, "SingleConnectionRuntime", { enumerable: true, get: function () { return malloy_1.SingleConnectionRuntime; } });
|
|
31
|
-
Object.defineProperty(exports, "EmptyURLReader", { enumerable: true, get: function () { return malloy_1.EmptyURLReader; } });
|
|
32
|
-
Object.defineProperty(exports, "InMemoryURLReader", { enumerable: true, get: function () { return malloy_1.InMemoryURLReader; } });
|
|
33
|
-
Object.defineProperty(exports, "FixedConnectionMap", { enumerable: true, get: function () { return malloy_1.FixedConnectionMap; } });
|
|
34
|
-
Object.defineProperty(exports, "MalloyError", { enumerable: true, get: function () { return malloy_1.MalloyError; } });
|
|
35
|
-
Object.defineProperty(exports, "JoinRelationship", { enumerable: true, get: function () { return malloy_1.JoinRelationship; } });
|
|
36
|
-
Object.defineProperty(exports, "SourceRelationship", { enumerable: true, get: function () { return malloy_1.SourceRelationship; } });
|
|
37
|
-
Object.defineProperty(exports, "DateTimeframe", { enumerable: true, get: function () { return malloy_1.DateTimeframe; } });
|
|
38
|
-
Object.defineProperty(exports, "TimestampTimeframe", { enumerable: true, get: function () { return malloy_1.TimestampTimeframe; } });
|
|
39
|
-
Object.defineProperty(exports, "Result", { enumerable: true, get: function () { return malloy_1.Result; } });
|
|
40
|
-
Object.defineProperty(exports, "parseTableURI", { enumerable: true, get: function () { return malloy_1.parseTableURI; } });
|
|
41
|
-
Object.defineProperty(exports, "QueryMaterializer", { enumerable: true, get: function () { return malloy_1.QueryMaterializer; } });
|
|
42
|
-
Object.defineProperty(exports, "CSVWriter", { enumerable: true, get: function () { return malloy_1.CSVWriter; } });
|
|
43
|
-
Object.defineProperty(exports, "JSONWriter", { enumerable: true, get: function () { return malloy_1.JSONWriter; } });
|
|
44
|
-
Object.defineProperty(exports, "DataWriter", { enumerable: true, get: function () { return malloy_1.DataWriter; } });
|
|
45
|
-
var connection_utils_1 = require("./connection_utils");
|
|
46
|
-
Object.defineProperty(exports, "toAsyncGenerator", { enumerable: true, get: function () { return connection_utils_1.toAsyncGenerator; } });
|
|
47
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,231 +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.nullsafeNot = exports.applyBinary = void 0;
|
|
16
|
-
const malloy_types_1 = require("../../model/malloy_types");
|
|
17
|
-
const index_1 = require("./index");
|
|
18
|
-
/**
|
|
19
|
-
* All of the magic of malloy expressions eventually flows to here,
|
|
20
|
-
* where an operator is applied to two values. Depending on the
|
|
21
|
-
* operator and value types this may involve transformations of
|
|
22
|
-
* the values or even the operator.
|
|
23
|
-
* @param fs FieldSpace for the symbols
|
|
24
|
-
* @param left Left value
|
|
25
|
-
* @param op The operator
|
|
26
|
-
* @param right Right Value
|
|
27
|
-
* @returns ExprValue of the expression
|
|
28
|
-
*/
|
|
29
|
-
function applyBinary(fs, left, op, right) {
|
|
30
|
-
if ((0, index_1.isEquality)(op)) {
|
|
31
|
-
return equality(fs, left, op, right);
|
|
32
|
-
}
|
|
33
|
-
if ((0, index_1.isComparison)(op)) {
|
|
34
|
-
return compare(fs, left, op, right);
|
|
35
|
-
}
|
|
36
|
-
if (oneOf(op, "+", "-")) {
|
|
37
|
-
return delta(fs, left, op, right);
|
|
38
|
-
}
|
|
39
|
-
if (oneOf(op, "*")) {
|
|
40
|
-
return numeric(fs, left, op, right);
|
|
41
|
-
}
|
|
42
|
-
if (oneOf(op, "/")) {
|
|
43
|
-
const num = left.getExpression(fs);
|
|
44
|
-
const denom = right.getExpression(fs);
|
|
45
|
-
if (num.dataType != "number") {
|
|
46
|
-
left.log("Numerator for division must be a number");
|
|
47
|
-
}
|
|
48
|
-
else if (denom.dataType != "number") {
|
|
49
|
-
right.log("Denominator for division must be a number");
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
const div = {
|
|
53
|
-
type: "dialect",
|
|
54
|
-
function: "div",
|
|
55
|
-
numerator: num.value,
|
|
56
|
-
denominator: denom.value,
|
|
57
|
-
};
|
|
58
|
-
return {
|
|
59
|
-
dataType: "number",
|
|
60
|
-
aggregate: num.aggregate || denom.aggregate,
|
|
61
|
-
value: [div],
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
return (0, index_1.errorFor)("divide type mismatch");
|
|
65
|
-
}
|
|
66
|
-
left.log(`Canot use ${op} operator here`);
|
|
67
|
-
return (0, index_1.errorFor)("applybinary bad operator");
|
|
68
|
-
}
|
|
69
|
-
exports.applyBinary = applyBinary;
|
|
70
|
-
function oneOf(op, ...operators) {
|
|
71
|
-
return operators.includes(op);
|
|
72
|
-
}
|
|
73
|
-
function allAre(oneType, ...values) {
|
|
74
|
-
for (const v of values) {
|
|
75
|
-
if (v.dataType !== oneType) {
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return true;
|
|
80
|
-
}
|
|
81
|
-
function regexEqual(left, right) {
|
|
82
|
-
if (left.dataType === "string") {
|
|
83
|
-
if (right.dataType === "regular expression") {
|
|
84
|
-
return [
|
|
85
|
-
{
|
|
86
|
-
type: "dialect",
|
|
87
|
-
function: "regexpMatch",
|
|
88
|
-
expr: left.value,
|
|
89
|
-
regexp: right.value[0].replace(/^r'/, "'"),
|
|
90
|
-
},
|
|
91
|
-
];
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
else if (right.dataType === "string") {
|
|
95
|
-
if (left.dataType === "regular expression") {
|
|
96
|
-
return [
|
|
97
|
-
{
|
|
98
|
-
type: "dialect",
|
|
99
|
-
function: "regexpMatch",
|
|
100
|
-
expr: right.value,
|
|
101
|
-
regexp: left.value[0].replace(/^r'/, "'"),
|
|
102
|
-
},
|
|
103
|
-
];
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return undefined;
|
|
107
|
-
}
|
|
108
|
-
function nullCompare(left, op, right) {
|
|
109
|
-
const not = op === "!=" || op === "!~";
|
|
110
|
-
if (left.dataType === "null" || right.dataType === "null") {
|
|
111
|
-
const maybeNot = not ? " NOT" : "";
|
|
112
|
-
if (left.dataType !== "null") {
|
|
113
|
-
return [...left.value, ` IS${maybeNot} NULL`];
|
|
114
|
-
}
|
|
115
|
-
if (right.dataType !== "null") {
|
|
116
|
-
return [...right.value, `IS${maybeNot} NULL`];
|
|
117
|
-
}
|
|
118
|
-
return [not ? "false" : "true"];
|
|
119
|
-
}
|
|
120
|
-
return undefined;
|
|
121
|
-
}
|
|
122
|
-
function timeCompare(lhs, op, rhs) {
|
|
123
|
-
if ((0, malloy_types_1.isTimeFieldType)(lhs.dataType) && (0, malloy_types_1.isTimeFieldType)(rhs.dataType)) {
|
|
124
|
-
if (lhs.dataType !== rhs.dataType) {
|
|
125
|
-
let lval = lhs.value;
|
|
126
|
-
let rval = rhs.value;
|
|
127
|
-
if (lhs.dataType === "timestamp") {
|
|
128
|
-
lval = (0, index_1.castTimestampToDate)(lval);
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
rval = (0, index_1.castTimestampToDate)(rval);
|
|
132
|
-
}
|
|
133
|
-
return (0, index_1.compose)(lval, op, rval);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return undefined;
|
|
137
|
-
}
|
|
138
|
-
function nullsafeNot(expr, op) {
|
|
139
|
-
if (op === undefined || op === "!=" || op === "!~") {
|
|
140
|
-
return (0, malloy_types_1.mkExpr) `COALESCE(NOT(${expr}),FALSE)`;
|
|
141
|
-
}
|
|
142
|
-
return expr;
|
|
143
|
-
}
|
|
144
|
-
exports.nullsafeNot = nullsafeNot;
|
|
145
|
-
function equality(fs, left, op, right) {
|
|
146
|
-
const lhs = left.getExpression(fs);
|
|
147
|
-
const rhs = right.getExpression(fs);
|
|
148
|
-
let value = timeCompare(lhs, op, rhs) || (0, index_1.compose)(lhs.value, op, rhs.value);
|
|
149
|
-
if (lhs.dataType != "unknown" && rhs.dataType != "unknown") {
|
|
150
|
-
switch (op) {
|
|
151
|
-
case "~":
|
|
152
|
-
case "!~": {
|
|
153
|
-
if (lhs.dataType === "string" && rhs.dataType === "string") {
|
|
154
|
-
value = (0, index_1.compose)(lhs.value, "LIKE", rhs.value);
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
const regexCmp = regexEqual(lhs, rhs);
|
|
158
|
-
if (regexCmp === undefined) {
|
|
159
|
-
throw new index_1.TypeMistmatch("Incompatible types for match('~') operator");
|
|
160
|
-
}
|
|
161
|
-
value = regexCmp;
|
|
162
|
-
}
|
|
163
|
-
value = nullsafeNot(value, op);
|
|
164
|
-
break;
|
|
165
|
-
}
|
|
166
|
-
case "=":
|
|
167
|
-
case "!=": {
|
|
168
|
-
const nullCmp = nullCompare(lhs, op, rhs);
|
|
169
|
-
if (nullCmp) {
|
|
170
|
-
value = nullCmp;
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
value = nullsafeNot(regexEqual(lhs, rhs) || (0, index_1.compose)(lhs.value, "=", rhs.value), op);
|
|
174
|
-
}
|
|
175
|
-
break;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return {
|
|
180
|
-
dataType: "boolean",
|
|
181
|
-
aggregate: lhs.aggregate || rhs.aggregate,
|
|
182
|
-
value,
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
function compare(fs, left, op, right) {
|
|
186
|
-
const lhs = left.getExpression(fs);
|
|
187
|
-
const rhs = right.getExpression(fs);
|
|
188
|
-
const anyAggregate = lhs.aggregate || rhs.aggregate;
|
|
189
|
-
const value = timeCompare(lhs, op, rhs) || (0, index_1.compose)(lhs.value, op, rhs.value);
|
|
190
|
-
return {
|
|
191
|
-
dataType: "boolean",
|
|
192
|
-
aggregate: anyAggregate,
|
|
193
|
-
value: value,
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
function numeric(fs, left, op, right) {
|
|
197
|
-
const lhs = left.getExpression(fs);
|
|
198
|
-
const rhs = right.getExpression(fs);
|
|
199
|
-
const anyAggregate = lhs.aggregate || rhs.aggregate;
|
|
200
|
-
if (allAre("number", lhs, rhs)) {
|
|
201
|
-
return {
|
|
202
|
-
dataType: "number",
|
|
203
|
-
aggregate: anyAggregate,
|
|
204
|
-
value: (0, index_1.compose)(lhs.value, op, rhs.value),
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
left.log(`Non numeric('${lhs.dataType},${rhs.dataType}') value with '${op}'`);
|
|
208
|
-
return (0, index_1.errorFor)("numbers required");
|
|
209
|
-
}
|
|
210
|
-
function delta(fs, left, op, right) {
|
|
211
|
-
const lhs = left.getExpression(fs);
|
|
212
|
-
const rhs = right.getExpression(fs);
|
|
213
|
-
if ((0, malloy_types_1.isTimeFieldType)(lhs.dataType)) {
|
|
214
|
-
let duration = right;
|
|
215
|
-
if (rhs.dataType !== "duration") {
|
|
216
|
-
if ((0, index_1.isGranularResult)(lhs)) {
|
|
217
|
-
duration = new index_1.ExprDuration(right, lhs.timeframe);
|
|
218
|
-
}
|
|
219
|
-
else if (lhs.dataType === "date") {
|
|
220
|
-
duration = new index_1.ExprDuration(right, "day");
|
|
221
|
-
}
|
|
222
|
-
else {
|
|
223
|
-
left.log(`Can not offset time by '${rhs.dataType}'`);
|
|
224
|
-
return (0, index_1.errorFor)(`time plus ${rhs.dataType}`);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
return duration.apply(fs, op, left);
|
|
228
|
-
}
|
|
229
|
-
return numeric(fs, left, op, right);
|
|
230
|
-
}
|
|
231
|
-
//# sourceMappingURL=apply-expr.js.map
|