@malloydata/malloy 0.0.225-dev250113200903 → 0.0.225-dev250113203344

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.
@@ -62,9 +62,9 @@ export declare abstract class Dialect {
62
62
  supportsCountApprox: boolean;
63
63
  supportsHyperLogLog: boolean;
64
64
  supportsFullJoin: boolean;
65
- nativeBoolean: boolean;
66
65
  nestedArrays: boolean;
67
66
  compoundObjectInSchema: boolean;
67
+ booleanAsNumbers: boolean;
68
68
  abstract getDialectFunctionOverrides(): {
69
69
  [name: string]: DialectFunctionOverloadDef[];
70
70
  };
@@ -85,11 +85,12 @@ class Dialect {
85
85
  this.supportsHyperLogLog = false;
86
86
  // MYSQL doesn't have full join, maybe others.
87
87
  this.supportsFullJoin = true;
88
- this.nativeBoolean = true;
89
88
  // Can have arrays of arrays
90
89
  this.nestedArrays = true;
91
90
  // An array or record will reveal type of contents on schema read
92
91
  this.compoundObjectInSchema = true;
92
+ // No true boolean type, e.g. true=1 and false=0, set this to true
93
+ this.booleanAsNumbers = false;
93
94
  }
94
95
  sqlFinalStage(_lastStageName, _fields) {
95
96
  throw new Error('Dialect has no final Stage but called Anyway');
@@ -22,13 +22,13 @@ export declare class MySQLDialect extends Dialect {
22
22
  supportsQualify: boolean;
23
23
  supportsNesting: boolean;
24
24
  experimental: boolean;
25
- nativeBoolean: boolean;
26
25
  supportsFullJoin: boolean;
27
26
  supportsPipelinesInViews: boolean;
28
27
  readsNestedData: boolean;
29
28
  supportsComplexFilteredSources: boolean;
30
29
  supportsArraysInData: boolean;
31
30
  compoundObjectInSchema: boolean;
31
+ booleanAsNumbers: boolean;
32
32
  malloyTypeToSQLType(malloyType: AtomicTypeDef): string;
33
33
  sqlTypeToMalloyType(sqlType: string): LeafAtomicTypeDef;
34
34
  quoteTablePath(tablePath: string): string;
@@ -80,7 +80,7 @@ class MySQLDialect extends dialect_1.Dialect {
80
80
  this.defaultDecimalType = 'DECIMAL';
81
81
  this.udfPrefix = 'ms_temp.__udf';
82
82
  this.hasFinalStage = false;
83
- // TODO: this may not be enough for lager casts.
83
+ // TODO: this may not be enough for larger casts.
84
84
  this.stringTypeName = 'VARCHAR(255)';
85
85
  this.divisionIsInteger = true;
86
86
  this.supportsSumDistinctFunction = true;
@@ -94,13 +94,13 @@ class MySQLDialect extends dialect_1.Dialect {
94
94
  this.supportsQualify = false;
95
95
  this.supportsNesting = true;
96
96
  this.experimental = false;
97
- this.nativeBoolean = false;
98
97
  this.supportsFullJoin = false;
99
98
  this.supportsPipelinesInViews = false;
100
99
  this.readsNestedData = false;
101
100
  this.supportsComplexFilteredSources = false;
102
101
  this.supportsArraysInData = false;
103
102
  this.compoundObjectInSchema = false;
103
+ this.booleanAsNumbers = true;
104
104
  }
105
105
  malloyTypeToSQLType(malloyType) {
106
106
  switch (malloyType.type) {
@@ -55,7 +55,13 @@ class ExprNot extends unary_1.Unary {
55
55
  this.legalChildTypes = [TDU.boolT, TDU.nullT];
56
56
  }
57
57
  getExpression(fs) {
58
+ var _a;
58
59
  const notThis = this.expr.getExpression(fs);
60
+ if ((_a = fs.dialectObj()) === null || _a === void 0 ? void 0 : _a.booleanAsNumbers) {
61
+ if (this.legalChildTypes.find(t => t.type === 'number') === undefined) {
62
+ this.legalChildTypes.push(TDU.numberT);
63
+ }
64
+ }
59
65
  const doNot = this.typeCheck(this.expr, notThis);
60
66
  return {
61
67
  ...notThis,
@@ -1,6 +1,24 @@
1
+ import { BinaryMalloyOperator, FieldSpace } from '..';
1
2
  import { ExprValue } from '../types/expr-value';
2
- import { ExpressionDef } from '../types/expression-def';
3
+ import { ATNodeType, ExpressionDef } from '../types/expression-def';
3
4
  export declare class ExprNULL extends ExpressionDef {
4
5
  elementType: string;
5
6
  getExpression(): ExprValue;
7
+ apply(fs: FieldSpace, op: BinaryMalloyOperator, left: ExpressionDef): ExprValue;
8
+ }
9
+ export declare class PartialIsNull extends ExpressionDef {
10
+ readonly op: '=' | '!=';
11
+ elementType: string;
12
+ constructor(op: '=' | '!=');
13
+ apply(fs: FieldSpace, op: string, expr: ExpressionDef): ExprValue;
14
+ requestExpression(_fs: FieldSpace): ExprValue | undefined;
15
+ getExpression(_fs: FieldSpace): ExprValue;
16
+ atNodeType(): ATNodeType;
17
+ }
18
+ export declare class ExprIsNull extends ExpressionDef {
19
+ readonly expr: ExpressionDef;
20
+ readonly op: '=' | '!=';
21
+ elementType: string;
22
+ constructor(expr: ExpressionDef, op: '=' | '!=');
23
+ getExpression(fs: FieldSpace): ExprValue;
6
24
  }
@@ -22,9 +22,18 @@
22
22
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  */
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.ExprNULL = void 0;
25
+ exports.ExprIsNull = exports.PartialIsNull = exports.ExprNULL = void 0;
26
26
  const expr_value_1 = require("../types/expr-value");
27
27
  const expression_def_1 = require("../types/expression-def");
28
+ function doIsNull(fs, op, expr) {
29
+ const nullCmp = expr.getExpression(fs);
30
+ nullCmp.type = 'boolean';
31
+ nullCmp.value = {
32
+ node: op === '=' ? 'is-null' : 'is-not-null',
33
+ e: nullCmp.value,
34
+ };
35
+ return nullCmp;
36
+ }
28
37
  class ExprNULL extends expression_def_1.ExpressionDef {
29
38
  constructor() {
30
39
  super(...arguments);
@@ -36,6 +45,45 @@ class ExprNULL extends expression_def_1.ExpressionDef {
36
45
  value: { node: 'null' },
37
46
  });
38
47
  }
48
+ apply(fs, op, left) {
49
+ if (op === '!=' || op === '=') {
50
+ return doIsNull(fs, op, left);
51
+ }
52
+ return super.apply(fs, op, left, true);
53
+ }
39
54
  }
40
55
  exports.ExprNULL = ExprNULL;
56
+ class PartialIsNull extends expression_def_1.ExpressionDef {
57
+ constructor(op) {
58
+ super();
59
+ this.op = op;
60
+ this.elementType = '<=> NULL';
61
+ }
62
+ apply(fs, op, expr) {
63
+ return doIsNull(fs, this.op, expr);
64
+ }
65
+ requestExpression(_fs) {
66
+ return undefined;
67
+ }
68
+ getExpression(_fs) {
69
+ return this.loggedErrorExpr('partial-as-value', 'Partial null check does not have a value');
70
+ }
71
+ atNodeType() {
72
+ return expression_def_1.ATNodeType.Partial;
73
+ }
74
+ }
75
+ exports.PartialIsNull = PartialIsNull;
76
+ class ExprIsNull extends expression_def_1.ExpressionDef {
77
+ constructor(expr, op) {
78
+ super();
79
+ this.expr = expr;
80
+ this.op = op;
81
+ this.elementType = 'is null';
82
+ this.has({ expr });
83
+ }
84
+ getExpression(fs) {
85
+ return doIsNull(fs, this.op, this.expr);
86
+ }
87
+ }
88
+ exports.ExprIsNull = ExprIsNull;
41
89
  //# sourceMappingURL=expr-null.js.map
@@ -251,22 +251,7 @@ function regexEqual(left, right) {
251
251
  }
252
252
  return undefined;
253
253
  }
254
- function nullCompare(left, op, right) {
255
- const not = op === '!=' || op === '!~';
256
- const nullCmp = not ? 'is-not-null' : 'is-null';
257
- if (left.type === 'null' || right.type === 'null') {
258
- if (left.type !== 'null') {
259
- return { node: nullCmp, e: left.value };
260
- }
261
- if (right.type !== 'null') {
262
- return { node: nullCmp, e: right.value };
263
- }
264
- return { node: not ? 'false' : 'true' };
265
- }
266
- return undefined;
267
- }
268
254
  function equality(fs, left, op, right) {
269
- var _a;
270
255
  const lhs = left.getExpression(fs);
271
256
  const rhs = right.getExpression(fs);
272
257
  const node = (0, binary_operators_1.getExprNode)(op);
@@ -289,29 +274,20 @@ function equality(fs, left, op, right) {
289
274
  node,
290
275
  kids: { left: lhs.value, right: rhs.value },
291
276
  };
292
- if (lhs.type !== 'error' && rhs.type !== 'error') {
293
- switch (op) {
294
- case '~':
295
- case '!~': {
296
- if (lhs.type !== 'string' || rhs.type !== 'string') {
297
- let regexCmp = regexEqual(lhs, rhs);
298
- if (regexCmp) {
299
- if (op[0] === '!') {
300
- regexCmp = { node: 'not', e: { ...regexCmp } };
301
- }
302
- }
303
- else {
304
- throw new TypeMismatch("Incompatible types for match('~') operator");
305
- }
306
- value = regexCmp;
277
+ if (lhs.type !== 'error' &&
278
+ rhs.type !== 'error' &&
279
+ (op === '~' || op === '!~')) {
280
+ if (lhs.type !== 'string' || rhs.type !== 'string') {
281
+ let regexCmp = regexEqual(lhs, rhs);
282
+ if (regexCmp) {
283
+ if (op[0] === '!') {
284
+ regexCmp = { node: 'not', e: { ...regexCmp } };
307
285
  }
308
- break;
309
286
  }
310
- case '=':
311
- case '!=': {
312
- value = (_a = nullCompare(lhs, op, rhs)) !== null && _a !== void 0 ? _a : value;
313
- break;
287
+ else {
288
+ throw new TypeMismatch("Incompatible types for match('~') operator");
314
289
  }
290
+ value = regexCmp;
315
291
  }
316
292
  }
317
293
  return (0, expr_value_1.computedExprValue)({
@@ -296,32 +296,34 @@ export declare class MalloyParser extends Parser {
296
296
  static readonly RULE_ungroup = 121;
297
297
  static readonly RULE_malloyOrSQLType = 122;
298
298
  static readonly RULE_fieldExpr = 123;
299
- static readonly RULE_partialAllowedFieldExpr = 124;
300
- static readonly RULE_fieldExprList = 125;
301
- static readonly RULE_pickStatement = 126;
302
- static readonly RULE_pick = 127;
303
- static readonly RULE_caseStatement = 128;
304
- static readonly RULE_caseWhen = 129;
305
- static readonly RULE_recordKey = 130;
306
- static readonly RULE_recordElement = 131;
307
- static readonly RULE_argumentList = 132;
308
- static readonly RULE_fieldNameList = 133;
309
- static readonly RULE_fieldCollection = 134;
310
- static readonly RULE_collectionWildCard = 135;
311
- static readonly RULE_starQualified = 136;
312
- static readonly RULE_taggedRef = 137;
313
- static readonly RULE_refExpr = 138;
314
- static readonly RULE_collectionMember = 139;
315
- static readonly RULE_fieldPath = 140;
316
- static readonly RULE_joinName = 141;
317
- static readonly RULE_fieldName = 142;
318
- static readonly RULE_sqlExploreNameRef = 143;
319
- static readonly RULE_nameSQLBlock = 144;
320
- static readonly RULE_connectionName = 145;
321
- static readonly RULE_debugExpr = 146;
322
- static readonly RULE_debugPartial = 147;
323
- static readonly RULE_experimentalStatementForTesting = 148;
324
- static readonly RULE_closeCurly = 149;
299
+ static readonly RULE_partialCompare = 124;
300
+ static readonly RULE_partialTest = 125;
301
+ static readonly RULE_partialAllowedFieldExpr = 126;
302
+ static readonly RULE_fieldExprList = 127;
303
+ static readonly RULE_pickStatement = 128;
304
+ static readonly RULE_pick = 129;
305
+ static readonly RULE_caseStatement = 130;
306
+ static readonly RULE_caseWhen = 131;
307
+ static readonly RULE_recordKey = 132;
308
+ static readonly RULE_recordElement = 133;
309
+ static readonly RULE_argumentList = 134;
310
+ static readonly RULE_fieldNameList = 135;
311
+ static readonly RULE_fieldCollection = 136;
312
+ static readonly RULE_collectionWildCard = 137;
313
+ static readonly RULE_starQualified = 138;
314
+ static readonly RULE_taggedRef = 139;
315
+ static readonly RULE_refExpr = 140;
316
+ static readonly RULE_collectionMember = 141;
317
+ static readonly RULE_fieldPath = 142;
318
+ static readonly RULE_joinName = 143;
319
+ static readonly RULE_fieldName = 144;
320
+ static readonly RULE_sqlExploreNameRef = 145;
321
+ static readonly RULE_nameSQLBlock = 146;
322
+ static readonly RULE_connectionName = 147;
323
+ static readonly RULE_debugExpr = 148;
324
+ static readonly RULE_debugPartial = 149;
325
+ static readonly RULE_experimentalStatementForTesting = 150;
326
+ static readonly RULE_closeCurly = 151;
325
327
  static readonly ruleNames: string[];
326
328
  private static readonly _LITERAL_NAMES;
327
329
  private static readonly _SYMBOLIC_NAMES;
@@ -459,6 +461,8 @@ export declare class MalloyParser extends Parser {
459
461
  malloyOrSQLType(): MalloyOrSQLTypeContext;
460
462
  fieldExpr(): FieldExprContext;
461
463
  fieldExpr(_p: number): FieldExprContext;
464
+ partialCompare(): PartialCompareContext;
465
+ partialTest(): PartialTestContext;
462
466
  partialAllowedFieldExpr(): PartialAllowedFieldExprContext;
463
467
  fieldExprList(): FieldExprListContext;
464
468
  pickStatement(): PickStatementContext;
@@ -2330,7 +2334,7 @@ export declare class ExprWarnLikeContext extends FieldExprContext {
2330
2334
  exitRule(listener: MalloyParserListener): void;
2331
2335
  accept<Result>(visitor: MalloyParserVisitor<Result>): Result;
2332
2336
  }
2333
- export declare class ExprWarnNullCmpContext extends FieldExprContext {
2337
+ export declare class ExprNullCheckContext extends FieldExprContext {
2334
2338
  fieldExpr(): FieldExprContext;
2335
2339
  IS(): TerminalNode;
2336
2340
  NULL(): TerminalNode;
@@ -2483,11 +2487,31 @@ export declare class ExprUngroupContext extends FieldExprContext {
2483
2487
  exitRule(listener: MalloyParserListener): void;
2484
2488
  accept<Result>(visitor: MalloyParserVisitor<Result>): Result;
2485
2489
  }
2490
+ export declare class PartialCompareContext extends ParserRuleContext {
2491
+ compareOp(): CompareOpContext;
2492
+ fieldExpr(): FieldExprContext;
2493
+ constructor(parent: ParserRuleContext | undefined, invokingState: number);
2494
+ get ruleIndex(): number;
2495
+ enterRule(listener: MalloyParserListener): void;
2496
+ exitRule(listener: MalloyParserListener): void;
2497
+ accept<Result>(visitor: MalloyParserVisitor<Result>): Result;
2498
+ }
2499
+ export declare class PartialTestContext extends ParserRuleContext {
2500
+ partialCompare(): PartialCompareContext | undefined;
2501
+ IS(): TerminalNode | undefined;
2502
+ NULL(): TerminalNode | undefined;
2503
+ NOT(): TerminalNode | undefined;
2504
+ constructor(parent: ParserRuleContext | undefined, invokingState: number);
2505
+ get ruleIndex(): number;
2506
+ enterRule(listener: MalloyParserListener): void;
2507
+ exitRule(listener: MalloyParserListener): void;
2508
+ accept<Result>(visitor: MalloyParserVisitor<Result>): Result;
2509
+ }
2486
2510
  export declare class PartialAllowedFieldExprContext extends ParserRuleContext {
2511
+ partialTest(): PartialTestContext | undefined;
2487
2512
  OPAREN(): TerminalNode | undefined;
2488
- fieldExpr(): FieldExprContext;
2489
2513
  CPAREN(): TerminalNode | undefined;
2490
- compareOp(): CompareOpContext | undefined;
2514
+ fieldExpr(): FieldExprContext | undefined;
2491
2515
  constructor(parent: ParserRuleContext | undefined, invokingState: number);
2492
2516
  get ruleIndex(): number;
2493
2517
  enterRule(listener: MalloyParserListener): void;