@malloydata/malloy 0.0.22-dev230207144036 → 0.0.22-dev230207180844
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.d.ts +1 -0
- package/dist/connection_utils.js +66 -0
- package/dist/dialect/dialect.d.ts +66 -0
- package/dist/dialect/dialect.js +85 -0
- package/dist/dialect/dialect_map.d.ts +3 -0
- package/dist/dialect/dialect_map.js +45 -0
- package/dist/dialect/duckdb.d.ts +52 -0
- package/dist/dialect/duckdb.js +364 -0
- package/dist/dialect/index.d.ts +6 -0
- package/dist/dialect/index.js +37 -0
- package/dist/dialect/postgres.d.ts +52 -0
- package/dist/dialect/postgres.js +330 -0
- package/dist/dialect/standardsql.d.ts +49 -0
- package/dist/dialect/standardsql.js +381 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +59 -0
- package/dist/lang/ast/ast-utils.d.ts +10 -0
- package/dist/lang/ast/ast-utils.js +42 -0
- package/dist/lang/ast/elements/define-query.d.ts +14 -0
- package/dist/lang/ast/elements/define-query.js +56 -0
- package/dist/lang/ast/elements/define-source.d.ts +17 -0
- package/dist/lang/ast/elements/define-source.js +79 -0
- package/dist/lang/ast/elements/import-statement.d.ts +9 -0
- package/dist/lang/ast/elements/import-statement.js +78 -0
- package/dist/lang/ast/elements/pipeline-desc.d.ts +30 -0
- package/dist/lang/ast/elements/pipeline-desc.js +102 -0
- package/dist/lang/ast/elements/refined-source.d.ts +15 -0
- package/dist/lang/ast/elements/refined-source.js +121 -0
- package/dist/lang/ast/elements/source.d.ts +12 -0
- package/dist/lang/ast/elements/source.js +53 -0
- package/dist/lang/ast/error-factory.d.ts +9 -0
- package/dist/lang/ast/error-factory.js +61 -0
- package/dist/lang/ast/executors/index-executor.d.ts +18 -0
- package/dist/lang/ast/executors/index-executor.js +96 -0
- package/dist/lang/ast/executors/project-executor.d.ts +10 -0
- package/dist/lang/ast/executors/project-executor.js +68 -0
- package/dist/lang/ast/executors/reduce-executor.d.ts +21 -0
- package/dist/lang/ast/executors/reduce-executor.js +149 -0
- package/dist/lang/ast/expressions/apply.d.ts +8 -0
- package/dist/lang/ast/expressions/apply.js +37 -0
- package/dist/lang/ast/expressions/binary-boolean.d.ts +12 -0
- package/dist/lang/ast/expressions/binary-boolean.js +54 -0
- package/dist/lang/ast/expressions/binary-numeric.d.ts +11 -0
- package/dist/lang/ast/expressions/binary-numeric.js +42 -0
- package/dist/lang/ast/expressions/boolean.d.ts +8 -0
- package/dist/lang/ast/expressions/boolean.js +39 -0
- package/dist/lang/ast/expressions/constant-sub-expression.d.ts +16 -0
- package/dist/lang/ast/expressions/constant-sub-expression.js +98 -0
- package/dist/lang/ast/expressions/expr-add-sub.d.ts +4 -0
- package/dist/lang/ast/expressions/expr-add-sub.js +34 -0
- package/dist/lang/ast/expressions/expr-aggregate-function.d.ts +15 -0
- package/dist/lang/ast/expressions/expr-aggregate-function.js +99 -0
- package/dist/lang/ast/expressions/expr-alternation-tree.d.ts +11 -0
- package/dist/lang/ast/expressions/expr-alternation-tree.js +54 -0
- package/dist/lang/ast/expressions/expr-asymmetric.d.ts +10 -0
- package/dist/lang/ast/expressions/expr-asymmetric.js +27 -0
- package/dist/lang/ast/expressions/expr-avg.d.ts +6 -0
- package/dist/lang/ast/expressions/expr-avg.js +34 -0
- package/dist/lang/ast/expressions/expr-cast.d.ts +13 -0
- package/dist/lang/ast/expressions/expr-cast.js +29 -0
- package/dist/lang/ast/expressions/expr-compare.d.ts +10 -0
- package/dist/lang/ast/expressions/expr-compare.js +58 -0
- package/dist/lang/ast/expressions/expr-count-distinct.d.ts +6 -0
- package/dist/lang/ast/expressions/expr-count-distinct.js +35 -0
- package/dist/lang/ast/expressions/expr-count.d.ts +11 -0
- package/dist/lang/ast/expressions/expr-count.js +57 -0
- package/dist/lang/ast/expressions/expr-filter.d.ts +12 -0
- package/dist/lang/ast/expressions/expr-filter.js +69 -0
- package/dist/lang/ast/expressions/expr-func.d.ts +10 -0
- package/dist/lang/ast/expressions/expr-func.js +63 -0
- package/dist/lang/ast/expressions/expr-granular-time.d.ts +24 -0
- package/dist/lang/ast/expressions/expr-granular-time.js +117 -0
- package/dist/lang/ast/expressions/expr-id-reference.d.ts +12 -0
- package/dist/lang/ast/expressions/expr-id-reference.js +75 -0
- package/dist/lang/ast/expressions/expr-logical-op.d.ts +9 -0
- package/dist/lang/ast/expressions/expr-logical-op.js +36 -0
- package/dist/lang/ast/expressions/expr-max.d.ts +9 -0
- package/dist/lang/ast/expressions/expr-max.js +16 -0
- package/dist/lang/ast/expressions/expr-min.d.ts +9 -0
- package/dist/lang/ast/expressions/expr-min.js +16 -0
- package/dist/lang/ast/expressions/expr-minus.d.ts +9 -0
- package/dist/lang/ast/expressions/expr-minus.js +48 -0
- package/dist/lang/ast/expressions/expr-mul-div.d.ts +4 -0
- package/dist/lang/ast/expressions/expr-mul-div.js +34 -0
- package/dist/lang/ast/expressions/expr-not.d.ts +10 -0
- package/dist/lang/ast/expressions/expr-not.js +49 -0
- package/dist/lang/ast/expressions/expr-now.d.ts +7 -0
- package/dist/lang/ast/expressions/expr-now.js +46 -0
- package/dist/lang/ast/expressions/expr-null.d.ts +6 -0
- package/dist/lang/ast/expressions/expr-null.js +41 -0
- package/dist/lang/ast/expressions/expr-number.d.ts +10 -0
- package/dist/lang/ast/expressions/expr-number.js +42 -0
- package/dist/lang/ast/expressions/expr-parens.d.ts +10 -0
- package/dist/lang/ast/expressions/expr-parens.js +42 -0
- package/dist/lang/ast/expressions/expr-regex.d.ts +8 -0
- package/dist/lang/ast/expressions/expr-regex.js +42 -0
- package/dist/lang/ast/expressions/expr-string.d.ts +9 -0
- package/dist/lang/ast/expressions/expr-string.js +50 -0
- package/dist/lang/ast/expressions/expr-sum.d.ts +6 -0
- package/dist/lang/ast/expressions/expr-sum.js +12 -0
- package/dist/lang/ast/expressions/expr-time-extract.d.ts +13 -0
- package/dist/lang/ast/expressions/expr-time-extract.js +117 -0
- package/dist/lang/ast/expressions/expr-time.d.ts +11 -0
- package/dist/lang/ast/expressions/expr-time.js +62 -0
- package/dist/lang/ast/expressions/expr-ungroup.d.ts +14 -0
- package/dist/lang/ast/expressions/expr-ungroup.js +83 -0
- package/dist/lang/ast/expressions/for-range.d.ts +19 -0
- package/dist/lang/ast/expressions/for-range.js +101 -0
- package/dist/lang/ast/expressions/granular-literal.d.ts +20 -0
- package/dist/lang/ast/expressions/granular-literal.js +148 -0
- package/dist/lang/ast/expressions/partial-compare.d.ts +14 -0
- package/dist/lang/ast/expressions/partial-compare.js +50 -0
- package/dist/lang/ast/expressions/pick-when.d.ts +19 -0
- package/dist/lang/ast/expressions/pick-when.js +156 -0
- package/dist/lang/ast/expressions/range.d.ts +12 -0
- package/dist/lang/ast/expressions/range.js +80 -0
- package/dist/lang/ast/expressions/time-frame.d.ts +7 -0
- package/dist/lang/ast/expressions/time-frame.js +40 -0
- package/dist/lang/ast/expressions/top-by.d.ts +10 -0
- package/dist/lang/ast/expressions/top-by.js +51 -0
- package/dist/lang/ast/expressions/unary.d.ts +5 -0
- package/dist/lang/ast/expressions/unary.js +34 -0
- package/dist/lang/ast/expressions/utils.d.ts +12 -0
- package/dist/lang/ast/expressions/utils.js +87 -0
- package/dist/lang/ast/field-space/column-space-field.d.ts +9 -0
- package/dist/lang/ast/field-space/column-space-field.js +40 -0
- package/dist/lang/ast/field-space/dynamic-space.d.ts +22 -0
- package/dist/lang/ast/field-space/dynamic-space.js +140 -0
- package/dist/lang/ast/field-space/field-definition-value.d.ts +16 -0
- package/dist/lang/ast/field-space/field-definition-value.js +55 -0
- package/dist/lang/ast/field-space/index-field-space.d.ts +10 -0
- package/dist/lang/ast/field-space/index-field-space.js +57 -0
- package/dist/lang/ast/field-space/join-space-field.d.ts +8 -0
- package/dist/lang/ast/field-space/join-space-field.js +35 -0
- package/dist/lang/ast/field-space/project-field-space.d.ts +6 -0
- package/dist/lang/ast/field-space/project-field-space.js +51 -0
- package/dist/lang/ast/field-space/query-field-struct.d.ts +10 -0
- package/dist/lang/ast/field-space/query-field-struct.js +46 -0
- package/dist/lang/ast/field-space/query-space-field.d.ts +11 -0
- package/dist/lang/ast/field-space/query-space-field.js +37 -0
- package/dist/lang/ast/field-space/query-spaces.d.ts +50 -0
- package/dist/lang/ast/field-space/query-spaces.js +233 -0
- package/dist/lang/ast/field-space/reference-field.d.ts +11 -0
- package/dist/lang/ast/field-space/reference-field.js +45 -0
- package/dist/lang/ast/field-space/refined-space.d.ts +13 -0
- package/dist/lang/ast/field-space/refined-space.js +100 -0
- package/dist/lang/ast/field-space/rename-space-field.d.ts +11 -0
- package/dist/lang/ast/field-space/rename-space-field.js +50 -0
- package/dist/lang/ast/field-space/static-space.d.ts +29 -0
- package/dist/lang/ast/field-space/static-space.js +156 -0
- package/dist/lang/ast/field-space/struct-space-field-base.d.ts +11 -0
- package/dist/lang/ast/field-space/struct-space-field-base.js +40 -0
- package/dist/lang/ast/field-space/wild-space-field.d.ts +10 -0
- package/dist/lang/ast/field-space/wild-space-field.js +40 -0
- package/dist/lang/ast/fragtype-utils.d.ts +39 -0
- package/dist/lang/ast/fragtype-utils.js +100 -0
- package/dist/lang/ast/index.d.ts +90 -0
- package/dist/lang/ast/index.js +129 -0
- package/dist/lang/ast/parameters/constant-parameter.d.ts +8 -0
- package/dist/lang/ast/parameters/constant-parameter.js +54 -0
- package/dist/lang/ast/parameters/has-parameter.d.ts +19 -0
- package/dist/lang/ast/parameters/has-parameter.js +64 -0
- package/dist/lang/ast/query-elements/anonymous-query.d.ts +9 -0
- package/dist/lang/ast/query-elements/anonymous-query.js +41 -0
- package/dist/lang/ast/query-elements/existing-query.d.ts +11 -0
- package/dist/lang/ast/query-elements/existing-query.js +79 -0
- package/dist/lang/ast/query-elements/full-query.d.ts +10 -0
- package/dist/lang/ast/query-elements/full-query.js +85 -0
- package/dist/lang/ast/query-elements/query-head-struct.d.ts +9 -0
- package/dist/lang/ast/query-elements/query-head-struct.js +48 -0
- package/dist/lang/ast/query-items/field-declaration.d.ts +31 -0
- package/dist/lang/ast/query-items/field-declaration.js +137 -0
- package/dist/lang/ast/query-items/field-references.d.ts +25 -0
- package/dist/lang/ast/query-items/field-references.js +80 -0
- package/dist/lang/ast/query-properties/aggregate.d.ts +5 -0
- package/dist/lang/ast/query-properties/aggregate.js +39 -0
- package/dist/lang/ast/query-properties/declare-fields.d.ts +5 -0
- package/dist/lang/ast/query-properties/declare-fields.js +33 -0
- package/dist/lang/ast/query-properties/dimmensions.d.ts +5 -0
- package/dist/lang/ast/query-properties/dimmensions.js +36 -0
- package/dist/lang/ast/query-properties/filters.d.ts +18 -0
- package/dist/lang/ast/query-properties/filters.js +89 -0
- package/dist/lang/ast/query-properties/group-by.d.ts +5 -0
- package/dist/lang/ast/query-properties/group-by.js +39 -0
- package/dist/lang/ast/query-properties/indexing.d.ts +10 -0
- package/dist/lang/ast/query-properties/indexing.js +39 -0
- package/dist/lang/ast/query-properties/joins.d.ts +36 -0
- package/dist/lang/ast/query-properties/joins.js +143 -0
- package/dist/lang/ast/query-properties/limit.d.ts +6 -0
- package/dist/lang/ast/query-properties/limit.js +35 -0
- package/dist/lang/ast/query-properties/measures.d.ts +5 -0
- package/dist/lang/ast/query-properties/measures.js +36 -0
- package/dist/lang/ast/query-properties/nest-reference.d.ts +7 -0
- package/dist/lang/ast/query-properties/nest-reference.js +35 -0
- package/dist/lang/ast/query-properties/nest.d.ts +31 -0
- package/dist/lang/ast/query-properties/nest.js +133 -0
- package/dist/lang/ast/query-properties/nests.d.ts +5 -0
- package/dist/lang/ast/query-properties/nests.js +33 -0
- package/dist/lang/ast/query-properties/ordering.d.ts +15 -0
- package/dist/lang/ast/query-properties/ordering.js +66 -0
- package/dist/lang/ast/query-properties/project-statement.d.ts +5 -0
- package/dist/lang/ast/query-properties/project-statement.js +33 -0
- package/dist/lang/ast/query-properties/qop-desc.d.ts +17 -0
- package/dist/lang/ast/query-properties/qop-desc.js +124 -0
- package/dist/lang/ast/query-properties/sampling.d.ts +8 -0
- package/dist/lang/ast/query-properties/sampling.js +38 -0
- package/dist/lang/ast/query-properties/top.d.ts +13 -0
- package/dist/lang/ast/query-properties/top.js +60 -0
- package/dist/lang/ast/source-properties/field-list-edit.d.ts +8 -0
- package/dist/lang/ast/source-properties/field-list-edit.js +36 -0
- package/dist/lang/ast/source-properties/primary-key.d.ts +7 -0
- package/dist/lang/ast/source-properties/primary-key.js +35 -0
- package/dist/lang/ast/source-properties/renames.d.ts +11 -0
- package/dist/lang/ast/source-properties/renames.js +43 -0
- package/dist/lang/ast/source-properties/turtles.d.ts +5 -0
- package/dist/lang/ast/source-properties/turtles.js +33 -0
- package/dist/lang/ast/sources/named-source.d.ts +19 -0
- package/dist/lang/ast/sources/named-source.js +147 -0
- package/dist/lang/ast/sources/query-source.d.ts +9 -0
- package/dist/lang/ast/sources/query-source.js +41 -0
- package/dist/lang/ast/sources/sql-source.d.ts +7 -0
- package/dist/lang/ast/sources/sql-source.js +54 -0
- package/dist/lang/ast/sources/table-source.d.ts +8 -0
- package/dist/lang/ast/sources/table-source.js +60 -0
- package/dist/lang/ast/space-seed.d.ts +16 -0
- package/dist/lang/ast/space-seed.js +59 -0
- package/dist/lang/ast/sql-elements/sql-statement.d.ts +19 -0
- package/dist/lang/ast/sql-elements/sql-statement.js +80 -0
- package/dist/lang/ast/sql-elements/sql-string.d.ts +12 -0
- package/dist/lang/ast/sql-elements/sql-string.js +60 -0
- package/dist/lang/ast/struct-utils.d.ts +4 -0
- package/dist/lang/ast/struct-utils.js +48 -0
- package/dist/lang/ast/time-utils.d.ts +12 -0
- package/dist/lang/ast/time-utils.js +140 -0
- package/dist/lang/ast/types/comparison.d.ts +11 -0
- package/dist/lang/ast/types/comparison.js +41 -0
- package/dist/lang/ast/types/document-compile-result.d.ts +8 -0
- package/dist/lang/ast/types/document-compile-result.js +25 -0
- package/dist/lang/ast/types/equality.d.ts +7 -0
- package/dist/lang/ast/types/equality.js +37 -0
- package/dist/lang/ast/types/executor.d.ts +9 -0
- package/dist/lang/ast/types/executor.js +25 -0
- package/dist/lang/ast/types/explore-desc.d.ts +5 -0
- package/dist/lang/ast/types/explore-desc.js +33 -0
- package/dist/lang/ast/types/explore-field.d.ts +5 -0
- package/dist/lang/ast/types/explore-field.js +32 -0
- package/dist/lang/ast/types/expr-result.d.ts +5 -0
- package/dist/lang/ast/types/expr-result.js +25 -0
- package/dist/lang/ast/types/expr-value.d.ts +3 -0
- package/dist/lang/ast/types/expr-value.js +25 -0
- package/dist/lang/ast/types/expression-def.d.ts +69 -0
- package/dist/lang/ast/types/expression-def.js +346 -0
- package/dist/lang/ast/types/field-collection-member.d.ts +5 -0
- package/dist/lang/ast/types/field-collection-member.js +34 -0
- package/dist/lang/ast/types/field-decl.d.ts +7 -0
- package/dist/lang/ast/types/field-decl.js +37 -0
- package/dist/lang/ast/types/field-space.d.ts +24 -0
- package/dist/lang/ast/types/field-space.js +44 -0
- package/dist/lang/ast/types/granular-result.d.ts +7 -0
- package/dist/lang/ast/types/granular-result.js +11 -0
- package/dist/lang/ast/types/lookup-result.d.ts +10 -0
- package/dist/lang/ast/types/lookup-result.js +25 -0
- package/dist/lang/ast/types/malloy-element.d.ts +106 -0
- package/dist/lang/ast/types/malloy-element.js +398 -0
- package/dist/lang/ast/types/model-entry.d.ts +6 -0
- package/dist/lang/ast/types/model-entry.js +25 -0
- package/dist/lang/ast/types/name-space.d.ts +5 -0
- package/dist/lang/ast/types/name-space.js +25 -0
- package/dist/lang/ast/types/nested-query.d.ts +3 -0
- package/dist/lang/ast/types/nested-query.js +25 -0
- package/dist/lang/ast/types/op-desc.d.ts +6 -0
- package/dist/lang/ast/types/op-desc.js +25 -0
- package/dist/lang/ast/types/query-comp.d.ts +5 -0
- package/dist/lang/ast/types/query-comp.js +25 -0
- package/dist/lang/ast/types/query-element.d.ts +5 -0
- package/dist/lang/ast/types/query-element.js +32 -0
- package/dist/lang/ast/types/query-item.d.ts +5 -0
- package/dist/lang/ast/types/query-item.js +25 -0
- package/dist/lang/ast/types/query-property.d.ts +17 -0
- package/dist/lang/ast/types/query-property.js +55 -0
- package/dist/lang/ast/types/source-property.d.ts +10 -0
- package/dist/lang/ast/types/source-property.js +43 -0
- package/dist/lang/ast/types/space-entry.d.ts +5 -0
- package/dist/lang/ast/types/space-entry.js +29 -0
- package/dist/lang/ast/types/space-field.d.ts +10 -0
- package/dist/lang/ast/types/space-field.js +48 -0
- package/dist/lang/ast/types/space-param.d.ts +20 -0
- package/dist/lang/ast/types/space-param.js +61 -0
- package/dist/lang/ast/types/time-result.d.ts +6 -0
- package/dist/lang/ast/types/time-result.js +25 -0
- package/dist/lang/ast/types/turtle-headed-pipe.d.ts +7 -0
- package/dist/lang/ast/types/turtle-headed-pipe.js +37 -0
- package/dist/lang/ast/types/type-desc.d.ts +7 -0
- package/dist/lang/ast/types/type-desc.js +25 -0
- package/dist/lang/field-utils.d.ts +5 -0
- package/dist/lang/field-utils.js +43 -0
- package/dist/lang/index.d.ts +10 -0
- package/dist/lang/index.js +32 -0
- package/dist/lang/lib/Malloy/MalloyLexer.d.ts +165 -0
- package/dist/lang/lib/Malloy/MalloyLexer.js +1232 -0
- package/dist/lang/lib/Malloy/MalloyParser.d.ts +1947 -0
- package/dist/lang/lib/Malloy/MalloyParser.js +11909 -0
- package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +2022 -0
- package/dist/lang/lib/Malloy/MalloyParserListener.js +4 -0
- package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +1274 -0
- package/dist/lang/lib/Malloy/MalloyParserVisitor.js +4 -0
- package/dist/lang/malloy-to-ast.d.ts +155 -0
- package/dist/lang/malloy-to-ast.js +990 -0
- package/dist/lang/parse-error-handler.d.ts +9 -0
- package/dist/lang/parse-error-handler.js +44 -0
- package/dist/lang/parse-log.d.ts +27 -0
- package/dist/lang/parse-log.js +51 -0
- package/dist/lang/parse-malloy.d.ts +182 -0
- package/dist/lang/parse-malloy.js +728 -0
- package/dist/lang/parse-tree-walkers/document-completion-walker.d.ts +10 -0
- package/dist/lang/parse-tree-walkers/document-completion-walker.js +148 -0
- package/dist/lang/parse-tree-walkers/document-help-context-walker.d.ts +9 -0
- package/dist/lang/parse-tree-walkers/document-help-context-walker.js +107 -0
- package/dist/lang/parse-tree-walkers/document-highlight-walker.d.ts +83 -0
- package/dist/lang/parse-tree-walkers/document-highlight-walker.js +385 -0
- package/dist/lang/parse-tree-walkers/document-symbol-walker.d.ts +11 -0
- package/dist/lang/parse-tree-walkers/document-symbol-walker.js +182 -0
- package/dist/lang/parse-tree-walkers/explore-query-walker.d.ts +34 -0
- package/dist/lang/parse-tree-walkers/explore-query-walker.js +74 -0
- package/dist/lang/parse-tree-walkers/find-external-references.d.ts +11 -0
- package/dist/lang/parse-tree-walkers/find-external-references.js +61 -0
- package/dist/lang/reference-list.d.ts +10 -0
- package/dist/lang/reference-list.js +90 -0
- package/dist/lang/test/document-help-context-walker.spec.d.ts +1 -0
- package/dist/lang/test/document-help-context-walker.spec.js +55 -0
- package/dist/lang/test/document-symbol-walker.spec.d.ts +1 -0
- package/dist/lang/test/document-symbol-walker.spec.js +110 -0
- package/dist/lang/test/field-symbols.spec.d.ts +1 -0
- package/dist/lang/test/field-symbols.spec.js +184 -0
- package/dist/lang/test/parse.spec.d.ts +14 -0
- package/dist/lang/test/parse.spec.js +2135 -0
- package/dist/lang/test/test-translator.d.ts +41 -0
- package/dist/lang/test/test-translator.js +344 -0
- package/dist/lang/translate-response.d.ts +59 -0
- package/dist/lang/translate-response.js +30 -0
- package/dist/lang/zone.d.ts +57 -0
- package/dist/lang/zone.js +107 -0
- package/dist/malloy.d.ts +1146 -0
- package/dist/malloy.js +2413 -0
- package/dist/model/index.d.ts +2 -0
- package/dist/model/index.js +45 -0
- package/dist/model/malloy_query.d.ts +351 -0
- package/dist/model/malloy_query.js +3174 -0
- package/dist/model/malloy_types.d.ts +551 -0
- package/dist/model/malloy_types.js +378 -0
- package/dist/model/sql_block.d.ts +7 -0
- package/dist/model/sql_block.js +56 -0
- package/dist/model/utils.d.ts +22 -0
- package/dist/model/utils.js +102 -0
- package/dist/run_sql_options.d.ts +3 -0
- package/dist/run_sql_options.js +25 -0
- package/dist/runtime_types.d.ts +105 -0
- package/dist/runtime_types.js +25 -0
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function toAsyncGenerator<T>(startStreaming: (onError: (error: Error) => void, onData: (data: T) => void, onEnd: () => void) => void): AsyncIterableIterator<T>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2023 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
* a copy of this software and associated documentation files
|
|
7
|
+
* (the "Software"), to deal in the Software without restriction,
|
|
8
|
+
* including without limitation the rights to use, copy, modify, merge,
|
|
9
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
10
|
+
* and to permit persons to whom the Software is furnished to do so,
|
|
11
|
+
* subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be
|
|
14
|
+
* included in all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.toAsyncGenerator = void 0;
|
|
26
|
+
async function* toAsyncGenerator(startStreaming) {
|
|
27
|
+
let done = false;
|
|
28
|
+
function getResults(startStreaming) {
|
|
29
|
+
let resolve;
|
|
30
|
+
const promise = new Promise((res) => {
|
|
31
|
+
resolve = res;
|
|
32
|
+
});
|
|
33
|
+
startStreaming((error) => {
|
|
34
|
+
resolve({ done: true, isError: true, error });
|
|
35
|
+
}, (data) => {
|
|
36
|
+
resolve({
|
|
37
|
+
done: false,
|
|
38
|
+
value: data,
|
|
39
|
+
isError: false,
|
|
40
|
+
next: new Promise((res) => {
|
|
41
|
+
resolve = res;
|
|
42
|
+
}),
|
|
43
|
+
});
|
|
44
|
+
}, () => {
|
|
45
|
+
resolve({ done: true, isError: false });
|
|
46
|
+
});
|
|
47
|
+
return promise;
|
|
48
|
+
}
|
|
49
|
+
let next = getResults(startStreaming);
|
|
50
|
+
while (!done) {
|
|
51
|
+
const result = await next;
|
|
52
|
+
if (result.done) {
|
|
53
|
+
done = true;
|
|
54
|
+
if (result.isError) {
|
|
55
|
+
throw result.error;
|
|
56
|
+
}
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
next = result.next;
|
|
61
|
+
yield result.value;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.toAsyncGenerator = toAsyncGenerator;
|
|
66
|
+
//# sourceMappingURL=connection_utils.js.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { AtomicFieldType as AtomicFieldTypeInner, TimeFieldType, TimestampUnit, ExtractUnit, DialectFragment, TimeValue, Expr, Sampling, StructDef, TypecastFragment } from "../model/malloy_types";
|
|
2
|
+
interface DialectField {
|
|
3
|
+
type: string;
|
|
4
|
+
sqlExpression: string;
|
|
5
|
+
sqlOutputName: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Someday this might be used to control how a function call in malloy is
|
|
9
|
+
* translated into a function call in SQL. Today this is just so that
|
|
10
|
+
* the expression compiler can know the output type of a function.
|
|
11
|
+
*/
|
|
12
|
+
export interface FunctionInfo {
|
|
13
|
+
returnType: AtomicFieldTypeInner;
|
|
14
|
+
}
|
|
15
|
+
export declare type DialectFieldList = DialectField[];
|
|
16
|
+
export declare abstract class Dialect {
|
|
17
|
+
abstract name: string;
|
|
18
|
+
abstract defaultNumberType: string;
|
|
19
|
+
abstract udfPrefix: string;
|
|
20
|
+
abstract hasFinalStage: boolean;
|
|
21
|
+
abstract stringTypeName: string;
|
|
22
|
+
abstract divisionIsInteger: boolean;
|
|
23
|
+
abstract supportsSumDistinctFunction: boolean;
|
|
24
|
+
abstract unnestWithNumbers: boolean;
|
|
25
|
+
protected abstract functionInfo: Record<string, FunctionInfo>;
|
|
26
|
+
abstract defaultSampling: Sampling;
|
|
27
|
+
abstract supportUnnestArrayAgg: boolean;
|
|
28
|
+
abstract supportsCTEinCoorelatedSubQueries: boolean;
|
|
29
|
+
abstract dontUnionIndex: boolean;
|
|
30
|
+
abstract supportsQualify: boolean;
|
|
31
|
+
abstract quoteTablePath(tablePath: string): string;
|
|
32
|
+
abstract sqlGroupSetTable(groupSetCount: number): string;
|
|
33
|
+
abstract sqlAnyValue(groupSet: number, fieldName: string): string;
|
|
34
|
+
abstract sqlAggregateTurtle(groupSet: number, fieldList: DialectFieldList, orderBy: string | undefined, limit: number | undefined): string;
|
|
35
|
+
abstract sqlAnyValueTurtle(groupSet: number, fieldList: DialectFieldList): string;
|
|
36
|
+
abstract sqlAnyValueLastTurtle(name: string, groupSet: number, sqlName: string): string;
|
|
37
|
+
abstract sqlCoaleseMeasuresInline(groupSet: number, fieldList: DialectFieldList): string;
|
|
38
|
+
abstract sqlUnnestAlias(source: string, alias: string, fieldList: DialectFieldList, needDistinctKey: boolean, isArray: boolean): string;
|
|
39
|
+
abstract sqlSumDistinctHashedKey(sqlDistinctKey: string): string;
|
|
40
|
+
abstract sqlGenerateUUID(): string;
|
|
41
|
+
abstract sqlFieldReference(alias: string, fieldName: string, fieldType: string, isNested: boolean, isArray: boolean): string;
|
|
42
|
+
abstract sqlUnnestPipelineHead(isSingleton: boolean, sourceSQLExpression: string): string;
|
|
43
|
+
abstract sqlCreateFunction(id: string, funcText: string): string;
|
|
44
|
+
abstract sqlCreateFunctionCombineLastStage(lastStageName: string, structDef: StructDef): string;
|
|
45
|
+
abstract sqlCreateTableAsSelect(tableName: string, sql: string): string;
|
|
46
|
+
abstract sqlSelectAliasAsStruct(alias: string, physicalFieldNames: string[]): string;
|
|
47
|
+
sqlFinalStage(_lastStageName: string, _fields: string[]): string;
|
|
48
|
+
sqlDateToString(sqlDateExp: string): string;
|
|
49
|
+
abstract sqlMaybeQuoteIdentifier(identifier: string): string;
|
|
50
|
+
abstract sqlNow(): Expr;
|
|
51
|
+
abstract sqlTrunc(sqlTime: TimeValue, units: TimestampUnit): Expr;
|
|
52
|
+
abstract sqlExtract(sqlTime: TimeValue, units: ExtractUnit): Expr;
|
|
53
|
+
abstract sqlMeasureTime(from: TimeValue, to: TimeValue, units: TimestampUnit): Expr;
|
|
54
|
+
abstract sqlAlterTime(op: "+" | "-", expr: TimeValue, n: Expr, timeframe: TimestampUnit): Expr;
|
|
55
|
+
ignoreInProject(_fieldName: string): boolean;
|
|
56
|
+
abstract sqlCast(cast: TypecastFragment): Expr;
|
|
57
|
+
abstract sqlLiteralTime(timeString: string, type: TimeFieldType, timezone: string): string;
|
|
58
|
+
abstract sqlLiteralString(literak: string): string;
|
|
59
|
+
abstract sqlRegexpMatch(expr: Expr, regex: string): Expr;
|
|
60
|
+
getFunctionInfo(functionName: string): FunctionInfo | undefined;
|
|
61
|
+
dialectExpr(df: DialectFragment): Expr;
|
|
62
|
+
sqlSumDistinct(_key: string, _value: string): string;
|
|
63
|
+
sqlSampleTable(tableSQL: string, sample: Sampling | undefined): string;
|
|
64
|
+
sqlOrderBy(orderTerms: string[]): string;
|
|
65
|
+
}
|
|
66
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2023 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
* a copy of this software and associated documentation files
|
|
7
|
+
* (the "Software"), to deal in the Software without restriction,
|
|
8
|
+
* including without limitation the rights to use, copy, modify, merge,
|
|
9
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
10
|
+
* and to permit persons to whom the Software is furnished to do so,
|
|
11
|
+
* subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be
|
|
14
|
+
* included in all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.Dialect = void 0;
|
|
26
|
+
const malloy_types_1 = require("../model/malloy_types");
|
|
27
|
+
class Dialect {
|
|
28
|
+
sqlFinalStage(_lastStageName, _fields) {
|
|
29
|
+
throw new Error("Dialect has no final Stage but called Anyway");
|
|
30
|
+
}
|
|
31
|
+
// default implementation will probably work most of the time
|
|
32
|
+
sqlDateToString(sqlDateExp) {
|
|
33
|
+
return `CAST(DATE(${sqlDateExp}) AS ${this.stringTypeName} )`;
|
|
34
|
+
}
|
|
35
|
+
// BigQuery has some fieldNames that are Pseudo Fields and shouldn't be
|
|
36
|
+
// included in projections.
|
|
37
|
+
ignoreInProject(_fieldName) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
getFunctionInfo(functionName) {
|
|
41
|
+
return this.functionInfo[functionName.toLowerCase()];
|
|
42
|
+
}
|
|
43
|
+
dialectExpr(df) {
|
|
44
|
+
switch (df.function) {
|
|
45
|
+
case "now":
|
|
46
|
+
return this.sqlNow();
|
|
47
|
+
case "timeDiff":
|
|
48
|
+
return this.sqlMeasureTime(df.left, df.right, df.units);
|
|
49
|
+
case "delta":
|
|
50
|
+
return this.sqlAlterTime(df.op, df.base, df.delta, df.units);
|
|
51
|
+
case "trunc":
|
|
52
|
+
return this.sqlTrunc(df.expr, df.units);
|
|
53
|
+
case "extract":
|
|
54
|
+
return this.sqlExtract(df.expr, df.units);
|
|
55
|
+
case "cast":
|
|
56
|
+
return this.sqlCast(df);
|
|
57
|
+
case "regexpMatch":
|
|
58
|
+
return this.sqlRegexpMatch(df.expr, df.regexp);
|
|
59
|
+
case "div": {
|
|
60
|
+
if (this.divisionIsInteger) {
|
|
61
|
+
return (0, malloy_types_1.mkExpr) `${df.numerator}*1.0/${df.denominator}`;
|
|
62
|
+
}
|
|
63
|
+
return (0, malloy_types_1.mkExpr) `${df.numerator}/${df.denominator}`;
|
|
64
|
+
}
|
|
65
|
+
case "timeLiteral":
|
|
66
|
+
return [this.sqlLiteralTime(df.literal, df.literalType, df.timezone)];
|
|
67
|
+
case "stringLiteral":
|
|
68
|
+
return [this.sqlLiteralString(df.literal)];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
sqlSumDistinct(_key, _value) {
|
|
72
|
+
return "sqlSumDistinct called bu not implemented";
|
|
73
|
+
}
|
|
74
|
+
sqlSampleTable(tableSQL, sample) {
|
|
75
|
+
if (sample !== undefined) {
|
|
76
|
+
throw new Error(`Sampling is not supported on dialect ${this.name}.`);
|
|
77
|
+
}
|
|
78
|
+
return tableSQL;
|
|
79
|
+
}
|
|
80
|
+
sqlOrderBy(orderTerms) {
|
|
81
|
+
return `ORDER BY ${orderTerms.join(",")}`;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.Dialect = Dialect;
|
|
85
|
+
//# sourceMappingURL=dialect.js.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2023 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
* a copy of this software and associated documentation files
|
|
7
|
+
* (the "Software"), to deal in the Software without restriction,
|
|
8
|
+
* including without limitation the rights to use, copy, modify, merge,
|
|
9
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
10
|
+
* and to permit persons to whom the Software is furnished to do so,
|
|
11
|
+
* subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be
|
|
14
|
+
* included in all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.registerDialect = exports.getDialect = void 0;
|
|
26
|
+
const duckdb_1 = require("./duckdb");
|
|
27
|
+
const postgres_1 = require("./postgres");
|
|
28
|
+
const standardsql_1 = require("./standardsql");
|
|
29
|
+
const dialectMap = new Map();
|
|
30
|
+
function getDialect(name) {
|
|
31
|
+
const d = dialectMap.get(name);
|
|
32
|
+
if (d === undefined) {
|
|
33
|
+
throw new Error(`Unknown Dialect ${name}`);
|
|
34
|
+
}
|
|
35
|
+
return d;
|
|
36
|
+
}
|
|
37
|
+
exports.getDialect = getDialect;
|
|
38
|
+
function registerDialect(d) {
|
|
39
|
+
dialectMap.set(d.name, d);
|
|
40
|
+
}
|
|
41
|
+
exports.registerDialect = registerDialect;
|
|
42
|
+
registerDialect(new postgres_1.PostgresDialect());
|
|
43
|
+
registerDialect(new standardsql_1.StandardSQLDialect());
|
|
44
|
+
registerDialect(new duckdb_1.DuckDBDialect());
|
|
45
|
+
//# sourceMappingURL=dialect_map.js.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { DateUnit, Expr, ExtractUnit, Sampling, StructDef, TimeFieldType, TimestampUnit, TimeValue, TypecastFragment } from "../model/malloy_types";
|
|
2
|
+
import { Dialect, DialectFieldList, FunctionInfo } from "./dialect";
|
|
3
|
+
export declare class DuckDBDialect extends Dialect {
|
|
4
|
+
name: string;
|
|
5
|
+
defaultNumberType: string;
|
|
6
|
+
hasFinalStage: boolean;
|
|
7
|
+
stringTypeName: string;
|
|
8
|
+
divisionIsInteger: boolean;
|
|
9
|
+
supportsSumDistinctFunction: boolean;
|
|
10
|
+
unnestWithNumbers: boolean;
|
|
11
|
+
defaultSampling: {
|
|
12
|
+
rows: number;
|
|
13
|
+
};
|
|
14
|
+
supportUnnestArrayAgg: boolean;
|
|
15
|
+
supportsCTEinCoorelatedSubQueries: boolean;
|
|
16
|
+
dontUnionIndex: boolean;
|
|
17
|
+
supportsQualify: boolean;
|
|
18
|
+
functionInfo: Record<string, FunctionInfo>;
|
|
19
|
+
get udfPrefix(): string;
|
|
20
|
+
quoteTablePath(tableName: string): string;
|
|
21
|
+
sqlGroupSetTable(groupSetCount: number): string;
|
|
22
|
+
sqlAnyValue(groupSet: number, fieldName: string): string;
|
|
23
|
+
mapFields(fieldList: DialectFieldList): string;
|
|
24
|
+
sqlAggregateTurtle(groupSet: number, fieldList: DialectFieldList, orderBy: string | undefined, limit: number | undefined): string;
|
|
25
|
+
sqlAnyValueTurtle(groupSet: number, fieldList: DialectFieldList): string;
|
|
26
|
+
sqlAnyValueLastTurtle(name: string, groupSet: number, sqlName: string): string;
|
|
27
|
+
sqlCoaleseMeasuresInline(groupSet: number, fieldList: DialectFieldList): string;
|
|
28
|
+
sqlUnnestAlias(source: string, alias: string, _fieldList: DialectFieldList, _needDistinctKey: boolean): string;
|
|
29
|
+
sqlSumDistinctHashedKey(_sqlDistinctKey: string): string;
|
|
30
|
+
sqlGenerateUUID(): string;
|
|
31
|
+
sqlDateToString(sqlDateExp: string): string;
|
|
32
|
+
sqlFieldReference(alias: string, fieldName: string, _fieldType: string, _isNested: boolean, isArray: boolean): string;
|
|
33
|
+
sqlUnnestPipelineHead(isSingleton: boolean, sourceSQLExpression: string): string;
|
|
34
|
+
sqlCreateFunction(id: string, funcText: string): string;
|
|
35
|
+
sqlCreateFunctionCombineLastStage(lastStageName: string, structDef: StructDef): string;
|
|
36
|
+
sqlSelectAliasAsStruct(alias: string, physicalFieldNames: string[]): string;
|
|
37
|
+
sqlMaybeQuoteIdentifier(identifier: string): string;
|
|
38
|
+
sqlCreateTableAsSelect(_tableName: string, _sql: string): string;
|
|
39
|
+
getFunctionInfo(functionName: string): FunctionInfo | undefined;
|
|
40
|
+
sqlMeasureTime(from: TimeValue, to: TimeValue, units: string): Expr;
|
|
41
|
+
sqlNow(): Expr;
|
|
42
|
+
sqlTrunc(sqlTime: TimeValue, units: TimestampUnit): Expr;
|
|
43
|
+
sqlExtract(from: TimeValue, units: ExtractUnit): Expr;
|
|
44
|
+
sqlAlterTime(op: "+" | "-", expr: TimeValue, n: Expr, timeframe: DateUnit): Expr;
|
|
45
|
+
sqlCast(cast: TypecastFragment): Expr;
|
|
46
|
+
sqlRegexpMatch(expr: Expr, regexp: string): Expr;
|
|
47
|
+
sqlLiteralTime(timeString: string, type: TimeFieldType, _timezone: string): string;
|
|
48
|
+
sqlSumDistinct(key: string, value: string): string;
|
|
49
|
+
sqlSampleTable(tableSQL: string, sample: Sampling | undefined): string;
|
|
50
|
+
sqlOrderBy(orderTerms: string[]): string;
|
|
51
|
+
sqlLiteralString(literal: string): string;
|
|
52
|
+
}
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2023 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
* a copy of this software and associated documentation files
|
|
7
|
+
* (the "Software"), to deal in the Software without restriction,
|
|
8
|
+
* including without limitation the rights to use, copy, modify, merge,
|
|
9
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
10
|
+
* and to permit persons to whom the Software is furnished to do so,
|
|
11
|
+
* subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be
|
|
14
|
+
* included in all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.DuckDBDialect = void 0;
|
|
26
|
+
const malloy_types_1 = require("../model/malloy_types");
|
|
27
|
+
const utils_1 = require("../model/utils");
|
|
28
|
+
const dialect_1 = require("./dialect");
|
|
29
|
+
// need to refactor runSQL to take a SQLBlock instead of just a sql string.
|
|
30
|
+
const hackSplitComment = "-- hack: split on this";
|
|
31
|
+
const keywords = `
|
|
32
|
+
ALL
|
|
33
|
+
ANALYSE
|
|
34
|
+
ANALYZE
|
|
35
|
+
AND
|
|
36
|
+
ANY
|
|
37
|
+
ARRAY
|
|
38
|
+
AS
|
|
39
|
+
ASC_P
|
|
40
|
+
ASYMMETRIC
|
|
41
|
+
BOTH
|
|
42
|
+
CASE
|
|
43
|
+
CAST
|
|
44
|
+
CHECK_P
|
|
45
|
+
COLLATE
|
|
46
|
+
COLUMN
|
|
47
|
+
CONSTRAINT
|
|
48
|
+
CREATE_P
|
|
49
|
+
CURRENT_CATALOG
|
|
50
|
+
CURRENT_DATE
|
|
51
|
+
CURRENT_ROLE
|
|
52
|
+
CURRENT_TIME
|
|
53
|
+
CURRENT_TIMESTAMP
|
|
54
|
+
CURRENT_USER
|
|
55
|
+
DEFAULT
|
|
56
|
+
DEFERRABLE
|
|
57
|
+
DESC_P
|
|
58
|
+
DISTINCT
|
|
59
|
+
DO
|
|
60
|
+
ELSE
|
|
61
|
+
END_P
|
|
62
|
+
EXCEPT
|
|
63
|
+
FALSE_P
|
|
64
|
+
FETCH
|
|
65
|
+
FOR
|
|
66
|
+
FOREIGN
|
|
67
|
+
FROM
|
|
68
|
+
GRANT
|
|
69
|
+
GROUP_P
|
|
70
|
+
HAVING
|
|
71
|
+
IN_P
|
|
72
|
+
INITIALLY
|
|
73
|
+
INTERSECT
|
|
74
|
+
INTO
|
|
75
|
+
LATERAL_P
|
|
76
|
+
LEADING
|
|
77
|
+
LIMIT
|
|
78
|
+
LOCALTIME
|
|
79
|
+
LOCALTIMESTAMP
|
|
80
|
+
NOT
|
|
81
|
+
NULL_P
|
|
82
|
+
OFFSET
|
|
83
|
+
ON
|
|
84
|
+
ONLY
|
|
85
|
+
OR
|
|
86
|
+
ORDER
|
|
87
|
+
PLACING
|
|
88
|
+
PRIMARY
|
|
89
|
+
REFERENCES
|
|
90
|
+
RETURNING
|
|
91
|
+
SELECT
|
|
92
|
+
SESSION_USER
|
|
93
|
+
SOME
|
|
94
|
+
SYMMETRIC
|
|
95
|
+
TABLE
|
|
96
|
+
THEN
|
|
97
|
+
TO
|
|
98
|
+
TRAILING
|
|
99
|
+
TRUE_P
|
|
100
|
+
UNION
|
|
101
|
+
UNIQUE
|
|
102
|
+
USER
|
|
103
|
+
USING
|
|
104
|
+
VARIADIC
|
|
105
|
+
WHEN
|
|
106
|
+
WHERE
|
|
107
|
+
WINDOW
|
|
108
|
+
WITH
|
|
109
|
+
`.split(/\s/);
|
|
110
|
+
const castMap = {
|
|
111
|
+
number: "double precision",
|
|
112
|
+
string: "varchar",
|
|
113
|
+
};
|
|
114
|
+
const pgExtractionMap = {
|
|
115
|
+
day_of_week: "dow",
|
|
116
|
+
day_of_year: "doy",
|
|
117
|
+
};
|
|
118
|
+
const inSeconds = {
|
|
119
|
+
second: 1,
|
|
120
|
+
minute: 60,
|
|
121
|
+
hour: 3600,
|
|
122
|
+
};
|
|
123
|
+
class DuckDBDialect extends dialect_1.Dialect {
|
|
124
|
+
constructor() {
|
|
125
|
+
super(...arguments);
|
|
126
|
+
this.name = "duckdb";
|
|
127
|
+
this.defaultNumberType = "DOUBLE";
|
|
128
|
+
this.hasFinalStage = false;
|
|
129
|
+
this.stringTypeName = "VARCHAR";
|
|
130
|
+
this.divisionIsInteger = true;
|
|
131
|
+
this.supportsSumDistinctFunction = true;
|
|
132
|
+
this.unnestWithNumbers = true;
|
|
133
|
+
this.defaultSampling = { rows: 50000 };
|
|
134
|
+
this.supportUnnestArrayAgg = true;
|
|
135
|
+
this.supportsCTEinCoorelatedSubQueries = true;
|
|
136
|
+
this.dontUnionIndex = false;
|
|
137
|
+
this.supportsQualify = true;
|
|
138
|
+
this.functionInfo = {
|
|
139
|
+
concat: { returnType: "string" },
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
// hack until they support temporary macros.
|
|
143
|
+
get udfPrefix() {
|
|
144
|
+
return `__udf${Math.floor(Math.random() * 100000)}`;
|
|
145
|
+
}
|
|
146
|
+
quoteTablePath(tableName) {
|
|
147
|
+
return tableName.match(/\//) ? `'${tableName}'` : tableName;
|
|
148
|
+
}
|
|
149
|
+
sqlGroupSetTable(groupSetCount) {
|
|
150
|
+
return `CROSS JOIN (SELECT UNNEST(GENERATE_SERIES(0,${groupSetCount},1)) as group_set ) as group_set`;
|
|
151
|
+
}
|
|
152
|
+
sqlAnyValue(groupSet, fieldName) {
|
|
153
|
+
return `FIRST(${fieldName}) FILTER (WHERE ${fieldName} IS NOT NULL)`;
|
|
154
|
+
}
|
|
155
|
+
mapFields(fieldList) {
|
|
156
|
+
return fieldList.join(", ");
|
|
157
|
+
}
|
|
158
|
+
sqlAggregateTurtle(groupSet, fieldList, orderBy, limit) {
|
|
159
|
+
let tail = "";
|
|
160
|
+
if (limit !== undefined) {
|
|
161
|
+
tail += `[1:${limit}]`;
|
|
162
|
+
}
|
|
163
|
+
const fields = fieldList
|
|
164
|
+
.map((f) => `\n ${f.sqlOutputName}: ${f.sqlExpression}`)
|
|
165
|
+
.join(", ");
|
|
166
|
+
return `COALESCE(LIST({${fields}} ${orderBy}) FILTER (WHERE group_set=${groupSet})${tail},[])`;
|
|
167
|
+
}
|
|
168
|
+
sqlAnyValueTurtle(groupSet, fieldList) {
|
|
169
|
+
const fields = fieldList
|
|
170
|
+
.map((f) => `${f.sqlExpression} as ${f.sqlOutputName}`)
|
|
171
|
+
.join(", ");
|
|
172
|
+
return `ANY_VALUE(CASE WHEN group_set=${groupSet} THEN ROW(${fields}))`;
|
|
173
|
+
}
|
|
174
|
+
sqlAnyValueLastTurtle(name, groupSet, sqlName) {
|
|
175
|
+
return `MAX(CASE WHEN group_set=${groupSet} THEN ${name}__${groupSet} END) as ${sqlName}`;
|
|
176
|
+
}
|
|
177
|
+
sqlCoaleseMeasuresInline(groupSet, fieldList) {
|
|
178
|
+
const fields = fieldList
|
|
179
|
+
.map((f) => `${f.sqlOutputName}: ${f.sqlExpression} `)
|
|
180
|
+
.join(", ");
|
|
181
|
+
const nullValues = fieldList
|
|
182
|
+
.map((f) => `${f.sqlOutputName}: NULL`)
|
|
183
|
+
.join(", ");
|
|
184
|
+
return `COALESCE(FIRST({${fields}}) FILTER(WHERE group_set=${groupSet}), {${nullValues}})`;
|
|
185
|
+
}
|
|
186
|
+
sqlUnnestAlias(source, alias, _fieldList, _needDistinctKey) {
|
|
187
|
+
return `LEFT JOIN (select UNNEST(generate_series(1,
|
|
188
|
+
100000, --
|
|
189
|
+
-- (SELECT genres_length FROM movies limit 1),
|
|
190
|
+
1)) as __row_id) as ${alias} ON ${alias}.__row_id <= array_length(${source})`;
|
|
191
|
+
// When DuckDB supports lateral joins...
|
|
192
|
+
//return `,(select UNNEST(generate_series(1, length(${source}),1))) as ${alias}(__row_id)`;
|
|
193
|
+
}
|
|
194
|
+
sqlSumDistinctHashedKey(_sqlDistinctKey) {
|
|
195
|
+
return "uses sumDistinctFunction, should not be called";
|
|
196
|
+
}
|
|
197
|
+
sqlGenerateUUID() {
|
|
198
|
+
return `GEN_RANDOM_UUID()`;
|
|
199
|
+
}
|
|
200
|
+
sqlDateToString(sqlDateExp) {
|
|
201
|
+
return `(${sqlDateExp})::date::varchar`;
|
|
202
|
+
}
|
|
203
|
+
sqlFieldReference(alias, fieldName, _fieldType, _isNested, isArray) {
|
|
204
|
+
if (isArray) {
|
|
205
|
+
return alias;
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
return `${alias}.${this.sqlMaybeQuoteIdentifier(fieldName)}`;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
sqlUnnestPipelineHead(isSingleton, sourceSQLExpression) {
|
|
212
|
+
let p = sourceSQLExpression;
|
|
213
|
+
if (isSingleton) {
|
|
214
|
+
p = `[${p}]`;
|
|
215
|
+
}
|
|
216
|
+
return `(SELECT UNNEST(${p}) as base)`;
|
|
217
|
+
}
|
|
218
|
+
sqlCreateFunction(id, funcText) {
|
|
219
|
+
return `DROP MACRO IF EXISTS ${id}; \n${hackSplitComment}\n CREATE MACRO ${id}(_param) AS (\n${(0, utils_1.indent)(funcText)}\n);\n${hackSplitComment}\n`;
|
|
220
|
+
}
|
|
221
|
+
sqlCreateFunctionCombineLastStage(lastStageName, structDef) {
|
|
222
|
+
return `SELECT LIST(ROW(${structDef.fields
|
|
223
|
+
.map((fieldDef) => this.sqlMaybeQuoteIdentifier((0, malloy_types_1.getIdentifier)(fieldDef)))
|
|
224
|
+
.join(",")})) FROM ${lastStageName}\n`;
|
|
225
|
+
}
|
|
226
|
+
sqlSelectAliasAsStruct(alias, physicalFieldNames) {
|
|
227
|
+
return `ROW(${physicalFieldNames
|
|
228
|
+
.map((name) => `${alias}.${name}`)
|
|
229
|
+
.join(", ")})`;
|
|
230
|
+
}
|
|
231
|
+
// TODO
|
|
232
|
+
// sqlMaybeQuoteIdentifier(identifier: string): string {
|
|
233
|
+
// return keywords.indexOf(identifier.toUpperCase()) > 0 ||
|
|
234
|
+
// identifier.match(/[a-zA-Z][a-zA-Z0-9]*/) === null || true
|
|
235
|
+
// ? '"' + identifier + '"'
|
|
236
|
+
// : identifier;
|
|
237
|
+
// }
|
|
238
|
+
sqlMaybeQuoteIdentifier(identifier) {
|
|
239
|
+
return '"' + identifier + '"';
|
|
240
|
+
}
|
|
241
|
+
// The simple way to do this is to add a comment on the table
|
|
242
|
+
// with the expiration time. https://www.postgresql.org/docs/current/sql-comment.html
|
|
243
|
+
// and have a reaper that read comments.
|
|
244
|
+
sqlCreateTableAsSelect(_tableName, _sql) {
|
|
245
|
+
throw new Error("Not implemented Yet");
|
|
246
|
+
}
|
|
247
|
+
getFunctionInfo(functionName) {
|
|
248
|
+
return this.functionInfo[functionName];
|
|
249
|
+
}
|
|
250
|
+
sqlMeasureTime(from, to, units) {
|
|
251
|
+
let lVal = from.value;
|
|
252
|
+
let rVal = to.value;
|
|
253
|
+
if (inSeconds[units]) {
|
|
254
|
+
lVal = (0, malloy_types_1.mkExpr) `EXTRACT(EPOCH FROM ${lVal})`;
|
|
255
|
+
rVal = (0, malloy_types_1.mkExpr) `EXTRACT(EPOCH FROM ${rVal})`;
|
|
256
|
+
const duration = (0, malloy_types_1.mkExpr) `(${rVal} - ${lVal})`;
|
|
257
|
+
return units == "second"
|
|
258
|
+
? duration
|
|
259
|
+
: (0, malloy_types_1.mkExpr) `FLOOR(${duration}/${inSeconds[units].toString()})`;
|
|
260
|
+
}
|
|
261
|
+
if (from.valueType != "date") {
|
|
262
|
+
lVal = (0, malloy_types_1.mkExpr) `CAST((${lVal}) AS DATE)`;
|
|
263
|
+
}
|
|
264
|
+
if (to.valueType != "date") {
|
|
265
|
+
rVal = (0, malloy_types_1.mkExpr) `CAST((${rVal}) AS DATE)`;
|
|
266
|
+
}
|
|
267
|
+
if (units == "week") {
|
|
268
|
+
// DuckDB's weeks start on Monday, but Malloy's weeks start on Sunday
|
|
269
|
+
lVal = (0, malloy_types_1.mkExpr) `(${lVal} + INTERVAL 1 DAY)`;
|
|
270
|
+
rVal = (0, malloy_types_1.mkExpr) `(${rVal} + INTERVAL 1 DAY)`;
|
|
271
|
+
}
|
|
272
|
+
return (0, malloy_types_1.mkExpr) `DATE_DIFF('${units}', ${lVal}, ${rVal})`;
|
|
273
|
+
}
|
|
274
|
+
sqlNow() {
|
|
275
|
+
return (0, malloy_types_1.mkExpr) `CURRENT_TIMESTAMP::TIMESTAMP`;
|
|
276
|
+
}
|
|
277
|
+
sqlTrunc(sqlTime, units) {
|
|
278
|
+
// adjusting for monday/sunday weeks
|
|
279
|
+
const week = units == "week";
|
|
280
|
+
const truncThis = week
|
|
281
|
+
? (0, malloy_types_1.mkExpr) `${sqlTime.value} + INTERVAL 1 DAY`
|
|
282
|
+
: sqlTime.value;
|
|
283
|
+
const trunced = (0, malloy_types_1.mkExpr) `DATE_TRUNC('${units}', ${truncThis})`;
|
|
284
|
+
return week ? (0, malloy_types_1.mkExpr) `(${trunced} - INTERVAL 1 DAY)` : trunced;
|
|
285
|
+
}
|
|
286
|
+
sqlExtract(from, units) {
|
|
287
|
+
const pgUnits = pgExtractionMap[units] || units;
|
|
288
|
+
const extracted = (0, malloy_types_1.mkExpr) `EXTRACT(${pgUnits} FROM ${from.value})`;
|
|
289
|
+
return units == "day_of_week" ? (0, malloy_types_1.mkExpr) `(${extracted}+1)` : extracted;
|
|
290
|
+
}
|
|
291
|
+
sqlAlterTime(op, expr, n, timeframe) {
|
|
292
|
+
if (timeframe == "quarter") {
|
|
293
|
+
timeframe = "month";
|
|
294
|
+
n = (0, malloy_types_1.mkExpr) `${n}*3`;
|
|
295
|
+
}
|
|
296
|
+
if (timeframe == "week") {
|
|
297
|
+
timeframe = "day";
|
|
298
|
+
n = (0, malloy_types_1.mkExpr) `${n}*7`;
|
|
299
|
+
}
|
|
300
|
+
const interval = (0, malloy_types_1.mkExpr) `INTERVAL (${n}) ${timeframe}`;
|
|
301
|
+
return (0, malloy_types_1.mkExpr) `((${expr.value})) ${op} ${interval}`;
|
|
302
|
+
}
|
|
303
|
+
sqlCast(cast) {
|
|
304
|
+
if (cast.dstType !== cast.srcType) {
|
|
305
|
+
const castTo = castMap[cast.dstType] || cast.dstType;
|
|
306
|
+
return (0, malloy_types_1.mkExpr) `cast(${cast.expr} as ${castTo})`;
|
|
307
|
+
}
|
|
308
|
+
return cast.expr;
|
|
309
|
+
}
|
|
310
|
+
sqlRegexpMatch(expr, regexp) {
|
|
311
|
+
return (0, malloy_types_1.mkExpr) `REGEXP_MATCHES(${expr}, ${regexp})`;
|
|
312
|
+
}
|
|
313
|
+
sqlLiteralTime(timeString, type, _timezone) {
|
|
314
|
+
if (type == "date") {
|
|
315
|
+
return `DATE '${timeString}'`;
|
|
316
|
+
}
|
|
317
|
+
else if (type == "timestamp") {
|
|
318
|
+
return `TIMESTAMP '${timeString}'`;
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
throw new Error(`Unknown Literal time format ${type}`);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
sqlSumDistinct(key, value) {
|
|
325
|
+
// return `sum_distinct(list({key:${key}, val: ${value}}))`;
|
|
326
|
+
return `(
|
|
327
|
+
SELECT sum(a.val) as value
|
|
328
|
+
FROM (
|
|
329
|
+
SELECT UNNEST(list(distinct {key:${key}, val: ${value}})) a
|
|
330
|
+
)
|
|
331
|
+
)`;
|
|
332
|
+
}
|
|
333
|
+
// sqlSumDistinct(key: string, value: string): string {
|
|
334
|
+
// const _factor = 32;
|
|
335
|
+
// const precision = 0.000001;
|
|
336
|
+
// const keySQL = `md5_number_lower(${key}::varchar)::int128`;
|
|
337
|
+
// return `
|
|
338
|
+
// (SUM(DISTINCT ${keySQL} + FLOOR(IFNULL(${value},0)/${precision})::int128) - SUM(DISTINCT ${keySQL}))*${precision}
|
|
339
|
+
// `;
|
|
340
|
+
// }
|
|
341
|
+
// default duckdb to sampling 50K rows.
|
|
342
|
+
sqlSampleTable(tableSQL, sample) {
|
|
343
|
+
if (sample !== undefined) {
|
|
344
|
+
if ((0, malloy_types_1.isSamplingEnable)(sample) && sample.enable) {
|
|
345
|
+
sample = this.defaultSampling;
|
|
346
|
+
}
|
|
347
|
+
if ((0, malloy_types_1.isSamplingRows)(sample)) {
|
|
348
|
+
return `(SELECT * FROM ${tableSQL} USING SAMPLE ${sample.rows})`;
|
|
349
|
+
}
|
|
350
|
+
else if ((0, malloy_types_1.isSamplingPercent)(sample)) {
|
|
351
|
+
return `(SELECT * FROM ${tableSQL} USING SAMPLE ${sample.percent} PERCENT (bernoulli))`;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
return tableSQL;
|
|
355
|
+
}
|
|
356
|
+
sqlOrderBy(orderTerms) {
|
|
357
|
+
return `ORDER BY ${orderTerms.map((t) => `${t} NULLS LAST`).join(",")}`;
|
|
358
|
+
}
|
|
359
|
+
sqlLiteralString(literal) {
|
|
360
|
+
return "'" + literal.replace(/'/g, "''") + "'";
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
exports.DuckDBDialect = DuckDBDialect;
|
|
364
|
+
//# sourceMappingURL=duckdb.js.map
|