@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.
@@ -1,4 +1,4 @@
1
- import { Expr, Sampling, AtomicTypeDef, MeasureTimeExpr, TimeTruncExpr, TimeExtractExpr, TimeDeltaExpr, TypecastExpr, RegexMatchExpr, TimeLiteralNode, RecordLiteralNode, ArrayLiteralNode, LeafAtomicTypeDef, OrderBy, BinaryExpr } from '../model/malloy_types';
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
- likeExpr(expr: BinaryExpr): string;
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 {};
@@ -225,21 +225,34 @@ class Dialect {
225
225
  dstSQLType: this.malloyTypeToSQLType(cast.dstType),
226
226
  };
227
227
  }
228
- likeExpr(expr) {
229
- const isLike = expr.kids.right;
230
- if (expr.node === 'like' || expr.node === '!like') {
231
- const likeOp = expr.node === '!like' ? 'NOT LIKE' : 'LIKE';
232
- if (this.likeEscape && isLike.node === 'stringLiteral') {
233
- const likeStr = isLike.literal;
234
- if (likeStr.includes('\\')) {
235
- const escapeUp = likeStr.replace(/\^/g, '^^');
236
- const newLikeStr = escapeUp.replace(/\\/g, '^');
237
- return `${expr.kids.left.sql} ${likeOp} '${newLikeStr}' ESCAPE '^'`;
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
- return 'false';
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
@@ -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';
@@ -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 SQ_STRING = 107;
113
- static readonly DQ_STRING = 108;
114
- static readonly BQ_STRING = 109;
115
- static readonly DOC_ANNOTATION = 110;
116
- static readonly ANNOTATION = 111;
117
- static readonly AMPER = 112;
118
- static readonly ARROW = 113;
119
- static readonly FAT_ARROW = 114;
120
- static readonly OPAREN = 115;
121
- static readonly CPAREN = 116;
122
- static readonly OBRACK = 117;
123
- static readonly CBRACK = 118;
124
- static readonly OCURLY = 119;
125
- static readonly CCURLY = 120;
126
- static readonly DOUBLECOLON = 121;
127
- static readonly TRIPLECOLON = 122;
128
- static readonly EXCLAM = 123;
129
- static readonly COLON = 124;
130
- static readonly COMMA = 125;
131
- static readonly DOT = 126;
132
- static readonly LT = 127;
133
- static readonly GT = 128;
134
- static readonly EQ = 129;
135
- static readonly NE = 130;
136
- static readonly LTE = 131;
137
- static readonly GTE = 132;
138
- static readonly PLUS = 133;
139
- static readonly MINUS = 134;
140
- static readonly STAR = 135;
141
- static readonly STARSTAR = 136;
142
- static readonly SLASH = 137;
143
- static readonly BAR = 138;
144
- static readonly SEMI = 139;
145
- static readonly NOT_MATCH = 140;
146
- static readonly MATCH = 141;
147
- static readonly PERCENT = 142;
148
- static readonly DOUBLE_QMARK = 143;
149
- static readonly QMARK = 144;
150
- static readonly LITERAL_TIMESTAMP = 145;
151
- static readonly LITERAL_HOUR = 146;
152
- static readonly LITERAL_DAY = 147;
153
- static readonly LITERAL_QUARTER = 148;
154
- static readonly LITERAL_MONTH = 149;
155
- static readonly LITERAL_WEEK = 150;
156
- static readonly LITERAL_YEAR = 151;
157
- static readonly IDENTIFIER = 152;
158
- static readonly PERCENT_LITERAL = 153;
159
- static readonly NUMERIC_LITERAL = 154;
160
- static readonly INTEGER_LITERAL = 155;
161
- static readonly BLOCK_COMMENT = 156;
162
- static readonly COMMENT_TO_EOL = 157;
163
- static readonly WHITE_SPACE = 158;
164
- static readonly SQL_BEGIN = 159;
165
- static readonly CLOSE_CODE = 160;
166
- static readonly UNWATED_CHARS_TRAILING_NUMBERS = 161;
167
- static readonly UNEXPECTED_CHAR = 162;
168
- static readonly OPEN_CODE = 163;
169
- static readonly SQL_END = 164;
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[];