@malloydata/malloy 0.0.24-dev230224214106 → 0.0.24-dev230228224434
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/connection_utils.js +10 -10
- package/dist/dialect/dialect.d.ts +2 -2
- package/dist/dialect/dialect.js +13 -13
- package/dist/dialect/dialect_map.d.ts +1 -1
- package/dist/dialect/duckdb.d.ts +3 -3
- package/dist/dialect/duckdb.js +44 -44
- package/dist/dialect/index.d.ts +6 -6
- package/dist/dialect/postgres.d.ts +3 -3
- package/dist/dialect/postgres.js +46 -46
- package/dist/dialect/standardsql.d.ts +4 -4
- package/dist/dialect/standardsql.js +51 -51
- package/dist/index.d.ts +10 -10
- package/dist/lang/ast/ast-utils.d.ts +1 -1
- package/dist/lang/ast/ast-utils.js +3 -3
- package/dist/lang/ast/elements/define-query.d.ts +3 -3
- package/dist/lang/ast/elements/define-query.js +6 -6
- package/dist/lang/ast/elements/define-source.d.ts +4 -4
- package/dist/lang/ast/elements/define-source.js +8 -8
- package/dist/lang/ast/elements/import-statement.d.ts +2 -2
- package/dist/lang/ast/elements/import-statement.js +7 -7
- package/dist/lang/ast/elements/pipeline-desc.d.ts +5 -5
- package/dist/lang/ast/elements/pipeline-desc.js +11 -11
- package/dist/lang/ast/elements/refined-source.d.ts +4 -4
- package/dist/lang/ast/elements/refined-source.js +6 -6
- package/dist/lang/ast/elements/source.d.ts +3 -3
- package/dist/lang/ast/elements/source.js +1 -1
- package/dist/lang/ast/error-factory.d.ts +1 -1
- package/dist/lang/ast/error-factory.js +15 -15
- package/dist/lang/ast/executors/index-executor.d.ts +7 -7
- package/dist/lang/ast/executors/index-executor.js +4 -4
- package/dist/lang/ast/executors/project-executor.d.ts +5 -5
- package/dist/lang/ast/executors/project-executor.js +2 -2
- package/dist/lang/ast/executors/reduce-executor.d.ts +8 -8
- package/dist/lang/ast/executors/reduce-executor.js +5 -5
- package/dist/lang/ast/expressions/apply.d.ts +2 -2
- package/dist/lang/ast/expressions/apply.js +1 -1
- package/dist/lang/ast/expressions/binary-boolean.d.ts +3 -3
- package/dist/lang/ast/expressions/binary-boolean.js +6 -6
- package/dist/lang/ast/expressions/binary-numeric.d.ts +3 -3
- package/dist/lang/ast/expressions/binary-numeric.js +2 -2
- package/dist/lang/ast/expressions/boolean.d.ts +4 -4
- package/dist/lang/ast/expressions/boolean.js +2 -2
- package/dist/lang/ast/expressions/constant-sub-expression.d.ts +4 -4
- package/dist/lang/ast/expressions/constant-sub-expression.js +12 -12
- package/dist/lang/ast/expressions/expr-add-sub.d.ts +2 -2
- package/dist/lang/ast/expressions/expr-add-sub.js +1 -1
- package/dist/lang/ast/expressions/expr-aggregate-function.d.ts +5 -5
- package/dist/lang/ast/expressions/expr-aggregate-function.js +15 -15
- package/dist/lang/ast/expressions/expr-alternation-tree.d.ts +6 -6
- package/dist/lang/ast/expressions/expr-alternation-tree.js +6 -6
- package/dist/lang/ast/expressions/expr-asymmetric.d.ts +5 -5
- package/dist/lang/ast/expressions/expr-asymmetric.js +3 -3
- package/dist/lang/ast/expressions/expr-avg.d.ts +3 -3
- package/dist/lang/ast/expressions/expr-avg.js +2 -2
- package/dist/lang/ast/expressions/expr-cast.d.ts +4 -4
- package/dist/lang/ast/expressions/expr-cast.js +6 -6
- package/dist/lang/ast/expressions/expr-compare.d.ts +5 -5
- package/dist/lang/ast/expressions/expr-compare.js +9 -9
- package/dist/lang/ast/expressions/expr-count-distinct.d.ts +2 -2
- package/dist/lang/ast/expressions/expr-count-distinct.js +1 -1
- package/dist/lang/ast/expressions/expr-count.d.ts +4 -4
- package/dist/lang/ast/expressions/expr-count.js +10 -10
- package/dist/lang/ast/expressions/expr-filter.d.ts +4 -4
- package/dist/lang/ast/expressions/expr-filter.js +13 -13
- package/dist/lang/ast/expressions/expr-func.d.ts +3 -3
- package/dist/lang/ast/expressions/expr-func.js +8 -8
- package/dist/lang/ast/expressions/expr-granular-time.d.ts +4 -4
- package/dist/lang/ast/expressions/expr-granular-time.js +17 -17
- package/dist/lang/ast/expressions/expr-id-reference.d.ts +4 -4
- package/dist/lang/ast/expressions/expr-id-reference.js +11 -11
- package/dist/lang/ast/expressions/expr-logical-op.d.ts +2 -2
- package/dist/lang/ast/expressions/expr-logical-op.js +1 -1
- package/dist/lang/ast/expressions/expr-max.d.ts +4 -4
- package/dist/lang/ast/expressions/expr-max.js +1 -1
- package/dist/lang/ast/expressions/expr-min.d.ts +4 -4
- package/dist/lang/ast/expressions/expr-min.js +1 -1
- package/dist/lang/ast/expressions/expr-minus.d.ts +3 -3
- package/dist/lang/ast/expressions/expr-minus.js +5 -5
- package/dist/lang/ast/expressions/expr-mul-div.d.ts +2 -2
- package/dist/lang/ast/expressions/expr-mul-div.js +1 -1
- package/dist/lang/ast/expressions/expr-not.d.ts +4 -4
- package/dist/lang/ast/expressions/expr-not.js +3 -3
- package/dist/lang/ast/expressions/expr-now.d.ts +3 -3
- package/dist/lang/ast/expressions/expr-now.js +8 -8
- package/dist/lang/ast/expressions/expr-null.d.ts +2 -2
- package/dist/lang/ast/expressions/expr-null.js +4 -4
- package/dist/lang/ast/expressions/expr-number.d.ts +3 -3
- package/dist/lang/ast/expressions/expr-number.js +2 -2
- package/dist/lang/ast/expressions/expr-parens.d.ts +3 -3
- package/dist/lang/ast/expressions/expr-parens.js +3 -3
- package/dist/lang/ast/expressions/expr-regex.d.ts +2 -2
- package/dist/lang/ast/expressions/expr-regex.js +4 -4
- package/dist/lang/ast/expressions/expr-string.d.ts +3 -3
- package/dist/lang/ast/expressions/expr-string.js +8 -8
- package/dist/lang/ast/expressions/expr-sum.d.ts +3 -3
- package/dist/lang/ast/expressions/expr-sum.js +2 -2
- package/dist/lang/ast/expressions/expr-time-extract.d.ts +4 -4
- package/dist/lang/ast/expressions/expr-time-extract.js +30 -30
- package/dist/lang/ast/expressions/expr-time.d.ts +4 -4
- package/dist/lang/ast/expressions/expr-time.js +10 -10
- package/dist/lang/ast/expressions/expr-ungroup.d.ts +6 -6
- package/dist/lang/ast/expressions/expr-ungroup.js +13 -13
- package/dist/lang/ast/expressions/for-range.d.ts +4 -4
- package/dist/lang/ast/expressions/for-range.js +17 -17
- package/dist/lang/ast/expressions/granular-literal.d.ts +4 -4
- package/dist/lang/ast/expressions/granular-literal.js +34 -34
- package/dist/lang/ast/expressions/partial-compare.d.ts +4 -4
- package/dist/lang/ast/expressions/partial-compare.js +4 -4
- package/dist/lang/ast/expressions/pick-when.d.ts +4 -4
- package/dist/lang/ast/expressions/pick-when.js +32 -32
- package/dist/lang/ast/expressions/range.d.ts +3 -3
- package/dist/lang/ast/expressions/range.js +20 -20
- package/dist/lang/ast/expressions/time-frame.d.ts +2 -2
- package/dist/lang/ast/expressions/time-frame.js +3 -3
- package/dist/lang/ast/expressions/top-by.d.ts +4 -4
- package/dist/lang/ast/expressions/top-by.js +5 -5
- package/dist/lang/ast/expressions/unary.d.ts +1 -1
- package/dist/lang/ast/expressions/unary.js +1 -1
- package/dist/lang/ast/expressions/utils.d.ts +2 -2
- package/dist/lang/ast/expressions/utils.js +6 -6
- package/dist/lang/ast/field-space/column-space-field.d.ts +3 -3
- package/dist/lang/ast/field-space/dynamic-space.d.ts +7 -7
- package/dist/lang/ast/field-space/dynamic-space.js +2 -2
- package/dist/lang/ast/field-space/field-definition-value.d.ts +5 -5
- package/dist/lang/ast/field-space/index-field-space.d.ts +3 -3
- package/dist/lang/ast/field-space/index-field-space.js +4 -4
- package/dist/lang/ast/field-space/join-space-field.d.ts +3 -3
- package/dist/lang/ast/field-space/project-field-space.d.ts +2 -2
- package/dist/lang/ast/field-space/project-field-space.js +5 -5
- package/dist/lang/ast/field-space/query-field-struct.d.ts +3 -3
- package/dist/lang/ast/field-space/query-field-struct.js +1 -1
- package/dist/lang/ast/field-space/query-space-field.d.ts +4 -4
- package/dist/lang/ast/field-space/query-space-field.js +1 -1
- package/dist/lang/ast/field-space/query-spaces.d.ts +11 -11
- package/dist/lang/ast/field-space/query-spaces.js +8 -8
- package/dist/lang/ast/field-space/reference-field.d.ts +5 -5
- package/dist/lang/ast/field-space/reference-field.js +1 -1
- package/dist/lang/ast/field-space/refined-space.d.ts +4 -4
- package/dist/lang/ast/field-space/refined-space.js +2 -2
- package/dist/lang/ast/field-space/rename-space-field.d.ts +3 -3
- package/dist/lang/ast/field-space/rename-space-field.js +2 -2
- package/dist/lang/ast/field-space/static-space.d.ts +7 -7
- package/dist/lang/ast/field-space/static-space.js +12 -12
- package/dist/lang/ast/field-space/struct-space-field-base.d.ts +4 -4
- package/dist/lang/ast/field-space/struct-space-field-base.js +1 -1
- package/dist/lang/ast/field-space/wild-space-field.d.ts +4 -4
- package/dist/lang/ast/field-space/wild-space-field.js +1 -1
- package/dist/lang/ast/fragtype-utils.d.ts +1 -1
- package/dist/lang/ast/fragtype-utils.js +15 -15
- package/dist/lang/ast/index.d.ts +90 -90
- package/dist/lang/ast/parameters/constant-parameter.d.ts +3 -3
- package/dist/lang/ast/parameters/constant-parameter.js +10 -10
- package/dist/lang/ast/parameters/has-parameter.d.ts +3 -3
- package/dist/lang/ast/parameters/has-parameter.js +7 -7
- package/dist/lang/ast/query-elements/anonymous-query.d.ts +3 -3
- package/dist/lang/ast/query-elements/anonymous-query.js +2 -2
- package/dist/lang/ast/query-elements/existing-query.d.ts +4 -4
- package/dist/lang/ast/query-elements/existing-query.js +10 -10
- package/dist/lang/ast/query-elements/full-query.d.ts +4 -4
- package/dist/lang/ast/query-elements/full-query.js +10 -10
- package/dist/lang/ast/query-elements/query-head-struct.d.ts +2 -2
- package/dist/lang/ast/query-elements/query-head-struct.js +2 -2
- package/dist/lang/ast/query-items/field-declaration.d.ts +6 -6
- package/dist/lang/ast/query-items/field-declaration.js +14 -14
- package/dist/lang/ast/query-items/field-references.d.ts +6 -6
- package/dist/lang/ast/query-items/field-references.js +9 -9
- package/dist/lang/ast/query-properties/aggregate.d.ts +2 -2
- package/dist/lang/ast/query-properties/aggregate.js +1 -1
- package/dist/lang/ast/query-properties/declare-fields.d.ts +2 -2
- package/dist/lang/ast/query-properties/declare-fields.js +1 -1
- package/dist/lang/ast/query-properties/dimmensions.d.ts +2 -2
- package/dist/lang/ast/query-properties/dimmensions.js +1 -1
- package/dist/lang/ast/query-properties/filters.d.ts +4 -4
- package/dist/lang/ast/query-properties/filters.js +16 -16
- package/dist/lang/ast/query-properties/group-by.d.ts +2 -2
- package/dist/lang/ast/query-properties/group-by.js +1 -1
- package/dist/lang/ast/query-properties/indexing.d.ts +3 -3
- package/dist/lang/ast/query-properties/indexing.js +3 -3
- package/dist/lang/ast/query-properties/joins.d.ts +6 -6
- package/dist/lang/ast/query-properties/joins.js +27 -27
- package/dist/lang/ast/query-properties/limit.d.ts +1 -1
- package/dist/lang/ast/query-properties/limit.js +1 -1
- package/dist/lang/ast/query-properties/measures.d.ts +2 -2
- package/dist/lang/ast/query-properties/measures.js +1 -1
- package/dist/lang/ast/query-properties/nest-reference.d.ts +2 -2
- package/dist/lang/ast/query-properties/nest-reference.js +1 -1
- package/dist/lang/ast/query-properties/nest.d.ts +7 -7
- package/dist/lang/ast/query-properties/nest.js +7 -7
- package/dist/lang/ast/query-properties/nests.d.ts +2 -2
- package/dist/lang/ast/query-properties/nests.js +1 -1
- package/dist/lang/ast/query-properties/ordering.d.ts +3 -3
- package/dist/lang/ast/query-properties/ordering.js +6 -6
- package/dist/lang/ast/query-properties/project-statement.d.ts +2 -2
- package/dist/lang/ast/query-properties/project-statement.js +1 -1
- package/dist/lang/ast/query-properties/qop-desc.d.ts +7 -7
- package/dist/lang/ast/query-properties/qop-desc.js +20 -20
- package/dist/lang/ast/query-properties/sampling.d.ts +2 -2
- package/dist/lang/ast/query-properties/sampling.js +1 -1
- package/dist/lang/ast/query-properties/top.d.ts +4 -4
- package/dist/lang/ast/query-properties/top.js +5 -5
- package/dist/lang/ast/source-properties/field-list-edit.d.ts +4 -4
- package/dist/lang/ast/source-properties/field-list-edit.js +2 -2
- package/dist/lang/ast/source-properties/primary-key.d.ts +2 -2
- package/dist/lang/ast/source-properties/primary-key.js +2 -2
- package/dist/lang/ast/source-properties/renames.d.ts +2 -2
- package/dist/lang/ast/source-properties/renames.js +3 -3
- package/dist/lang/ast/source-properties/turtles.d.ts +2 -2
- package/dist/lang/ast/source-properties/turtles.js +1 -1
- package/dist/lang/ast/sources/named-source.d.ts +4 -4
- package/dist/lang/ast/sources/named-source.js +5 -5
- package/dist/lang/ast/sources/query-source.d.ts +3 -3
- package/dist/lang/ast/sources/query-source.js +3 -3
- package/dist/lang/ast/sources/sql-source.d.ts +2 -2
- package/dist/lang/ast/sources/sql-source.js +2 -2
- package/dist/lang/ast/sources/table-source.d.ts +2 -2
- package/dist/lang/ast/sources/table-source.js +7 -7
- package/dist/lang/ast/space-seed.d.ts +2 -2
- package/dist/lang/ast/space-seed.js +1 -1
- package/dist/lang/ast/sql-elements/sql-statement.d.ts +4 -4
- package/dist/lang/ast/sql-elements/sql-statement.js +9 -9
- package/dist/lang/ast/sql-elements/sql-string.d.ts +3 -3
- package/dist/lang/ast/sql-elements/sql-string.js +6 -6
- package/dist/lang/ast/struct-utils.d.ts +2 -2
- package/dist/lang/ast/struct-utils.js +3 -3
- package/dist/lang/ast/time-utils.d.ts +6 -6
- package/dist/lang/ast/time-utils.js +46 -46
- package/dist/lang/ast/types/document-compile-result.d.ts +2 -2
- package/dist/lang/ast/types/executor.d.ts +3 -3
- package/dist/lang/ast/types/explore-desc.d.ts +2 -2
- package/dist/lang/ast/types/explore-desc.js +1 -1
- package/dist/lang/ast/types/explore-field.d.ts +3 -3
- package/dist/lang/ast/types/expr-result.d.ts +2 -2
- package/dist/lang/ast/types/expr-value.d.ts +2 -2
- package/dist/lang/ast/types/expression-def.d.ts +4 -4
- package/dist/lang/ast/types/expression-def.js +86 -86
- package/dist/lang/ast/types/field-collection-member.d.ts +3 -3
- package/dist/lang/ast/types/field-decl.d.ts +5 -5
- package/dist/lang/ast/types/field-space.d.ts +5 -5
- package/dist/lang/ast/types/field-space.js +1 -1
- package/dist/lang/ast/types/granular-result.d.ts +3 -3
- package/dist/lang/ast/types/granular-result.js +1 -1
- package/dist/lang/ast/types/lookup-result.d.ts +1 -1
- package/dist/lang/ast/types/malloy-element.d.ts +6 -6
- package/dist/lang/ast/types/malloy-element.js +49 -49
- package/dist/lang/ast/types/model-entry.d.ts +1 -1
- package/dist/lang/ast/types/name-space.d.ts +1 -1
- package/dist/lang/ast/types/nested-query.d.ts +2 -2
- package/dist/lang/ast/types/op-desc.d.ts +2 -2
- package/dist/lang/ast/types/query-comp.d.ts +1 -1
- package/dist/lang/ast/types/query-element.d.ts +3 -3
- package/dist/lang/ast/types/query-item.d.ts +4 -4
- package/dist/lang/ast/types/query-property.d.ts +15 -15
- package/dist/lang/ast/types/source-property.d.ts +8 -8
- package/dist/lang/ast/types/space-entry.d.ts +2 -2
- package/dist/lang/ast/types/space-field.d.ts +4 -4
- package/dist/lang/ast/types/space-field.js +4 -4
- package/dist/lang/ast/types/space-param.d.ts +4 -4
- package/dist/lang/ast/types/space-param.js +4 -4
- package/dist/lang/ast/types/time-result.d.ts +2 -2
- package/dist/lang/ast/types/turtle-headed-pipe.d.ts +2 -2
- package/dist/lang/ast/types/turtle-headed-pipe.js +1 -1
- package/dist/lang/ast/types/type-desc.d.ts +3 -3
- package/dist/lang/field-utils.d.ts +1 -1
- package/dist/lang/field-utils.js +4 -4
- package/dist/lang/index.d.ts +10 -10
- package/dist/lang/malloy-to-ast.d.ts +8 -8
- package/dist/lang/malloy-to-ast.js +68 -68
- package/dist/lang/parse-error-handler.d.ts +3 -3
- package/dist/lang/parse-error-handler.js +4 -4
- package/dist/lang/parse-log.d.ts +2 -2
- package/dist/lang/parse-log.js +1 -1
- package/dist/lang/parse-malloy.d.ts +7 -7
- package/dist/lang/parse-malloy.js +81 -81
- package/dist/lang/parse-tree-walkers/document-completion-walker.d.ts +2 -2
- package/dist/lang/parse-tree-walkers/document-completion-walker.js +38 -38
- package/dist/lang/parse-tree-walkers/document-help-context-walker.d.ts +1 -1
- package/dist/lang/parse-tree-walkers/document-help-context-walker.js +14 -14
- package/dist/lang/parse-tree-walkers/document-highlight-walker.d.ts +3 -3
- package/dist/lang/parse-tree-walkers/document-highlight-walker.js +85 -85
- package/dist/lang/parse-tree-walkers/document-symbol-walker.d.ts +4 -4
- package/dist/lang/parse-tree-walkers/document-symbol-walker.js +40 -40
- package/dist/lang/parse-tree-walkers/explore-query-walker.d.ts +3 -3
- package/dist/lang/parse-tree-walkers/explore-query-walker.js +3 -3
- package/dist/lang/parse-tree-walkers/find-external-references.d.ts +4 -4
- package/dist/lang/parse-tree-walkers/find-external-references.js +2 -2
- package/dist/lang/reference-list.d.ts +1 -1
- package/dist/lang/test/document-help-context-walker.spec.js +9 -9
- package/dist/lang/test/document-symbol-walker.spec.js +32 -32
- package/dist/lang/test/field-symbols.spec.js +87 -87
- package/dist/lang/test/parse.spec.d.ts +1 -1
- package/dist/lang/test/parse.spec.js +768 -768
- package/dist/lang/test/test-translator.d.ts +6 -6
- package/dist/lang/test/test-translator.js +159 -159
- package/dist/lang/translate-response.d.ts +7 -7
- package/dist/lang/translate-response.js +1 -1
- package/dist/lang/zone.d.ts +5 -5
- package/dist/lang/zone.js +8 -8
- package/dist/malloy.d.ts +7 -7
- package/dist/malloy.js +192 -192
- package/dist/model/index.d.ts +2 -2
- package/dist/model/malloy_query.d.ts +12 -12
- package/dist/model/malloy_query.js +497 -502
- package/dist/model/malloy_types.d.ts +68 -68
- package/dist/model/malloy_types.js +102 -102
- package/dist/model/sql_block.d.ts +1 -1
- package/dist/model/sql_block.js +4 -4
- package/dist/model/utils.d.ts +1 -1
- package/dist/model/utils.js +10 -10
- package/dist/runtime_types.d.ts +2 -2
- package/package.json +4 -1
|
@@ -50,8 +50,8 @@ class BetaModel extends Testable {
|
|
|
50
50
|
compile() {
|
|
51
51
|
const compileTo = this.translate();
|
|
52
52
|
if (compileTo.translated && inspectCompile) {
|
|
53
|
-
console.log(
|
|
54
|
-
console.log(
|
|
53
|
+
console.log('MODEL: ', (0, test_translator_1.pretty)(compileTo.translated.modelDef));
|
|
54
|
+
console.log('QUERIES: ', (0, test_translator_1.pretty)(compileTo.translated.queryList));
|
|
55
55
|
}
|
|
56
56
|
// All the stuff to ask the ast for a translation is already in TestTranslator
|
|
57
57
|
}
|
|
@@ -62,7 +62,7 @@ class BetaModel extends Testable {
|
|
|
62
62
|
const t = this.translate().translated;
|
|
63
63
|
if (t) {
|
|
64
64
|
const s = t.modelDef.contents[srcName];
|
|
65
|
-
if (s.type
|
|
65
|
+
if (s.type === 'struct') {
|
|
66
66
|
return s;
|
|
67
67
|
}
|
|
68
68
|
}
|
|
@@ -71,10 +71,10 @@ class BetaModel extends Testable {
|
|
|
71
71
|
getQuery(queryName) {
|
|
72
72
|
const t = this.translate().translated;
|
|
73
73
|
if (t) {
|
|
74
|
-
const s = typeof queryName
|
|
74
|
+
const s = typeof queryName === 'string'
|
|
75
75
|
? t.modelDef.contents[queryName]
|
|
76
76
|
: t.queryList[queryName];
|
|
77
|
-
if ((s === null || s === void 0 ? void 0 : s.type)
|
|
77
|
+
if ((s === null || s === void 0 ? void 0 : s.type) === 'query') {
|
|
78
78
|
return s;
|
|
79
79
|
}
|
|
80
80
|
}
|
|
@@ -83,31 +83,31 @@ class BetaModel extends Testable {
|
|
|
83
83
|
}
|
|
84
84
|
function checkForErrors(trans) {
|
|
85
85
|
if (trans.logger === undefined) {
|
|
86
|
-
throw new Error(
|
|
86
|
+
throw new Error('JESTERY BROKEN, CANT FIND ERORR LOG');
|
|
87
87
|
}
|
|
88
88
|
if (trans.logger.hasErrors()) {
|
|
89
89
|
return {
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
message: () => `Translation Errors:\n${trans.prettyErrors()}`,
|
|
91
|
+
pass: false,
|
|
92
92
|
};
|
|
93
93
|
}
|
|
94
94
|
return {
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
message: () => 'Unexpected error free translation',
|
|
96
|
+
pass: true,
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
99
|
function prettyNeeds(response) {
|
|
100
|
-
let needString =
|
|
100
|
+
let needString = '';
|
|
101
101
|
if (response.tables) {
|
|
102
|
-
needString +=
|
|
103
|
-
response.tables.forEach(
|
|
102
|
+
needString += 'Tables:\n';
|
|
103
|
+
response.tables.forEach(table => (needString += ` - ${table}`));
|
|
104
104
|
}
|
|
105
105
|
if (response.compileSQL) {
|
|
106
106
|
needString += `Compile SQL: ${response.compileSQL.name}`;
|
|
107
107
|
}
|
|
108
108
|
if (response.urls) {
|
|
109
|
-
needString +=
|
|
110
|
-
response.urls.forEach(
|
|
109
|
+
needString += 'URLs:\n';
|
|
110
|
+
response.urls.forEach(url => (needString += ` - ${url}`));
|
|
111
111
|
}
|
|
112
112
|
return needString;
|
|
113
113
|
}
|
|
@@ -115,42 +115,42 @@ function checkForNeededs(trans) {
|
|
|
115
115
|
const response = trans.translateStep.step(trans);
|
|
116
116
|
if (!response.final) {
|
|
117
117
|
return {
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
message: () => `Translation is not complete, needs:\n${prettyNeeds(response)}`,
|
|
119
|
+
pass: false,
|
|
120
120
|
};
|
|
121
121
|
}
|
|
122
122
|
return {
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
message: () => 'Unexpected complete translation',
|
|
124
|
+
pass: true,
|
|
125
125
|
};
|
|
126
126
|
}
|
|
127
127
|
function highlightError(dl, txt) {
|
|
128
|
-
if (dl
|
|
129
|
-
return
|
|
128
|
+
if (dl === undefined) {
|
|
129
|
+
return '~Location Undefined~';
|
|
130
130
|
}
|
|
131
131
|
const { start, end } = dl.range;
|
|
132
132
|
const output = [
|
|
133
|
-
`${start.line}:${start.character}-${end.line}:${end.character}
|
|
133
|
+
`${start.line}:${start.character}-${end.line}:${end.character}`,
|
|
134
134
|
];
|
|
135
135
|
let errStart = start.character;
|
|
136
|
-
const doc = txt.split(
|
|
136
|
+
const doc = txt.split('\n');
|
|
137
137
|
for (let line = start.line; line <= end.line; line += 1) {
|
|
138
138
|
const lineText = doc[line];
|
|
139
139
|
const lineStr = ` ${line}`.slice(-5);
|
|
140
140
|
output.push(`${lineStr}| ${lineText}`);
|
|
141
|
-
const upToError =
|
|
141
|
+
const upToError = ' | ' + ' '.repeat(errStart);
|
|
142
142
|
let errLen = end.character - errStart;
|
|
143
143
|
if (line < end.line) {
|
|
144
144
|
errLen = lineText.length - errStart;
|
|
145
145
|
errStart = 0;
|
|
146
146
|
}
|
|
147
|
-
output.push(upToError +
|
|
147
|
+
output.push(upToError + '-'.repeat(errLen));
|
|
148
148
|
}
|
|
149
|
-
return output.join(
|
|
149
|
+
return output.join('\n');
|
|
150
150
|
}
|
|
151
151
|
function unlocatedStructDef(sd) {
|
|
152
152
|
const ret = { ...sd };
|
|
153
|
-
ret.fields = sd.fields.map(
|
|
153
|
+
ret.fields = sd.fields.map(f => {
|
|
154
154
|
const nf = { ...f };
|
|
155
155
|
delete nf.location;
|
|
156
156
|
return nf;
|
|
@@ -159,7 +159,7 @@ function unlocatedStructDef(sd) {
|
|
|
159
159
|
return ret;
|
|
160
160
|
}
|
|
161
161
|
expect.extend({
|
|
162
|
-
|
|
162
|
+
toCompile: function (s) {
|
|
163
163
|
const x = new BetaModel(s);
|
|
164
164
|
x.compile();
|
|
165
165
|
const errorCheck = checkForErrors(x);
|
|
@@ -169,11 +169,11 @@ expect.extend({
|
|
|
169
169
|
x.translate();
|
|
170
170
|
return checkForNeededs(x);
|
|
171
171
|
},
|
|
172
|
-
|
|
172
|
+
modelParsed: function (x) {
|
|
173
173
|
x.compile();
|
|
174
174
|
return checkForErrors(x);
|
|
175
175
|
},
|
|
176
|
-
|
|
176
|
+
modelCompiled: function (x) {
|
|
177
177
|
x.compile();
|
|
178
178
|
const errorCheck = checkForErrors(x);
|
|
179
179
|
if (!errorCheck.pass) {
|
|
@@ -182,33 +182,33 @@ expect.extend({
|
|
|
182
182
|
x.translate();
|
|
183
183
|
return checkForNeededs(x);
|
|
184
184
|
},
|
|
185
|
-
|
|
185
|
+
toBeErrorless: function (trans) {
|
|
186
186
|
return checkForErrors(trans);
|
|
187
187
|
},
|
|
188
|
-
|
|
188
|
+
toReturnType: function (functionCall, returnType) {
|
|
189
189
|
const exprModel = new BetaModel(`explore: x is a { dimension: d is ${functionCall} }`);
|
|
190
190
|
expect(exprModel).modelCompiled();
|
|
191
|
-
const x = exprModel.getSourceDef(
|
|
191
|
+
const x = exprModel.getSourceDef('x');
|
|
192
192
|
expect(x).toBeDefined();
|
|
193
193
|
if (x) {
|
|
194
|
-
const d = x.fields.find(
|
|
194
|
+
const d = x.fields.find(f => f.name === 'd');
|
|
195
195
|
expect(d === null || d === void 0 ? void 0 : d.type).toBe(returnType);
|
|
196
196
|
}
|
|
197
197
|
return {
|
|
198
|
-
|
|
199
|
-
|
|
198
|
+
pass: true,
|
|
199
|
+
message: () => '',
|
|
200
200
|
};
|
|
201
201
|
},
|
|
202
|
-
|
|
202
|
+
compileToFailWith: function (s, ...msgs) {
|
|
203
203
|
var _a;
|
|
204
|
-
let emsg =
|
|
204
|
+
let emsg = 'Compile Error expectation not met\nExpected error';
|
|
205
205
|
let mSrc;
|
|
206
|
-
const qmsgs = msgs.map(
|
|
207
|
-
if (msgs.length
|
|
206
|
+
const qmsgs = msgs.map(s => `error '${s}'`);
|
|
207
|
+
if (msgs.length === 1) {
|
|
208
208
|
emsg += ` ${qmsgs[0]}`;
|
|
209
209
|
}
|
|
210
210
|
else {
|
|
211
|
-
emsg += `s [\n${qmsgs.join(
|
|
211
|
+
emsg += `s [\n${qmsgs.join('\n')}\n]`;
|
|
212
212
|
}
|
|
213
213
|
let m;
|
|
214
214
|
let src;
|
|
@@ -217,7 +217,7 @@ expect.extend({
|
|
|
217
217
|
src = m.testSrc;
|
|
218
218
|
}
|
|
219
219
|
else {
|
|
220
|
-
if (typeof s
|
|
220
|
+
if (typeof s === 'string') {
|
|
221
221
|
src = s;
|
|
222
222
|
}
|
|
223
223
|
else {
|
|
@@ -229,15 +229,15 @@ expect.extend({
|
|
|
229
229
|
emsg += `\nSource:\n${src}`;
|
|
230
230
|
const t = m.translate();
|
|
231
231
|
if (t.translated) {
|
|
232
|
-
return {
|
|
232
|
+
return { pass: false, message: () => emsg };
|
|
233
233
|
}
|
|
234
|
-
else if (t.errors
|
|
234
|
+
else if (t.errors === undefined) {
|
|
235
235
|
return {
|
|
236
|
-
|
|
237
|
-
|
|
236
|
+
pass: false,
|
|
237
|
+
message: () => 'TEST ERROR, not all objects resolved in source\n' +
|
|
238
238
|
(0, test_translator_1.pretty)(t) +
|
|
239
|
-
|
|
240
|
-
emsg
|
|
239
|
+
'\n' +
|
|
240
|
+
emsg,
|
|
241
241
|
};
|
|
242
242
|
}
|
|
243
243
|
else {
|
|
@@ -247,7 +247,7 @@ expect.extend({
|
|
|
247
247
|
for (i = 0; i < msgs.length && errList[i]; i += 1) {
|
|
248
248
|
const msg = msgs[i];
|
|
249
249
|
const err = errList[i];
|
|
250
|
-
if (msg
|
|
250
|
+
if (msg !== err.message) {
|
|
251
251
|
explain.push(`Expected: ${msg}\nGot: ${err.message}`);
|
|
252
252
|
}
|
|
253
253
|
else {
|
|
@@ -261,53 +261,53 @@ expect.extend({
|
|
|
261
261
|
}
|
|
262
262
|
}
|
|
263
263
|
}
|
|
264
|
-
if (i
|
|
265
|
-
explain.push(...msgs.slice(i).map(
|
|
264
|
+
if (i !== msgs.length) {
|
|
265
|
+
explain.push(...msgs.slice(i).map(m => `Missing: ${m}`));
|
|
266
266
|
}
|
|
267
|
-
if (i
|
|
268
|
-
explain.push(...errList.slice(i).map(
|
|
267
|
+
if (i !== errList.length) {
|
|
268
|
+
explain.push(...errList.slice(i).map(m => `Unexpected Error: ${m.message}`));
|
|
269
269
|
}
|
|
270
|
-
if (explain.length
|
|
270
|
+
if (explain.length === 0) {
|
|
271
271
|
return {
|
|
272
|
-
|
|
273
|
-
|
|
272
|
+
pass: true,
|
|
273
|
+
message: () => `All expected errors found: ${(0, test_translator_1.pretty)(msgs)}`,
|
|
274
274
|
};
|
|
275
275
|
}
|
|
276
276
|
return {
|
|
277
|
-
|
|
278
|
-
|
|
277
|
+
pass: false,
|
|
278
|
+
message: () => `Compiler did not generated expected errors\n${explain.join('\n')}`,
|
|
279
279
|
};
|
|
280
280
|
}
|
|
281
281
|
},
|
|
282
|
-
|
|
282
|
+
isLocationIn: function (checkAt, at, text) {
|
|
283
283
|
if (this.equals(at, checkAt)) {
|
|
284
284
|
return {
|
|
285
|
-
|
|
286
|
-
|
|
285
|
+
pass: true,
|
|
286
|
+
message: () => 'Locations match',
|
|
287
287
|
};
|
|
288
288
|
}
|
|
289
|
-
const errMsg =
|
|
289
|
+
const errMsg = 'Locations do not match\n' +
|
|
290
290
|
`Expected: ${highlightError(at, text)}\n` +
|
|
291
291
|
`Received: ${highlightError(checkAt, text)}\n`;
|
|
292
292
|
return {
|
|
293
|
-
|
|
294
|
-
|
|
293
|
+
pass: false,
|
|
294
|
+
message: () => errMsg,
|
|
295
295
|
};
|
|
296
|
-
}
|
|
296
|
+
},
|
|
297
297
|
});
|
|
298
298
|
class BetaExpression extends Testable {
|
|
299
299
|
constructor(src) {
|
|
300
|
-
super(src,
|
|
300
|
+
super(src, 'justExpr');
|
|
301
301
|
}
|
|
302
302
|
compile() {
|
|
303
303
|
const exprAst = this.ast();
|
|
304
304
|
if (exprAst instanceof expression_def_1.ExpressionDef) {
|
|
305
305
|
const aStruct = this.internalModel.contents.ab;
|
|
306
|
-
if (aStruct.type ===
|
|
306
|
+
if (aStruct.type === 'struct') {
|
|
307
307
|
const tstFS = new static_space_1.StaticSpace(aStruct);
|
|
308
308
|
const exprDef = exprAst.getExpression(tstFS);
|
|
309
309
|
if (inspectCompile) {
|
|
310
|
-
console.log(
|
|
310
|
+
console.log('EXPRESSION: ', (0, test_translator_1.pretty)(exprDef));
|
|
311
311
|
}
|
|
312
312
|
}
|
|
313
313
|
else {
|
|
@@ -318,7 +318,7 @@ class BetaExpression extends Testable {
|
|
|
318
318
|
return;
|
|
319
319
|
}
|
|
320
320
|
else {
|
|
321
|
-
const whatIsIt = (exprAst === null || exprAst === void 0 ? void 0 : exprAst.toString()) ||
|
|
321
|
+
const whatIsIt = (exprAst === null || exprAst === void 0 ? void 0 : exprAst.toString()) || 'NO AST GENERATED';
|
|
322
322
|
throw new Error(`Not an expression: ${whatIsIt}`);
|
|
323
323
|
}
|
|
324
324
|
}
|
|
@@ -338,7 +338,7 @@ function modelOK(s) {
|
|
|
338
338
|
}
|
|
339
339
|
function badModel(s, msg) {
|
|
340
340
|
return () => {
|
|
341
|
-
const src = typeof s
|
|
341
|
+
const src = typeof s === 'string' ? s : s.code;
|
|
342
342
|
const emsg = `Error expectation not met\nExpected error: '${msg}'\nSource:\n${src}`;
|
|
343
343
|
const m = new BetaModel(src);
|
|
344
344
|
const t = m.translate();
|
|
@@ -348,10 +348,10 @@ function badModel(s, msg) {
|
|
|
348
348
|
else {
|
|
349
349
|
const errList = m.errors().errors;
|
|
350
350
|
const firstError = errList[0];
|
|
351
|
-
if (firstError.message
|
|
351
|
+
if (firstError.message !== msg) {
|
|
352
352
|
fail(`Received errror: ${firstError.message}\n${emsg}`);
|
|
353
353
|
}
|
|
354
|
-
if (typeof s
|
|
354
|
+
if (typeof s !== 'string') {
|
|
355
355
|
if (!(0, isEqual_1.default)(errList[0].at, s.locations[0])) {
|
|
356
356
|
fail(`Expected location: ${s.locations[0]}\n` +
|
|
357
357
|
`Received location: ${errList[0].at}\n${emsg}`);
|
|
@@ -361,49 +361,49 @@ function badModel(s, msg) {
|
|
|
361
361
|
return undefined;
|
|
362
362
|
};
|
|
363
363
|
}
|
|
364
|
-
describe(
|
|
365
|
-
describe(
|
|
366
|
-
test(
|
|
367
|
-
test(
|
|
368
|
-
expect(
|
|
364
|
+
describe('model statements', () => {
|
|
365
|
+
describe('explore:', () => {
|
|
366
|
+
test('explore table', modelOK("explore: testA is table('aTable')"));
|
|
367
|
+
test('explore shorcut fitlered table', () => {
|
|
368
|
+
expect("explore: testA is table('aTable') {? astr ~ 'a%' } ").toCompile();
|
|
369
369
|
});
|
|
370
|
-
test(
|
|
370
|
+
test('explore fitlered table', modelOK(`
|
|
371
371
|
explore: testA is table('aTable') { where: astr ~ 'a%' }
|
|
372
372
|
`));
|
|
373
|
-
test(
|
|
374
|
-
test(
|
|
375
|
-
test(
|
|
376
|
-
test(
|
|
377
|
-
const x = new BetaModel(
|
|
373
|
+
test('explore explore', modelOK('explore: testA is a'));
|
|
374
|
+
test('explore query', modelOK('explore: testA is from(a->{group_by: astr})'));
|
|
375
|
+
test('refine explore', modelOK('explore: aa is a { dimension: a is astr }'));
|
|
376
|
+
test('source refinement preserves original', () => {
|
|
377
|
+
const x = new BetaModel('source: na is a + { dimension: one is 1 }');
|
|
378
378
|
expect(x).modelCompiled();
|
|
379
|
-
const a = x.getSourceDef(
|
|
379
|
+
const a = x.getSourceDef('a');
|
|
380
380
|
if (a) {
|
|
381
|
-
const aFields = a.fields.map(
|
|
382
|
-
expect(aFields).toContain(
|
|
383
|
-
expect(aFields).not.toContain(
|
|
381
|
+
const aFields = a.fields.map(f => f.as || f.name);
|
|
382
|
+
expect(aFields).toContain('astr');
|
|
383
|
+
expect(aFields).not.toContain('one');
|
|
384
384
|
}
|
|
385
385
|
});
|
|
386
386
|
});
|
|
387
|
-
describe(
|
|
388
|
-
test(
|
|
389
|
-
test(
|
|
390
|
-
test(
|
|
387
|
+
describe('query:', () => {
|
|
388
|
+
test('anonymous query', modelOK("query: table('aTable') -> { group_by: astr }"));
|
|
389
|
+
test('query', modelOK("query: name is table('aTable') -> { group_by: astr }"));
|
|
390
|
+
test('query from query', modelOK(`
|
|
391
391
|
query: q1 is ab->{ group_by: astr limit: 10 }
|
|
392
392
|
query: q2 is ->q1
|
|
393
393
|
`));
|
|
394
|
-
test(
|
|
394
|
+
test('query with refinements from query', modelOK(`
|
|
395
395
|
query: q1 is ab->{ group_by: astr limit: 10 }
|
|
396
396
|
query: q2 is ->q1 { aggregate: acount }
|
|
397
397
|
`));
|
|
398
|
-
test(
|
|
398
|
+
test('chained query operations', modelOK(`
|
|
399
399
|
query: ab
|
|
400
400
|
-> { group_by: astr; aggregate: acount }
|
|
401
401
|
-> { top: 5; where: astr ~ 'a%' group_by: astr }
|
|
402
402
|
`));
|
|
403
|
-
test(
|
|
404
|
-
test(
|
|
405
|
-
test(
|
|
406
|
-
test(
|
|
403
|
+
test('query from explore from query', modelOK('query: from(ab -> {group_by: astr}) { dimension: bigstr is UPPER(astr) } -> { group_by: bigstr }'));
|
|
404
|
+
test('query with shortcut filtered turtle', modelOK("query: allA is ab->aturtle {? astr ~ 'a%' }"));
|
|
405
|
+
test('query with filtered turtle', modelOK("query: allA is ab->aturtle { where: astr ~ 'a%' }"));
|
|
406
|
+
test('nest: in group_by:', modelOK(`
|
|
407
407
|
query: ab -> {
|
|
408
408
|
group_by: astr;
|
|
409
409
|
nest: nested_count is {
|
|
@@ -411,39 +411,39 @@ describe("model statements", () => {
|
|
|
411
411
|
}
|
|
412
412
|
}
|
|
413
413
|
`));
|
|
414
|
-
test(
|
|
414
|
+
test('reduce pipe project', modelOK(`
|
|
415
415
|
query: a -> { aggregate: f is count() } -> { project: f2 is f + 1 }
|
|
416
416
|
`));
|
|
417
|
-
test(
|
|
417
|
+
test('refine and extend query', modelOK(`
|
|
418
418
|
query: a_by_str is a -> { group_by: astr }
|
|
419
419
|
query: -> a_by_str { aggregate: str_count is count() }
|
|
420
420
|
`));
|
|
421
|
-
test(
|
|
421
|
+
test('query refinement preserves original', () => {
|
|
422
422
|
const x = new BetaModel(`
|
|
423
423
|
query: q is a -> { aggregate: acount is count() }
|
|
424
424
|
query: nq is -> q + { group_by: astr }
|
|
425
425
|
`);
|
|
426
426
|
expect(x).modelCompiled();
|
|
427
|
-
const q = x.getQuery(
|
|
427
|
+
const q = x.getQuery('q');
|
|
428
428
|
expect(q).toBeDefined();
|
|
429
429
|
if (q) {
|
|
430
430
|
const qFields = q.pipeline[0].fields;
|
|
431
431
|
expect(qFields.length).toBe(1);
|
|
432
432
|
}
|
|
433
433
|
});
|
|
434
|
-
test(
|
|
434
|
+
test('query composition preserves original', () => {
|
|
435
435
|
const x = new BetaModel(`
|
|
436
436
|
query: q is ab -> { aggregate: acount }
|
|
437
437
|
query: nq is -> q -> { project: * }
|
|
438
438
|
`);
|
|
439
439
|
expect(x).modelCompiled();
|
|
440
|
-
const q = x.getQuery(
|
|
440
|
+
const q = x.getQuery('q');
|
|
441
441
|
expect(q).toBeDefined();
|
|
442
442
|
if (q) {
|
|
443
443
|
expect(q.pipeline.length).toBe(1);
|
|
444
444
|
}
|
|
445
445
|
});
|
|
446
|
-
test(
|
|
446
|
+
test('all ungroup with args', modelOK(`
|
|
447
447
|
query: a -> {
|
|
448
448
|
group_by: astr
|
|
449
449
|
nest: by_int is {
|
|
@@ -452,7 +452,7 @@ describe("model statements", () => {
|
|
|
452
452
|
}
|
|
453
453
|
}
|
|
454
454
|
`));
|
|
455
|
-
test(
|
|
455
|
+
test('all ungroup checks args', () => {
|
|
456
456
|
expect(`
|
|
457
457
|
query: a -> {
|
|
458
458
|
group_by: astr
|
|
@@ -461,9 +461,9 @@ describe("model statements", () => {
|
|
|
461
461
|
aggregate: bi_count is all(count(), afloat)
|
|
462
462
|
}
|
|
463
463
|
}
|
|
464
|
-
`).compileToFailWith(
|
|
464
|
+
`).compileToFailWith("all() 'afloat' is missing from query output");
|
|
465
465
|
});
|
|
466
|
-
test(
|
|
466
|
+
test('exclude ungroup with args', modelOK(`
|
|
467
467
|
query: a -> {
|
|
468
468
|
group_by: aa is 'a'
|
|
469
469
|
nest: by_b is {
|
|
@@ -475,7 +475,7 @@ describe("model statements", () => {
|
|
|
475
475
|
}
|
|
476
476
|
}
|
|
477
477
|
`));
|
|
478
|
-
test(
|
|
478
|
+
test('exclude ungroup checks args', () => {
|
|
479
479
|
expect(`
|
|
480
480
|
query: a -> {
|
|
481
481
|
group_by: aa is 'a'
|
|
@@ -489,7 +489,7 @@ describe("model statements", () => {
|
|
|
489
489
|
}
|
|
490
490
|
`).compileToFailWith("exclude() 'aaa' is missing from query output");
|
|
491
491
|
});
|
|
492
|
-
test(
|
|
492
|
+
test('exclude problem revealed by production models', modelOK(`
|
|
493
493
|
source: carriers is table('malloytest.carriers') {
|
|
494
494
|
primary_key: code
|
|
495
495
|
}
|
|
@@ -508,128 +508,128 @@ describe("model statements", () => {
|
|
|
508
508
|
}
|
|
509
509
|
`));
|
|
510
510
|
});
|
|
511
|
-
describe(
|
|
512
|
-
test(
|
|
513
|
-
const docParse = new BetaModel(
|
|
511
|
+
describe('import:', () => {
|
|
512
|
+
test('simple import', () => {
|
|
513
|
+
const docParse = new BetaModel('import "child"');
|
|
514
514
|
const xr = docParse.unresolved();
|
|
515
515
|
expect(docParse).toBeErrorless();
|
|
516
|
-
expect(xr).toEqual({
|
|
516
|
+
expect(xr).toEqual({ urls: ['internal://test/langtests/child'] });
|
|
517
517
|
docParse.update({
|
|
518
|
-
|
|
518
|
+
urls: { 'internal://test/langtests/child': 'explore: aa is a' },
|
|
519
519
|
});
|
|
520
520
|
const yr = docParse.unresolved();
|
|
521
521
|
expect(yr).toBeNull();
|
|
522
522
|
});
|
|
523
|
-
test(
|
|
524
|
-
const docParse = new BetaModel(
|
|
523
|
+
test('missing import', () => {
|
|
524
|
+
const docParse = new BetaModel('import "child"');
|
|
525
525
|
const xr = docParse.unresolved();
|
|
526
526
|
expect(docParse).toBeErrorless();
|
|
527
|
-
expect(xr).toEqual({
|
|
528
|
-
const reportedError =
|
|
527
|
+
expect(xr).toEqual({ urls: ['internal://test/langtests/child'] });
|
|
528
|
+
const reportedError = 'ENOWAY: No way to find your child';
|
|
529
529
|
docParse.update({
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
}
|
|
530
|
+
errors: {
|
|
531
|
+
urls: { 'internal://test/langtests/child': reportedError },
|
|
532
|
+
},
|
|
533
533
|
});
|
|
534
534
|
docParse.translate();
|
|
535
535
|
expect(docParse).not.toBeErrorless();
|
|
536
536
|
expect(docParse.prettyErrors()).toContain(reportedError);
|
|
537
537
|
});
|
|
538
|
-
test(
|
|
539
|
-
const docParse = new BetaModel(
|
|
538
|
+
test('chained imports', () => {
|
|
539
|
+
const docParse = new BetaModel('import "child"');
|
|
540
540
|
docParse.update({
|
|
541
|
-
|
|
541
|
+
urls: { 'internal://test/langtests/child': 'import "grandChild"' },
|
|
542
542
|
});
|
|
543
543
|
const xr = docParse.unresolved();
|
|
544
544
|
expect(docParse).toBeErrorless();
|
|
545
|
-
expect(xr).toEqual({
|
|
545
|
+
expect(xr).toEqual({ urls: ['internal://test/langtests/grandChild'] });
|
|
546
546
|
});
|
|
547
|
-
test(
|
|
548
|
-
const docParse = new BetaModel(
|
|
547
|
+
test('relative imports', () => {
|
|
548
|
+
const docParse = new BetaModel('import "../parent.malloy"');
|
|
549
549
|
expect(docParse).modelParsed();
|
|
550
550
|
const xr = docParse.unresolved();
|
|
551
|
-
expect(xr).toEqual({
|
|
551
|
+
expect(xr).toEqual({ urls: ['internal://test/parent.malloy'] });
|
|
552
552
|
docParse.update({
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
}
|
|
553
|
+
urls: {
|
|
554
|
+
'internal://test/parent.malloy': "source: aa is table('aTable')",
|
|
555
|
+
},
|
|
556
556
|
});
|
|
557
557
|
expect(docParse).modelCompiled();
|
|
558
558
|
});
|
|
559
|
-
test(
|
|
560
|
-
const docParse = new BetaModel(
|
|
559
|
+
test('relative imports with errors', () => {
|
|
560
|
+
const docParse = new BetaModel('import "../parent.malloy"');
|
|
561
561
|
expect(docParse).modelParsed();
|
|
562
562
|
const xr = docParse.unresolved();
|
|
563
|
-
expect(xr).toEqual({
|
|
563
|
+
expect(xr).toEqual({ urls: ['internal://test/parent.malloy'] });
|
|
564
564
|
docParse.update({
|
|
565
|
-
|
|
566
|
-
|
|
565
|
+
urls: {
|
|
566
|
+
'internal://test/parent.malloy': `
|
|
567
567
|
source: aa is table('aTable') {
|
|
568
568
|
dimension: astr is 'not legal beause astr exists'
|
|
569
|
-
}
|
|
570
|
-
}
|
|
569
|
+
}`,
|
|
570
|
+
},
|
|
571
571
|
});
|
|
572
572
|
expect(docParse).compileToFailWith("Cannot redefine 'astr'");
|
|
573
573
|
});
|
|
574
|
-
test(
|
|
574
|
+
test('source references expanded when not exported', () => {
|
|
575
575
|
const srcFiles = {
|
|
576
|
-
|
|
576
|
+
'internal://test/langtests/middle': `
|
|
577
577
|
import "bottom"
|
|
578
578
|
source: midSrc is from(bottomSrc -> { group_by: astr })
|
|
579
579
|
`,
|
|
580
|
-
|
|
580
|
+
'internal://test/langtests/bottom': "source: bottomSrc is table('aTable')",
|
|
581
581
|
};
|
|
582
582
|
const fullModel = new BetaModel(`
|
|
583
583
|
import "middle"
|
|
584
584
|
`);
|
|
585
|
-
fullModel.update({
|
|
585
|
+
fullModel.update({ urls: srcFiles });
|
|
586
586
|
expect(fullModel).modelCompiled();
|
|
587
|
-
const ms = fullModel.getSourceDef(
|
|
587
|
+
const ms = fullModel.getSourceDef('midSrc');
|
|
588
588
|
expect(ms).toBeDefined();
|
|
589
589
|
if (ms) {
|
|
590
|
-
expect(ms.structSource.type).toBe(
|
|
591
|
-
if (ms.structSource.type
|
|
590
|
+
expect(ms.structSource.type).toBe('query');
|
|
591
|
+
if (ms.structSource.type === 'query') {
|
|
592
592
|
const qs = ms.structSource.query.structRef;
|
|
593
|
-
expect(typeof qs).not.toBe(
|
|
593
|
+
expect(typeof qs).not.toBe('string');
|
|
594
594
|
}
|
|
595
595
|
}
|
|
596
596
|
});
|
|
597
597
|
});
|
|
598
598
|
});
|
|
599
|
-
describe(
|
|
600
|
-
test(
|
|
601
|
-
test(
|
|
599
|
+
describe('explore properties', () => {
|
|
600
|
+
test('single dimension', modelOK('explore: aa is a { dimension: x is 1 }'));
|
|
601
|
+
test('multiple dimensions', modelOK(`
|
|
602
602
|
explore: aa is a {
|
|
603
603
|
dimension:
|
|
604
604
|
x is 1
|
|
605
605
|
y is 2
|
|
606
606
|
}
|
|
607
607
|
`));
|
|
608
|
-
test(
|
|
609
|
-
test(
|
|
608
|
+
test('single declare', modelOK('explore: aa is a { declare: x is 1 }'));
|
|
609
|
+
test('multiple declare', modelOK(`
|
|
610
610
|
explore: aa is a {
|
|
611
611
|
declare:
|
|
612
612
|
x is 1
|
|
613
613
|
y is 2
|
|
614
614
|
}
|
|
615
615
|
`));
|
|
616
|
-
test(
|
|
617
|
-
test(
|
|
616
|
+
test('single measure', modelOK('explore: aa is a { measure: x is count() }'));
|
|
617
|
+
test('multiple measures', modelOK(`
|
|
618
618
|
explore: aa is a {
|
|
619
619
|
dimension:
|
|
620
620
|
x is count()
|
|
621
621
|
y is x * x
|
|
622
622
|
}
|
|
623
623
|
`));
|
|
624
|
-
test(
|
|
625
|
-
test(
|
|
624
|
+
test('single where', modelOK('explore: aa is a { where: ai > 10 }'));
|
|
625
|
+
test('multiple where', modelOK(`
|
|
626
626
|
explore: aa is a {
|
|
627
627
|
where:
|
|
628
628
|
ai > 10,
|
|
629
629
|
af < 1000
|
|
630
630
|
}
|
|
631
631
|
`));
|
|
632
|
-
test(
|
|
632
|
+
test('where clause can use the join namespace in source refined query', modelOK(`
|
|
633
633
|
source: flights is table('malloytest.flights') + {
|
|
634
634
|
query: boo is {
|
|
635
635
|
join_one: carriers is table('malloytest.carriers') on carrier = carriers.code
|
|
@@ -638,60 +638,60 @@ describe("explore properties", () => {
|
|
|
638
638
|
aggregate: flight_count is count()
|
|
639
639
|
}
|
|
640
640
|
}`));
|
|
641
|
-
describe(
|
|
642
|
-
test(
|
|
643
|
-
test(
|
|
644
|
-
test(
|
|
645
|
-
test(
|
|
646
|
-
test(
|
|
647
|
-
test(
|
|
648
|
-
test(
|
|
649
|
-
test(
|
|
650
|
-
test(
|
|
651
|
-
test(
|
|
652
|
-
test(
|
|
641
|
+
describe('joins', () => {
|
|
642
|
+
test('with', modelOK('explore: x is a { join_one: b with astr }'));
|
|
643
|
+
test('with', modelOK('explore: x is a { join_one: y is b with astr }'));
|
|
644
|
+
test('with dotted ref', modelOK('explore: x is ab { join_one: xz is a with b.astr }'));
|
|
645
|
+
test('one on', modelOK('explore: x is a { join_one: b on astr = b.astr }'));
|
|
646
|
+
test('one is on', modelOK('explore: x is a { join_one: y is b on astr = y.astr }'));
|
|
647
|
+
test('many on', modelOK('explore: nab is a { join_many: b on astr = b.astr }'));
|
|
648
|
+
test('many is on', modelOK('explore: y is a { join_many: x is b on astr = x.astr }'));
|
|
649
|
+
test('cross', modelOK('explore: nab is a { join_cross: b }'));
|
|
650
|
+
test('cross is', modelOK('explore: nab is a { join_cross: xb is b }'));
|
|
651
|
+
test('cross on', modelOK('explore: nab is a { join_cross: b on true}'));
|
|
652
|
+
test('multiple joins', modelOK(`
|
|
653
653
|
explore: nab is a {
|
|
654
654
|
join_one:
|
|
655
655
|
b with astr,
|
|
656
656
|
br is b with astr
|
|
657
657
|
}
|
|
658
658
|
`));
|
|
659
|
-
test(
|
|
659
|
+
test('with requires primary key', () => {
|
|
660
660
|
expect((0, test_translator_1.markSource) `
|
|
661
661
|
source: nb is b {
|
|
662
662
|
join_one: ${"bb is table('aTable') with astr"}
|
|
663
663
|
}
|
|
664
|
-
`).compileToFailWith(
|
|
664
|
+
`).compileToFailWith('join_one: Cannot use with unless source has a primary key');
|
|
665
665
|
});
|
|
666
666
|
});
|
|
667
|
-
test(
|
|
668
|
-
test(
|
|
669
|
-
test(
|
|
670
|
-
const onlyAstr = new BetaModel(
|
|
667
|
+
test('primary_key', modelOK('explore: c is a { primary_key: ai }'));
|
|
668
|
+
test('rename', modelOK('explore: c is a { rename: nn is ai }'));
|
|
669
|
+
test('accept single', () => {
|
|
670
|
+
const onlyAstr = new BetaModel('explore: c is a { accept: astr }');
|
|
671
671
|
expect(onlyAstr).modelCompiled();
|
|
672
|
-
const c = onlyAstr.getSourceDef(
|
|
672
|
+
const c = onlyAstr.getSourceDef('c');
|
|
673
673
|
if (c) {
|
|
674
674
|
expect(c.fields.length).toBe(1);
|
|
675
675
|
}
|
|
676
676
|
});
|
|
677
|
-
test(
|
|
678
|
-
test(
|
|
679
|
-
const noAstr = new BetaModel(
|
|
677
|
+
test('accept multi', modelOK('explore: c is a { accept: astr, af }'));
|
|
678
|
+
test('except single', () => {
|
|
679
|
+
const noAstr = new BetaModel('explore: c is a { except: astr }');
|
|
680
680
|
expect(noAstr).modelCompiled();
|
|
681
|
-
const c = noAstr.getSourceDef(
|
|
681
|
+
const c = noAstr.getSourceDef('c');
|
|
682
682
|
if (c) {
|
|
683
|
-
const foundAstr = c.fields.find(
|
|
683
|
+
const foundAstr = c.fields.find(f => f.name === 'astr');
|
|
684
684
|
expect(foundAstr).toBeUndefined();
|
|
685
685
|
}
|
|
686
686
|
});
|
|
687
|
-
test(
|
|
688
|
-
test(
|
|
689
|
-
test(
|
|
687
|
+
test('except multi', modelOK('explore: c is a { except: astr, af }'));
|
|
688
|
+
test('explore-query', modelOK('explore: c is a {query: q is { group_by: astr } }'));
|
|
689
|
+
test('refined explore-query', modelOK(`
|
|
690
690
|
explore: abNew is ab {
|
|
691
691
|
query: for1 is aturtle {? ai = 1 }
|
|
692
692
|
}
|
|
693
693
|
`));
|
|
694
|
-
test(
|
|
694
|
+
test('chained explore-query', modelOK(`
|
|
695
695
|
explore: c is a {
|
|
696
696
|
query: chain is {
|
|
697
697
|
group_by: astr
|
|
@@ -701,7 +701,7 @@ describe("explore properties", () => {
|
|
|
701
701
|
}
|
|
702
702
|
}
|
|
703
703
|
`));
|
|
704
|
-
test(
|
|
704
|
+
test('multiple explore-query', modelOK(`
|
|
705
705
|
explore: abNew is ab {
|
|
706
706
|
query:
|
|
707
707
|
q1 is { group_by: astr },
|
|
@@ -709,90 +709,90 @@ describe("explore properties", () => {
|
|
|
709
709
|
}
|
|
710
710
|
`));
|
|
711
711
|
});
|
|
712
|
-
describe(
|
|
713
|
-
test(
|
|
714
|
-
test("group_by x is x'", modelOK(
|
|
715
|
-
test(
|
|
716
|
-
test(
|
|
717
|
-
test(
|
|
712
|
+
describe('qops', () => {
|
|
713
|
+
test('group by single', modelOK('query: a->{ group_by: astr }'));
|
|
714
|
+
test("group_by x is x'", modelOK('query: a->{ group_by: ai is ai/2 }'));
|
|
715
|
+
test('group by multiple', modelOK('query: a->{ group_by: astr,ai }'));
|
|
716
|
+
test('aggregate single', modelOK('query: a->{ aggregate: num is count() }'));
|
|
717
|
+
test('aggregate multiple', modelOK(`
|
|
718
718
|
query: a->{
|
|
719
719
|
aggregate: num is count(), total is sum(ai)
|
|
720
720
|
}
|
|
721
721
|
`));
|
|
722
|
-
test(
|
|
723
|
-
test(
|
|
724
|
-
test(
|
|
725
|
-
test(
|
|
722
|
+
test('project ref', modelOK('query:ab->{ project: b.astr }'));
|
|
723
|
+
test('project *', modelOK('query:ab->{ project: * }'));
|
|
724
|
+
test('project def', modelOK('query:ab->{ project: one is 1 }'));
|
|
725
|
+
test('project multiple', modelOK(`
|
|
726
726
|
query: a->{
|
|
727
727
|
project: one is 1, astr
|
|
728
728
|
}
|
|
729
729
|
`));
|
|
730
|
-
test(
|
|
731
|
-
test(
|
|
732
|
-
test(
|
|
733
|
-
test(
|
|
734
|
-
test(
|
|
735
|
-
const model = new BetaModel(
|
|
730
|
+
test('index single', modelOK('query:a->{index: astr}'));
|
|
731
|
+
test('index path', modelOK('query:ab->{index: ab.astr}'));
|
|
732
|
+
test('index unique on path', modelOK('query:ab->{index: b.astr, ab.astr}'));
|
|
733
|
+
test('index join.*', modelOK('query:ab->{index: ab.*}'));
|
|
734
|
+
test('index multiple', () => {
|
|
735
|
+
const model = new BetaModel('query:a->{index: af, astr}');
|
|
736
736
|
expect(model).modelCompiled();
|
|
737
737
|
const q = model.getQuery(0);
|
|
738
738
|
expect(q).toBeDefined();
|
|
739
739
|
if (q) {
|
|
740
740
|
const index = q.pipeline[0];
|
|
741
|
-
expect(index.type).toBe(
|
|
742
|
-
expect(index.fields).toEqual([
|
|
741
|
+
expect(index.type).toBe('index');
|
|
742
|
+
expect(index.fields).toEqual(['af', 'astr']);
|
|
743
743
|
}
|
|
744
744
|
});
|
|
745
|
-
test(
|
|
746
|
-
const model = new BetaModel(
|
|
745
|
+
test('index star', () => {
|
|
746
|
+
const model = new BetaModel('query:a->{index: *, astr}');
|
|
747
747
|
expect(model).modelCompiled();
|
|
748
748
|
const q = model.getQuery(0);
|
|
749
749
|
expect(q).toBeDefined();
|
|
750
750
|
if (q) {
|
|
751
751
|
const index = q.pipeline[0];
|
|
752
|
-
expect(index.type).toBe(
|
|
753
|
-
expect(index.fields).toEqual([
|
|
752
|
+
expect(index.type).toBe('index');
|
|
753
|
+
expect(index.fields).toEqual(['*', 'astr']);
|
|
754
754
|
}
|
|
755
755
|
});
|
|
756
|
-
test(
|
|
757
|
-
test(
|
|
758
|
-
test(
|
|
759
|
-
test(
|
|
760
|
-
const model = new BetaModel(
|
|
756
|
+
test('index by', modelOK('query:a->{index: * by ai}'));
|
|
757
|
+
test('index sampled', modelOK('query:a->{index: *; sample: true}'));
|
|
758
|
+
test('index unsampled', modelOK('query:a->{index: *; sample: false}'));
|
|
759
|
+
test('index sample-percent', () => {
|
|
760
|
+
const model = new BetaModel('query:a->{index: *; sample: 42%}');
|
|
761
761
|
expect(model).modelCompiled();
|
|
762
762
|
const q = model.getQuery(0);
|
|
763
763
|
expect(q).toBeDefined();
|
|
764
764
|
if (q) {
|
|
765
765
|
const index = q.pipeline[0];
|
|
766
|
-
expect(index.type).toBe(
|
|
767
|
-
if (index.type
|
|
768
|
-
expect(index.sample).toEqual({
|
|
766
|
+
expect(index.type).toBe('index');
|
|
767
|
+
if (index.type === 'index') {
|
|
768
|
+
expect(index.sample).toEqual({ percent: 42 });
|
|
769
769
|
}
|
|
770
770
|
}
|
|
771
771
|
});
|
|
772
|
-
test(
|
|
773
|
-
test(
|
|
774
|
-
test(
|
|
775
|
-
test(
|
|
776
|
-
test(
|
|
777
|
-
test(
|
|
778
|
-
test(
|
|
779
|
-
test(
|
|
780
|
-
test(
|
|
781
|
-
test(
|
|
772
|
+
test('index sample-rows', modelOK('query:a->{index: *; sample: 100000}'));
|
|
773
|
+
test('top N', modelOK('query: a->{ top: 5; group_by: astr }'));
|
|
774
|
+
test('top N by field', modelOK('query: a->{top: 5 by af; group_by: astr}'));
|
|
775
|
+
test('top N by expression', modelOK('query: ab->{top: 5 by acount; group_by: astr}'));
|
|
776
|
+
test('limit N', modelOK('query: a->{ limit: 5; group_by: astr }'));
|
|
777
|
+
test('order by', modelOK('query: a->{ order_by: af; group_by: astr }'));
|
|
778
|
+
test('order by asc', modelOK('query: a->{ order_by: af asc; group_by: astr }'));
|
|
779
|
+
test('order by desc', modelOK('query: a->{ order_by: af desc; group_by: astr }'));
|
|
780
|
+
test('order by N', modelOK('query: a->{ order_by: 1 asc; group_by: astr }'));
|
|
781
|
+
test('order by multiple', modelOK(`
|
|
782
782
|
query: a->{
|
|
783
783
|
order_by: 1 asc, af desc
|
|
784
784
|
group_by: astr, af
|
|
785
785
|
}
|
|
786
786
|
`));
|
|
787
|
-
test(
|
|
788
|
-
test(
|
|
789
|
-
test(
|
|
790
|
-
test(
|
|
791
|
-
test(
|
|
792
|
-
test(
|
|
793
|
-
const model = new BetaModel(
|
|
787
|
+
test('where single', modelOK('query:a->{ group_by: astr; where: af > 10 }'));
|
|
788
|
+
test('having single', modelOK('query:ab->{ aggregate: acount; group_by: astr; having: acount > 10 }'));
|
|
789
|
+
test('compound having still works', modelOK('query:ab->{ aggregate: acount; having: acount > 10 and acount < 100 }'));
|
|
790
|
+
test('compound aggregate still works', modelOK('query:ab->{ aggregate: thing is acount > 10 and acount < 100 }'));
|
|
791
|
+
test('where multiple', modelOK("query:a->{ group_by: astr; where: af > 10,astr~'a%' }"));
|
|
792
|
+
test('filters preserve source formatting in code:', () => {
|
|
793
|
+
const model = new BetaModel("source: notb is a + { where: astr != 'b' }");
|
|
794
794
|
expect(model).modelCompiled();
|
|
795
|
-
const notb = model.getSourceDef(
|
|
795
|
+
const notb = model.getSourceDef('notb');
|
|
796
796
|
expect(notb).toBeDefined();
|
|
797
797
|
if (notb) {
|
|
798
798
|
const f = notb.filterList;
|
|
@@ -802,27 +802,27 @@ describe("qops", () => {
|
|
|
802
802
|
}
|
|
803
803
|
}
|
|
804
804
|
});
|
|
805
|
-
test(
|
|
806
|
-
const model = new BetaModel(
|
|
805
|
+
test('field expressions preserve source formatting in code:', () => {
|
|
806
|
+
const model = new BetaModel('source: notb is a + { dimension: d is 1 + 2 }');
|
|
807
807
|
expect(model).modelCompiled();
|
|
808
|
-
const notb = model.getSourceDef(
|
|
808
|
+
const notb = model.getSourceDef('notb');
|
|
809
809
|
expect(notb).toBeDefined();
|
|
810
810
|
if (notb) {
|
|
811
|
-
const d = notb.fields.find(
|
|
811
|
+
const d = notb.fields.find(f => f.as || f.name === 'd');
|
|
812
812
|
expect(d).toBeDefined();
|
|
813
|
-
expect(d === null || d === void 0 ? void 0 : d.type).toBe(
|
|
814
|
-
if ((d === null || d === void 0 ? void 0 : d.type) ===
|
|
815
|
-
expect(d.code).toBe(
|
|
813
|
+
expect(d === null || d === void 0 ? void 0 : d.type).toBe('number');
|
|
814
|
+
if ((d === null || d === void 0 ? void 0 : d.type) === 'number') {
|
|
815
|
+
expect(d.code).toBe('1 + 2');
|
|
816
816
|
}
|
|
817
817
|
}
|
|
818
818
|
});
|
|
819
|
-
test(
|
|
819
|
+
test('nest single', modelOK(`
|
|
820
820
|
query: a->{
|
|
821
821
|
group_by: ai
|
|
822
822
|
nest: nestbystr is { group_by: astr; aggregate: N is count() }
|
|
823
823
|
}
|
|
824
824
|
`));
|
|
825
|
-
test(
|
|
825
|
+
test('nest multiple', modelOK(`
|
|
826
826
|
query: a->{
|
|
827
827
|
group_by: ai
|
|
828
828
|
nest:
|
|
@@ -830,8 +830,8 @@ describe("qops", () => {
|
|
|
830
830
|
renest is { group_by: astr; aggregate: N is count() }
|
|
831
831
|
}
|
|
832
832
|
`));
|
|
833
|
-
test(
|
|
834
|
-
test(
|
|
833
|
+
test('nest ref', modelOK('query: ab->{group_by: ai; nest: aturtle}'));
|
|
834
|
+
test('refine query with extended source', () => {
|
|
835
835
|
const m = new BetaModel(`
|
|
836
836
|
source: nab is ab {
|
|
837
837
|
query: xturtle is aturtle + {
|
|
@@ -844,20 +844,20 @@ describe("qops", () => {
|
|
|
844
844
|
const t = m.translate();
|
|
845
845
|
if (t.translated) {
|
|
846
846
|
const q = t.translated.queryList[0].pipeline[0];
|
|
847
|
-
if (q.type
|
|
847
|
+
if (q.type === 'reduce' && q.extendSource) {
|
|
848
848
|
expect(q.extendSource.length).toBe(1);
|
|
849
849
|
const f = q.extendSource[0];
|
|
850
|
-
expect(f.type).toBe(
|
|
851
|
-
if (f.type
|
|
850
|
+
expect(f.type).toBe('number');
|
|
851
|
+
if (f.type === 'number') {
|
|
852
852
|
expect((0, model_1.expressionIsCalculation)(f.expressionType)).toBeTruthy();
|
|
853
853
|
}
|
|
854
854
|
}
|
|
855
855
|
else {
|
|
856
|
-
fail(
|
|
856
|
+
fail('Did not generate extendSource');
|
|
857
857
|
}
|
|
858
858
|
}
|
|
859
859
|
});
|
|
860
|
-
test(
|
|
860
|
+
test('refine query source with field', () => {
|
|
861
861
|
const m = new BetaModel(`
|
|
862
862
|
query: ab -> aturtle + {
|
|
863
863
|
declare: aratio is ai / acount
|
|
@@ -868,20 +868,20 @@ describe("qops", () => {
|
|
|
868
868
|
const t = m.translate();
|
|
869
869
|
if (t.translated) {
|
|
870
870
|
const q = t.translated.queryList[0].pipeline[0];
|
|
871
|
-
if (q.type
|
|
871
|
+
if (q.type === 'reduce' && q.extendSource) {
|
|
872
872
|
expect(q.extendSource.length).toBe(1);
|
|
873
873
|
const f = q.extendSource[0];
|
|
874
|
-
expect(f.type).toBe(
|
|
875
|
-
if (f.type
|
|
874
|
+
expect(f.type).toBe('number');
|
|
875
|
+
if (f.type === 'number') {
|
|
876
876
|
expect((0, model_1.expressionIsCalculation)(f.expressionType)).toBeTruthy();
|
|
877
877
|
}
|
|
878
878
|
}
|
|
879
879
|
else {
|
|
880
|
-
fail(
|
|
880
|
+
fail('Did not generate extendSource');
|
|
881
881
|
}
|
|
882
882
|
}
|
|
883
883
|
});
|
|
884
|
-
test(
|
|
884
|
+
test('refine query source with join', () => {
|
|
885
885
|
const m = new BetaModel(`
|
|
886
886
|
query: ab -> aturtle + {
|
|
887
887
|
join_one: bb is b on bb.astr = astr
|
|
@@ -892,89 +892,89 @@ describe("qops", () => {
|
|
|
892
892
|
const t = m.translate();
|
|
893
893
|
if (t.translated) {
|
|
894
894
|
const q = t.translated.queryList[0].pipeline[0];
|
|
895
|
-
if (q.type
|
|
895
|
+
if (q.type === 'reduce' && q.extendSource) {
|
|
896
896
|
expect(q.extendSource.length).toBe(1);
|
|
897
|
-
expect(q.extendSource[0].type).toBe(
|
|
897
|
+
expect(q.extendSource[0].type).toBe('struct');
|
|
898
898
|
}
|
|
899
899
|
else {
|
|
900
|
-
fail(
|
|
900
|
+
fail('Did not generate extendSource');
|
|
901
901
|
}
|
|
902
902
|
}
|
|
903
903
|
});
|
|
904
904
|
});
|
|
905
|
-
describe(
|
|
906
|
-
describe(
|
|
907
|
-
test(
|
|
908
|
-
test(
|
|
909
|
-
test(
|
|
910
|
-
test(
|
|
911
|
-
test(
|
|
912
|
-
test(
|
|
913
|
-
test(
|
|
914
|
-
test(
|
|
915
|
-
test(
|
|
916
|
-
test(
|
|
917
|
-
test(
|
|
918
|
-
test(
|
|
919
|
-
test(
|
|
920
|
-
test(
|
|
921
|
-
test(
|
|
922
|
-
test(
|
|
923
|
-
});
|
|
924
|
-
describe(
|
|
905
|
+
describe('expressions', () => {
|
|
906
|
+
describe('literals', () => {
|
|
907
|
+
test('integer', exprOK('42'));
|
|
908
|
+
test('string', exprOK("'fortywo-two'"));
|
|
909
|
+
test('string with quoted quote', exprOK("'Isn" + '\\' + "'t this nice'"));
|
|
910
|
+
test('string with quoted backslash', exprOK("'Is " + '\\' + '\\' + " nice'"));
|
|
911
|
+
test('year', exprOK('@1960'));
|
|
912
|
+
test('quarter', exprOK('@1960-Q1'));
|
|
913
|
+
test('week', exprOK('@WK1960-06-26'));
|
|
914
|
+
test('month', exprOK('@1960-06'));
|
|
915
|
+
test('day', exprOK('@1960-06-30'));
|
|
916
|
+
test('minute', exprOK('@1960-06-30 10:30'));
|
|
917
|
+
test('second', exprOK('@1960-06-30 10:30:31'));
|
|
918
|
+
test('null', exprOK('null'));
|
|
919
|
+
test('now', exprOK('now'));
|
|
920
|
+
test('true', exprOK('true'));
|
|
921
|
+
test('false', exprOK('false'));
|
|
922
|
+
test('regex', exprOK("r'RegularExpression'"));
|
|
923
|
+
});
|
|
924
|
+
describe('timeframes', () => {
|
|
925
925
|
const timeframes = [
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
926
|
+
'second',
|
|
927
|
+
'minute',
|
|
928
|
+
'hour',
|
|
929
|
+
'day',
|
|
930
|
+
'week',
|
|
931
|
+
'month',
|
|
932
|
+
'quarter',
|
|
933
|
+
'year',
|
|
934
934
|
];
|
|
935
|
-
describe(
|
|
935
|
+
describe('timestamp truncation', () => {
|
|
936
936
|
for (const unit of timeframes) {
|
|
937
937
|
test(`timestamp truncate ${unit}`, exprOK(`ats.${unit}`));
|
|
938
938
|
}
|
|
939
939
|
});
|
|
940
|
-
describe(
|
|
940
|
+
describe('timestamp difference', () => {
|
|
941
941
|
for (const unit of timeframes) {
|
|
942
942
|
// TODO expect these to error ...
|
|
943
943
|
test(`timestamp extract ${unit}`, exprOK(`${unit}(@2021 to ats)`));
|
|
944
944
|
}
|
|
945
945
|
});
|
|
946
946
|
});
|
|
947
|
-
test(
|
|
948
|
-
test(
|
|
949
|
-
describe(
|
|
950
|
-
test(
|
|
951
|
-
test(
|
|
952
|
-
test(
|
|
953
|
-
test(
|
|
954
|
-
test(
|
|
955
|
-
test(
|
|
956
|
-
test(
|
|
957
|
-
test(
|
|
958
|
-
test(
|
|
959
|
-
test(
|
|
960
|
-
test(
|
|
961
|
-
test(
|
|
962
|
-
test(
|
|
963
|
-
test(
|
|
964
|
-
test(
|
|
965
|
-
test(
|
|
966
|
-
test(
|
|
967
|
-
test(
|
|
968
|
-
});
|
|
969
|
-
test(
|
|
970
|
-
describe(
|
|
971
|
-
test(
|
|
972
|
-
test(
|
|
973
|
-
test(
|
|
974
|
-
for (const f of [
|
|
947
|
+
test('field name', exprOK('astr'));
|
|
948
|
+
test('function call', exprOK('CURRENT_TIMESTAMP()'));
|
|
949
|
+
describe('operators', () => {
|
|
950
|
+
test('addition', exprOK('42 + 7'));
|
|
951
|
+
test('subtraction', exprOK('42 - 7'));
|
|
952
|
+
test('multiplication', exprOK('42 * 7'));
|
|
953
|
+
test('mod', exprOK('42 % 7'));
|
|
954
|
+
test('division', exprOK('42 / 7'));
|
|
955
|
+
test('unary negation', exprOK('- ai'));
|
|
956
|
+
test('equal', exprOK('42 = 7'));
|
|
957
|
+
test('not equal', exprOK('42 != 7'));
|
|
958
|
+
test('greater than', exprOK('42 > 7'));
|
|
959
|
+
test('greater than or equal', exprOK('42 >= 7'));
|
|
960
|
+
test('less than or equal', exprOK('42 <= 7'));
|
|
961
|
+
test('less than', exprOK('42 < 7'));
|
|
962
|
+
test('match', exprOK("'forty-two' ~ 'fifty-four'"));
|
|
963
|
+
test('not match', exprOK("'forty-two' !~ 'fifty-four'"));
|
|
964
|
+
test('apply', exprOK("'forty-two' ? 'fifty-four'"));
|
|
965
|
+
test('not', exprOK('not true'));
|
|
966
|
+
test('and', exprOK('true and false'));
|
|
967
|
+
test('or', exprOK('true or false'));
|
|
968
|
+
});
|
|
969
|
+
test('filtered measure', exprOK("acount {? astr = 'why?' }"));
|
|
970
|
+
describe('aggregate forms', () => {
|
|
971
|
+
test('count', exprOK('count()'));
|
|
972
|
+
test('count distinct', exprOK('count(distinct astr)'));
|
|
973
|
+
test('join.count()', exprOK('b.count()'));
|
|
974
|
+
for (const f of ['sum', 'min', 'max', 'avg']) {
|
|
975
975
|
const fOfT = `${f}(af)`;
|
|
976
976
|
test(fOfT, exprOK(fOfT));
|
|
977
|
-
if (f !==
|
|
977
|
+
if (f !== 'min' && f !== 'max') {
|
|
978
978
|
const joinDot = `b.af.${f}()`;
|
|
979
979
|
test(joinDot, exprOK(joinDot));
|
|
980
980
|
const joinAgg = `b.${f}(af)`;
|
|
@@ -982,47 +982,47 @@ describe("expressions", () => {
|
|
|
982
982
|
}
|
|
983
983
|
}
|
|
984
984
|
});
|
|
985
|
-
describe(
|
|
986
|
-
test(
|
|
985
|
+
describe('pick statements', () => {
|
|
986
|
+
test('full', exprOK(`
|
|
987
987
|
pick 'the answer' when ai = 42
|
|
988
988
|
pick 'the questionable answer' when ai = 54
|
|
989
989
|
else 'random'
|
|
990
990
|
`));
|
|
991
|
-
test(
|
|
991
|
+
test('applied', exprOK(`
|
|
992
992
|
astr ?
|
|
993
993
|
pick 'the answer' when = '42'
|
|
994
994
|
pick 'the questionable answer' when = '54'
|
|
995
995
|
else 'random'
|
|
996
996
|
`));
|
|
997
|
-
test(
|
|
997
|
+
test('filtering', exprOK(`
|
|
998
998
|
astr ? pick 'missing value' when NULL
|
|
999
999
|
`));
|
|
1000
|
-
test(
|
|
1000
|
+
test('tiering', exprOK(`
|
|
1001
1001
|
ai ?
|
|
1002
1002
|
pick 1 when < 10
|
|
1003
1003
|
pick 10 when < 100
|
|
1004
1004
|
pick 100 when < 1000
|
|
1005
1005
|
else 10000
|
|
1006
1006
|
`));
|
|
1007
|
-
test(
|
|
1007
|
+
test('transforming', exprOK(`
|
|
1008
1008
|
ai ?
|
|
1009
1009
|
pick 'small' when < 10
|
|
1010
1010
|
pick 'medium' when < 100
|
|
1011
1011
|
else 'large'
|
|
1012
1012
|
`));
|
|
1013
|
-
test(
|
|
1013
|
+
test('when single values', exprOK(`
|
|
1014
1014
|
ai ?
|
|
1015
1015
|
pick 'one' when 1
|
|
1016
1016
|
else 'a lot'
|
|
1017
1017
|
`));
|
|
1018
|
-
test(
|
|
1018
|
+
test('n-ary without else', () => {
|
|
1019
1019
|
expect((0, test_translator_1.markSource) `
|
|
1020
1020
|
explore: na is a + { dimension: d is
|
|
1021
1021
|
pick 7 when true and true
|
|
1022
1022
|
}
|
|
1023
1023
|
`).compileToFailWith("pick incomplete, missing 'else'", "Cannot define 'd', value has unknown type");
|
|
1024
1024
|
});
|
|
1025
|
-
test(
|
|
1025
|
+
test('n-ary with mismatch when clauses', () => {
|
|
1026
1026
|
expect((0, test_translator_1.markSource) `
|
|
1027
1027
|
explore: na is a + { dimension: d is
|
|
1028
1028
|
pick 7 when true and true
|
|
@@ -1031,7 +1031,7 @@ describe("expressions", () => {
|
|
|
1031
1031
|
}
|
|
1032
1032
|
`).compileToFailWith("pick type 'string', expected 'number'", "Cannot define 'd', value has unknown type");
|
|
1033
1033
|
});
|
|
1034
|
-
test(
|
|
1034
|
+
test('n-ary with mismatched else clause', () => {
|
|
1035
1035
|
expect((0, test_translator_1.markSource) `
|
|
1036
1036
|
explore: na is a + { dimension: d is
|
|
1037
1037
|
pick 7 when true and true
|
|
@@ -1039,21 +1039,21 @@ describe("expressions", () => {
|
|
|
1039
1039
|
}
|
|
1040
1040
|
`).compileToFailWith("else type 'string', expected 'number'", "Cannot define 'd', value has unknown type");
|
|
1041
1041
|
});
|
|
1042
|
-
test(
|
|
1042
|
+
test('applied else mismatch', () => {
|
|
1043
1043
|
expect((0, test_translator_1.markSource) `
|
|
1044
1044
|
explore: na is a + { dimension: d is
|
|
1045
1045
|
7 ? pick 7 when 7 else 'not seven'
|
|
1046
1046
|
}
|
|
1047
1047
|
`).compileToFailWith("else type 'string', expected 'number'", "Cannot define 'd', value has unknown type");
|
|
1048
1048
|
});
|
|
1049
|
-
test(
|
|
1049
|
+
test('applied default mismatch', () => {
|
|
1050
1050
|
expect((0, test_translator_1.markSource) `
|
|
1051
1051
|
explore: na is a + { dimension: d is
|
|
1052
1052
|
7 ? pick 'seven' when 7
|
|
1053
1053
|
}
|
|
1054
1054
|
`).compileToFailWith("pick default type 'number', expected 'string'", "Cannot define 'd', value has unknown type");
|
|
1055
1055
|
});
|
|
1056
|
-
test(
|
|
1056
|
+
test('applied when mismatch', () => {
|
|
1057
1057
|
expect((0, test_translator_1.markSource) `
|
|
1058
1058
|
explore: na is a + { dimension: d is
|
|
1059
1059
|
7 ? pick 'seven' when 7 pick 6 when 6
|
|
@@ -1061,89 +1061,89 @@ describe("expressions", () => {
|
|
|
1061
1061
|
`).compileToFailWith("pick type 'number', expected 'string'", "Cannot define 'd', value has unknown type");
|
|
1062
1062
|
});
|
|
1063
1063
|
});
|
|
1064
|
-
test(
|
|
1064
|
+
test('paren and applied div', () => {
|
|
1065
1065
|
var _a, _b;
|
|
1066
|
-
const modelSrc =
|
|
1066
|
+
const modelSrc = 'query: z is a -> { group_by: x is 1+(3/4) }';
|
|
1067
1067
|
const m = new BetaModel(modelSrc);
|
|
1068
1068
|
expect(m).modelCompiled();
|
|
1069
1069
|
const queryDef = (_b = (_a = m.translate()) === null || _a === void 0 ? void 0 : _a.translated) === null || _b === void 0 ? void 0 : _b.modelDef.contents.z;
|
|
1070
1070
|
expect(queryDef).toBeDefined();
|
|
1071
|
-
expect(queryDef === null || queryDef === void 0 ? void 0 : queryDef.type).toBe(
|
|
1072
|
-
if (queryDef && queryDef.type
|
|
1071
|
+
expect(queryDef === null || queryDef === void 0 ? void 0 : queryDef.type).toBe('query');
|
|
1072
|
+
if (queryDef && queryDef.type === 'query') {
|
|
1073
1073
|
const x = queryDef.pipeline[0].fields[0];
|
|
1074
|
-
if (typeof x
|
|
1074
|
+
if (typeof x !== 'string' &&
|
|
1075
1075
|
!(0, model_1.isFilteredAliasedName)(x) &&
|
|
1076
1076
|
(0, model_1.isFieldTypeDef)(x) &&
|
|
1077
|
-
x.type
|
|
1077
|
+
x.type === 'number' &&
|
|
1078
1078
|
x.e) {
|
|
1079
1079
|
const firstFrag = x.e[0];
|
|
1080
|
-
if (typeof firstFrag
|
|
1081
|
-
expect(firstFrag).toContain(
|
|
1080
|
+
if (typeof firstFrag === 'string') {
|
|
1081
|
+
expect(firstFrag).toContain('(');
|
|
1082
1082
|
}
|
|
1083
1083
|
else {
|
|
1084
|
-
fail(
|
|
1084
|
+
fail('expression with parens compiled oddly');
|
|
1085
1085
|
}
|
|
1086
1086
|
}
|
|
1087
1087
|
else {
|
|
1088
|
-
fail(
|
|
1088
|
+
fail('expression with parens compiled oddly');
|
|
1089
1089
|
}
|
|
1090
1090
|
}
|
|
1091
1091
|
});
|
|
1092
1092
|
});
|
|
1093
|
-
describe(
|
|
1094
|
-
test(
|
|
1095
|
-
const uModel = new BetaModel(
|
|
1093
|
+
describe('unspported fields in schema', () => {
|
|
1094
|
+
test('unsupported reference in result allowed', () => {
|
|
1095
|
+
const uModel = new BetaModel('query: a->{ group_by: aun }');
|
|
1096
1096
|
expect(uModel).modelCompiled();
|
|
1097
1097
|
});
|
|
1098
|
-
test(
|
|
1099
|
-
const uModel = new BetaModel(
|
|
1098
|
+
test('unsupported reference can be compared to NULL', () => {
|
|
1099
|
+
const uModel = new BetaModel('query: a->{ where: aun != NULL; project: * }');
|
|
1100
1100
|
expect(uModel).modelCompiled();
|
|
1101
1101
|
});
|
|
1102
|
-
test(
|
|
1102
|
+
test('flag unsupported equality', () => {
|
|
1103
1103
|
// because we don't know if the two unsupported types are comparable
|
|
1104
|
-
const uModel = new BetaModel(
|
|
1105
|
-
expect(uModel).compileToFailWith(
|
|
1104
|
+
const uModel = new BetaModel('query: ab->{ where: aun = b.aun project: * }');
|
|
1105
|
+
expect(uModel).compileToFailWith('Unsupported type not allowed in expression');
|
|
1106
1106
|
});
|
|
1107
|
-
test(
|
|
1107
|
+
test('flag unsupported compare', () => {
|
|
1108
1108
|
// because we don't know if the two unsupported types are comparable
|
|
1109
|
-
const uModel = new BetaModel(
|
|
1110
|
-
expect(uModel).compileToFailWith(
|
|
1109
|
+
const uModel = new BetaModel('query: ab->{ where: aun > b.aun project: * }');
|
|
1110
|
+
expect(uModel).compileToFailWith('Unsupported type not allowed in expression');
|
|
1111
1111
|
});
|
|
1112
|
-
test(
|
|
1113
|
-
const uModel = new BetaModel(
|
|
1112
|
+
test('allow unsupported equality when raw types match', () => {
|
|
1113
|
+
const uModel = new BetaModel('query: ab->{ where: aweird = b.aweird project: * }');
|
|
1114
1114
|
expect(uModel).modelCompiled();
|
|
1115
1115
|
});
|
|
1116
|
-
test(
|
|
1117
|
-
const uModel = new BetaModel(
|
|
1116
|
+
test('flag not applied to unsupported', () => {
|
|
1117
|
+
const uModel = new BetaModel('source: x is a { dimension: notUn is not aun }');
|
|
1118
1118
|
expect(uModel).compileToFailWith("'not' Can't use type unsupported");
|
|
1119
1119
|
});
|
|
1120
|
-
test(
|
|
1121
|
-
const uModel = new BetaModel(
|
|
1120
|
+
test('allow unsupported to be cast', () => {
|
|
1121
|
+
const uModel = new BetaModel('source: x is a { dimension: notUn is aun::string }');
|
|
1122
1122
|
expect(uModel).modelCompiled();
|
|
1123
1123
|
});
|
|
1124
1124
|
});
|
|
1125
|
-
describe(
|
|
1125
|
+
describe('sql:', () => {
|
|
1126
1126
|
function makeSchemaResponse(sql) {
|
|
1127
|
-
const cname = sql.connection ||
|
|
1127
|
+
const cname = sql.connection || 'bigquery';
|
|
1128
1128
|
return {
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1129
|
+
type: 'struct',
|
|
1130
|
+
name: sql.name,
|
|
1131
|
+
dialect: "standardsql'",
|
|
1132
|
+
structSource: {
|
|
1133
|
+
type: 'sql',
|
|
1134
|
+
method: 'subquery',
|
|
1135
|
+
sqlBlock: {
|
|
1136
|
+
type: 'sqlBlock',
|
|
1137
1137
|
...sql,
|
|
1138
|
-
|
|
1139
|
-
}
|
|
1138
|
+
selectStr: sql.select.filter(s => typeof s === 'string').join(''),
|
|
1139
|
+
},
|
|
1140
1140
|
},
|
|
1141
|
-
|
|
1142
|
-
|
|
1141
|
+
structRelationship: { type: 'basetable', connectionName: cname },
|
|
1142
|
+
fields: test_translator_1.aTableDef.fields,
|
|
1143
1143
|
};
|
|
1144
1144
|
}
|
|
1145
|
-
test(
|
|
1146
|
-
const selStmt =
|
|
1145
|
+
test('definition', () => {
|
|
1146
|
+
const selStmt = 'SELECT * FROM aTable';
|
|
1147
1147
|
const model = new BetaModel(`
|
|
1148
1148
|
sql: users IS {
|
|
1149
1149
|
select: """${selStmt}"""
|
|
@@ -1155,20 +1155,20 @@ describe("sql:", () => {
|
|
|
1155
1155
|
const needs = needReq === null || needReq === void 0 ? void 0 : needReq.compileSQL;
|
|
1156
1156
|
expect(needs).toBeDefined();
|
|
1157
1157
|
if (needs) {
|
|
1158
|
-
const sql = (0, sql_block_1.makeSQLBlock)([{
|
|
1158
|
+
const sql = (0, sql_block_1.makeSQLBlock)([{ sql: selStmt }], 'aConnection');
|
|
1159
1159
|
expect(needs).toMatchObject(sql);
|
|
1160
1160
|
const refKey = needs.name;
|
|
1161
1161
|
expect(refKey).toBeDefined();
|
|
1162
1162
|
if (refKey) {
|
|
1163
1163
|
const sr = makeSchemaResponse(sql);
|
|
1164
|
-
model.update({
|
|
1164
|
+
model.update({ compileSQL: { [refKey]: sr } });
|
|
1165
1165
|
expect(model).modelCompiled();
|
|
1166
|
-
expect(unlocatedStructDef(model.sqlBlocks[0])).toEqual(unlocatedStructDef({ ...sr,
|
|
1166
|
+
expect(unlocatedStructDef(model.sqlBlocks[0])).toEqual(unlocatedStructDef({ ...sr, as: 'users' }));
|
|
1167
1167
|
}
|
|
1168
1168
|
}
|
|
1169
1169
|
});
|
|
1170
|
-
test(
|
|
1171
|
-
const selStmt =
|
|
1170
|
+
test('source from sql', () => {
|
|
1171
|
+
const selStmt = 'SELECT * FROM aTable';
|
|
1172
1172
|
const model = new BetaModel(`
|
|
1173
1173
|
sql: users IS { select: """${selStmt}""" }
|
|
1174
1174
|
source: malloyUsers is from_sql(users) { primary_key: ai }
|
|
@@ -1178,16 +1178,16 @@ describe("sql:", () => {
|
|
|
1178
1178
|
const needs = needReq === null || needReq === void 0 ? void 0 : needReq.compileSQL;
|
|
1179
1179
|
expect(needs).toBeDefined();
|
|
1180
1180
|
if (needs) {
|
|
1181
|
-
const sql = (0, sql_block_1.makeSQLBlock)([{
|
|
1181
|
+
const sql = (0, sql_block_1.makeSQLBlock)([{ sql: selStmt }], 'aConnection');
|
|
1182
1182
|
const refKey = needs.name;
|
|
1183
|
-
model.update({
|
|
1183
|
+
model.update({ compileSQL: { [refKey]: makeSchemaResponse(sql) } });
|
|
1184
1184
|
expect(model).modelCompiled();
|
|
1185
|
-
const users = model.getSourceDef(
|
|
1185
|
+
const users = model.getSourceDef('malloyUsers');
|
|
1186
1186
|
expect(users).toBeDefined();
|
|
1187
1187
|
}
|
|
1188
1188
|
});
|
|
1189
|
-
test(
|
|
1190
|
-
const selStmt =
|
|
1189
|
+
test('explore from imported sql-based-source', () => {
|
|
1190
|
+
const selStmt = 'SELECT * FROM aTable';
|
|
1191
1191
|
const createModel = `
|
|
1192
1192
|
sql: users IS { select: """${selStmt}""" }
|
|
1193
1193
|
source: malloyUsers is from_sql(users) { primary_key: ai }
|
|
@@ -1196,16 +1196,16 @@ describe("sql:", () => {
|
|
|
1196
1196
|
import "createModel.malloy"
|
|
1197
1197
|
source: importUsers is malloyUsers
|
|
1198
1198
|
`);
|
|
1199
|
-
model.importZone.define(
|
|
1199
|
+
model.importZone.define('internal://test/langtests/createModel.malloy', createModel);
|
|
1200
1200
|
expect(model).modelParsed();
|
|
1201
1201
|
const needReq = model.translate();
|
|
1202
1202
|
const needs = needReq === null || needReq === void 0 ? void 0 : needReq.compileSQL;
|
|
1203
1203
|
expect(needs).toBeDefined();
|
|
1204
|
-
const sql = (0, sql_block_1.makeSQLBlock)([{
|
|
1205
|
-
model.update({
|
|
1204
|
+
const sql = (0, sql_block_1.makeSQLBlock)([{ sql: selStmt }]);
|
|
1205
|
+
model.update({ compileSQL: { [sql.name]: makeSchemaResponse(sql) } });
|
|
1206
1206
|
expect(model).modelCompiled();
|
|
1207
1207
|
});
|
|
1208
|
-
it(
|
|
1208
|
+
it('turducken', () => {
|
|
1209
1209
|
const m = new BetaModel(`
|
|
1210
1210
|
sql: someSql is {
|
|
1211
1211
|
select: """SELECT * FROM %{ a -> { group_by: astr } }% WHERE 1=1"""
|
|
@@ -1218,13 +1218,13 @@ describe("sql:", () => {
|
|
|
1218
1218
|
const select = compileSql.select[0];
|
|
1219
1219
|
const star = compileSql.select[1];
|
|
1220
1220
|
const where = compileSql.select[2];
|
|
1221
|
-
expect(select).toEqual({
|
|
1221
|
+
expect(select).toEqual({ sql: 'SELECT * FROM ' });
|
|
1222
1222
|
expect((0, model_1.isSQLFragment)(star)).toBeFalsy();
|
|
1223
|
-
expect(where).toEqual({
|
|
1223
|
+
expect(where).toEqual({ sql: ' WHERE 1=1' });
|
|
1224
1224
|
}
|
|
1225
1225
|
});
|
|
1226
|
-
it(
|
|
1227
|
-
const selStmt =
|
|
1226
|
+
it('model preserved', () => {
|
|
1227
|
+
const selStmt = 'SELECT * FROM aTable';
|
|
1228
1228
|
const shouldBeOK = `
|
|
1229
1229
|
source: newa is a
|
|
1230
1230
|
sql: someSql is { select: """${selStmt}""" }
|
|
@@ -1235,20 +1235,20 @@ describe("sql:", () => {
|
|
|
1235
1235
|
const needReq = model.translate();
|
|
1236
1236
|
const needs = needReq === null || needReq === void 0 ? void 0 : needReq.compileSQL;
|
|
1237
1237
|
expect(needs).toBeDefined();
|
|
1238
|
-
const sql = (0, sql_block_1.makeSQLBlock)([{
|
|
1239
|
-
model.update({
|
|
1238
|
+
const sql = (0, sql_block_1.makeSQLBlock)([{ sql: selStmt }]);
|
|
1239
|
+
model.update({ compileSQL: { [sql.name]: makeSchemaResponse(sql) } });
|
|
1240
1240
|
expect(model).modelCompiled();
|
|
1241
1241
|
});
|
|
1242
1242
|
});
|
|
1243
|
-
describe(
|
|
1244
|
-
test(
|
|
1243
|
+
describe('error handling', () => {
|
|
1244
|
+
test('field and query with same name does not overflow', () => {
|
|
1245
1245
|
expect(`
|
|
1246
1246
|
source: flights is table('malloytest.flights') {
|
|
1247
1247
|
query: carrier is { group_by: carrier }
|
|
1248
1248
|
}
|
|
1249
1249
|
`).compileToFailWith("Cannot redefine 'carrier'");
|
|
1250
1250
|
});
|
|
1251
|
-
test(
|
|
1251
|
+
test('redefine source', () => {
|
|
1252
1252
|
expect((0, test_translator_1.markSource) `
|
|
1253
1253
|
source: airports is table('malloytest.airports') + {
|
|
1254
1254
|
primary_key: code
|
|
@@ -1258,27 +1258,27 @@ describe("error handling", () => {
|
|
|
1258
1258
|
}
|
|
1259
1259
|
`).compileToFailWith("Cannot redefine 'airports'");
|
|
1260
1260
|
});
|
|
1261
|
-
test(
|
|
1262
|
-
expect((0, test_translator_1.markSource) `query: ${
|
|
1261
|
+
test('query from undefined source', () => {
|
|
1262
|
+
expect((0, test_translator_1.markSource) `query: ${'x'}->{ project: y }`).compileToFailWith("Undefined source 'x'");
|
|
1263
1263
|
});
|
|
1264
|
-
test(
|
|
1264
|
+
test('query with expression from undefined source', () => {
|
|
1265
1265
|
// Regression check: Once upon a time this died with an exception even
|
|
1266
1266
|
// when "query: x->{ group_by: y}" (above) generated the correct error.
|
|
1267
|
-
expect((0, test_translator_1.markSource) `query: ${
|
|
1267
|
+
expect((0, test_translator_1.markSource) `query: ${'x'}->{ project: y is z / 2 }`).compileToFailWith("Undefined source 'x'");
|
|
1268
1268
|
});
|
|
1269
|
-
test(
|
|
1269
|
+
test('join reference before definition', () => {
|
|
1270
1270
|
expect((0, test_translator_1.markSource) `
|
|
1271
|
-
explore: newAB is a { join_one: newB is ${
|
|
1271
|
+
explore: newAB is a { join_one: newB is ${'bb'} on astring }
|
|
1272
1272
|
explore: newB is b
|
|
1273
1273
|
`).compileToFailWith("Undefined source 'bb'");
|
|
1274
1274
|
});
|
|
1275
|
-
test(
|
|
1276
|
-
test(
|
|
1277
|
-
test(
|
|
1278
|
-
test(
|
|
1279
|
-
test(
|
|
1280
|
-
test("refine can't change query type", badModel(
|
|
1281
|
-
test(
|
|
1275
|
+
test('non-rename rename', badModel('explore: na is a { rename: astr is astr }', "Can't rename field to itself"));
|
|
1276
|
+
test('reference to field in its definition', badModel('explore: na is a { dimension: ustr is UPPER(ustr) } ', "Circular reference to 'ustr' in definition"));
|
|
1277
|
+
test('empty model', modelOK(''));
|
|
1278
|
+
test('one line model ', modelOK('\n'));
|
|
1279
|
+
test('query without fields', badModel('query: a -> { top: 5 }', "Can't determine query type (group_by/aggregate/nest,project,index)"));
|
|
1280
|
+
test("refine can't change query type", badModel('query: ab -> aturtle { project: astr }', 'project: not legal in grouping query'));
|
|
1281
|
+
test('undefined field ref in query', badModel('query: ab -> { aggregate: xyzzy }', "'xyzzy' is not defined"));
|
|
1282
1282
|
// test("queries with anonymous expressions", () => {
|
|
1283
1283
|
// const m = new BetaModel("query: a->{\n group_by: a+1\n}");
|
|
1284
1284
|
// expect(m).not.modelParsed();
|
|
@@ -1286,32 +1286,32 @@ describe("error handling", () => {
|
|
|
1286
1286
|
// const firstError = errList[0];
|
|
1287
1287
|
// expect(firstError.message).toBe("Expressions in queries must have names");
|
|
1288
1288
|
// });
|
|
1289
|
-
test(
|
|
1289
|
+
test('query on source with errors', () => {
|
|
1290
1290
|
expect((0, test_translator_1.markSource) `
|
|
1291
|
-
explore: na is a { join_one: ${
|
|
1291
|
+
explore: na is a { join_one: ${'n'} on astr }
|
|
1292
1292
|
`).compileToFailWith("Undefined source 'n'");
|
|
1293
1293
|
});
|
|
1294
|
-
test(
|
|
1295
|
-
expect((0, test_translator_1.markSource) `query: ab -> { group_by: astr, ${
|
|
1294
|
+
test('detect duplicate output field names', () => {
|
|
1295
|
+
expect((0, test_translator_1.markSource) `query: ab -> { group_by: astr, ${'astr'} }`).compileToFailWith("Output already has a field named 'astr'");
|
|
1296
1296
|
});
|
|
1297
|
-
test(
|
|
1298
|
-
expect((0, test_translator_1.markSource) `query: ab -> { group_by: astr, ${
|
|
1297
|
+
test('detect join tail overlap existing ref', () => {
|
|
1298
|
+
expect((0, test_translator_1.markSource) `query: ab -> { group_by: astr, ${'b.astr'} }`).compileToFailWith("Output already has a field named 'astr'");
|
|
1299
1299
|
});
|
|
1300
|
-
test(
|
|
1300
|
+
test('undefined in expression with regex compare', () => {
|
|
1301
1301
|
expect(`
|
|
1302
1302
|
source: c is a {
|
|
1303
1303
|
dimension: d is meaning_of_life ~ r'(forty two|fifty four)'
|
|
1304
1304
|
}
|
|
1305
1305
|
`).compileToFailWith("'meaning_of_life' is not defined");
|
|
1306
1306
|
});
|
|
1307
|
-
test(
|
|
1307
|
+
test('detect output collision on join references', () => {
|
|
1308
1308
|
expect(`
|
|
1309
1309
|
query: ab -> {
|
|
1310
1310
|
group_by: astr, b.astr
|
|
1311
1311
|
}
|
|
1312
1312
|
`).compileToFailWith("Output already has a field named 'astr'");
|
|
1313
1313
|
});
|
|
1314
|
-
test(
|
|
1314
|
+
test('rejoin a query is renamed', modelOK(`
|
|
1315
1315
|
source: querySrc is from(
|
|
1316
1316
|
table('malloytest.flights')->{
|
|
1317
1317
|
group_by: origin
|
|
@@ -1326,123 +1326,123 @@ describe("error handling", () => {
|
|
|
1326
1326
|
}
|
|
1327
1327
|
}
|
|
1328
1328
|
`));
|
|
1329
|
-
test(
|
|
1330
|
-
expect(
|
|
1329
|
+
test('popping out of embedding when not embedded', () => {
|
|
1330
|
+
expect('}%').compileToFailWith("extraneous input '}%' expecting {<EOF>, EXPLORE, QUERY, SOURCE, SQL, IMPORT, ';'}");
|
|
1331
1331
|
});
|
|
1332
|
-
test(
|
|
1333
|
-
const badModel = new BetaModel(
|
|
1332
|
+
test('bad sql in sql block', () => {
|
|
1333
|
+
const badModel = new BetaModel('sql: { select: """)""" }');
|
|
1334
1334
|
expect(badModel).modelParsed();
|
|
1335
1335
|
const needSchema = badModel.translate();
|
|
1336
1336
|
expect(needSchema.compileSQL).toBeDefined();
|
|
1337
1337
|
if (needSchema.compileSQL) {
|
|
1338
1338
|
badModel.update({
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
[needSchema.compileSQL.name]:
|
|
1342
|
-
}
|
|
1343
|
-
}
|
|
1339
|
+
errors: {
|
|
1340
|
+
compileSQL: {
|
|
1341
|
+
[needSchema.compileSQL.name]: 'ZZZZ',
|
|
1342
|
+
},
|
|
1343
|
+
},
|
|
1344
1344
|
});
|
|
1345
1345
|
}
|
|
1346
|
-
expect(badModel).compileToFailWith(
|
|
1346
|
+
expect(badModel).compileToFailWith('Invalid SQL, ZZZZ');
|
|
1347
1347
|
});
|
|
1348
1348
|
});
|
|
1349
1349
|
function getSelectOneStruct(sqlBlock) {
|
|
1350
1350
|
const selectThis = sqlBlock.select[0];
|
|
1351
1351
|
if (!(0, model_1.isSQLFragment)(selectThis)) {
|
|
1352
|
-
throw new Error(
|
|
1352
|
+
throw new Error('weird test support error sorry');
|
|
1353
1353
|
}
|
|
1354
1354
|
return {
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
}
|
|
1355
|
+
type: 'struct',
|
|
1356
|
+
name: sqlBlock.name,
|
|
1357
|
+
dialect: 'bigquery',
|
|
1358
|
+
structSource: {
|
|
1359
|
+
type: 'sql',
|
|
1360
|
+
method: 'subquery',
|
|
1361
|
+
sqlBlock: {
|
|
1362
|
+
type: 'sqlBlock',
|
|
1363
|
+
name: sqlBlock.name,
|
|
1364
|
+
selectStr: selectThis.sql,
|
|
1365
|
+
},
|
|
1366
1366
|
},
|
|
1367
|
-
|
|
1368
|
-
|
|
1367
|
+
structRelationship: { type: 'basetable', connectionName: 'bigquery' },
|
|
1368
|
+
fields: [{ type: 'number', name: 'one' }],
|
|
1369
1369
|
};
|
|
1370
1370
|
}
|
|
1371
|
-
describe(
|
|
1372
|
-
test(
|
|
1373
|
-
const source = (0, test_translator_1.markSource) `explore: ${
|
|
1371
|
+
describe('source locations', () => {
|
|
1372
|
+
test('renamed explore location', () => {
|
|
1373
|
+
const source = (0, test_translator_1.markSource) `explore: ${'na is a'}`;
|
|
1374
1374
|
const m = new BetaModel(source.code);
|
|
1375
1375
|
expect(m).modelParsed();
|
|
1376
|
-
expect((0, test_translator_1.getExplore)(m.modelDef,
|
|
1376
|
+
expect((0, test_translator_1.getExplore)(m.modelDef, 'na').location).toMatchObject(source.locations[0]);
|
|
1377
1377
|
});
|
|
1378
|
-
test(
|
|
1379
|
-
const source = (0, test_translator_1.markSource) `explore: ${
|
|
1378
|
+
test('refined explore location', () => {
|
|
1379
|
+
const source = (0, test_translator_1.markSource) `explore: ${'na is a {}'}`;
|
|
1380
1380
|
const m = new BetaModel(source.code);
|
|
1381
1381
|
expect(m).modelParsed();
|
|
1382
|
-
expect((0, test_translator_1.getExplore)(m.modelDef,
|
|
1382
|
+
expect((0, test_translator_1.getExplore)(m.modelDef, 'na').location).toMatchObject(source.locations[0]);
|
|
1383
1383
|
});
|
|
1384
|
-
test(
|
|
1385
|
-
const source = (0, test_translator_1.markSource) `explore: na is a { dimension: ${
|
|
1384
|
+
test('location of defined dimension', () => {
|
|
1385
|
+
const source = (0, test_translator_1.markSource) `explore: na is a { dimension: ${'x is 1'} }`;
|
|
1386
1386
|
const m = new BetaModel(source.code);
|
|
1387
1387
|
expect(m).modelCompiled();
|
|
1388
|
-
const na = (0, test_translator_1.getExplore)(m.modelDef,
|
|
1389
|
-
const x = (0, test_translator_1.getField)(na,
|
|
1388
|
+
const na = (0, test_translator_1.getExplore)(m.modelDef, 'na');
|
|
1389
|
+
const x = (0, test_translator_1.getField)(na, 'x');
|
|
1390
1390
|
expect(x.location).toMatchObject(source.locations[0]);
|
|
1391
1391
|
});
|
|
1392
|
-
test(
|
|
1393
|
-
const source = (0, test_translator_1.markSource) `explore: na is a { measure: ${
|
|
1392
|
+
test('location of defined measure', () => {
|
|
1393
|
+
const source = (0, test_translator_1.markSource) `explore: na is a { measure: ${'x is count()'} }`;
|
|
1394
1394
|
const m = new BetaModel(source.code);
|
|
1395
1395
|
expect(m).modelCompiled();
|
|
1396
|
-
const na = (0, test_translator_1.getExplore)(m.modelDef,
|
|
1397
|
-
const x = (0, test_translator_1.getField)(na,
|
|
1396
|
+
const na = (0, test_translator_1.getExplore)(m.modelDef, 'na');
|
|
1397
|
+
const x = (0, test_translator_1.getField)(na, 'x');
|
|
1398
1398
|
expect(x.location).toMatchObject(source.locations[0]);
|
|
1399
1399
|
});
|
|
1400
|
-
test(
|
|
1401
|
-
const source = (0, test_translator_1.markSource) `explore: na is a { query: ${
|
|
1400
|
+
test('location of defined query', () => {
|
|
1401
|
+
const source = (0, test_translator_1.markSource) `explore: na is a { query: ${'x is { group_by: y is 1 }'} }`;
|
|
1402
1402
|
const m = new BetaModel(source.code);
|
|
1403
1403
|
expect(m).modelCompiled();
|
|
1404
|
-
const na = (0, test_translator_1.getExplore)(m.modelDef,
|
|
1405
|
-
const x = (0, test_translator_1.getField)(na,
|
|
1404
|
+
const na = (0, test_translator_1.getExplore)(m.modelDef, 'na');
|
|
1405
|
+
const x = (0, test_translator_1.getField)(na, 'x');
|
|
1406
1406
|
expect(x.location).toMatchObject(source.locations[0]);
|
|
1407
1407
|
});
|
|
1408
|
-
test(
|
|
1408
|
+
test('location of defined field inside a query', () => {
|
|
1409
1409
|
const source = (0, test_translator_1.markSource) `
|
|
1410
1410
|
explore: na is a {
|
|
1411
1411
|
query: x is {
|
|
1412
|
-
group_by: ${
|
|
1412
|
+
group_by: ${'y is 1'}
|
|
1413
1413
|
}
|
|
1414
1414
|
}`;
|
|
1415
1415
|
const m = new BetaModel(source.code);
|
|
1416
1416
|
expect(m).modelCompiled();
|
|
1417
|
-
const na = (0, test_translator_1.getExplore)(m.modelDef,
|
|
1418
|
-
const x = (0, test_translator_1.getQueryField)(na,
|
|
1419
|
-
const y = (0, test_translator_1.getField)(x.pipeline[0],
|
|
1417
|
+
const na = (0, test_translator_1.getExplore)(m.modelDef, 'na');
|
|
1418
|
+
const x = (0, test_translator_1.getQueryField)(na, 'x');
|
|
1419
|
+
const y = (0, test_translator_1.getField)(x.pipeline[0], 'y');
|
|
1420
1420
|
expect(y.location).toMatchObject(source.locations[0]);
|
|
1421
1421
|
});
|
|
1422
|
-
test(
|
|
1422
|
+
test('location of filtered field inside a query', () => {
|
|
1423
1423
|
const source = (0, test_translator_1.markSource) `
|
|
1424
1424
|
explore: na is a {
|
|
1425
1425
|
measure: y is count()
|
|
1426
1426
|
query: x is {
|
|
1427
|
-
group_by: ${
|
|
1427
|
+
group_by: ${'z is y { where: true }'}
|
|
1428
1428
|
}
|
|
1429
1429
|
}`;
|
|
1430
1430
|
const m = new BetaModel(source.code);
|
|
1431
1431
|
expect(m).modelCompiled();
|
|
1432
|
-
const na = (0, test_translator_1.getExplore)(m.modelDef,
|
|
1433
|
-
const x = (0, test_translator_1.getQueryField)(na,
|
|
1434
|
-
const z = (0, test_translator_1.getField)(x.pipeline[0],
|
|
1432
|
+
const na = (0, test_translator_1.getExplore)(m.modelDef, 'na');
|
|
1433
|
+
const x = (0, test_translator_1.getQueryField)(na, 'x');
|
|
1434
|
+
const z = (0, test_translator_1.getField)(x.pipeline[0], 'z');
|
|
1435
1435
|
expect(z.location).toMatchObject(source.locations[0]);
|
|
1436
1436
|
});
|
|
1437
|
-
test(
|
|
1437
|
+
test('location of field inherited from table', () => {
|
|
1438
1438
|
const source = (0, test_translator_1.markSource) `explore: na is ${"table('aTable')"}`;
|
|
1439
1439
|
const m = new BetaModel(source.code);
|
|
1440
1440
|
expect(m).modelCompiled();
|
|
1441
|
-
const na = (0, test_translator_1.getExplore)(m.modelDef,
|
|
1442
|
-
const abool = (0, test_translator_1.getField)(na,
|
|
1441
|
+
const na = (0, test_translator_1.getExplore)(m.modelDef, 'na');
|
|
1442
|
+
const abool = (0, test_translator_1.getField)(na, 'abool');
|
|
1443
1443
|
expect(abool.location).toMatchObject(source.locations[0]);
|
|
1444
1444
|
});
|
|
1445
|
-
test(
|
|
1445
|
+
test('location of field inherited from sql block', () => {
|
|
1446
1446
|
const source = (0, test_translator_1.markSource) `--- comment
|
|
1447
1447
|
sql: s is { select: ${'"""SELECT 1 as one """'} }
|
|
1448
1448
|
explore: na is from_sql(s)
|
|
@@ -1453,112 +1453,112 @@ describe("source locations", () => {
|
|
|
1453
1453
|
expect(compileSql).toBeDefined();
|
|
1454
1454
|
if (compileSql) {
|
|
1455
1455
|
m.update({
|
|
1456
|
-
|
|
1456
|
+
compileSQL: { [compileSql.name]: getSelectOneStruct(compileSql) },
|
|
1457
1457
|
});
|
|
1458
1458
|
expect(m).modelCompiled();
|
|
1459
|
-
const na = (0, test_translator_1.getExplore)(m.modelDef,
|
|
1460
|
-
const one = (0, test_translator_1.getField)(na,
|
|
1459
|
+
const na = (0, test_translator_1.getExplore)(m.modelDef, 'na');
|
|
1460
|
+
const one = (0, test_translator_1.getField)(na, 'one');
|
|
1461
1461
|
expect(one.location).isLocationIn(source.locations[0], source.code);
|
|
1462
1462
|
}
|
|
1463
1463
|
});
|
|
1464
|
-
test(
|
|
1464
|
+
test('location of fields inherited from a query', () => {
|
|
1465
1465
|
const source = (0, test_translator_1.markSource) `
|
|
1466
1466
|
explore: na is from(
|
|
1467
1467
|
${"table('aTable')"} -> {
|
|
1468
1468
|
group_by:
|
|
1469
1469
|
abool
|
|
1470
|
-
${
|
|
1470
|
+
${'y is 1'}
|
|
1471
1471
|
}
|
|
1472
1472
|
)
|
|
1473
1473
|
`;
|
|
1474
1474
|
const m = new BetaModel(source.code);
|
|
1475
1475
|
expect(m).modelCompiled();
|
|
1476
|
-
const na = (0, test_translator_1.getExplore)(m.modelDef,
|
|
1477
|
-
const abool = (0, test_translator_1.getField)(na,
|
|
1476
|
+
const na = (0, test_translator_1.getExplore)(m.modelDef, 'na');
|
|
1477
|
+
const abool = (0, test_translator_1.getField)(na, 'abool');
|
|
1478
1478
|
expect(abool.location).toMatchObject(source.locations[0]);
|
|
1479
|
-
const y = (0, test_translator_1.getField)(na,
|
|
1479
|
+
const y = (0, test_translator_1.getField)(na, 'y');
|
|
1480
1480
|
expect(y.location).toMatchObject(source.locations[1]);
|
|
1481
1481
|
});
|
|
1482
|
-
test(
|
|
1483
|
-
const source = (0, test_translator_1.markSource) `query: ${
|
|
1482
|
+
test('location of named query', () => {
|
|
1483
|
+
const source = (0, test_translator_1.markSource) `query: ${'q is a -> { project: * }'}`;
|
|
1484
1484
|
const m = new BetaModel(source.code);
|
|
1485
1485
|
expect(m).modelCompiled();
|
|
1486
|
-
const q = (0, test_translator_1.getExplore)(m.modelDef,
|
|
1486
|
+
const q = (0, test_translator_1.getExplore)(m.modelDef, 'q');
|
|
1487
1487
|
expect(q.location).toMatchObject(source.locations[0]);
|
|
1488
1488
|
});
|
|
1489
|
-
test(
|
|
1490
|
-
const source = (0, test_translator_1.markSource) `query: q is a -> { group_by: ${
|
|
1489
|
+
test('location of field in named query', () => {
|
|
1490
|
+
const source = (0, test_translator_1.markSource) `query: q is a -> { group_by: ${'b is 1'} }`;
|
|
1491
1491
|
const m = new BetaModel(source.code);
|
|
1492
1492
|
expect(m).modelCompiled();
|
|
1493
|
-
const q = (0, test_translator_1.getModelQuery)(m.modelDef,
|
|
1494
|
-
const a = (0, test_translator_1.getField)(q.pipeline[0],
|
|
1493
|
+
const q = (0, test_translator_1.getModelQuery)(m.modelDef, 'q');
|
|
1494
|
+
const a = (0, test_translator_1.getField)(q.pipeline[0], 'b');
|
|
1495
1495
|
expect(a.location).toMatchObject(source.locations[0]);
|
|
1496
1496
|
});
|
|
1497
|
-
test(
|
|
1498
|
-
const source = (0, test_translator_1.markSource) `${
|
|
1497
|
+
test('location of named SQL block', () => {
|
|
1498
|
+
const source = (0, test_translator_1.markSource) `${'sql: s is { select: """SELECT 1 as one""" }'}`;
|
|
1499
1499
|
const m = new BetaModel(source.code);
|
|
1500
1500
|
expect(m).modelParsed();
|
|
1501
1501
|
const compileSql = m.translate().compileSQL;
|
|
1502
1502
|
expect(compileSql).toBeDefined();
|
|
1503
1503
|
if (compileSql) {
|
|
1504
1504
|
m.update({
|
|
1505
|
-
|
|
1505
|
+
compileSQL: { [compileSql.name]: getSelectOneStruct(compileSql) },
|
|
1506
1506
|
});
|
|
1507
1507
|
expect(m).modelCompiled();
|
|
1508
1508
|
const s = m.sqlBlocks[0];
|
|
1509
1509
|
expect(s.location).isLocationIn(source.locations[0], source.code);
|
|
1510
1510
|
}
|
|
1511
1511
|
});
|
|
1512
|
-
test(
|
|
1512
|
+
test('location of renamed field', () => {
|
|
1513
1513
|
const source = (0, test_translator_1.markSource) `
|
|
1514
1514
|
explore: na is a {
|
|
1515
|
-
rename: ${
|
|
1515
|
+
rename: ${'bbool is abool'}
|
|
1516
1516
|
}
|
|
1517
1517
|
`;
|
|
1518
1518
|
const m = new BetaModel(source.code);
|
|
1519
1519
|
expect(m).modelCompiled();
|
|
1520
|
-
const na = (0, test_translator_1.getExplore)(m.modelDef,
|
|
1521
|
-
const bbool = (0, test_translator_1.getField)(na,
|
|
1520
|
+
const na = (0, test_translator_1.getExplore)(m.modelDef, 'na');
|
|
1521
|
+
const bbool = (0, test_translator_1.getField)(na, 'bbool');
|
|
1522
1522
|
expect(bbool.location).toMatchObject(source.locations[0]);
|
|
1523
1523
|
});
|
|
1524
|
-
test(
|
|
1524
|
+
test('location of join on', () => {
|
|
1525
1525
|
const source = (0, test_translator_1.markSource) `
|
|
1526
1526
|
explore: na is a {
|
|
1527
|
-
join_one: ${
|
|
1527
|
+
join_one: ${'x is a { primary_key: abool } on abool'}
|
|
1528
1528
|
}
|
|
1529
1529
|
`;
|
|
1530
1530
|
const m = new BetaModel(source.code);
|
|
1531
1531
|
expect(m).modelCompiled();
|
|
1532
|
-
const na = (0, test_translator_1.getExplore)(m.modelDef,
|
|
1533
|
-
const x = (0, test_translator_1.getField)(na,
|
|
1532
|
+
const na = (0, test_translator_1.getExplore)(m.modelDef, 'na');
|
|
1533
|
+
const x = (0, test_translator_1.getField)(na, 'x');
|
|
1534
1534
|
expect(x.location).toMatchObject(source.locations[0]);
|
|
1535
1535
|
});
|
|
1536
|
-
test(
|
|
1536
|
+
test('location of join with', () => {
|
|
1537
1537
|
const source = (0, test_translator_1.markSource) `
|
|
1538
1538
|
explore: na is a {
|
|
1539
|
-
join_one: ${
|
|
1539
|
+
join_one: ${'x is a { primary_key: astr } with astr'}
|
|
1540
1540
|
}
|
|
1541
1541
|
`;
|
|
1542
1542
|
const m = new BetaModel(source.code);
|
|
1543
1543
|
expect(m).modelCompiled();
|
|
1544
|
-
const na = (0, test_translator_1.getExplore)(m.modelDef,
|
|
1545
|
-
const x = (0, test_translator_1.getField)(na,
|
|
1544
|
+
const na = (0, test_translator_1.getExplore)(m.modelDef, 'na');
|
|
1545
|
+
const x = (0, test_translator_1.getField)(na, 'x');
|
|
1546
1546
|
expect(x.location).toMatchObject(source.locations[0]);
|
|
1547
1547
|
});
|
|
1548
|
-
test(
|
|
1548
|
+
test('location of field in join', () => {
|
|
1549
1549
|
const source = (0, test_translator_1.markSource) `
|
|
1550
1550
|
explore: na is a {
|
|
1551
1551
|
join_one: x is a {
|
|
1552
1552
|
primary_key: abool
|
|
1553
|
-
dimension: ${
|
|
1553
|
+
dimension: ${'y is 1'}
|
|
1554
1554
|
} on abool
|
|
1555
1555
|
}
|
|
1556
1556
|
`;
|
|
1557
1557
|
const m = new BetaModel(source.code);
|
|
1558
1558
|
expect(m).modelCompiled();
|
|
1559
|
-
const na = (0, test_translator_1.getExplore)(m.modelDef,
|
|
1560
|
-
const x = (0, test_translator_1.getJoinField)(na,
|
|
1561
|
-
const y = (0, test_translator_1.getField)(x,
|
|
1559
|
+
const na = (0, test_translator_1.getExplore)(m.modelDef, 'na');
|
|
1560
|
+
const x = (0, test_translator_1.getJoinField)(na, 'x');
|
|
1561
|
+
const y = (0, test_translator_1.getField)(x, 'y');
|
|
1562
1562
|
expect(y.location).toMatchObject(source.locations[0]);
|
|
1563
1563
|
});
|
|
1564
1564
|
// Since """ strings are not single tokens, I don't know how to do this.
|
|
@@ -1569,67 +1569,67 @@ describe("source locations", () => {
|
|
|
1569
1569
|
// const errList = m.errors().errors;
|
|
1570
1570
|
// expect(errList[0].at?.range.end).toEqual({ line: 2, character: 11 });
|
|
1571
1571
|
// });
|
|
1572
|
-
test(
|
|
1573
|
-
test(
|
|
1574
|
-
test(
|
|
1575
|
-
test.skip(
|
|
1576
|
-
test.skip(
|
|
1572
|
+
test('undefined query location', badModel((0, test_translator_1.markSource) `query: ${'-> xyz'}`, "Reference to undefined query 'xyz'"));
|
|
1573
|
+
test('undefined field reference', badModel((0, test_translator_1.markSource) `query: a -> { group_by: ${'xyz'} }`, "'xyz' is not defined"));
|
|
1574
|
+
test('bad query', badModel((0, test_translator_1.markSource) `query: a -> { group_by: astr; ${'project: *'} }`, 'project: not legal in grouping query'));
|
|
1575
|
+
test.skip('undefined field reference in top', badModel((0, test_translator_1.markSource) `query: a -> { group_by: one is 1; top: 1 by ${'xyz'} }`, "'xyz' is not defined"));
|
|
1576
|
+
test.skip('undefined field reference in order_by', badModel((0, test_translator_1.markSource) `query: a -> { group_by: one is 1; order_by: ${'xyz'} }`, "'xyz' is not defined"));
|
|
1577
1577
|
});
|
|
1578
|
-
describe(
|
|
1579
|
-
test(
|
|
1578
|
+
describe('source references', () => {
|
|
1579
|
+
test('reference to explore', () => {
|
|
1580
1580
|
const source = (0, test_translator_1.markSource) `
|
|
1581
|
-
explore: ${
|
|
1582
|
-
query: ${
|
|
1581
|
+
explore: ${'na is a'}
|
|
1582
|
+
query: ${'na'} -> { project: * }
|
|
1583
1583
|
`;
|
|
1584
1584
|
const m = new BetaModel(source.code);
|
|
1585
1585
|
expect(m).modelCompiled();
|
|
1586
1586
|
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
}
|
|
1587
|
+
location: source.locations[1],
|
|
1588
|
+
type: 'exploreReference',
|
|
1589
|
+
text: 'na',
|
|
1590
|
+
definition: {
|
|
1591
|
+
location: source.locations[0],
|
|
1592
|
+
},
|
|
1593
1593
|
});
|
|
1594
1594
|
});
|
|
1595
|
-
test(
|
|
1595
|
+
test('reference to query in query', () => {
|
|
1596
1596
|
const source = (0, test_translator_1.markSource) `
|
|
1597
1597
|
explore: t is a {
|
|
1598
|
-
query: ${
|
|
1598
|
+
query: ${'q is { project: * }'}
|
|
1599
1599
|
}
|
|
1600
|
-
query: t -> ${
|
|
1600
|
+
query: t -> ${'q'}
|
|
1601
1601
|
`;
|
|
1602
1602
|
const m = new BetaModel(source.code);
|
|
1603
1603
|
expect(m).modelCompiled();
|
|
1604
1604
|
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
}
|
|
1605
|
+
location: source.locations[1],
|
|
1606
|
+
type: 'fieldReference',
|
|
1607
|
+
text: 'q',
|
|
1608
|
+
definition: {
|
|
1609
|
+
location: source.locations[0],
|
|
1610
|
+
},
|
|
1611
1611
|
});
|
|
1612
1612
|
});
|
|
1613
|
-
test(
|
|
1613
|
+
test('reference to query in query (version 2)', () => {
|
|
1614
1614
|
const source = (0, test_translator_1.markSource) `
|
|
1615
|
-
explore: na is a { query: ${
|
|
1616
|
-
query: na -> ${
|
|
1615
|
+
explore: na is a { query: ${'x is { group_by: y is 1 }'} }
|
|
1616
|
+
query: na -> ${'x'}
|
|
1617
1617
|
`;
|
|
1618
1618
|
const m = new BetaModel(source.code);
|
|
1619
1619
|
expect(m).modelCompiled();
|
|
1620
1620
|
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
}
|
|
1621
|
+
location: source.locations[1],
|
|
1622
|
+
type: 'fieldReference',
|
|
1623
|
+
text: 'x',
|
|
1624
|
+
definition: {
|
|
1625
|
+
location: source.locations[0],
|
|
1626
|
+
},
|
|
1627
1627
|
});
|
|
1628
1628
|
});
|
|
1629
|
-
test(
|
|
1629
|
+
test('reference to sql block', () => {
|
|
1630
1630
|
const source = (0, test_translator_1.markSource) `
|
|
1631
|
-
${
|
|
1632
|
-
explore: na is from_sql(${
|
|
1631
|
+
${'sql: s is {select:"""SELECT 1 as one"""}'}
|
|
1632
|
+
explore: na is from_sql(${'s'})
|
|
1633
1633
|
`;
|
|
1634
1634
|
const m = new BetaModel(source.code);
|
|
1635
1635
|
expect(m).modelParsed();
|
|
@@ -1637,436 +1637,436 @@ describe("source references", () => {
|
|
|
1637
1637
|
expect(compileSql).toBeDefined();
|
|
1638
1638
|
if (compileSql) {
|
|
1639
1639
|
m.update({
|
|
1640
|
-
|
|
1640
|
+
compileSQL: { [compileSql.name]: getSelectOneStruct(compileSql) },
|
|
1641
1641
|
});
|
|
1642
1642
|
expect(m).modelCompiled();
|
|
1643
1643
|
const ref = m.referenceAt(pos(source.locations[1]));
|
|
1644
1644
|
expect(ref).toMatchObject({
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1645
|
+
location: source.locations[1],
|
|
1646
|
+
type: 'sqlBlockReference',
|
|
1647
|
+
text: 's',
|
|
1648
|
+
definition: {
|
|
1649
1649
|
...getSelectOneStruct(compileSql),
|
|
1650
|
-
|
|
1651
|
-
}
|
|
1650
|
+
location: source.locations[0],
|
|
1651
|
+
},
|
|
1652
1652
|
});
|
|
1653
1653
|
}
|
|
1654
1654
|
});
|
|
1655
|
-
test(
|
|
1655
|
+
test('reference to query in from', () => {
|
|
1656
1656
|
const source = (0, test_translator_1.markSource) `
|
|
1657
|
-
query: ${
|
|
1658
|
-
explore: na is from(-> ${
|
|
1657
|
+
query: ${'q is a -> { project: * }'}
|
|
1658
|
+
explore: na is from(-> ${'q'})
|
|
1659
1659
|
`;
|
|
1660
1660
|
const m = new BetaModel(source.code);
|
|
1661
1661
|
expect(m).modelCompiled();
|
|
1662
1662
|
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
}
|
|
1663
|
+
location: source.locations[1],
|
|
1664
|
+
type: 'queryReference',
|
|
1665
|
+
text: 'q',
|
|
1666
|
+
definition: {
|
|
1667
|
+
location: source.locations[0],
|
|
1668
|
+
},
|
|
1669
1669
|
});
|
|
1670
1670
|
});
|
|
1671
|
-
test(
|
|
1671
|
+
test('reference to query in query head', () => {
|
|
1672
1672
|
const source = (0, test_translator_1.markSource) `
|
|
1673
|
-
query: ${
|
|
1674
|
-
query: q2 is -> ${
|
|
1673
|
+
query: ${'q is a -> { project: * }'}
|
|
1674
|
+
query: q2 is -> ${'q'} -> { project: * }
|
|
1675
1675
|
`;
|
|
1676
1676
|
const m = new BetaModel(source.code);
|
|
1677
1677
|
expect(m).modelCompiled();
|
|
1678
1678
|
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
}
|
|
1679
|
+
location: source.locations[1],
|
|
1680
|
+
type: 'queryReference',
|
|
1681
|
+
text: 'q',
|
|
1682
|
+
definition: {
|
|
1683
|
+
location: source.locations[0],
|
|
1684
|
+
},
|
|
1685
1685
|
});
|
|
1686
1686
|
});
|
|
1687
|
-
test(
|
|
1687
|
+
test('reference to query in refined query', () => {
|
|
1688
1688
|
const source = (0, test_translator_1.markSource) `
|
|
1689
|
-
query: ${
|
|
1690
|
-
query: q2 is -> ${
|
|
1689
|
+
query: ${'q is a -> { project: * }'}
|
|
1690
|
+
query: q2 is -> ${'q'} { limit: 10 }
|
|
1691
1691
|
`;
|
|
1692
1692
|
const m = new BetaModel(source.code);
|
|
1693
1693
|
expect(m).modelCompiled();
|
|
1694
1694
|
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
}
|
|
1695
|
+
location: source.locations[1],
|
|
1696
|
+
type: 'queryReference',
|
|
1697
|
+
text: 'q',
|
|
1698
|
+
definition: {
|
|
1699
|
+
location: source.locations[0],
|
|
1700
|
+
},
|
|
1701
1701
|
});
|
|
1702
1702
|
});
|
|
1703
|
-
test(
|
|
1703
|
+
test('reference to field in expression', () => {
|
|
1704
1704
|
const source = (0, test_translator_1.markSource) `
|
|
1705
1705
|
explore: na is ${"table('aTable')"}
|
|
1706
|
-
query: na -> { project: bbool is not ${
|
|
1706
|
+
query: na -> { project: bbool is not ${'abool'} }
|
|
1707
1707
|
`;
|
|
1708
1708
|
const m = new BetaModel(source.code);
|
|
1709
1709
|
expect(m).modelCompiled();
|
|
1710
1710
|
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
}
|
|
1711
|
+
location: source.locations[1],
|
|
1712
|
+
type: 'fieldReference',
|
|
1713
|
+
text: 'abool',
|
|
1714
|
+
definition: {
|
|
1715
|
+
location: source.locations[0],
|
|
1716
|
+
},
|
|
1717
1717
|
});
|
|
1718
1718
|
});
|
|
1719
|
-
test(
|
|
1719
|
+
test('reference to quoted field in expression', () => {
|
|
1720
1720
|
const source = (0, test_translator_1.markSource) `
|
|
1721
1721
|
explore: na is a {
|
|
1722
1722
|
dimension: ${"`name` is 'name'"}
|
|
1723
1723
|
}
|
|
1724
|
-
query: na -> { project: ${
|
|
1724
|
+
query: na -> { project: ${'`name`'} }
|
|
1725
1725
|
`;
|
|
1726
1726
|
const m = new BetaModel(source.code);
|
|
1727
1727
|
expect(m).modelCompiled();
|
|
1728
1728
|
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
}
|
|
1729
|
+
location: source.locations[1],
|
|
1730
|
+
type: 'fieldReference',
|
|
1731
|
+
text: 'name',
|
|
1732
|
+
definition: {
|
|
1733
|
+
location: source.locations[0],
|
|
1734
|
+
},
|
|
1735
1735
|
});
|
|
1736
1736
|
});
|
|
1737
|
-
test(
|
|
1737
|
+
test('reference to joined field in expression', () => {
|
|
1738
1738
|
const source = (0, test_translator_1.markSource) `
|
|
1739
1739
|
explore: na is a {
|
|
1740
1740
|
join_one: self is ${"table('aTable')"}
|
|
1741
1741
|
on astr = self.astr
|
|
1742
1742
|
}
|
|
1743
|
-
query: na -> { project: bstr is self.${
|
|
1743
|
+
query: na -> { project: bstr is self.${'astr'} }
|
|
1744
1744
|
`;
|
|
1745
1745
|
const m = new BetaModel(source.code);
|
|
1746
1746
|
expect(m).modelCompiled();
|
|
1747
1747
|
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
}
|
|
1748
|
+
location: source.locations[1],
|
|
1749
|
+
type: 'fieldReference',
|
|
1750
|
+
text: 'astr',
|
|
1751
|
+
definition: {
|
|
1752
|
+
location: source.locations[0],
|
|
1753
|
+
},
|
|
1754
1754
|
});
|
|
1755
1755
|
});
|
|
1756
|
-
test(
|
|
1756
|
+
test('reference to joined join in expression', () => {
|
|
1757
1757
|
const source = (0, test_translator_1.markSource) `
|
|
1758
1758
|
explore: na is a {
|
|
1759
|
-
join_one: ${
|
|
1759
|
+
join_one: ${'self is a on astr = self.astr'}
|
|
1760
1760
|
}
|
|
1761
|
-
query: na -> { project: bstr is ${
|
|
1761
|
+
query: na -> { project: bstr is ${'self'}.astr }
|
|
1762
1762
|
`;
|
|
1763
1763
|
const m = new BetaModel(source.code);
|
|
1764
1764
|
expect(m).modelCompiled();
|
|
1765
1765
|
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
}
|
|
1766
|
+
location: source.locations[1],
|
|
1767
|
+
type: 'joinReference',
|
|
1768
|
+
text: 'self',
|
|
1769
|
+
definition: {
|
|
1770
|
+
location: source.locations[0],
|
|
1771
|
+
},
|
|
1772
1772
|
});
|
|
1773
1773
|
});
|
|
1774
|
-
test(
|
|
1774
|
+
test('reference to field not in expression (group by)', () => {
|
|
1775
1775
|
const source = (0, test_translator_1.markSource) `
|
|
1776
|
-
query: ${"table('aTable')"} -> { group_by: ${
|
|
1776
|
+
query: ${"table('aTable')"} -> { group_by: ${'abool'} }
|
|
1777
1777
|
`;
|
|
1778
1778
|
const m = new BetaModel(source.code);
|
|
1779
1779
|
expect(m).modelCompiled();
|
|
1780
1780
|
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
}
|
|
1781
|
+
location: source.locations[1],
|
|
1782
|
+
type: 'fieldReference',
|
|
1783
|
+
text: 'abool',
|
|
1784
|
+
definition: {
|
|
1785
|
+
location: source.locations[0],
|
|
1786
|
+
},
|
|
1787
1787
|
});
|
|
1788
1788
|
});
|
|
1789
|
-
test(
|
|
1789
|
+
test('reference to field not in expression (project)', () => {
|
|
1790
1790
|
const source = (0, test_translator_1.markSource) `
|
|
1791
1791
|
explore: na is ${"table('aTable')"}
|
|
1792
|
-
query: na -> { project: ${
|
|
1792
|
+
query: na -> { project: ${'abool'} }
|
|
1793
1793
|
`;
|
|
1794
1794
|
const m = new BetaModel(source.code);
|
|
1795
1795
|
expect(m).modelCompiled();
|
|
1796
1796
|
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
}
|
|
1797
|
+
location: source.locations[1],
|
|
1798
|
+
type: 'fieldReference',
|
|
1799
|
+
text: 'abool',
|
|
1800
|
+
definition: {
|
|
1801
|
+
location: source.locations[0],
|
|
1802
|
+
},
|
|
1803
1803
|
});
|
|
1804
1804
|
});
|
|
1805
|
-
test.skip(
|
|
1805
|
+
test.skip('reference to field in order by', () => {
|
|
1806
1806
|
const source = (0, test_translator_1.markSource) `
|
|
1807
1807
|
query: ${"table('aTable')"} -> {
|
|
1808
1808
|
group_by: abool
|
|
1809
|
-
order_by: ${
|
|
1809
|
+
order_by: ${'abool'}
|
|
1810
1810
|
}
|
|
1811
1811
|
`;
|
|
1812
1812
|
const m = new BetaModel(source.code);
|
|
1813
1813
|
expect(m).modelCompiled();
|
|
1814
1814
|
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
}
|
|
1815
|
+
location: source.locations[1],
|
|
1816
|
+
type: 'fieldReference',
|
|
1817
|
+
text: 'abool',
|
|
1818
|
+
definition: {
|
|
1819
|
+
location: source.locations[0],
|
|
1820
|
+
},
|
|
1821
1821
|
});
|
|
1822
1822
|
});
|
|
1823
|
-
test.skip(
|
|
1823
|
+
test.skip('reference to field in order by (output space)', () => {
|
|
1824
1824
|
const source = (0, test_translator_1.markSource) `
|
|
1825
1825
|
query: a -> {
|
|
1826
|
-
group_by: ${
|
|
1827
|
-
order_by: ${
|
|
1826
|
+
group_by: ${'one is 1'}
|
|
1827
|
+
order_by: ${'one'}
|
|
1828
1828
|
}
|
|
1829
1829
|
`;
|
|
1830
1830
|
const m = new BetaModel(source.code);
|
|
1831
1831
|
expect(m).modelCompiled();
|
|
1832
1832
|
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
}
|
|
1833
|
+
location: source.locations[1],
|
|
1834
|
+
type: 'fieldReference',
|
|
1835
|
+
text: 'abool',
|
|
1836
|
+
definition: {
|
|
1837
|
+
location: source.locations[0],
|
|
1838
|
+
},
|
|
1839
1839
|
});
|
|
1840
1840
|
});
|
|
1841
|
-
test(
|
|
1841
|
+
test('reference to field in aggregate', () => {
|
|
1842
1842
|
const source = (0, test_translator_1.markSource) `
|
|
1843
|
-
query: a { measure: ${
|
|
1843
|
+
query: a { measure: ${'c is count()'} } -> {
|
|
1844
1844
|
group_by: abool
|
|
1845
|
-
aggregate: ${
|
|
1845
|
+
aggregate: ${'c'}
|
|
1846
1846
|
}
|
|
1847
1847
|
`;
|
|
1848
1848
|
const m = new BetaModel(source.code);
|
|
1849
1849
|
expect(m).modelCompiled();
|
|
1850
1850
|
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
}
|
|
1851
|
+
location: source.locations[1],
|
|
1852
|
+
type: 'fieldReference',
|
|
1853
|
+
text: 'c',
|
|
1854
|
+
definition: {
|
|
1855
|
+
location: source.locations[0],
|
|
1856
|
+
},
|
|
1857
1857
|
});
|
|
1858
1858
|
});
|
|
1859
|
-
test(
|
|
1859
|
+
test('reference to field in measure', () => {
|
|
1860
1860
|
const source = (0, test_translator_1.markSource) `
|
|
1861
1861
|
explore: e is a {
|
|
1862
|
-
measure: ${
|
|
1863
|
-
measure: c2 is ${
|
|
1862
|
+
measure: ${'c is count()'}
|
|
1863
|
+
measure: c2 is ${'c'}
|
|
1864
1864
|
}
|
|
1865
1865
|
`;
|
|
1866
1866
|
const m = new BetaModel(source.code);
|
|
1867
1867
|
expect(m).modelCompiled();
|
|
1868
1868
|
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
}
|
|
1869
|
+
location: source.locations[1],
|
|
1870
|
+
type: 'fieldReference',
|
|
1871
|
+
text: 'c',
|
|
1872
|
+
definition: {
|
|
1873
|
+
location: source.locations[0],
|
|
1874
|
+
},
|
|
1875
1875
|
});
|
|
1876
1876
|
});
|
|
1877
|
-
test.skip(
|
|
1877
|
+
test.skip('reference to field in top', () => {
|
|
1878
1878
|
const source = (0, test_translator_1.markSource) `
|
|
1879
1879
|
query: ${"table('aTable')"} -> {
|
|
1880
1880
|
group_by: abool
|
|
1881
|
-
top: 10 by ${
|
|
1881
|
+
top: 10 by ${'abool'}
|
|
1882
1882
|
}
|
|
1883
1883
|
`;
|
|
1884
1884
|
const m = new BetaModel(source.code);
|
|
1885
1885
|
expect(m).modelCompiled();
|
|
1886
1886
|
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
}
|
|
1887
|
+
location: source.locations[1],
|
|
1888
|
+
type: 'fieldReference',
|
|
1889
|
+
text: 'abool',
|
|
1890
|
+
definition: {
|
|
1891
|
+
location: source.locations[0],
|
|
1892
|
+
},
|
|
1893
1893
|
});
|
|
1894
1894
|
});
|
|
1895
|
-
test.skip(
|
|
1895
|
+
test.skip('reference to field in top (output space)', () => {
|
|
1896
1896
|
const source = (0, test_translator_1.markSource) `
|
|
1897
1897
|
query: a -> {
|
|
1898
|
-
group_by: ${
|
|
1899
|
-
top: 10 by ${
|
|
1898
|
+
group_by: ${'one is 1'}
|
|
1899
|
+
top: 10 by ${'one'}
|
|
1900
1900
|
}
|
|
1901
1901
|
`;
|
|
1902
1902
|
const m = new BetaModel(source.code);
|
|
1903
1903
|
expect(m).modelCompiled();
|
|
1904
1904
|
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
}
|
|
1905
|
+
location: source.locations[1],
|
|
1906
|
+
type: 'fieldReference',
|
|
1907
|
+
text: 'abool',
|
|
1908
|
+
definition: {
|
|
1909
|
+
location: source.locations[0],
|
|
1910
|
+
},
|
|
1911
1911
|
});
|
|
1912
1912
|
});
|
|
1913
|
-
test(
|
|
1913
|
+
test('reference to field in filter', () => {
|
|
1914
1914
|
const source = (0, test_translator_1.markSource) `
|
|
1915
1915
|
query: ${"table('aTable')"} -> {
|
|
1916
1916
|
group_by: abool
|
|
1917
|
-
where: ${
|
|
1917
|
+
where: ${'abool'}
|
|
1918
1918
|
}
|
|
1919
1919
|
`;
|
|
1920
1920
|
const m = new BetaModel(source.code);
|
|
1921
1921
|
expect(m).modelCompiled();
|
|
1922
1922
|
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
}
|
|
1923
|
+
location: source.locations[1],
|
|
1924
|
+
type: 'fieldReference',
|
|
1925
|
+
text: 'abool',
|
|
1926
|
+
definition: {
|
|
1927
|
+
location: source.locations[0],
|
|
1928
|
+
},
|
|
1929
1929
|
});
|
|
1930
1930
|
});
|
|
1931
|
-
test(
|
|
1931
|
+
test('reference to field in aggregate source', () => {
|
|
1932
1932
|
const source = (0, test_translator_1.markSource) `
|
|
1933
1933
|
explore: na is ${"table('aTable')"}
|
|
1934
|
-
query: na -> { aggregate: ai_sum is ${
|
|
1934
|
+
query: na -> { aggregate: ai_sum is ${'ai'}.sum() }
|
|
1935
1935
|
`;
|
|
1936
1936
|
const m = new BetaModel(source.code);
|
|
1937
1937
|
expect(m).modelCompiled();
|
|
1938
1938
|
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
}
|
|
1939
|
+
location: source.locations[1],
|
|
1940
|
+
type: 'fieldReference',
|
|
1941
|
+
text: 'ai',
|
|
1942
|
+
definition: {
|
|
1943
|
+
location: source.locations[0],
|
|
1944
|
+
},
|
|
1945
1945
|
});
|
|
1946
1946
|
});
|
|
1947
1947
|
function pos(location) {
|
|
1948
1948
|
return location.range.start;
|
|
1949
1949
|
}
|
|
1950
|
-
test(
|
|
1950
|
+
test('reference to join in aggregate source', () => {
|
|
1951
1951
|
const source = (0, test_translator_1.markSource) `
|
|
1952
1952
|
explore: na is a {
|
|
1953
|
-
join_one: ${
|
|
1953
|
+
join_one: ${'self is a on astr = self.astr'}
|
|
1954
1954
|
}
|
|
1955
|
-
query: na -> { aggregate: ai_sum is ${
|
|
1955
|
+
query: na -> { aggregate: ai_sum is ${'self'}.sum(self.ai) }
|
|
1956
1956
|
`;
|
|
1957
1957
|
const m = new BetaModel(source.code);
|
|
1958
1958
|
expect(m).modelCompiled();
|
|
1959
1959
|
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
}
|
|
1960
|
+
location: source.locations[1],
|
|
1961
|
+
type: 'joinReference',
|
|
1962
|
+
text: 'self',
|
|
1963
|
+
definition: {
|
|
1964
|
+
location: source.locations[0],
|
|
1965
|
+
},
|
|
1966
1966
|
});
|
|
1967
1967
|
});
|
|
1968
|
-
test(
|
|
1968
|
+
test('reference to join in aggregate in expr', () => {
|
|
1969
1969
|
const source = (0, test_translator_1.markSource) `
|
|
1970
1970
|
explore: na is a {
|
|
1971
|
-
join_one: ${
|
|
1971
|
+
join_one: ${'self is a on astr = self.astr'}
|
|
1972
1972
|
}
|
|
1973
|
-
query: na -> { aggregate: ai_sum is self.sum(${
|
|
1973
|
+
query: na -> { aggregate: ai_sum is self.sum(${'self'}.ai) }
|
|
1974
1974
|
`;
|
|
1975
1975
|
const m = new BetaModel(source.code);
|
|
1976
1976
|
expect(m).modelCompiled();
|
|
1977
1977
|
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
}
|
|
1978
|
+
location: source.locations[1],
|
|
1979
|
+
type: 'joinReference',
|
|
1980
|
+
text: 'self',
|
|
1981
|
+
definition: {
|
|
1982
|
+
location: source.locations[0],
|
|
1983
|
+
},
|
|
1984
1984
|
});
|
|
1985
1985
|
});
|
|
1986
|
-
test(
|
|
1986
|
+
test('reference to explore in join', () => {
|
|
1987
1987
|
const source = (0, test_translator_1.markSource) `
|
|
1988
|
-
explore: ${
|
|
1988
|
+
explore: ${'exp1 is a'}
|
|
1989
1989
|
explore: exp2 is a {
|
|
1990
|
-
join_one: ${
|
|
1990
|
+
join_one: ${'exp1'} on astr = exp1.astr
|
|
1991
1991
|
}
|
|
1992
1992
|
`;
|
|
1993
1993
|
const m = new BetaModel(source.code);
|
|
1994
1994
|
expect(m).modelCompiled();
|
|
1995
1995
|
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
}
|
|
1996
|
+
location: source.locations[1],
|
|
1997
|
+
type: 'exploreReference',
|
|
1998
|
+
text: 'exp1',
|
|
1999
|
+
definition: {
|
|
2000
|
+
location: source.locations[0],
|
|
2001
|
+
},
|
|
2002
2002
|
});
|
|
2003
2003
|
});
|
|
2004
|
-
test(
|
|
2004
|
+
test('reference to field in aggregate (in expr)', () => {
|
|
2005
2005
|
const source = (0, test_translator_1.markSource) `
|
|
2006
2006
|
explore: na is ${"table('aTable')"}
|
|
2007
|
-
query: na -> { aggregate: ai_sum is sum(${
|
|
2007
|
+
query: na -> { aggregate: ai_sum is sum(${'ai'}) }
|
|
2008
2008
|
`;
|
|
2009
2009
|
const m = new BetaModel(source.code);
|
|
2010
2010
|
expect(m).modelCompiled();
|
|
2011
2011
|
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
}
|
|
2012
|
+
location: source.locations[1],
|
|
2013
|
+
type: 'fieldReference',
|
|
2014
|
+
text: 'ai',
|
|
2015
|
+
definition: {
|
|
2016
|
+
location: source.locations[0],
|
|
2017
|
+
},
|
|
2018
2018
|
});
|
|
2019
2019
|
});
|
|
2020
|
-
test(
|
|
2020
|
+
test('reference to field in rename', () => {
|
|
2021
2021
|
const source = (0, test_translator_1.markSource) `
|
|
2022
2022
|
explore: na is ${"table('aTable')"} {
|
|
2023
|
-
rename: bbool is ${
|
|
2023
|
+
rename: bbool is ${'abool'}
|
|
2024
2024
|
}
|
|
2025
2025
|
`;
|
|
2026
2026
|
const m = new BetaModel(source.code);
|
|
2027
2027
|
expect(m).modelCompiled();
|
|
2028
2028
|
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
}
|
|
2029
|
+
location: source.locations[1],
|
|
2030
|
+
type: 'fieldReference',
|
|
2031
|
+
text: 'abool',
|
|
2032
|
+
definition: {
|
|
2033
|
+
location: source.locations[0],
|
|
2034
|
+
},
|
|
2035
2035
|
});
|
|
2036
2036
|
});
|
|
2037
|
-
test(
|
|
2037
|
+
test('reference to field in join with', () => {
|
|
2038
2038
|
const source = (0, test_translator_1.markSource) `
|
|
2039
2039
|
explore: exp1 is a { primary_key: astr }
|
|
2040
2040
|
explore: exp2 is ${"table('aTable')"} {
|
|
2041
|
-
join_one: exp1 with ${
|
|
2041
|
+
join_one: exp1 with ${'astr'}
|
|
2042
2042
|
}
|
|
2043
2043
|
`;
|
|
2044
2044
|
const m = new BetaModel(source.code);
|
|
2045
2045
|
expect(m).modelCompiled();
|
|
2046
2046
|
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
}
|
|
2047
|
+
location: source.locations[1],
|
|
2048
|
+
type: 'fieldReference',
|
|
2049
|
+
text: 'astr',
|
|
2050
|
+
definition: {
|
|
2051
|
+
location: source.locations[0],
|
|
2052
|
+
},
|
|
2053
2053
|
});
|
|
2054
2054
|
});
|
|
2055
2055
|
});
|
|
2056
|
-
describe(
|
|
2057
|
-
test(
|
|
2056
|
+
describe('translation need error locations', () => {
|
|
2057
|
+
test('import error location', () => {
|
|
2058
2058
|
const source = (0, test_translator_1.markSource) `import ${'"badfile"'}`;
|
|
2059
2059
|
const m = new BetaModel(source.code);
|
|
2060
2060
|
const result = m.translate();
|
|
2061
2061
|
m.update({
|
|
2062
|
-
|
|
2062
|
+
errors: { urls: { [(result.urls || [])[0]]: 'Bad file!' } },
|
|
2063
2063
|
});
|
|
2064
2064
|
expect(m).not.modelParsed();
|
|
2065
2065
|
const errList = m.errors().errors;
|
|
2066
2066
|
expect(errList[0].at).isLocationIn(source.locations[0], source.code);
|
|
2067
2067
|
return undefined;
|
|
2068
2068
|
});
|
|
2069
|
-
test(
|
|
2069
|
+
test('sql struct error location', () => {
|
|
2070
2070
|
const source = (0, test_translator_1.markSource) `
|
|
2071
2071
|
sql: bad_sql is {select: ${'"""BAD_SQL"""'}}
|
|
2072
2072
|
query: from_sql(bad_sql) -> { project: * }
|
|
@@ -2076,22 +2076,22 @@ describe("translation need error locations", () => {
|
|
|
2076
2076
|
const req = m.translate().compileSQL;
|
|
2077
2077
|
expect(req).toBeDefined();
|
|
2078
2078
|
if (req) {
|
|
2079
|
-
m.update({
|
|
2079
|
+
m.update({ errors: { compileSQL: { [req.name]: 'Bad SQL!' } } });
|
|
2080
2080
|
}
|
|
2081
2081
|
expect(m).not.modelCompiled();
|
|
2082
2082
|
const errList = m.errors().errors;
|
|
2083
2083
|
expect(errList[0].at).isLocationIn(source.locations[0], source.code);
|
|
2084
2084
|
});
|
|
2085
|
-
test(
|
|
2085
|
+
test('table struct error location', () => {
|
|
2086
2086
|
const source = (0, test_translator_1.markSource) `
|
|
2087
2087
|
explore: bad_explore is ${"table('malloy-data.bad.table')"}
|
|
2088
2088
|
`;
|
|
2089
2089
|
const m = new BetaModel(source.code);
|
|
2090
2090
|
const result = m.translate();
|
|
2091
2091
|
m.update({
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
}
|
|
2092
|
+
errors: {
|
|
2093
|
+
tables: { [(result.tables || [])[0]]: 'Bad table!' },
|
|
2094
|
+
},
|
|
2095
2095
|
});
|
|
2096
2096
|
expect(m).not.modelParsed();
|
|
2097
2097
|
const errList = m.errors().errors;
|
|
@@ -2099,8 +2099,8 @@ describe("translation need error locations", () => {
|
|
|
2099
2099
|
return undefined;
|
|
2100
2100
|
});
|
|
2101
2101
|
});
|
|
2102
|
-
describe(
|
|
2103
|
-
test(
|
|
2102
|
+
describe('pipeline comprehension', () => {
|
|
2103
|
+
test('second query gets namespace from first', modelOK(`
|
|
2104
2104
|
explore: aq is a {
|
|
2105
2105
|
query: t1 is {
|
|
2106
2106
|
group_by: t1int is ai, t1str is astr
|
|
@@ -2114,11 +2114,11 @@ describe("pipeline comprehension", () => {
|
|
|
2114
2114
|
query: t1 is {
|
|
2115
2115
|
group_by: t1int is ai, t1str is astr
|
|
2116
2116
|
} -> {
|
|
2117
|
-
project: ${
|
|
2117
|
+
project: ${'ai'}
|
|
2118
2118
|
}
|
|
2119
2119
|
}
|
|
2120
2120
|
`, "'ai' is not defined"));
|
|
2121
|
-
test(
|
|
2121
|
+
test('new query can append ops to existing query', modelOK(`
|
|
2122
2122
|
explore: aq is a {
|
|
2123
2123
|
query: t0 is {
|
|
2124
2124
|
group_by: t1int is ai, t1str is astr
|
|
@@ -2128,7 +2128,7 @@ describe("pipeline comprehension", () => {
|
|
|
2128
2128
|
}
|
|
2129
2129
|
}
|
|
2130
2130
|
`));
|
|
2131
|
-
test(
|
|
2131
|
+
test('new query can refine and append to exisiting query', modelOK(`
|
|
2132
2132
|
explore: aq is table('aTable') {
|
|
2133
2133
|
query: by_region is { group_by: astr }
|
|
2134
2134
|
query: by_region2 is by_region {
|
|
@@ -2138,20 +2138,20 @@ describe("pipeline comprehension", () => {
|
|
|
2138
2138
|
}
|
|
2139
2139
|
}
|
|
2140
2140
|
`));
|
|
2141
|
-
test(
|
|
2141
|
+
test('reference to a query can include a refinement', modelOK(`
|
|
2142
2142
|
query: ab -> {
|
|
2143
2143
|
group_by: ai
|
|
2144
2144
|
nest: aturtle { limit: 1 }
|
|
2145
2145
|
}
|
|
2146
2146
|
`));
|
|
2147
|
-
test(
|
|
2147
|
+
test('Querying an explore based on a query', modelOK(`
|
|
2148
2148
|
query: q is a -> { group_by: astr; aggregate: strsum is ai.sum() }
|
|
2149
2149
|
explore: aq is a {
|
|
2150
2150
|
join_one: aq is from(->q) on astr = aq.astr
|
|
2151
2151
|
}
|
|
2152
2152
|
query: aqf is aq -> { project: * }
|
|
2153
2153
|
`));
|
|
2154
|
-
test(
|
|
2154
|
+
test('new query appends to existing query', () => {
|
|
2155
2155
|
const src = `
|
|
2156
2156
|
query: s1 is table('malloytest.flights') -> {
|
|
2157
2157
|
group_by: origin, destination
|
|
@@ -2162,13 +2162,13 @@ describe("pipeline comprehension", () => {
|
|
|
2162
2162
|
`;
|
|
2163
2163
|
const m = new BetaModel(src);
|
|
2164
2164
|
expect(m).modelCompiled();
|
|
2165
|
-
const s2 = m.getQuery(
|
|
2165
|
+
const s2 = m.getQuery('s2');
|
|
2166
2166
|
expect(s2 === null || s2 === void 0 ? void 0 : s2.pipeline.length).toBe(2);
|
|
2167
2167
|
});
|
|
2168
2168
|
});
|
|
2169
|
-
describe(
|
|
2170
|
-
test(
|
|
2171
|
-
expect(
|
|
2169
|
+
describe('standard sql function return types', () => {
|
|
2170
|
+
test('timestamp_seconds', () => {
|
|
2171
|
+
expect('timestamp_seconds(0)').toReturnType('timestamp');
|
|
2172
2172
|
});
|
|
2173
2173
|
});
|
|
2174
2174
|
//# sourceMappingURL=parse.spec.js.map
|