@malloydata/malloy 0.0.242-dev250313002313 → 0.0.242-dev250313045635
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/dialect/dialect.d.ts +7 -3
- package/dist/dialect/dialect.js +25 -12
- package/dist/lang/ast/expressions/expr-filter-expr.d.ts +11 -0
- package/dist/lang/ast/expressions/expr-filter-expr.js +61 -0
- package/dist/lang/ast/index.d.ts +1 -0
- package/dist/lang/ast/index.js +1 -0
- package/dist/lang/lib/Malloy/MalloyLexer.d.ts +64 -58
- package/dist/lang/lib/Malloy/MalloyLexer.js +1216 -1158
- package/dist/lang/lib/Malloy/MalloyParser.d.ts +109 -61
- package/dist/lang/lib/Malloy/MalloyParser.js +2059 -1734
- package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +46 -0
- package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +29 -0
- package/dist/lang/malloy-to-ast.d.ts +2 -0
- package/dist/lang/malloy-to-ast.js +19 -1
- package/dist/lang/parse-log.d.ts +2 -0
- package/dist/lang/test/expr-to-str.d.ts +9 -0
- package/dist/lang/test/expr-to-str.js +124 -0
- package/dist/lang/test/parse-expects.js +2 -91
- package/dist/model/filter_compilers.d.ts +5 -0
- package/dist/model/filter_compilers.js +160 -0
- package/dist/model/malloy_query.js +12 -4
- package/dist/model/malloy_types.d.ts +12 -2
- package/dist/model/malloy_types.js +6 -2
- package/package.json +4 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Expr, Sampling, AtomicTypeDef, MeasureTimeExpr, TimeTruncExpr, TimeExtractExpr, TimeDeltaExpr, TypecastExpr, RegexMatchExpr, TimeLiteralNode, RecordLiteralNode, ArrayLiteralNode, LeafAtomicTypeDef, OrderBy
|
|
1
|
+
import { Expr, Sampling, AtomicTypeDef, MeasureTimeExpr, TimeTruncExpr, TimeExtractExpr, TimeDeltaExpr, TypecastExpr, RegexMatchExpr, TimeLiteralNode, RecordLiteralNode, ArrayLiteralNode, LeafAtomicTypeDef, OrderBy } from '../model/malloy_types';
|
|
2
2
|
import { DialectFunctionOverloadDef } from './functions';
|
|
3
3
|
type DialectFieldTypes = string | 'struct';
|
|
4
4
|
interface DialectField {
|
|
@@ -101,10 +101,10 @@ export declare abstract class Dialect {
|
|
|
101
101
|
abstract sqlMeasureTimeExpr(e: MeasureTimeExpr): string;
|
|
102
102
|
abstract sqlAlterTimeExpr(df: TimeDeltaExpr): string;
|
|
103
103
|
abstract sqlCast(qi: QueryInfo, cast: TypecastExpr): string;
|
|
104
|
+
abstract sqlRegexpMatch(df: RegexMatchExpr): string;
|
|
104
105
|
abstract sqlLiteralTime(qi: QueryInfo, df: TimeLiteralNode): string;
|
|
105
106
|
abstract sqlLiteralString(literal: string): string;
|
|
106
107
|
abstract sqlLiteralRegexp(literal: string): string;
|
|
107
|
-
abstract sqlRegexpMatch(df: RegexMatchExpr): string;
|
|
108
108
|
abstract sqlLiteralArray(lit: ArrayLiteralNode): string;
|
|
109
109
|
abstract sqlLiteralRecord(lit: RecordLiteralNode): string;
|
|
110
110
|
/**
|
|
@@ -139,6 +139,10 @@ export declare abstract class Dialect {
|
|
|
139
139
|
dstTypeDef: LeafAtomicTypeDef | undefined;
|
|
140
140
|
dstSQLType: string;
|
|
141
141
|
};
|
|
142
|
-
|
|
142
|
+
/**
|
|
143
|
+
* Write a LIKE expression. Malloy like strings are escaped with \\% and \\_
|
|
144
|
+
* but some SQL dialects use an ESCAPE clause.
|
|
145
|
+
*/
|
|
146
|
+
sqlLike(likeOp: 'LIKE' | 'NOT LIKE', left: string, likeStr: string): string;
|
|
143
147
|
}
|
|
144
148
|
export {};
|
package/dist/dialect/dialect.js
CHANGED
|
@@ -225,21 +225,34 @@ class Dialect {
|
|
|
225
225
|
dstSQLType: this.malloyTypeToSQLType(cast.dstType),
|
|
226
226
|
};
|
|
227
227
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
228
|
+
/**
|
|
229
|
+
* Write a LIKE expression. Malloy like strings are escaped with \\% and \\_
|
|
230
|
+
* but some SQL dialects use an ESCAPE clause.
|
|
231
|
+
*/
|
|
232
|
+
sqlLike(likeOp, left, likeStr) {
|
|
233
|
+
let escaped = '';
|
|
234
|
+
let escapeActive = false;
|
|
235
|
+
let escapeClause = false;
|
|
236
|
+
for (const c of likeStr) {
|
|
237
|
+
if (c === '\\' && !escapeActive) {
|
|
238
|
+
escapeActive = true;
|
|
239
|
+
}
|
|
240
|
+
else if (this.likeEscape && c === '^') {
|
|
241
|
+
escaped += '^^';
|
|
242
|
+
escapeActive = false;
|
|
243
|
+
escapeClause = true;
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
if (escapeActive && (c === '%' || c === '_')) {
|
|
247
|
+
escaped += this.likeEscape ? '^' : '\\';
|
|
248
|
+
escapeClause = this.likeEscape;
|
|
238
249
|
}
|
|
250
|
+
escaped += c;
|
|
251
|
+
escapeActive = false;
|
|
239
252
|
}
|
|
240
|
-
return `${expr.kids.left.sql} ${likeOp} ${isLike.sql}`;
|
|
241
253
|
}
|
|
242
|
-
|
|
254
|
+
const compare = `${left} ${likeOp} ${this.sqlLiteralString(escaped)}`;
|
|
255
|
+
return escapeClause ? `${compare} ESCAPE '^'` : compare;
|
|
243
256
|
}
|
|
244
257
|
}
|
|
245
258
|
exports.Dialect = Dialect;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BinaryMalloyOperator } from '../types/binary_operators';
|
|
2
|
+
import { ExprValue } from '../types/expr-value';
|
|
3
|
+
import { ExpressionDef } from '../types/expression-def';
|
|
4
|
+
import { FieldSpace } from '../types/field-space';
|
|
5
|
+
export declare class ExprFilterExpression extends ExpressionDef {
|
|
6
|
+
readonly filterText: string;
|
|
7
|
+
elementType: string;
|
|
8
|
+
constructor(filterText: string);
|
|
9
|
+
getExpression(): ExprValue;
|
|
10
|
+
apply(fs: FieldSpace, op: BinaryMalloyOperator, left: ExpressionDef, _warnOnComplexTree?: boolean): ExprValue;
|
|
11
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ExprFilterExpression = void 0;
|
|
10
|
+
const expr_value_1 = require("../types/expr-value");
|
|
11
|
+
const expression_def_1 = require("../types/expression-def");
|
|
12
|
+
const malloy_filter_1 = require("@malloydata/malloy-filter");
|
|
13
|
+
class ExprFilterExpression extends expression_def_1.ExpressionDef {
|
|
14
|
+
constructor(filterText) {
|
|
15
|
+
super();
|
|
16
|
+
this.filterText = filterText;
|
|
17
|
+
this.elementType = 'filter expression literal';
|
|
18
|
+
// mtoy todo parse the filter and reflect errors into the error stream
|
|
19
|
+
}
|
|
20
|
+
getExpression() {
|
|
21
|
+
return this.loggedErrorExpr('filter-expression-type', 'Filter expression illegal here');
|
|
22
|
+
}
|
|
23
|
+
apply(fs, op, left, _warnOnComplexTree = false) {
|
|
24
|
+
if (op === '~' || op === '!~') {
|
|
25
|
+
const matchExpr = left.getExpression(fs);
|
|
26
|
+
if (matchExpr.type === 'error') {
|
|
27
|
+
return matchExpr;
|
|
28
|
+
}
|
|
29
|
+
if (matchExpr.type === 'string') {
|
|
30
|
+
const fParse = malloy_filter_1.StringFilterExpression.parse(this.filterText);
|
|
31
|
+
if (fParse.log.length > 0) {
|
|
32
|
+
for (const _err of fParse.log) {
|
|
33
|
+
// mtoy todo actuall get error and report correct position and error type
|
|
34
|
+
return this.loggedErrorExpr('filter-expression-type', 'FHJKL:DSHJKL error in parsing filter expression');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (!fParse.parsed) {
|
|
38
|
+
return this.loggedErrorExpr('filter-expression-type', 'FJKLD:JDKSL: expression parsed to null');
|
|
39
|
+
}
|
|
40
|
+
const filterMatch = {
|
|
41
|
+
node: 'filterMatch',
|
|
42
|
+
dataType: matchExpr.type,
|
|
43
|
+
filter: fParse.parsed,
|
|
44
|
+
e: matchExpr.value,
|
|
45
|
+
};
|
|
46
|
+
if (op === '!~') {
|
|
47
|
+
filterMatch.notMatch = true;
|
|
48
|
+
}
|
|
49
|
+
return (0, expr_value_1.computedExprValue)({
|
|
50
|
+
value: filterMatch,
|
|
51
|
+
dataType: { type: 'boolean' },
|
|
52
|
+
from: [matchExpr],
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return this.loggedErrorExpr('filter-expression-type', `CUISAO)VEFG Filter expressions for ${matchExpr.type} not available`);
|
|
56
|
+
}
|
|
57
|
+
return this.loggedErrorExpr('filter-expression-type', `Cannot use the '${op}' operator with a filter expression`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.ExprFilterExpression = ExprFilterExpression;
|
|
61
|
+
//# sourceMappingURL=expr-filter-expr.js.map
|
package/dist/lang/ast/index.d.ts
CHANGED
|
@@ -44,6 +44,7 @@ export * from './expressions/expr-now';
|
|
|
44
44
|
export * from './expressions/expr-null';
|
|
45
45
|
export * from './expressions/expr-number';
|
|
46
46
|
export * from './expressions/expr-parens';
|
|
47
|
+
export * from './expressions/expr-filter-expr';
|
|
47
48
|
export * from './expressions/expr-regex';
|
|
48
49
|
export * from './expressions/expr-string';
|
|
49
50
|
export * from './expressions/expr-sum';
|
package/dist/lang/ast/index.js
CHANGED
|
@@ -82,6 +82,7 @@ __exportStar(require("./expressions/expr-now"), exports);
|
|
|
82
82
|
__exportStar(require("./expressions/expr-null"), exports);
|
|
83
83
|
__exportStar(require("./expressions/expr-number"), exports);
|
|
84
84
|
__exportStar(require("./expressions/expr-parens"), exports);
|
|
85
|
+
__exportStar(require("./expressions/expr-filter-expr"), exports);
|
|
85
86
|
__exportStar(require("./expressions/expr-regex"), exports);
|
|
86
87
|
__exportStar(require("./expressions/expr-string"), exports);
|
|
87
88
|
__exportStar(require("./expressions/expr-sum"), exports);
|
|
@@ -109,64 +109,70 @@ export declare class MalloyLexer extends Lexer {
|
|
|
109
109
|
static readonly HACKY_REGEX = 104;
|
|
110
110
|
static readonly RAW_SQ = 105;
|
|
111
111
|
static readonly RAW_DQ = 106;
|
|
112
|
-
static readonly
|
|
113
|
-
static readonly
|
|
114
|
-
static readonly
|
|
115
|
-
static readonly
|
|
116
|
-
static readonly
|
|
117
|
-
static readonly
|
|
118
|
-
static readonly
|
|
119
|
-
static readonly
|
|
120
|
-
static readonly
|
|
121
|
-
static readonly
|
|
122
|
-
static readonly
|
|
123
|
-
static readonly
|
|
124
|
-
static readonly
|
|
125
|
-
static readonly
|
|
126
|
-
static readonly
|
|
127
|
-
static readonly
|
|
128
|
-
static readonly
|
|
129
|
-
static readonly
|
|
130
|
-
static readonly
|
|
131
|
-
static readonly
|
|
132
|
-
static readonly
|
|
133
|
-
static readonly
|
|
134
|
-
static readonly
|
|
135
|
-
static readonly
|
|
136
|
-
static readonly
|
|
137
|
-
static readonly
|
|
138
|
-
static readonly
|
|
139
|
-
static readonly
|
|
140
|
-
static readonly
|
|
141
|
-
static readonly
|
|
142
|
-
static readonly
|
|
143
|
-
static readonly
|
|
144
|
-
static readonly
|
|
145
|
-
static readonly
|
|
146
|
-
static readonly
|
|
147
|
-
static readonly
|
|
148
|
-
static readonly
|
|
149
|
-
static readonly
|
|
150
|
-
static readonly
|
|
151
|
-
static readonly
|
|
152
|
-
static readonly
|
|
153
|
-
static readonly
|
|
154
|
-
static readonly
|
|
155
|
-
static readonly
|
|
156
|
-
static readonly
|
|
157
|
-
static readonly
|
|
158
|
-
static readonly
|
|
159
|
-
static readonly
|
|
160
|
-
static readonly
|
|
161
|
-
static readonly
|
|
162
|
-
static readonly
|
|
163
|
-
static readonly
|
|
164
|
-
static readonly
|
|
165
|
-
static readonly
|
|
166
|
-
static readonly
|
|
167
|
-
static readonly
|
|
168
|
-
static readonly
|
|
169
|
-
static readonly
|
|
112
|
+
static readonly SQ3_FILTER = 107;
|
|
113
|
+
static readonly SQ_FILTER = 108;
|
|
114
|
+
static readonly DQ3_FILTER = 109;
|
|
115
|
+
static readonly DQ_FILTER = 110;
|
|
116
|
+
static readonly BQ3_FILTER = 111;
|
|
117
|
+
static readonly BQ_FILTER = 112;
|
|
118
|
+
static readonly SQ_STRING = 113;
|
|
119
|
+
static readonly DQ_STRING = 114;
|
|
120
|
+
static readonly BQ_STRING = 115;
|
|
121
|
+
static readonly DOC_ANNOTATION = 116;
|
|
122
|
+
static readonly ANNOTATION = 117;
|
|
123
|
+
static readonly AMPER = 118;
|
|
124
|
+
static readonly ARROW = 119;
|
|
125
|
+
static readonly FAT_ARROW = 120;
|
|
126
|
+
static readonly OPAREN = 121;
|
|
127
|
+
static readonly CPAREN = 122;
|
|
128
|
+
static readonly OBRACK = 123;
|
|
129
|
+
static readonly CBRACK = 124;
|
|
130
|
+
static readonly OCURLY = 125;
|
|
131
|
+
static readonly CCURLY = 126;
|
|
132
|
+
static readonly DOUBLECOLON = 127;
|
|
133
|
+
static readonly TRIPLECOLON = 128;
|
|
134
|
+
static readonly EXCLAM = 129;
|
|
135
|
+
static readonly COLON = 130;
|
|
136
|
+
static readonly COMMA = 131;
|
|
137
|
+
static readonly DOT = 132;
|
|
138
|
+
static readonly LT = 133;
|
|
139
|
+
static readonly GT = 134;
|
|
140
|
+
static readonly EQ = 135;
|
|
141
|
+
static readonly NE = 136;
|
|
142
|
+
static readonly LTE = 137;
|
|
143
|
+
static readonly GTE = 138;
|
|
144
|
+
static readonly PLUS = 139;
|
|
145
|
+
static readonly MINUS = 140;
|
|
146
|
+
static readonly STAR = 141;
|
|
147
|
+
static readonly STARSTAR = 142;
|
|
148
|
+
static readonly SLASH = 143;
|
|
149
|
+
static readonly BAR = 144;
|
|
150
|
+
static readonly SEMI = 145;
|
|
151
|
+
static readonly NOT_MATCH = 146;
|
|
152
|
+
static readonly MATCH = 147;
|
|
153
|
+
static readonly PERCENT = 148;
|
|
154
|
+
static readonly DOUBLE_QMARK = 149;
|
|
155
|
+
static readonly QMARK = 150;
|
|
156
|
+
static readonly LITERAL_TIMESTAMP = 151;
|
|
157
|
+
static readonly LITERAL_HOUR = 152;
|
|
158
|
+
static readonly LITERAL_DAY = 153;
|
|
159
|
+
static readonly LITERAL_QUARTER = 154;
|
|
160
|
+
static readonly LITERAL_MONTH = 155;
|
|
161
|
+
static readonly LITERAL_WEEK = 156;
|
|
162
|
+
static readonly LITERAL_YEAR = 157;
|
|
163
|
+
static readonly IDENTIFIER = 158;
|
|
164
|
+
static readonly PERCENT_LITERAL = 159;
|
|
165
|
+
static readonly NUMERIC_LITERAL = 160;
|
|
166
|
+
static readonly INTEGER_LITERAL = 161;
|
|
167
|
+
static readonly BLOCK_COMMENT = 162;
|
|
168
|
+
static readonly COMMENT_TO_EOL = 163;
|
|
169
|
+
static readonly WHITE_SPACE = 164;
|
|
170
|
+
static readonly SQL_BEGIN = 165;
|
|
171
|
+
static readonly CLOSE_CODE = 166;
|
|
172
|
+
static readonly UNWATED_CHARS_TRAILING_NUMBERS = 167;
|
|
173
|
+
static readonly UNEXPECTED_CHAR = 168;
|
|
174
|
+
static readonly OPEN_CODE = 169;
|
|
175
|
+
static readonly SQL_END = 170;
|
|
170
176
|
static readonly SQL_MODE = 1;
|
|
171
177
|
static readonly channelNames: string[];
|
|
172
178
|
static readonly modeNames: string[];
|