@malloydata/malloy 0.0.22-dev230126015148 → 0.0.22-dev230202171033
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-main.d.ts +18 -815
- package/dist/lang/ast/ast-main.js +106 -3241
- package/dist/lang/ast/ast-utils.d.ts +10 -0
- package/dist/lang/ast/ast-utils.js +42 -0
- package/dist/lang/ast/elements/define-explore.d.ts +17 -0
- package/dist/lang/ast/elements/define-explore.js +79 -0
- package/dist/lang/ast/elements/define-query.d.ts +14 -0
- package/dist/lang/ast/elements/define-query.js +56 -0
- package/dist/lang/ast/elements/mallobj.d.ts +12 -0
- package/dist/lang/ast/elements/mallobj.js +53 -0
- package/dist/lang/ast/elements/pipeline-desc.d.ts +28 -0
- package/dist/lang/ast/elements/pipeline-desc.js +102 -0
- package/dist/lang/ast/elements/refined-explore.d.ts +15 -0
- package/dist/lang/ast/elements/refined-explore.js +121 -0
- package/dist/lang/ast/error-factory.d.ts +9 -0
- package/dist/lang/ast/error-factory.js +61 -0
- package/dist/lang/ast/executors/index-executor.d.ts +18 -0
- package/dist/lang/ast/executors/index-executor.js +96 -0
- package/dist/lang/ast/executors/project-executor.d.ts +10 -0
- package/dist/lang/ast/executors/project-executor.js +68 -0
- package/dist/lang/ast/executors/reduce-executor.d.ts +20 -0
- package/dist/lang/ast/executors/reduce-executor.js +149 -0
- package/dist/lang/ast/explore-properties/field-list-edit.d.ts +8 -0
- package/dist/lang/ast/explore-properties/field-list-edit.js +36 -0
- package/dist/lang/ast/explore-properties/primary-key.d.ts +7 -0
- package/dist/lang/ast/{apply-expr.js → explore-properties/primary-key.js} +9 -8
- package/dist/lang/ast/explore-properties/renames.d.ts +11 -0
- package/dist/lang/ast/explore-properties/renames.js +43 -0
- package/dist/lang/ast/explore-properties/turtles.d.ts +5 -0
- package/dist/lang/ast/explore-properties/turtles.js +33 -0
- package/dist/lang/ast/expressions/apply.d.ts +8 -0
- package/dist/lang/ast/expressions/apply.js +37 -0
- package/dist/lang/ast/expressions/binary-boolean.d.ts +12 -0
- package/dist/lang/ast/expressions/binary-boolean.js +54 -0
- package/dist/lang/ast/expressions/binary-numeric.d.ts +11 -0
- package/dist/lang/ast/expressions/binary-numeric.js +42 -0
- package/dist/lang/ast/expressions/boolean.d.ts +8 -0
- package/dist/lang/ast/expressions/boolean.js +39 -0
- package/dist/lang/ast/expressions/constant-sub-expression.d.ts +16 -0
- package/dist/lang/ast/expressions/constant-sub-expression.js +98 -0
- package/dist/lang/ast/expressions/expr-add-sub.d.ts +4 -0
- package/dist/lang/ast/expressions/expr-add-sub.js +34 -0
- package/dist/lang/ast/expressions/expr-aggregate-function.d.ts +15 -0
- package/dist/lang/ast/expressions/expr-aggregate-function.js +99 -0
- package/dist/lang/ast/expressions/expr-alternation-tree.d.ts +11 -0
- package/dist/lang/ast/expressions/expr-alternation-tree.js +54 -0
- package/dist/lang/ast/expressions/expr-asymmetric.d.ts +10 -0
- package/dist/lang/ast/expressions/expr-asymmetric.js +27 -0
- package/dist/lang/ast/expressions/expr-avg.d.ts +6 -0
- package/dist/lang/ast/expressions/expr-avg.js +34 -0
- package/dist/lang/ast/expressions/expr-case.d.ts +11 -0
- package/dist/lang/ast/expressions/expr-case.js +84 -0
- package/dist/lang/ast/expressions/expr-cast.d.ts +13 -0
- package/dist/lang/ast/expressions/expr-cast.js +29 -0
- package/dist/lang/ast/expressions/expr-compare.d.ts +10 -0
- package/dist/lang/ast/expressions/expr-compare.js +48 -0
- package/dist/lang/ast/expressions/expr-count-distinct.d.ts +6 -0
- package/dist/lang/ast/expressions/expr-count-distinct.js +35 -0
- package/dist/lang/ast/expressions/expr-count.d.ts +11 -0
- package/dist/lang/ast/expressions/expr-count.js +57 -0
- package/dist/lang/ast/expressions/expr-filter.d.ts +12 -0
- package/dist/lang/ast/expressions/expr-filter.js +69 -0
- package/dist/lang/ast/expressions/expr-func.d.ts +10 -0
- package/dist/lang/ast/expressions/expr-func.js +63 -0
- package/dist/lang/ast/expressions/expr-granular-time.d.ts +24 -0
- package/dist/lang/ast/expressions/expr-granular-time.js +117 -0
- package/dist/lang/ast/expressions/expr-id-reference.d.ts +12 -0
- package/dist/lang/ast/expressions/expr-id-reference.js +76 -0
- package/dist/lang/ast/expressions/expr-logical-op.d.ts +9 -0
- package/dist/lang/ast/expressions/expr-logical-op.js +36 -0
- package/dist/lang/ast/expressions/expr-max.d.ts +9 -0
- package/dist/lang/ast/expressions/expr-max.js +16 -0
- package/dist/lang/ast/expressions/expr-min.d.ts +9 -0
- package/dist/lang/ast/expressions/expr-min.js +16 -0
- package/dist/lang/ast/expressions/expr-minus.d.ts +9 -0
- package/dist/lang/ast/expressions/expr-minus.js +48 -0
- package/dist/lang/ast/expressions/expr-mul-div.d.ts +4 -0
- package/dist/lang/ast/expressions/expr-mul-div.js +34 -0
- package/dist/lang/ast/expressions/expr-not.d.ts +10 -0
- package/dist/lang/ast/expressions/expr-not.js +49 -0
- package/dist/lang/ast/expressions/expr-now.d.ts +7 -0
- package/dist/lang/ast/expressions/expr-now.js +46 -0
- package/dist/lang/ast/expressions/expr-null.d.ts +6 -0
- package/dist/lang/ast/expressions/expr-null.js +41 -0
- package/dist/lang/ast/expressions/expr-number.d.ts +10 -0
- package/dist/lang/ast/expressions/expr-number.js +42 -0
- package/dist/lang/ast/expressions/expr-parens.d.ts +10 -0
- package/dist/lang/ast/expressions/expr-parens.js +42 -0
- package/dist/lang/ast/expressions/expr-regex.d.ts +8 -0
- package/dist/lang/ast/expressions/expr-regex.js +42 -0
- package/dist/lang/ast/expressions/expr-string.d.ts +9 -0
- package/dist/lang/ast/expressions/expr-string.js +50 -0
- package/dist/lang/ast/expressions/expr-sum.d.ts +6 -0
- package/dist/lang/ast/expressions/expr-sum.js +12 -0
- package/dist/lang/ast/expressions/expr-time-extract.d.ts +13 -0
- package/dist/lang/ast/expressions/expr-time-extract.js +117 -0
- package/dist/lang/ast/expressions/expr-time.d.ts +11 -0
- package/dist/lang/ast/expressions/expr-time.js +62 -0
- package/dist/lang/ast/expressions/expr-ungroup.d.ts +14 -0
- package/dist/lang/ast/expressions/expr-ungroup.js +83 -0
- package/dist/lang/ast/expressions/for-range.d.ts +19 -0
- package/dist/lang/ast/expressions/for-range.js +101 -0
- package/dist/lang/ast/expressions/granular-literal.d.ts +20 -0
- package/dist/lang/ast/expressions/granular-literal.js +148 -0
- package/dist/lang/ast/expressions/partial-compare.d.ts +14 -0
- package/dist/lang/ast/expressions/partial-compare.js +50 -0
- package/dist/lang/ast/expressions/pick-when.d.ts +19 -0
- package/dist/lang/ast/expressions/pick-when.js +156 -0
- package/dist/lang/ast/expressions/range.d.ts +12 -0
- package/dist/lang/ast/expressions/range.js +80 -0
- package/dist/lang/ast/expressions/time-frame.d.ts +7 -0
- package/dist/lang/ast/expressions/time-frame.js +40 -0
- package/dist/lang/ast/expressions/top-by.d.ts +10 -0
- package/dist/lang/ast/expressions/top-by.js +51 -0
- package/dist/lang/ast/expressions/unary.d.ts +5 -0
- package/dist/lang/ast/expressions/unary.js +34 -0
- package/dist/lang/ast/expressions/utils.d.ts +15 -0
- package/dist/lang/ast/expressions/utils.js +106 -0
- package/dist/lang/ast/expressions/when-clause.d.ts +10 -0
- package/dist/lang/ast/expressions/when-clause.js +17 -0
- package/dist/lang/ast/fragtype-utils.d.ts +39 -0
- package/dist/lang/ast/fragtype-utils.js +100 -0
- package/dist/lang/ast/import-elements/import-statement.d.ts +9 -0
- package/dist/lang/ast/import-elements/import-statement.js +78 -0
- package/dist/lang/ast/index.d.ts +94 -3
- package/dist/lang/ast/index.js +94 -3
- package/dist/lang/ast/json-elements/json-element.d.ts +6 -0
- package/dist/lang/ast/json-elements/json-element.js +41 -0
- package/dist/lang/ast/json-elements/json-struct-def.d.ts +10 -0
- package/dist/lang/ast/json-elements/json-struct-def.js +48 -0
- package/dist/lang/ast/nesting/nest-reference.d.ts +7 -0
- package/dist/lang/ast/nesting/nest-reference.js +35 -0
- package/dist/lang/ast/parameters/constant-parameter.d.ts +8 -0
- package/dist/lang/ast/parameters/constant-parameter.js +54 -0
- package/dist/lang/ast/parameters/has-parameter.d.ts +19 -0
- package/dist/lang/ast/parameters/has-parameter.js +64 -0
- package/dist/lang/ast/query-elements/anonymous-query.d.ts +9 -0
- package/dist/lang/ast/query-elements/anonymous-query.js +41 -0
- package/dist/lang/ast/query-elements/existing-query.d.ts +11 -0
- package/dist/lang/ast/query-elements/existing-query.js +79 -0
- package/dist/lang/ast/query-elements/full-query.d.ts +10 -0
- package/dist/lang/ast/query-elements/full-query.js +85 -0
- package/dist/lang/ast/query-elements/query-head-struct.d.ts +9 -0
- package/dist/lang/ast/query-elements/query-head-struct.js +48 -0
- package/dist/lang/ast/query-items/field-declaration.d.ts +31 -0
- package/dist/lang/ast/query-items/field-declaration.js +137 -0
- package/dist/lang/ast/query-items/field-references.d.ts +25 -0
- package/dist/lang/ast/query-items/field-references.js +80 -0
- package/dist/lang/ast/query-properties/aggregate.d.ts +5 -0
- package/dist/lang/ast/query-properties/aggregate.js +39 -0
- package/dist/lang/ast/query-properties/declare-fields.d.ts +5 -0
- package/dist/lang/ast/query-properties/declare-fields.js +33 -0
- package/dist/lang/ast/query-properties/dimmensions.d.ts +5 -0
- package/dist/lang/ast/query-properties/dimmensions.js +36 -0
- package/dist/lang/ast/query-properties/filters.d.ts +18 -0
- package/dist/lang/ast/query-properties/filters.js +89 -0
- package/dist/lang/ast/query-properties/group-by.d.ts +5 -0
- package/dist/lang/ast/query-properties/group-by.js +39 -0
- package/dist/lang/ast/query-properties/indexing.d.ts +10 -0
- package/dist/lang/ast/query-properties/indexing.js +39 -0
- package/dist/lang/ast/query-properties/joins.d.ts +36 -0
- package/dist/lang/ast/query-properties/joins.js +143 -0
- package/dist/lang/ast/query-properties/limit.d.ts +6 -0
- package/dist/lang/ast/query-properties/limit.js +35 -0
- package/dist/lang/ast/query-properties/measures.d.ts +5 -0
- package/dist/lang/ast/query-properties/measures.js +36 -0
- package/dist/lang/ast/query-properties/nests.d.ts +5 -0
- package/dist/lang/ast/query-properties/nests.js +33 -0
- package/dist/lang/ast/query-properties/ordering.d.ts +15 -0
- package/dist/lang/ast/query-properties/ordering.js +66 -0
- package/dist/lang/ast/query-properties/project-statement.d.ts +5 -0
- package/dist/lang/ast/query-properties/project-statement.js +33 -0
- package/dist/lang/ast/query-properties/qop-desc.d.ts +17 -0
- package/dist/lang/ast/query-properties/qop-desc.js +123 -0
- package/dist/lang/ast/query-properties/sampling.d.ts +8 -0
- package/dist/lang/ast/query-properties/sampling.js +38 -0
- package/dist/lang/ast/query-properties/top.d.ts +13 -0
- package/dist/lang/ast/query-properties/top.js +60 -0
- package/dist/lang/ast/result-spaces/index-field-space.d.ts +10 -0
- package/dist/lang/ast/result-spaces/index-field-space.js +57 -0
- package/dist/lang/ast/result-spaces/project-field-space.d.ts +6 -0
- package/dist/lang/ast/result-spaces/project-field-space.js +51 -0
- package/dist/lang/ast/result-spaces/reduce-field-space.d.ts +7 -0
- package/dist/lang/ast/result-spaces/reduce-field-space.js +37 -0
- package/dist/lang/ast/sources/named-source.d.ts +19 -0
- package/dist/lang/ast/sources/named-source.js +147 -0
- package/dist/lang/ast/sources/query-source.d.ts +9 -0
- package/dist/lang/ast/sources/query-source.js +41 -0
- package/dist/lang/ast/sources/sql-source.d.ts +7 -0
- package/dist/lang/ast/sources/sql-source.js +54 -0
- package/dist/lang/ast/sources/table-source.d.ts +8 -0
- package/dist/lang/ast/sources/table-source.js +60 -0
- package/dist/lang/ast/space-fields/column-space-field.d.ts +9 -0
- package/dist/lang/ast/space-fields/column-space-field.js +40 -0
- package/dist/lang/ast/space-fields/join-space-field.d.ts +8 -0
- package/dist/lang/ast/space-fields/join-space-field.js +35 -0
- package/dist/lang/ast/space-fields/query-field-struct.d.ts +10 -0
- package/dist/lang/ast/space-fields/query-field-struct.js +46 -0
- package/dist/lang/ast/space-fields/query-space-field.d.ts +11 -0
- package/dist/lang/ast/space-fields/query-space-field.js +37 -0
- package/dist/lang/ast/space-fields/reference-field.d.ts +11 -0
- package/dist/lang/ast/space-fields/reference-field.js +45 -0
- package/dist/lang/ast/space-fields/rename-space-field.d.ts +11 -0
- package/dist/lang/ast/space-fields/rename-space-field.js +50 -0
- package/dist/lang/ast/space-fields/wild-space-field.d.ts +10 -0
- package/dist/lang/ast/space-fields/wild-space-field.js +40 -0
- package/dist/lang/ast/space-parameters/abstract-parameter.d.ts +10 -0
- package/dist/lang/ast/space-parameters/abstract-parameter.js +41 -0
- package/dist/lang/ast/space-parameters/defined-parameter.d.ts +9 -0
- package/dist/lang/ast/space-parameters/defined-parameter.js +40 -0
- package/dist/lang/ast/space-seed.d.ts +17 -0
- package/dist/lang/ast/space-seed.js +59 -0
- package/dist/lang/ast/sql-elements/sql-statement.d.ts +19 -0
- package/dist/lang/ast/sql-elements/sql-statement.js +80 -0
- package/dist/lang/ast/sql-elements/sql-string.d.ts +12 -0
- package/dist/lang/ast/sql-elements/sql-string.js +60 -0
- package/dist/lang/ast/static-space.d.ts +33 -0
- package/dist/lang/ast/static-space.js +167 -0
- package/dist/lang/ast/struct-utils.d.ts +4 -0
- package/dist/lang/ast/struct-utils.js +48 -0
- package/dist/lang/ast/time-utils.d.ts +5 -2
- package/dist/lang/ast/time-utils.js +37 -1
- package/dist/lang/ast/types/comparison.d.ts +11 -0
- package/dist/lang/ast/types/comparison.js +41 -0
- package/dist/lang/ast/types/compart-types.d.ts +10 -0
- package/dist/lang/ast/types/compart-types.js +37 -0
- package/dist/lang/ast/types/document-compile-result.d.ts +8 -0
- package/dist/lang/ast/types/document-compile-result.js +25 -0
- package/dist/lang/ast/types/equality.d.ts +7 -0
- package/dist/lang/ast/types/equality.js +37 -0
- package/dist/lang/ast/types/executor.d.ts +9 -0
- package/dist/lang/ast/types/executor.js +25 -0
- package/dist/lang/ast/types/explore-desc.d.ts +5 -0
- package/dist/lang/ast/types/explore-desc.js +33 -0
- package/dist/lang/ast/types/explore-field.d.ts +5 -0
- package/dist/lang/ast/types/explore-field.js +32 -0
- package/dist/lang/ast/types/explore-property.d.ts +10 -0
- package/dist/lang/ast/types/explore-property.js +43 -0
- package/dist/lang/ast/types/expr-result.d.ts +5 -0
- package/dist/lang/ast/types/expr-result.js +25 -0
- package/dist/lang/ast/types/expr-value.d.ts +3 -0
- package/dist/lang/ast/types/expr-value.js +25 -0
- package/dist/lang/ast/types/expression-def.d.ts +69 -0
- package/dist/lang/ast/types/expression-def.js +346 -0
- package/dist/lang/ast/types/expression-value-type.d.ts +2 -0
- package/dist/lang/ast/types/expression-value-type.js +25 -0
- package/dist/lang/ast/types/field-collection-member.d.ts +5 -0
- package/dist/lang/ast/types/field-collection-member.js +34 -0
- package/dist/lang/ast/types/field-decl.d.ts +7 -0
- package/dist/lang/ast/types/field-decl.js +37 -0
- package/dist/lang/ast/types/field-map.d.ts +2 -0
- package/dist/lang/ast/types/field-map.js +25 -0
- package/dist/lang/ast/types/field-space.d.ts +26 -0
- package/dist/lang/ast/types/field-space.js +48 -0
- package/dist/lang/ast/types/field-type.d.ts +6 -0
- package/dist/lang/ast/types/field-type.js +25 -0
- package/dist/lang/ast/types/field-value-type.d.ts +3 -0
- package/dist/lang/ast/types/field-value-type.js +25 -0
- package/dist/lang/ast/types/frag-type.d.ts +6 -0
- package/dist/lang/ast/types/frag-type.js +25 -0
- package/dist/lang/ast/types/granular-result.d.ts +7 -0
- package/dist/lang/ast/types/granular-result.js +11 -0
- package/dist/lang/ast/types/lookup-result.d.ts +10 -0
- package/dist/lang/ast/types/lookup-result.js +25 -0
- package/dist/lang/ast/types/malloy-element.d.ts +105 -0
- package/dist/lang/ast/types/malloy-element.js +398 -0
- package/dist/lang/ast/types/model-entry.d.ts +6 -0
- package/dist/lang/ast/types/model-entry.js +25 -0
- package/dist/lang/ast/types/name-space.d.ts +5 -0
- package/dist/lang/ast/types/name-space.js +25 -0
- package/dist/lang/ast/types/nested-query.d.ts +3 -0
- package/dist/lang/ast/types/nested-query.js +25 -0
- package/dist/lang/ast/types/op-desc.d.ts +6 -0
- package/dist/lang/ast/types/op-desc.js +25 -0
- package/dist/lang/ast/types/query-comp.d.ts +5 -0
- package/dist/lang/ast/types/query-comp.js +25 -0
- package/dist/lang/ast/types/query-element.d.ts +5 -0
- package/dist/lang/ast/types/query-element.js +32 -0
- package/dist/lang/ast/types/query-item.d.ts +5 -0
- package/dist/lang/ast/types/query-item.js +25 -0
- package/dist/lang/ast/types/query-property.d.ts +17 -0
- package/dist/lang/ast/types/query-property.js +55 -0
- package/dist/lang/ast/types/space-entry.d.ts +5 -0
- package/dist/lang/ast/types/space-entry.js +29 -0
- package/dist/lang/ast/types/space-field.d.ts +10 -0
- package/dist/lang/ast/types/space-field.js +48 -0
- package/dist/lang/ast/types/space-param.d.ts +6 -0
- package/dist/lang/ast/types/space-param.js +34 -0
- package/dist/lang/ast/types/stage-field-type.d.ts +1 -0
- package/dist/lang/ast/types/stage-field-type.js +25 -0
- package/dist/lang/ast/types/time-result.d.ts +6 -0
- package/dist/lang/ast/types/time-result.js +25 -0
- package/dist/lang/ast/types/turtle-headed-pipe.d.ts +7 -0
- package/dist/lang/ast/types/turtle-headed-pipe.js +37 -0
- package/dist/lang/space-field.d.ts +4 -1
- package/dist/lang/space-field.js +4 -3
- package/dist/lang/test/field-symbols.spec.js +25 -21
- package/dist/lang/test/parse.spec.js +4 -3
- package/dist/lang/test/test-translator.d.ts +3 -1
- package/package.json +1 -1
- package/dist/lang/ast/apply-expr.d.ts +0 -3
- package/dist/lang/ast/ast-expr.d.ts +0 -206
- package/dist/lang/ast/ast-expr.js +0 -781
- package/dist/lang/ast/ast-time-expr.d.ts +0 -69
- package/dist/lang/ast/ast-time-expr.js +0 -389
- package/dist/lang/ast/ast-types.d.ts +0 -83
- package/dist/lang/ast/ast-types.js +0 -225
|
@@ -1,781 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright 2023 Google LLC
|
|
4
|
-
*
|
|
5
|
-
* Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
-
* a copy of this software and associated documentation files
|
|
7
|
-
* (the "Software"), to deal in the Software without restriction,
|
|
8
|
-
* including without limitation the rights to use, copy, modify, merge,
|
|
9
|
-
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
10
|
-
* and to permit persons to whom the Software is furnished to do so,
|
|
11
|
-
* subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be
|
|
14
|
-
* included in all copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
-
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
-
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
-
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
-
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
-
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
-
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.Apply = exports.Pick = exports.PickWhen = exports.TopBy = exports.ExprCast = exports.isCastType = exports.ExprFilter = exports.ExprCase = exports.WhenClause = exports.ExprUngroup = exports.ExprSum = exports.ExprAvg = exports.ExprCount = exports.ExprCountDistinct = exports.ExprMax = exports.ExprMin = exports.ExprAlternationTree = exports.ExprMulDiv = exports.ExprAddSub = exports.BinaryNumeric = exports.ExprMinus = exports.ExprParens = exports.ExprNULL = exports.ExprIdReference = exports.ExprLogicalOp = exports.Boolean = exports.ExprNot = exports.ExprRegEx = exports.ExprNumber = exports.ExprString = void 0;
|
|
26
|
-
/*
|
|
27
|
-
** This file is the general framework for expression nodes and expression
|
|
28
|
-
** evaluation.
|
|
29
|
-
*/
|
|
30
|
-
const malloy_types_1 = require("../../model/malloy_types");
|
|
31
|
-
const ast_main_1 = require("./ast-main");
|
|
32
|
-
const ast_types_1 = require("./ast-types");
|
|
33
|
-
const apply_expr_1 = require("./apply-expr");
|
|
34
|
-
const time_utils_1 = require("./time-utils");
|
|
35
|
-
class ExprString extends ast_main_1.ExpressionDef {
|
|
36
|
-
constructor(src) {
|
|
37
|
-
super();
|
|
38
|
-
this.elementType = "string literal";
|
|
39
|
-
const bareStr = src.slice(1, -1);
|
|
40
|
-
const val = bareStr.replace(/\\(.)/g, "$1");
|
|
41
|
-
this.value = val;
|
|
42
|
-
}
|
|
43
|
-
getExpression(_fs) {
|
|
44
|
-
return {
|
|
45
|
-
...ast_types_1.FT.stringT,
|
|
46
|
-
value: [
|
|
47
|
-
{
|
|
48
|
-
type: "dialect",
|
|
49
|
-
function: "stringLiteral",
|
|
50
|
-
literal: this.value,
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
exports.ExprString = ExprString;
|
|
57
|
-
class ExprNumber extends ast_main_1.ExpressionDef {
|
|
58
|
-
constructor(n) {
|
|
59
|
-
super();
|
|
60
|
-
this.n = n;
|
|
61
|
-
this.elementType = "numeric literal";
|
|
62
|
-
}
|
|
63
|
-
getExpression(_fs) {
|
|
64
|
-
return this.constantExpression();
|
|
65
|
-
}
|
|
66
|
-
constantExpression() {
|
|
67
|
-
return { ...ast_types_1.FT.numberT, value: [this.n] };
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.ExprNumber = ExprNumber;
|
|
71
|
-
class ExprRegEx extends ast_main_1.ExpressionDef {
|
|
72
|
-
constructor(regex) {
|
|
73
|
-
super();
|
|
74
|
-
this.regex = regex;
|
|
75
|
-
this.elementType = "regular expression literal";
|
|
76
|
-
}
|
|
77
|
-
getExpression() {
|
|
78
|
-
return {
|
|
79
|
-
dataType: "regular expression",
|
|
80
|
-
expressionType: "scalar",
|
|
81
|
-
value: [`r'${this.regex}'`],
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
exports.ExprRegEx = ExprRegEx;
|
|
86
|
-
class Unary extends ast_main_1.ExpressionDef {
|
|
87
|
-
constructor(expr) {
|
|
88
|
-
super({ expr });
|
|
89
|
-
this.expr = expr;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
class ExprNot extends Unary {
|
|
93
|
-
constructor(expr) {
|
|
94
|
-
super(expr);
|
|
95
|
-
this.elementType = "not";
|
|
96
|
-
this.legalChildTypes = [ast_types_1.FT.boolT, ast_types_1.FT.nullT];
|
|
97
|
-
}
|
|
98
|
-
getExpression(fs) {
|
|
99
|
-
const notThis = this.expr.getExpression(fs);
|
|
100
|
-
if (this.typeCheck(this.expr, notThis)) {
|
|
101
|
-
return {
|
|
102
|
-
...notThis,
|
|
103
|
-
dataType: "boolean",
|
|
104
|
-
value: (0, apply_expr_1.nullsafeNot)(notThis.value),
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
return (0, ast_types_1.errorFor)("not requires boolean");
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
exports.ExprNot = ExprNot;
|
|
111
|
-
class Boolean extends ast_main_1.ExpressionDef {
|
|
112
|
-
constructor(value) {
|
|
113
|
-
super();
|
|
114
|
-
this.value = value;
|
|
115
|
-
this.elementType = "boolean literal";
|
|
116
|
-
}
|
|
117
|
-
getExpression() {
|
|
118
|
-
return { ...ast_types_1.FT.boolT, value: [this.value] };
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
exports.Boolean = Boolean;
|
|
122
|
-
class ExprLogicalOp extends ast_main_1.BinaryBoolean {
|
|
123
|
-
constructor() {
|
|
124
|
-
super(...arguments);
|
|
125
|
-
this.elementType = "logical operator";
|
|
126
|
-
this.legalChildTypes = [ast_types_1.FT.boolT, { ...ast_types_1.FT.boolT, aggregate: true }];
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
exports.ExprLogicalOp = ExprLogicalOp;
|
|
130
|
-
class ExprIdReference extends ast_main_1.ExpressionDef {
|
|
131
|
-
constructor(fieldReference) {
|
|
132
|
-
super();
|
|
133
|
-
this.fieldReference = fieldReference;
|
|
134
|
-
this.elementType = "ExpressionIdReference";
|
|
135
|
-
this.has({ fieldPath: fieldReference });
|
|
136
|
-
}
|
|
137
|
-
get refString() {
|
|
138
|
-
return this.fieldReference.refString;
|
|
139
|
-
}
|
|
140
|
-
getExpression(fs) {
|
|
141
|
-
const def = this.fieldReference.getField(fs);
|
|
142
|
-
if (def.found) {
|
|
143
|
-
// TODO if type is a query or a struct this should fail nicely
|
|
144
|
-
const typeMixin = def.found.type();
|
|
145
|
-
const dataType = typeMixin.type;
|
|
146
|
-
const expressionType = typeMixin.expressionType || "scalar";
|
|
147
|
-
const value = [{ type: def.found.refType, path: this.refString }];
|
|
148
|
-
return { dataType, expressionType, value };
|
|
149
|
-
}
|
|
150
|
-
this.log(def.error);
|
|
151
|
-
return (0, ast_types_1.errorFor)(def.error);
|
|
152
|
-
}
|
|
153
|
-
apply(fs, op, expr) {
|
|
154
|
-
const entry = this.fieldReference.getField(fs).found;
|
|
155
|
-
if (entry instanceof ast_main_1.SpaceParam) {
|
|
156
|
-
const cParam = entry.parameter();
|
|
157
|
-
if ((0, malloy_types_1.isConditionParameter)(cParam)) {
|
|
158
|
-
const lval = expr.getExpression(fs);
|
|
159
|
-
return {
|
|
160
|
-
dataType: "boolean",
|
|
161
|
-
expressionType: lval.expressionType,
|
|
162
|
-
value: [
|
|
163
|
-
{
|
|
164
|
-
type: "apply",
|
|
165
|
-
value: lval.value,
|
|
166
|
-
to: [{ type: "parameter", path: this.refString }],
|
|
167
|
-
},
|
|
168
|
-
],
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return super.apply(fs, op, expr);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
exports.ExprIdReference = ExprIdReference;
|
|
176
|
-
class ExprNULL extends ast_main_1.ExpressionDef {
|
|
177
|
-
constructor() {
|
|
178
|
-
super(...arguments);
|
|
179
|
-
this.elementType = "NULL";
|
|
180
|
-
}
|
|
181
|
-
getExpression() {
|
|
182
|
-
return {
|
|
183
|
-
dataType: "null",
|
|
184
|
-
value: ["NULL"],
|
|
185
|
-
expressionType: "scalar",
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
exports.ExprNULL = ExprNULL;
|
|
190
|
-
class ExprParens extends ast_main_1.ExpressionDef {
|
|
191
|
-
constructor(expr) {
|
|
192
|
-
super({ expr });
|
|
193
|
-
this.expr = expr;
|
|
194
|
-
this.elementType = "(expression)";
|
|
195
|
-
}
|
|
196
|
-
requestExpression(fs) {
|
|
197
|
-
return this.expr.requestExpression(fs);
|
|
198
|
-
}
|
|
199
|
-
getExpression(fs) {
|
|
200
|
-
const subExpr = this.expr.getExpression(fs);
|
|
201
|
-
return { ...subExpr, value: ["(", ...subExpr.value, ")"] };
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
exports.ExprParens = ExprParens;
|
|
205
|
-
class ExprMinus extends ast_main_1.ExpressionDef {
|
|
206
|
-
constructor(expr) {
|
|
207
|
-
super({ expr });
|
|
208
|
-
this.expr = expr;
|
|
209
|
-
this.elementType = "unary minus";
|
|
210
|
-
this.legalChildTypes = [ast_types_1.FT.numberT];
|
|
211
|
-
}
|
|
212
|
-
getExpression(fs) {
|
|
213
|
-
const expr = this.expr.getExpression(fs);
|
|
214
|
-
if (this.typeCheck(this.expr, expr)) {
|
|
215
|
-
if (expr.value.length > 1) {
|
|
216
|
-
return { ...expr, value: ["-(", ...expr.value, ")"] };
|
|
217
|
-
}
|
|
218
|
-
return { ...expr, value: ["-", ...expr.value] };
|
|
219
|
-
}
|
|
220
|
-
return (0, ast_types_1.errorFor)("negate requires number");
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
exports.ExprMinus = ExprMinus;
|
|
224
|
-
class BinaryNumeric extends ast_main_1.ExpressionDef {
|
|
225
|
-
constructor(left, op, right) {
|
|
226
|
-
super({ left, right });
|
|
227
|
-
this.left = left;
|
|
228
|
-
this.op = op;
|
|
229
|
-
this.right = right;
|
|
230
|
-
this.elementType = "numeric binary abstract";
|
|
231
|
-
this.legalChildTypes = [ast_types_1.FT.numberT];
|
|
232
|
-
}
|
|
233
|
-
getExpression(fs) {
|
|
234
|
-
return this.right.apply(fs, this.op, this.left);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
exports.BinaryNumeric = BinaryNumeric;
|
|
238
|
-
class ExprAddSub extends BinaryNumeric {
|
|
239
|
-
constructor() {
|
|
240
|
-
super(...arguments);
|
|
241
|
-
this.elementType = "+-";
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
exports.ExprAddSub = ExprAddSub;
|
|
245
|
-
class ExprMulDiv extends BinaryNumeric {
|
|
246
|
-
constructor() {
|
|
247
|
-
super(...arguments);
|
|
248
|
-
this.elementType = "*/%";
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
exports.ExprMulDiv = ExprMulDiv;
|
|
252
|
-
class ExprAlternationTree extends ast_main_1.BinaryBoolean {
|
|
253
|
-
constructor(left, op, right) {
|
|
254
|
-
super(left, op, right);
|
|
255
|
-
this.elementType = "alternation";
|
|
256
|
-
this.elementType = `${op}alternation${op}`;
|
|
257
|
-
}
|
|
258
|
-
apply(fs, applyOp, expr) {
|
|
259
|
-
const choice1 = this.left.apply(fs, applyOp, expr);
|
|
260
|
-
const choice2 = this.right.apply(fs, applyOp, expr);
|
|
261
|
-
return {
|
|
262
|
-
dataType: "boolean",
|
|
263
|
-
expressionType: (0, malloy_types_1.maxExpressionType)(choice1.expressionType, choice2.expressionType),
|
|
264
|
-
value: (0, ast_types_1.compose)(choice1.value, this.op === "&" ? "and" : "or", choice2.value),
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
requestExpression(_fs) {
|
|
268
|
-
return undefined;
|
|
269
|
-
}
|
|
270
|
-
getExpression(_fs) {
|
|
271
|
-
this.log(`Alternation tree has no value`);
|
|
272
|
-
return (0, ast_types_1.errorFor)("no value from alternation tree");
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
exports.ExprAlternationTree = ExprAlternationTree;
|
|
276
|
-
class ExprAggregateFunction extends ast_main_1.ExpressionDef {
|
|
277
|
-
constructor(func, expr) {
|
|
278
|
-
super();
|
|
279
|
-
this.func = func;
|
|
280
|
-
this.legalChildTypes = [ast_types_1.FT.numberT];
|
|
281
|
-
this.elementType = func;
|
|
282
|
-
if (expr) {
|
|
283
|
-
this.expr = expr;
|
|
284
|
-
this.has({ expr });
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
returns(_forExpression) {
|
|
288
|
-
return "number";
|
|
289
|
-
}
|
|
290
|
-
getExpression(fs) {
|
|
291
|
-
var _a, _b;
|
|
292
|
-
let exprVal = (_a = this.expr) === null || _a === void 0 ? void 0 : _a.getExpression(fs);
|
|
293
|
-
let structPath = (_b = this.source) === null || _b === void 0 ? void 0 : _b.refString;
|
|
294
|
-
if (this.source) {
|
|
295
|
-
const sourceFoot = this.source.getField(fs).found;
|
|
296
|
-
if (sourceFoot) {
|
|
297
|
-
const footType = sourceFoot.type();
|
|
298
|
-
if ((0, malloy_types_1.isAtomicFieldType)(footType.type)) {
|
|
299
|
-
exprVal = {
|
|
300
|
-
dataType: footType.type,
|
|
301
|
-
expressionType: footType.expressionType || "scalar",
|
|
302
|
-
value: [{ type: "field", path: this.source.refString }],
|
|
303
|
-
};
|
|
304
|
-
structPath = this.source.sourceString;
|
|
305
|
-
}
|
|
306
|
-
else {
|
|
307
|
-
if (!(sourceFoot instanceof ast_main_1.StructSpaceField)) {
|
|
308
|
-
this.log(`Aggregate source cannot be a ${footType.type}`);
|
|
309
|
-
return (0, ast_types_1.errorFor)(`Aggregate source cannot be a ${footType.type}`);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
else {
|
|
314
|
-
this.log(`Reference to undefined value ${this.source.refString}`);
|
|
315
|
-
return (0, ast_types_1.errorFor)(`Reference to undefined value ${this.source.refString}`);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
if (exprVal === undefined) {
|
|
319
|
-
this.log("Missing expression for aggregate function");
|
|
320
|
-
return (0, ast_types_1.errorFor)("agggregate without expression");
|
|
321
|
-
}
|
|
322
|
-
if (this.typeCheck(this.expr || this, {
|
|
323
|
-
...exprVal,
|
|
324
|
-
expressionType: "scalar",
|
|
325
|
-
})) {
|
|
326
|
-
const f = {
|
|
327
|
-
type: "aggregate",
|
|
328
|
-
function: this.func,
|
|
329
|
-
e: exprVal.value,
|
|
330
|
-
};
|
|
331
|
-
if (structPath) {
|
|
332
|
-
f.structPath = structPath;
|
|
333
|
-
}
|
|
334
|
-
return {
|
|
335
|
-
dataType: this.returns(exprVal),
|
|
336
|
-
expressionType: "aggregate",
|
|
337
|
-
value: [f],
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
return (0, ast_types_1.errorFor)("aggregate type check");
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
class ExprMin extends ExprAggregateFunction {
|
|
344
|
-
constructor(expr) {
|
|
345
|
-
super("min", expr);
|
|
346
|
-
this.legalChildTypes = [ast_types_1.FT.numberT, ast_types_1.FT.stringT, ast_types_1.FT.dateT, ast_types_1.FT.timestampT];
|
|
347
|
-
}
|
|
348
|
-
returns(forExpression) {
|
|
349
|
-
return forExpression.dataType;
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
exports.ExprMin = ExprMin;
|
|
353
|
-
class ExprMax extends ExprAggregateFunction {
|
|
354
|
-
constructor(expr) {
|
|
355
|
-
super("max", expr);
|
|
356
|
-
this.legalChildTypes = [ast_types_1.FT.numberT, ast_types_1.FT.stringT, ast_types_1.FT.dateT, ast_types_1.FT.timestampT];
|
|
357
|
-
}
|
|
358
|
-
returns(forExpression) {
|
|
359
|
-
return forExpression.dataType;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
exports.ExprMax = ExprMax;
|
|
363
|
-
class ExprCountDistinct extends ExprAggregateFunction {
|
|
364
|
-
constructor(expr) {
|
|
365
|
-
super("count_distinct", expr);
|
|
366
|
-
this.legalChildTypes = [ast_types_1.FT.numberT, ast_types_1.FT.stringT, ast_types_1.FT.dateT, ast_types_1.FT.timestampT];
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
exports.ExprCountDistinct = ExprCountDistinct;
|
|
370
|
-
class ExprAsymmetric extends ExprAggregateFunction {
|
|
371
|
-
constructor(func, expr, source) {
|
|
372
|
-
super(func, expr);
|
|
373
|
-
this.func = func;
|
|
374
|
-
this.expr = expr;
|
|
375
|
-
this.source = source;
|
|
376
|
-
this.has({ source });
|
|
377
|
-
}
|
|
378
|
-
defaultFieldName() {
|
|
379
|
-
if (this.source && this.expr === undefined) {
|
|
380
|
-
const tag = this.source.nameString;
|
|
381
|
-
switch (this.func) {
|
|
382
|
-
case "sum":
|
|
383
|
-
return `total_${tag}`;
|
|
384
|
-
case "avg":
|
|
385
|
-
return `avg_${tag}`;
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
return undefined;
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
class ExprCount extends ExprAggregateFunction {
|
|
392
|
-
constructor(source) {
|
|
393
|
-
super("count");
|
|
394
|
-
this.source = source;
|
|
395
|
-
this.elementType = "count";
|
|
396
|
-
this.has({ source });
|
|
397
|
-
}
|
|
398
|
-
defaultFieldName() {
|
|
399
|
-
if (this.source) {
|
|
400
|
-
return "count_" + this.source.nameString;
|
|
401
|
-
}
|
|
402
|
-
return undefined;
|
|
403
|
-
}
|
|
404
|
-
getExpression(_fs) {
|
|
405
|
-
const ret = {
|
|
406
|
-
type: "aggregate",
|
|
407
|
-
function: "count",
|
|
408
|
-
e: [],
|
|
409
|
-
};
|
|
410
|
-
if (this.source) {
|
|
411
|
-
ret.structPath = this.source.refString;
|
|
412
|
-
}
|
|
413
|
-
return {
|
|
414
|
-
dataType: "number",
|
|
415
|
-
expressionType: "aggregate",
|
|
416
|
-
value: [ret],
|
|
417
|
-
};
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
exports.ExprCount = ExprCount;
|
|
421
|
-
class ExprAvg extends ExprAsymmetric {
|
|
422
|
-
constructor(expr, source) {
|
|
423
|
-
super("avg", expr, source);
|
|
424
|
-
this.has({ source });
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
exports.ExprAvg = ExprAvg;
|
|
428
|
-
class ExprSum extends ExprAsymmetric {
|
|
429
|
-
constructor(expr, source) {
|
|
430
|
-
super("sum", expr, source);
|
|
431
|
-
this.has({ source });
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
exports.ExprSum = ExprSum;
|
|
435
|
-
class ExprUngroup extends ast_main_1.ExpressionDef {
|
|
436
|
-
constructor(control, expr, fields) {
|
|
437
|
-
super({ expr, fields });
|
|
438
|
-
this.control = control;
|
|
439
|
-
this.expr = expr;
|
|
440
|
-
this.fields = fields;
|
|
441
|
-
this.legalChildTypes = ast_types_1.FT.anyAtomicT;
|
|
442
|
-
this.elementType = "ungroup";
|
|
443
|
-
}
|
|
444
|
-
returns(_forExpression) {
|
|
445
|
-
return "number";
|
|
446
|
-
}
|
|
447
|
-
getExpression(fs) {
|
|
448
|
-
const exprVal = this.expr.getExpression(fs);
|
|
449
|
-
if (!(0, malloy_types_1.expressionIsAggregate)(exprVal.expressionType)) {
|
|
450
|
-
this.expr.log(`${this.control}() expression must be an aggregate`);
|
|
451
|
-
return (0, ast_types_1.errorFor)("ungrouped scalar");
|
|
452
|
-
}
|
|
453
|
-
const ungroup = { type: this.control, e: exprVal.value };
|
|
454
|
-
if (this.typeCheck(this.expr, { ...exprVal, expressionType: "scalar" })) {
|
|
455
|
-
if (this.fields.length > 0) {
|
|
456
|
-
let qs = fs;
|
|
457
|
-
if (fs instanceof ast_main_1.DefSpace) {
|
|
458
|
-
qs = fs.realFS;
|
|
459
|
-
}
|
|
460
|
-
if (!(qs instanceof ast_main_1.QuerySpace)) {
|
|
461
|
-
this.log(`${this.control}() must be in a query -- weird internal error`);
|
|
462
|
-
return (0, ast_types_1.errorFor)("ungroup query check");
|
|
463
|
-
}
|
|
464
|
-
const output = qs.result;
|
|
465
|
-
const dstFields = [];
|
|
466
|
-
const isExclude = this.control == "exclude";
|
|
467
|
-
for (const mustBeInOutput of this.fields) {
|
|
468
|
-
output.whenComplete(() => {
|
|
469
|
-
output.checkUngroup(mustBeInOutput, isExclude);
|
|
470
|
-
});
|
|
471
|
-
dstFields.push(mustBeInOutput.refString);
|
|
472
|
-
}
|
|
473
|
-
ungroup.fields = dstFields;
|
|
474
|
-
}
|
|
475
|
-
return {
|
|
476
|
-
dataType: this.returns(exprVal),
|
|
477
|
-
expressionType: "analytic",
|
|
478
|
-
value: [ungroup],
|
|
479
|
-
};
|
|
480
|
-
}
|
|
481
|
-
this.log(`${this.control}() incompatible type`);
|
|
482
|
-
return (0, ast_types_1.errorFor)("ungrouped type check");
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
exports.ExprUngroup = ExprUngroup;
|
|
486
|
-
class WhenClause extends ast_main_1.ExpressionDef {
|
|
487
|
-
constructor(whenThis, thenThis) {
|
|
488
|
-
super({ whenThis, thenThis });
|
|
489
|
-
this.whenThis = whenThis;
|
|
490
|
-
this.thenThis = thenThis;
|
|
491
|
-
this.elementType = "when clause";
|
|
492
|
-
}
|
|
493
|
-
getExpression(_fs) {
|
|
494
|
-
throw new Error("expression did something unxpected with 'WHEN'");
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
exports.WhenClause = WhenClause;
|
|
498
|
-
class ExprCase extends ast_main_1.ExpressionDef {
|
|
499
|
-
constructor(when, elseClause) {
|
|
500
|
-
super({ when });
|
|
501
|
-
this.when = when;
|
|
502
|
-
this.elseClause = elseClause;
|
|
503
|
-
this.elementType = "case statement";
|
|
504
|
-
this.has({ elseClause });
|
|
505
|
-
}
|
|
506
|
-
getExpression(fs) {
|
|
507
|
-
let retType;
|
|
508
|
-
let expressionType = "scalar";
|
|
509
|
-
const caseExpr = ["CASE "];
|
|
510
|
-
for (const clause of this.when) {
|
|
511
|
-
const whenExpr = clause.whenThis.getExpression(fs);
|
|
512
|
-
const thenExpr = clause.thenThis.getExpression(fs);
|
|
513
|
-
expressionType = (0, malloy_types_1.maxExpressionType)(expressionType, (0, malloy_types_1.maxExpressionType)(whenExpr.expressionType, thenExpr.expressionType));
|
|
514
|
-
if (thenExpr.dataType !== "null") {
|
|
515
|
-
if (retType && !ast_types_1.FT.typeEq(retType, thenExpr)) {
|
|
516
|
-
this.log(`Mismatched THEN clause types, ${ast_types_1.FT.inspect(retType, thenExpr)}`);
|
|
517
|
-
return (0, ast_types_1.errorFor)("then typecheck");
|
|
518
|
-
}
|
|
519
|
-
else {
|
|
520
|
-
retType = thenExpr;
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
caseExpr.push("WHEN ", ...whenExpr.value, " THEN ", ...thenExpr.value);
|
|
524
|
-
}
|
|
525
|
-
if (this.elseClause) {
|
|
526
|
-
const elseExpr = this.elseClause.getExpression(fs);
|
|
527
|
-
expressionType = (0, malloy_types_1.maxExpressionType)(expressionType, elseExpr.expressionType);
|
|
528
|
-
caseExpr.push(" ELSE ", ...elseExpr.value);
|
|
529
|
-
if (elseExpr.dataType !== "null") {
|
|
530
|
-
if (retType && !ast_types_1.FT.typeEq(retType, elseExpr)) {
|
|
531
|
-
this.log(`Mismatched ELSE clause type, ${ast_types_1.FT.inspect(retType, elseExpr)}`);
|
|
532
|
-
return (0, ast_types_1.errorFor)("else typecheck");
|
|
533
|
-
}
|
|
534
|
-
else {
|
|
535
|
-
retType = elseExpr;
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
if (retType === undefined) {
|
|
540
|
-
this.log("case statement type not computable");
|
|
541
|
-
return (0, ast_types_1.errorFor)("typeless case");
|
|
542
|
-
}
|
|
543
|
-
caseExpr.push(" END");
|
|
544
|
-
return {
|
|
545
|
-
dataType: retType.dataType,
|
|
546
|
-
expressionType,
|
|
547
|
-
value: caseExpr,
|
|
548
|
-
};
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
exports.ExprCase = ExprCase;
|
|
552
|
-
class ExprFilter extends ast_main_1.ExpressionDef {
|
|
553
|
-
constructor(expr, filter) {
|
|
554
|
-
super({ expr, filter });
|
|
555
|
-
this.expr = expr;
|
|
556
|
-
this.filter = filter;
|
|
557
|
-
this.elementType = "filtered expression";
|
|
558
|
-
this.legalChildTypes = ast_types_1.FT.anyAtomicT;
|
|
559
|
-
}
|
|
560
|
-
getExpression(fs) {
|
|
561
|
-
const testList = this.filter.getFilterList(fs);
|
|
562
|
-
const resultExpr = this.expr.getExpression(fs);
|
|
563
|
-
for (const cond of testList) {
|
|
564
|
-
if ((0, malloy_types_1.expressionIsCalculation)(cond.expressionType)) {
|
|
565
|
-
this.filter.log("Cannot filter a field with an aggregate or analytical computation");
|
|
566
|
-
return (0, ast_types_1.errorFor)("no filter on aggregate");
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
if (resultExpr.expressionType === "scalar") {
|
|
570
|
-
// TODO could log a warning, but I have a problem with the
|
|
571
|
-
// idea of warnings, so for now ...
|
|
572
|
-
return resultExpr;
|
|
573
|
-
}
|
|
574
|
-
if (this.typeCheck(this.expr, { ...resultExpr, expressionType: "scalar" })) {
|
|
575
|
-
return {
|
|
576
|
-
...resultExpr,
|
|
577
|
-
value: [
|
|
578
|
-
{
|
|
579
|
-
type: "filterExpression",
|
|
580
|
-
e: resultExpr.value,
|
|
581
|
-
filterList: testList,
|
|
582
|
-
},
|
|
583
|
-
],
|
|
584
|
-
};
|
|
585
|
-
}
|
|
586
|
-
this.expr.log(`Cannot filter '${resultExpr.dataType}' data`);
|
|
587
|
-
return (0, ast_types_1.errorFor)("cannot filter type");
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
exports.ExprFilter = ExprFilter;
|
|
591
|
-
function isCastType(t) {
|
|
592
|
-
return ["string", "number", "boolean", "date", "timestamp"].includes(t);
|
|
593
|
-
}
|
|
594
|
-
exports.isCastType = isCastType;
|
|
595
|
-
class ExprCast extends ast_main_1.ExpressionDef {
|
|
596
|
-
constructor(expr, castType, safe = false) {
|
|
597
|
-
super({ expr });
|
|
598
|
-
this.expr = expr;
|
|
599
|
-
this.castType = castType;
|
|
600
|
-
this.safe = safe;
|
|
601
|
-
this.elementType = "cast";
|
|
602
|
-
}
|
|
603
|
-
getExpression(fs) {
|
|
604
|
-
const expr = this.expr.getExpression(fs);
|
|
605
|
-
return {
|
|
606
|
-
dataType: this.castType,
|
|
607
|
-
expressionType: expr.expressionType,
|
|
608
|
-
value: (0, ast_types_1.compressExpr)((0, time_utils_1.castTo)(this.castType, expr.value, this.safe)),
|
|
609
|
-
};
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
exports.ExprCast = ExprCast;
|
|
613
|
-
class TopBy extends ast_main_1.MalloyElement {
|
|
614
|
-
constructor(by) {
|
|
615
|
-
super();
|
|
616
|
-
this.by = by;
|
|
617
|
-
this.elementType = "topBy";
|
|
618
|
-
if (by instanceof ast_main_1.ExpressionDef) {
|
|
619
|
-
this.has({ by });
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
getBy(fs) {
|
|
623
|
-
if (this.by instanceof ast_main_1.ExpressionDef) {
|
|
624
|
-
const byExpr = this.by.getExpression(fs);
|
|
625
|
-
if (!(0, malloy_types_1.expressionIsAggregate)(byExpr.expressionType)) {
|
|
626
|
-
this.log("top by expression must be an aggregate");
|
|
627
|
-
}
|
|
628
|
-
return { by: "expression", e: (0, ast_types_1.compressExpr)(byExpr.value) };
|
|
629
|
-
}
|
|
630
|
-
return { by: "name", name: this.by };
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
exports.TopBy = TopBy;
|
|
634
|
-
class PickWhen extends ast_main_1.MalloyElement {
|
|
635
|
-
constructor(pick, when) {
|
|
636
|
-
super({ when });
|
|
637
|
-
this.pick = pick;
|
|
638
|
-
this.when = when;
|
|
639
|
-
this.elementType = "pickWhen";
|
|
640
|
-
this.has({ pick });
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
exports.PickWhen = PickWhen;
|
|
644
|
-
class Pick extends ast_main_1.ExpressionDef {
|
|
645
|
-
constructor(choices, elsePick) {
|
|
646
|
-
super({ choices });
|
|
647
|
-
this.choices = choices;
|
|
648
|
-
this.elsePick = elsePick;
|
|
649
|
-
this.elementType = "pick";
|
|
650
|
-
this.has({ elsePick });
|
|
651
|
-
}
|
|
652
|
-
requestExpression(fs) {
|
|
653
|
-
// pick statements are sometimes partials which must be applied
|
|
654
|
-
// and sometimes have a value.
|
|
655
|
-
if (this.elsePick === undefined) {
|
|
656
|
-
return undefined;
|
|
657
|
-
}
|
|
658
|
-
for (const c of this.choices) {
|
|
659
|
-
if (c.pick == undefined) {
|
|
660
|
-
return undefined;
|
|
661
|
-
}
|
|
662
|
-
const whenResp = c.when.requestExpression(fs);
|
|
663
|
-
if (whenResp == undefined || whenResp.dataType != "boolean") {
|
|
664
|
-
// If when is not a boolean, we'll treat it like a partial compare
|
|
665
|
-
return undefined;
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
return this.getExpression(fs);
|
|
669
|
-
}
|
|
670
|
-
apply(fs, op, expr) {
|
|
671
|
-
const caseValue = ["CASE"];
|
|
672
|
-
let returnType;
|
|
673
|
-
let anyExpressionType = "scalar";
|
|
674
|
-
for (const choice of this.choices) {
|
|
675
|
-
const whenExpr = choice.when.apply(fs, "=", expr);
|
|
676
|
-
const thenExpr = choice.pick
|
|
677
|
-
? choice.pick.getExpression(fs)
|
|
678
|
-
: expr.getExpression(fs);
|
|
679
|
-
anyExpressionType = (0, malloy_types_1.maxExpressionType)(anyExpressionType, (0, malloy_types_1.maxExpressionType)(whenExpr.expressionType, thenExpr.expressionType));
|
|
680
|
-
if (returnType) {
|
|
681
|
-
if (!ast_types_1.FT.typeEq(returnType, thenExpr, true)) {
|
|
682
|
-
const whenType = ast_types_1.FT.inspect(thenExpr);
|
|
683
|
-
this.log(`pick type '${whenType}', expected '${returnType.dataType}'`);
|
|
684
|
-
return (0, ast_types_1.errorFor)("pick when type");
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
else {
|
|
688
|
-
returnType = thenExpr;
|
|
689
|
-
}
|
|
690
|
-
caseValue.push(" WHEN ", ...whenExpr.value, " THEN ", ...thenExpr.value);
|
|
691
|
-
}
|
|
692
|
-
const elsePart = this.elsePick || expr;
|
|
693
|
-
const elseVal = elsePart.getExpression(fs);
|
|
694
|
-
returnType || (returnType = elseVal);
|
|
695
|
-
if (!ast_types_1.FT.typeEq(returnType, elseVal, true)) {
|
|
696
|
-
const errSrc = this.elsePick ? "else" : "pick default";
|
|
697
|
-
this.log(`${errSrc} type '${ast_types_1.FT.inspect(elseVal)}', expected '${returnType.dataType}'`);
|
|
698
|
-
return (0, ast_types_1.errorFor)("pick else type");
|
|
699
|
-
}
|
|
700
|
-
return {
|
|
701
|
-
dataType: returnType.dataType,
|
|
702
|
-
expressionType: (0, malloy_types_1.maxExpressionType)(anyExpressionType, elseVal.expressionType),
|
|
703
|
-
value: (0, ast_types_1.compressExpr)([...caseValue, " ELSE ", ...elseVal.value, " END"]),
|
|
704
|
-
};
|
|
705
|
-
}
|
|
706
|
-
getExpression(fs) {
|
|
707
|
-
if (this.elsePick === undefined) {
|
|
708
|
-
this.log("pick incomplete, missing 'else'");
|
|
709
|
-
return (0, ast_types_1.errorFor)("no value for partial pick");
|
|
710
|
-
}
|
|
711
|
-
const choiceValues = [];
|
|
712
|
-
for (const c of this.choices) {
|
|
713
|
-
if (c.pick === undefined) {
|
|
714
|
-
this.log("pick with no value can only be used with apply");
|
|
715
|
-
return (0, ast_types_1.errorFor)("no value for partial pick");
|
|
716
|
-
}
|
|
717
|
-
const pickWhen = c.when.requestExpression(fs);
|
|
718
|
-
if (pickWhen === undefined) {
|
|
719
|
-
this.log("pick with partial when can only be used with apply");
|
|
720
|
-
return (0, ast_types_1.errorFor)("partial when");
|
|
721
|
-
}
|
|
722
|
-
choiceValues.push({
|
|
723
|
-
pick: c.pick.getExpression(fs),
|
|
724
|
-
when: c.when.getExpression(fs),
|
|
725
|
-
});
|
|
726
|
-
}
|
|
727
|
-
const returnType = choiceValues[0].pick;
|
|
728
|
-
const caseValue = ["CASE"];
|
|
729
|
-
let anyExpressionType = returnType.expressionType;
|
|
730
|
-
for (const aChoice of choiceValues) {
|
|
731
|
-
if (!ast_types_1.FT.typeEq(aChoice.when, ast_types_1.FT.boolT)) {
|
|
732
|
-
this.log(`when expression must be boolean, not '${ast_types_1.FT.inspect(aChoice.when)}`);
|
|
733
|
-
return (0, ast_types_1.errorFor)("pick when type");
|
|
734
|
-
}
|
|
735
|
-
if (!ast_types_1.FT.typeEq(returnType, aChoice.pick, true)) {
|
|
736
|
-
const whenType = ast_types_1.FT.inspect(aChoice.pick);
|
|
737
|
-
this.log(`pick type '${whenType}', expected '${returnType.dataType}'`);
|
|
738
|
-
return (0, ast_types_1.errorFor)("pick value type");
|
|
739
|
-
}
|
|
740
|
-
anyExpressionType = (0, malloy_types_1.maxExpressionType)(anyExpressionType, (0, malloy_types_1.maxExpressionType)(aChoice.pick.expressionType, aChoice.when.expressionType));
|
|
741
|
-
caseValue.push(" WHEN ", ...aChoice.when.value, " THEN ", ...aChoice.pick.value);
|
|
742
|
-
}
|
|
743
|
-
const defVal = this.elsePick.getExpression(fs);
|
|
744
|
-
anyExpressionType = (0, malloy_types_1.maxExpressionType)(anyExpressionType, defVal.expressionType);
|
|
745
|
-
if (!ast_types_1.FT.typeEq(returnType, defVal, true)) {
|
|
746
|
-
this.elsePick.log(`else type '${ast_types_1.FT.inspect(defVal)}', expected '${returnType.dataType}'`);
|
|
747
|
-
return (0, ast_types_1.errorFor)("pick value type mismatch");
|
|
748
|
-
}
|
|
749
|
-
caseValue.push(" ELSE ", ...defVal.value, " END");
|
|
750
|
-
return {
|
|
751
|
-
dataType: returnType.dataType,
|
|
752
|
-
expressionType: anyExpressionType,
|
|
753
|
-
value: (0, ast_types_1.compressExpr)(caseValue),
|
|
754
|
-
};
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
exports.Pick = Pick;
|
|
758
|
-
function nullCompare(left, op, right) {
|
|
759
|
-
const not = op === "!=" || op === "!~";
|
|
760
|
-
if (left.dataType === "null" || right.dataType === "null") {
|
|
761
|
-
const maybeNot = not ? " NOT" : "";
|
|
762
|
-
if (left.dataType !== "null") {
|
|
763
|
-
return [...left.value, ` IS${maybeNot} NULL`];
|
|
764
|
-
}
|
|
765
|
-
if (right.dataType !== "null") {
|
|
766
|
-
return [...right.value, `IS${maybeNot} NULL`];
|
|
767
|
-
}
|
|
768
|
-
return [not ? "false" : "true"];
|
|
769
|
-
}
|
|
770
|
-
return undefined;
|
|
771
|
-
}
|
|
772
|
-
class Apply extends ast_main_1.ExprCompare {
|
|
773
|
-
constructor(left, right) {
|
|
774
|
-
super(left, "=", right);
|
|
775
|
-
this.left = left;
|
|
776
|
-
this.right = right;
|
|
777
|
-
this.elementType = "apply";
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
exports.Apply = Apply;
|
|
781
|
-
//# sourceMappingURL=ast-expr.js.map
|