@malloydata/malloy 0.0.24-dev230224184907 → 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
package/dist/connection_utils.js
CHANGED
|
@@ -27,22 +27,22 @@ async function* toAsyncGenerator(startStreaming) {
|
|
|
27
27
|
let done = false;
|
|
28
28
|
function getResults(startStreaming) {
|
|
29
29
|
let resolve;
|
|
30
|
-
const promise = new Promise(
|
|
30
|
+
const promise = new Promise(res => {
|
|
31
31
|
resolve = res;
|
|
32
32
|
});
|
|
33
|
-
startStreaming(
|
|
34
|
-
resolve({
|
|
35
|
-
},
|
|
33
|
+
startStreaming(error => {
|
|
34
|
+
resolve({ done: true, isError: true, error });
|
|
35
|
+
}, data => {
|
|
36
36
|
resolve({
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
done: false,
|
|
38
|
+
value: data,
|
|
39
|
+
isError: false,
|
|
40
|
+
next: new Promise(res => {
|
|
41
41
|
resolve = res;
|
|
42
|
-
})
|
|
42
|
+
}),
|
|
43
43
|
});
|
|
44
44
|
}, () => {
|
|
45
|
-
resolve({
|
|
45
|
+
resolve({ done: true, isError: false });
|
|
46
46
|
});
|
|
47
47
|
return promise;
|
|
48
48
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AtomicFieldType as AtomicFieldTypeInner, DialectFragment, Expr, ExtractUnit, Sampling, StructDef, TimeFieldType, TimeValue, TimestampUnit, TypecastFragment } from
|
|
1
|
+
import { AtomicFieldType as AtomicFieldTypeInner, DialectFragment, Expr, ExtractUnit, Sampling, StructDef, TimeFieldType, TimeValue, TimestampUnit, TypecastFragment } from '../model/malloy_types';
|
|
2
2
|
interface DialectField {
|
|
3
3
|
type: string;
|
|
4
4
|
sqlExpression: string;
|
|
@@ -51,7 +51,7 @@ export declare abstract class Dialect {
|
|
|
51
51
|
abstract sqlTrunc(sqlTime: TimeValue, units: TimestampUnit): Expr;
|
|
52
52
|
abstract sqlExtract(sqlTime: TimeValue, units: ExtractUnit): Expr;
|
|
53
53
|
abstract sqlMeasureTime(from: TimeValue, to: TimeValue, units: TimestampUnit): Expr;
|
|
54
|
-
abstract sqlAlterTime(op:
|
|
54
|
+
abstract sqlAlterTime(op: '+' | '-', expr: TimeValue, n: Expr, timeframe: TimestampUnit): Expr;
|
|
55
55
|
ignoreInProject(_fieldName: string): boolean;
|
|
56
56
|
abstract sqlCast(cast: TypecastFragment): Expr;
|
|
57
57
|
abstract sqlLiteralTime(timeString: string, type: TimeFieldType, timezone: string): string;
|
package/dist/dialect/dialect.js
CHANGED
|
@@ -26,7 +26,7 @@ exports.Dialect = void 0;
|
|
|
26
26
|
const malloy_types_1 = require("../model/malloy_types");
|
|
27
27
|
class Dialect {
|
|
28
28
|
sqlFinalStage(_lastStageName, _fields) {
|
|
29
|
-
throw new Error(
|
|
29
|
+
throw new Error('Dialect has no final Stage but called Anyway');
|
|
30
30
|
}
|
|
31
31
|
// default implementation will probably work most of the time
|
|
32
32
|
sqlDateToString(sqlDateExp) {
|
|
@@ -42,34 +42,34 @@ class Dialect {
|
|
|
42
42
|
}
|
|
43
43
|
dialectExpr(df) {
|
|
44
44
|
switch (df.function) {
|
|
45
|
-
case
|
|
45
|
+
case 'now':
|
|
46
46
|
return this.sqlNow();
|
|
47
|
-
case
|
|
47
|
+
case 'timeDiff':
|
|
48
48
|
return this.sqlMeasureTime(df.left, df.right, df.units);
|
|
49
|
-
case
|
|
49
|
+
case 'delta':
|
|
50
50
|
return this.sqlAlterTime(df.op, df.base, df.delta, df.units);
|
|
51
|
-
case
|
|
51
|
+
case 'trunc':
|
|
52
52
|
return this.sqlTrunc(df.expr, df.units);
|
|
53
|
-
case
|
|
53
|
+
case 'extract':
|
|
54
54
|
return this.sqlExtract(df.expr, df.units);
|
|
55
|
-
case
|
|
55
|
+
case 'cast':
|
|
56
56
|
return this.sqlCast(df);
|
|
57
|
-
case
|
|
57
|
+
case 'regexpMatch':
|
|
58
58
|
return this.sqlRegexpMatch(df.expr, df.regexp);
|
|
59
|
-
case
|
|
59
|
+
case 'div': {
|
|
60
60
|
if (this.divisionIsInteger) {
|
|
61
61
|
return (0, malloy_types_1.mkExpr) `${df.numerator}*1.0/${df.denominator}`;
|
|
62
62
|
}
|
|
63
63
|
return (0, malloy_types_1.mkExpr) `${df.numerator}/${df.denominator}`;
|
|
64
64
|
}
|
|
65
|
-
case
|
|
65
|
+
case 'timeLiteral':
|
|
66
66
|
return [this.sqlLiteralTime(df.literal, df.literalType, df.timezone)];
|
|
67
|
-
case
|
|
67
|
+
case 'stringLiteral':
|
|
68
68
|
return [this.sqlLiteralString(df.literal)];
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
sqlSumDistinct(_key, _value) {
|
|
72
|
-
return
|
|
72
|
+
return 'sqlSumDistinct called bu not implemented';
|
|
73
73
|
}
|
|
74
74
|
sqlSampleTable(tableSQL, sample) {
|
|
75
75
|
if (sample !== undefined) {
|
|
@@ -78,7 +78,7 @@ class Dialect {
|
|
|
78
78
|
return tableSQL;
|
|
79
79
|
}
|
|
80
80
|
sqlOrderBy(orderTerms) {
|
|
81
|
-
return `ORDER BY ${orderTerms.join(
|
|
81
|
+
return `ORDER BY ${orderTerms.join(',')}`;
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
exports.Dialect = Dialect;
|
package/dist/dialect/duckdb.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DateUnit, Expr, ExtractUnit, Sampling, StructDef, TimeFieldType, TimeValue, TimestampUnit, TypecastFragment } from
|
|
2
|
-
import { Dialect, DialectFieldList, FunctionInfo } from
|
|
1
|
+
import { DateUnit, Expr, ExtractUnit, Sampling, StructDef, TimeFieldType, TimeValue, TimestampUnit, TypecastFragment } from '../model/malloy_types';
|
|
2
|
+
import { Dialect, DialectFieldList, FunctionInfo } from './dialect';
|
|
3
3
|
export declare class DuckDBDialect extends Dialect {
|
|
4
4
|
name: string;
|
|
5
5
|
defaultNumberType: string;
|
|
@@ -41,7 +41,7 @@ export declare class DuckDBDialect extends Dialect {
|
|
|
41
41
|
sqlNow(): Expr;
|
|
42
42
|
sqlTrunc(sqlTime: TimeValue, units: TimestampUnit): Expr;
|
|
43
43
|
sqlExtract(from: TimeValue, units: ExtractUnit): Expr;
|
|
44
|
-
sqlAlterTime(op:
|
|
44
|
+
sqlAlterTime(op: '+' | '-', expr: TimeValue, n: Expr, timeframe: DateUnit): Expr;
|
|
45
45
|
sqlCast(cast: TypecastFragment): Expr;
|
|
46
46
|
sqlRegexpMatch(expr: Expr, regexp: string): Expr;
|
|
47
47
|
sqlLiteralTime(timeString: string, type: TimeFieldType, _timezone: string): string;
|
package/dist/dialect/duckdb.js
CHANGED
|
@@ -27,8 +27,8 @@ const malloy_types_1 = require("../model/malloy_types");
|
|
|
27
27
|
const utils_1 = require("../model/utils");
|
|
28
28
|
const dialect_1 = require("./dialect");
|
|
29
29
|
// need to refactor runSQL to take a SQLBlock instead of just a sql string.
|
|
30
|
-
const hackSplitComment =
|
|
31
|
-
const
|
|
30
|
+
const hackSplitComment = '-- hack: split on this';
|
|
31
|
+
const _keywords = `
|
|
32
32
|
ALL
|
|
33
33
|
ANALYSE
|
|
34
34
|
ANALYZE
|
|
@@ -108,35 +108,35 @@ WINDOW
|
|
|
108
108
|
WITH
|
|
109
109
|
`.split(/\s/);
|
|
110
110
|
const castMap = {
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
number: 'double precision',
|
|
112
|
+
string: 'varchar',
|
|
113
113
|
};
|
|
114
114
|
const pgExtractionMap = {
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
day_of_week: 'dow',
|
|
116
|
+
day_of_year: 'doy',
|
|
117
117
|
};
|
|
118
118
|
const inSeconds = {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
119
|
+
second: 1,
|
|
120
|
+
minute: 60,
|
|
121
|
+
hour: 3600,
|
|
122
122
|
};
|
|
123
123
|
class DuckDBDialect extends dialect_1.Dialect {
|
|
124
124
|
constructor() {
|
|
125
125
|
super(...arguments);
|
|
126
|
-
this.name =
|
|
127
|
-
this.defaultNumberType =
|
|
126
|
+
this.name = 'duckdb';
|
|
127
|
+
this.defaultNumberType = 'DOUBLE';
|
|
128
128
|
this.hasFinalStage = false;
|
|
129
|
-
this.stringTypeName =
|
|
129
|
+
this.stringTypeName = 'VARCHAR';
|
|
130
130
|
this.divisionIsInteger = true;
|
|
131
131
|
this.supportsSumDistinctFunction = true;
|
|
132
132
|
this.unnestWithNumbers = true;
|
|
133
|
-
this.defaultSampling = {
|
|
133
|
+
this.defaultSampling = { rows: 50000 };
|
|
134
134
|
this.supportUnnestArrayAgg = true;
|
|
135
135
|
this.supportsCTEinCoorelatedSubQueries = true;
|
|
136
136
|
this.dontUnionIndex = false;
|
|
137
137
|
this.supportsQualify = true;
|
|
138
138
|
this.functionInfo = {
|
|
139
|
-
|
|
139
|
+
concat: { returnType: 'string' },
|
|
140
140
|
};
|
|
141
141
|
}
|
|
142
142
|
// hack until they support temporary macros.
|
|
@@ -153,22 +153,22 @@ class DuckDBDialect extends dialect_1.Dialect {
|
|
|
153
153
|
return `FIRST(${fieldName}) FILTER (WHERE ${fieldName} IS NOT NULL)`;
|
|
154
154
|
}
|
|
155
155
|
mapFields(fieldList) {
|
|
156
|
-
return fieldList.join(
|
|
156
|
+
return fieldList.join(', ');
|
|
157
157
|
}
|
|
158
158
|
sqlAggregateTurtle(groupSet, fieldList, orderBy, limit) {
|
|
159
|
-
let tail =
|
|
159
|
+
let tail = '';
|
|
160
160
|
if (limit !== undefined) {
|
|
161
161
|
tail += `[1:${limit}]`;
|
|
162
162
|
}
|
|
163
163
|
const fields = fieldList
|
|
164
|
-
.map(
|
|
165
|
-
.join(
|
|
164
|
+
.map(f => `\n ${f.sqlOutputName}: ${f.sqlExpression}`)
|
|
165
|
+
.join(', ');
|
|
166
166
|
return `COALESCE(LIST({${fields}} ${orderBy}) FILTER (WHERE group_set=${groupSet})${tail},[])`;
|
|
167
167
|
}
|
|
168
168
|
sqlAnyValueTurtle(groupSet, fieldList) {
|
|
169
169
|
const fields = fieldList
|
|
170
|
-
.map(
|
|
171
|
-
.join(
|
|
170
|
+
.map(f => `${f.sqlExpression} as ${f.sqlOutputName}`)
|
|
171
|
+
.join(', ');
|
|
172
172
|
return `ANY_VALUE(CASE WHEN group_set=${groupSet} THEN ROW(${fields}))`;
|
|
173
173
|
}
|
|
174
174
|
sqlAnyValueLastTurtle(name, groupSet, sqlName) {
|
|
@@ -176,11 +176,11 @@ class DuckDBDialect extends dialect_1.Dialect {
|
|
|
176
176
|
}
|
|
177
177
|
sqlCoaleseMeasuresInline(groupSet, fieldList) {
|
|
178
178
|
const fields = fieldList
|
|
179
|
-
.map(
|
|
180
|
-
.join(
|
|
179
|
+
.map(f => `${f.sqlOutputName}: ${f.sqlExpression} `)
|
|
180
|
+
.join(', ');
|
|
181
181
|
const nullValues = fieldList
|
|
182
|
-
.map(
|
|
183
|
-
.join(
|
|
182
|
+
.map(f => `${f.sqlOutputName}: NULL`)
|
|
183
|
+
.join(', ');
|
|
184
184
|
return `COALESCE(FIRST({${fields}}) FILTER(WHERE group_set=${groupSet}), {${nullValues}})`;
|
|
185
185
|
}
|
|
186
186
|
sqlUnnestAlias(source, alias, _fieldList, _needDistinctKey) {
|
|
@@ -192,10 +192,10 @@ class DuckDBDialect extends dialect_1.Dialect {
|
|
|
192
192
|
//return `,(select UNNEST(generate_series(1, length(${source}),1))) as ${alias}(__row_id)`;
|
|
193
193
|
}
|
|
194
194
|
sqlSumDistinctHashedKey(_sqlDistinctKey) {
|
|
195
|
-
return
|
|
195
|
+
return 'uses sumDistinctFunction, should not be called';
|
|
196
196
|
}
|
|
197
197
|
sqlGenerateUUID() {
|
|
198
|
-
return
|
|
198
|
+
return 'GEN_RANDOM_UUID()';
|
|
199
199
|
}
|
|
200
200
|
sqlDateToString(sqlDateExp) {
|
|
201
201
|
return `(${sqlDateExp})::date::varchar`;
|
|
@@ -220,13 +220,13 @@ class DuckDBDialect extends dialect_1.Dialect {
|
|
|
220
220
|
}
|
|
221
221
|
sqlCreateFunctionCombineLastStage(lastStageName, structDef) {
|
|
222
222
|
return `SELECT LIST(ROW(${structDef.fields
|
|
223
|
-
.map(
|
|
224
|
-
.join(
|
|
223
|
+
.map(fieldDef => this.sqlMaybeQuoteIdentifier((0, malloy_types_1.getIdentifier)(fieldDef)))
|
|
224
|
+
.join(',')})) FROM ${lastStageName}\n`;
|
|
225
225
|
}
|
|
226
226
|
sqlSelectAliasAsStruct(alias, physicalFieldNames) {
|
|
227
227
|
return `ROW(${physicalFieldNames
|
|
228
|
-
.map(
|
|
229
|
-
.join(
|
|
228
|
+
.map(name => `${alias}.${name}`)
|
|
229
|
+
.join(', ')})`;
|
|
230
230
|
}
|
|
231
231
|
// TODO
|
|
232
232
|
// sqlMaybeQuoteIdentifier(identifier: string): string {
|
|
@@ -242,7 +242,7 @@ class DuckDBDialect extends dialect_1.Dialect {
|
|
|
242
242
|
// with the expiration time. https://www.postgresql.org/docs/current/sql-comment.html
|
|
243
243
|
// and have a reaper that read comments.
|
|
244
244
|
sqlCreateTableAsSelect(_tableName, _sql) {
|
|
245
|
-
throw new Error(
|
|
245
|
+
throw new Error('Not implemented Yet');
|
|
246
246
|
}
|
|
247
247
|
getFunctionInfo(functionName) {
|
|
248
248
|
return this.functionInfo[functionName];
|
|
@@ -254,17 +254,17 @@ class DuckDBDialect extends dialect_1.Dialect {
|
|
|
254
254
|
lVal = (0, malloy_types_1.mkExpr) `EXTRACT(EPOCH FROM ${lVal})`;
|
|
255
255
|
rVal = (0, malloy_types_1.mkExpr) `EXTRACT(EPOCH FROM ${rVal})`;
|
|
256
256
|
const duration = (0, malloy_types_1.mkExpr) `(${rVal} - ${lVal})`;
|
|
257
|
-
return units
|
|
257
|
+
return units === 'second'
|
|
258
258
|
? duration
|
|
259
259
|
: (0, malloy_types_1.mkExpr) `FLOOR(${duration}/${inSeconds[units].toString()})`;
|
|
260
260
|
}
|
|
261
|
-
if (from.valueType
|
|
261
|
+
if (from.valueType !== 'date') {
|
|
262
262
|
lVal = (0, malloy_types_1.mkExpr) `CAST((${lVal}) AS DATE)`;
|
|
263
263
|
}
|
|
264
|
-
if (to.valueType
|
|
264
|
+
if (to.valueType !== 'date') {
|
|
265
265
|
rVal = (0, malloy_types_1.mkExpr) `CAST((${rVal}) AS DATE)`;
|
|
266
266
|
}
|
|
267
|
-
if (units
|
|
267
|
+
if (units === 'week') {
|
|
268
268
|
// DuckDB's weeks start on Monday, but Malloy's weeks start on Sunday
|
|
269
269
|
lVal = (0, malloy_types_1.mkExpr) `(${lVal} + INTERVAL 1 DAY)`;
|
|
270
270
|
rVal = (0, malloy_types_1.mkExpr) `(${rVal} + INTERVAL 1 DAY)`;
|
|
@@ -276,7 +276,7 @@ class DuckDBDialect extends dialect_1.Dialect {
|
|
|
276
276
|
}
|
|
277
277
|
sqlTrunc(sqlTime, units) {
|
|
278
278
|
// adjusting for monday/sunday weeks
|
|
279
|
-
const week = units
|
|
279
|
+
const week = units === 'week';
|
|
280
280
|
const truncThis = week
|
|
281
281
|
? (0, malloy_types_1.mkExpr) `${sqlTime.value} + INTERVAL 1 DAY`
|
|
282
282
|
: sqlTime.value;
|
|
@@ -286,15 +286,15 @@ class DuckDBDialect extends dialect_1.Dialect {
|
|
|
286
286
|
sqlExtract(from, units) {
|
|
287
287
|
const pgUnits = pgExtractionMap[units] || units;
|
|
288
288
|
const extracted = (0, malloy_types_1.mkExpr) `EXTRACT(${pgUnits} FROM ${from.value})`;
|
|
289
|
-
return units
|
|
289
|
+
return units === 'day_of_week' ? (0, malloy_types_1.mkExpr) `(${extracted}+1)` : extracted;
|
|
290
290
|
}
|
|
291
291
|
sqlAlterTime(op, expr, n, timeframe) {
|
|
292
|
-
if (timeframe
|
|
293
|
-
timeframe =
|
|
292
|
+
if (timeframe === 'quarter') {
|
|
293
|
+
timeframe = 'month';
|
|
294
294
|
n = (0, malloy_types_1.mkExpr) `${n}*3`;
|
|
295
295
|
}
|
|
296
|
-
if (timeframe
|
|
297
|
-
timeframe =
|
|
296
|
+
if (timeframe === 'week') {
|
|
297
|
+
timeframe = 'day';
|
|
298
298
|
n = (0, malloy_types_1.mkExpr) `${n}*7`;
|
|
299
299
|
}
|
|
300
300
|
const interval = (0, malloy_types_1.mkExpr) `INTERVAL (${n}) ${timeframe}`;
|
|
@@ -311,10 +311,10 @@ class DuckDBDialect extends dialect_1.Dialect {
|
|
|
311
311
|
return (0, malloy_types_1.mkExpr) `REGEXP_MATCHES(${expr}, ${regexp})`;
|
|
312
312
|
}
|
|
313
313
|
sqlLiteralTime(timeString, type, _timezone) {
|
|
314
|
-
if (type
|
|
314
|
+
if (type === 'date') {
|
|
315
315
|
return `DATE '${timeString}'`;
|
|
316
316
|
}
|
|
317
|
-
else if (type
|
|
317
|
+
else if (type === 'timestamp') {
|
|
318
318
|
return `TIMESTAMP '${timeString}'`;
|
|
319
319
|
}
|
|
320
320
|
else {
|
|
@@ -354,7 +354,7 @@ class DuckDBDialect extends dialect_1.Dialect {
|
|
|
354
354
|
return tableSQL;
|
|
355
355
|
}
|
|
356
356
|
sqlOrderBy(orderTerms) {
|
|
357
|
-
return `ORDER BY ${orderTerms.map(
|
|
357
|
+
return `ORDER BY ${orderTerms.map(t => `${t} NULLS LAST`).join(',')}`;
|
|
358
358
|
}
|
|
359
359
|
sqlLiteralString(literal) {
|
|
360
360
|
return "'" + literal.replace(/'/g, "''") + "'";
|
package/dist/dialect/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { Dialect } from
|
|
2
|
-
export type { DialectFieldList } from
|
|
3
|
-
export { StandardSQLDialect } from
|
|
4
|
-
export { PostgresDialect } from
|
|
5
|
-
export { DuckDBDialect } from
|
|
6
|
-
export { getDialect, registerDialect } from
|
|
1
|
+
export { Dialect } from './dialect';
|
|
2
|
+
export type { DialectFieldList } from './dialect';
|
|
3
|
+
export { StandardSQLDialect } from './standardsql';
|
|
4
|
+
export { PostgresDialect } from './postgres';
|
|
5
|
+
export { DuckDBDialect } from './duckdb';
|
|
6
|
+
export { getDialect, registerDialect } from './dialect_map';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DateUnit, Expr, ExtractUnit, Sampling, TimeFieldType, TimeValue, TimestampUnit, TypecastFragment } from
|
|
2
|
-
import { Dialect, DialectFieldList, FunctionInfo } from
|
|
1
|
+
import { DateUnit, Expr, ExtractUnit, Sampling, TimeFieldType, TimeValue, TimestampUnit, TypecastFragment } from '../model/malloy_types';
|
|
2
|
+
import { Dialect, DialectFieldList, FunctionInfo } from './dialect';
|
|
3
3
|
export declare class PostgresDialect extends Dialect {
|
|
4
4
|
name: string;
|
|
5
5
|
defaultNumberType: string;
|
|
@@ -39,7 +39,7 @@ export declare class PostgresDialect extends Dialect {
|
|
|
39
39
|
sqlNow(): Expr;
|
|
40
40
|
sqlTrunc(sqlTime: TimeValue, units: TimestampUnit): Expr;
|
|
41
41
|
sqlExtract(from: TimeValue, units: ExtractUnit): Expr;
|
|
42
|
-
sqlAlterTime(op:
|
|
42
|
+
sqlAlterTime(op: '+' | '-', expr: TimeValue, n: Expr, timeframe: DateUnit): Expr;
|
|
43
43
|
sqlCast(cast: TypecastFragment): Expr;
|
|
44
44
|
sqlRegexpMatch(expr: Expr, regexp: string): Expr;
|
|
45
45
|
sqlLiteralTime(timeString: string, type: TimeFieldType, _timezone: string): string;
|
package/dist/dialect/postgres.js
CHANGED
|
@@ -27,52 +27,52 @@ const utils_1 = require("../model/utils");
|
|
|
27
27
|
const malloy_types_1 = require("../model/malloy_types");
|
|
28
28
|
const dialect_1 = require("./dialect");
|
|
29
29
|
const castMap = {
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
number: 'double precision',
|
|
31
|
+
string: 'varchar',
|
|
32
32
|
};
|
|
33
33
|
const pgExtractionMap = {
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
day_of_week: 'dow',
|
|
35
|
+
day_of_year: 'doy',
|
|
36
36
|
};
|
|
37
37
|
const pgMakeIntervalMap = {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
year: 'years',
|
|
39
|
+
month: 'months',
|
|
40
|
+
week: 'weeks',
|
|
41
|
+
day: 'days',
|
|
42
|
+
hour: 'hours',
|
|
43
|
+
minute: 'mins',
|
|
44
|
+
second: 'secs',
|
|
45
45
|
};
|
|
46
46
|
const inSeconds = {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
second: 1,
|
|
48
|
+
minute: 60,
|
|
49
|
+
hour: 3600,
|
|
50
50
|
};
|
|
51
51
|
class PostgresDialect extends dialect_1.Dialect {
|
|
52
52
|
constructor() {
|
|
53
53
|
super(...arguments);
|
|
54
|
-
this.name =
|
|
55
|
-
this.defaultNumberType =
|
|
56
|
-
this.udfPrefix =
|
|
54
|
+
this.name = 'postgres';
|
|
55
|
+
this.defaultNumberType = 'DOUBLE PRECISION';
|
|
56
|
+
this.udfPrefix = 'pg_temp.__udf';
|
|
57
57
|
this.hasFinalStage = true;
|
|
58
|
-
this.stringTypeName =
|
|
58
|
+
this.stringTypeName = 'VARCHAR';
|
|
59
59
|
this.divisionIsInteger = true;
|
|
60
60
|
this.supportsSumDistinctFunction = false;
|
|
61
61
|
this.unnestWithNumbers = false;
|
|
62
|
-
this.defaultSampling = {
|
|
62
|
+
this.defaultSampling = { rows: 50000 };
|
|
63
63
|
this.supportUnnestArrayAgg = true;
|
|
64
64
|
this.supportsCTEinCoorelatedSubQueries = true;
|
|
65
65
|
this.dontUnionIndex = false;
|
|
66
66
|
this.supportsQualify = false;
|
|
67
67
|
this.functionInfo = {
|
|
68
|
-
|
|
68
|
+
concat: { returnType: 'string' },
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
71
|
quoteTablePath(tablePath) {
|
|
72
72
|
return tablePath
|
|
73
|
-
.split(
|
|
74
|
-
.map(
|
|
75
|
-
.join(
|
|
73
|
+
.split('.')
|
|
74
|
+
.map(part => `"${part}"`)
|
|
75
|
+
.join('.');
|
|
76
76
|
}
|
|
77
77
|
sqlGroupSetTable(groupSetCount) {
|
|
78
78
|
return `CROSS JOIN GENERATE_SERIES(0,${groupSetCount},1) as group_set`;
|
|
@@ -82,13 +82,13 @@ class PostgresDialect extends dialect_1.Dialect {
|
|
|
82
82
|
}
|
|
83
83
|
mapFields(fieldList) {
|
|
84
84
|
return fieldList
|
|
85
|
-
.map(
|
|
85
|
+
.map(f => `\n ${f.sqlExpression}${f.type === 'number' ? `::${this.defaultNumberType}` : ''} as ${f.sqlOutputName}`
|
|
86
86
|
//`${f.sqlExpression} ${f.type} as ${f.sqlOutputName}`
|
|
87
87
|
)
|
|
88
|
-
.join(
|
|
88
|
+
.join(', ');
|
|
89
89
|
}
|
|
90
90
|
sqlAggregateTurtle(groupSet, fieldList, orderBy, limit) {
|
|
91
|
-
let tail =
|
|
91
|
+
let tail = '';
|
|
92
92
|
if (limit !== undefined) {
|
|
93
93
|
tail += `[1:${limit}]`;
|
|
94
94
|
}
|
|
@@ -98,8 +98,8 @@ class PostgresDialect extends dialect_1.Dialect {
|
|
|
98
98
|
}
|
|
99
99
|
sqlAnyValueTurtle(groupSet, fieldList) {
|
|
100
100
|
const fields = fieldList
|
|
101
|
-
.map(
|
|
102
|
-
.join(
|
|
101
|
+
.map(f => `${f.sqlExpression} as ${f.sqlOutputName}`)
|
|
102
|
+
.join(', ');
|
|
103
103
|
return `ANY_VALUE(CASE WHEN group_set=${groupSet} THEN STRUCT(${fields}))`;
|
|
104
104
|
}
|
|
105
105
|
sqlAnyValueLastTurtle(name, groupSet, sqlName) {
|
|
@@ -164,18 +164,18 @@ class PostgresDialect extends dialect_1.Dialect {
|
|
|
164
164
|
return `('x' || MD5(${sqlDistinctKey}::varchar))::bit(64)::bigint::DECIMAL(65,0) *18446744073709551616 + ('x' || SUBSTR(MD5(${sqlDistinctKey}::varchar),17))::bit(64)::bigint::DECIMAL(65,0)`;
|
|
165
165
|
}
|
|
166
166
|
sqlGenerateUUID() {
|
|
167
|
-
return
|
|
167
|
+
return 'GEN_RANDOM_UUID()';
|
|
168
168
|
}
|
|
169
169
|
sqlFieldReference(alias, fieldName, fieldType, isNested, _isArray) {
|
|
170
170
|
let ret = `${alias}->>'${fieldName}'`;
|
|
171
171
|
if (isNested) {
|
|
172
172
|
switch (fieldType) {
|
|
173
|
-
case
|
|
173
|
+
case 'string':
|
|
174
174
|
break;
|
|
175
|
-
case
|
|
175
|
+
case 'number':
|
|
176
176
|
ret = `(${ret})::double precision`;
|
|
177
177
|
break;
|
|
178
|
-
case
|
|
178
|
+
case 'struct':
|
|
179
179
|
ret = `(${ret})::jsonb`;
|
|
180
180
|
break;
|
|
181
181
|
}
|
|
@@ -213,14 +213,14 @@ class PostgresDialect extends dialect_1.Dialect {
|
|
|
213
213
|
// with the expiration time. https://www.postgresql.org/docs/current/sql-comment.html
|
|
214
214
|
// and have a reaper that read comments.
|
|
215
215
|
sqlCreateTableAsSelect(_tableName, _sql) {
|
|
216
|
-
throw new Error(
|
|
216
|
+
throw new Error('Not implemented Yet');
|
|
217
217
|
}
|
|
218
218
|
sqlNow() {
|
|
219
219
|
return (0, malloy_types_1.mkExpr) `CURRENT_TIMESTAMP`;
|
|
220
220
|
}
|
|
221
221
|
sqlTrunc(sqlTime, units) {
|
|
222
222
|
// adjusting for monday/sunday weeks
|
|
223
|
-
const week = units
|
|
223
|
+
const week = units === 'week';
|
|
224
224
|
const truncThis = week
|
|
225
225
|
? (0, malloy_types_1.mkExpr) `${sqlTime.value}+interval'1'day`
|
|
226
226
|
: sqlTime.value;
|
|
@@ -230,11 +230,11 @@ class PostgresDialect extends dialect_1.Dialect {
|
|
|
230
230
|
sqlExtract(from, units) {
|
|
231
231
|
const pgUnits = pgExtractionMap[units] || units;
|
|
232
232
|
const extracted = (0, malloy_types_1.mkExpr) `EXTRACT(${pgUnits} FROM ${from.value})`;
|
|
233
|
-
return units
|
|
233
|
+
return units === 'day_of_week' ? (0, malloy_types_1.mkExpr) `(${extracted}+1)` : extracted;
|
|
234
234
|
}
|
|
235
235
|
sqlAlterTime(op, expr, n, timeframe) {
|
|
236
|
-
if (timeframe
|
|
237
|
-
timeframe =
|
|
236
|
+
if (timeframe === 'quarter') {
|
|
237
|
+
timeframe = 'month';
|
|
238
238
|
n = (0, malloy_types_1.mkExpr) `${n}*3`;
|
|
239
239
|
}
|
|
240
240
|
const interval = (0, malloy_types_1.mkExpr) `make_interval(${pgMakeIntervalMap[timeframe]}=>${n})`;
|
|
@@ -251,10 +251,10 @@ class PostgresDialect extends dialect_1.Dialect {
|
|
|
251
251
|
return (0, malloy_types_1.mkExpr) `(${expr} ~ ${regexp})`;
|
|
252
252
|
}
|
|
253
253
|
sqlLiteralTime(timeString, type, _timezone) {
|
|
254
|
-
if (type
|
|
254
|
+
if (type === 'date') {
|
|
255
255
|
return `DATE('${timeString}')`;
|
|
256
256
|
}
|
|
257
|
-
else if (type
|
|
257
|
+
else if (type === 'timestamp') {
|
|
258
258
|
return `TIMESTAMP '${timeString}'`;
|
|
259
259
|
}
|
|
260
260
|
else {
|
|
@@ -271,26 +271,26 @@ class PostgresDialect extends dialect_1.Dialect {
|
|
|
271
271
|
lVal = (0, malloy_types_1.mkExpr) `EXTRACT(EPOCH FROM ${lVal})`;
|
|
272
272
|
rVal = (0, malloy_types_1.mkExpr) `EXTRACT(EPOCH FROM ${rVal})`;
|
|
273
273
|
const duration = (0, malloy_types_1.mkExpr) `(${rVal} - ${lVal})`;
|
|
274
|
-
return units
|
|
274
|
+
return units === 'second'
|
|
275
275
|
? duration
|
|
276
276
|
: (0, malloy_types_1.mkExpr) `TRUNC(${duration}/${inSeconds[units].toString()})`;
|
|
277
277
|
}
|
|
278
|
-
if (units ===
|
|
278
|
+
if (units === 'day') {
|
|
279
279
|
return (0, malloy_types_1.mkExpr) `${rVal}::date - ${lVal}::date`;
|
|
280
280
|
}
|
|
281
281
|
const yearDiff = (0, malloy_types_1.mkExpr) `(DATE_PART('year', ${rVal}) - DATE_PART('year', ${lVal}))`;
|
|
282
|
-
if (units
|
|
282
|
+
if (units === 'year') {
|
|
283
283
|
return yearDiff;
|
|
284
284
|
}
|
|
285
|
-
if (units
|
|
285
|
+
if (units === 'week') {
|
|
286
286
|
const dayDiffForWeekStart = (0, malloy_types_1.mkExpr) `(DATE_TRUNC('week', ${rVal} + '1 day'::interval)::date - DATE_TRUNC('week', ${lVal} + '1 day'::interval)::date)`;
|
|
287
287
|
return (0, malloy_types_1.mkExpr) `${dayDiffForWeekStart} / 7`;
|
|
288
288
|
}
|
|
289
|
-
if (units
|
|
289
|
+
if (units === 'month') {
|
|
290
290
|
const monthDiff = (0, malloy_types_1.mkExpr) `DATE_PART('month', ${rVal}) - DATE_PART('month', ${lVal})`;
|
|
291
291
|
return (0, malloy_types_1.mkExpr) `${yearDiff} * 12 + ${monthDiff}`;
|
|
292
292
|
}
|
|
293
|
-
if (units
|
|
293
|
+
if (units === 'quarter') {
|
|
294
294
|
const qDiff = (0, malloy_types_1.mkExpr) `DATE_PART('quarter', ${rVal}) - DATE_PART('quarter', ${lVal})`;
|
|
295
295
|
return (0, malloy_types_1.mkExpr) `${yearDiff} * 4 + ${qDiff}`;
|
|
296
296
|
}
|
|
@@ -320,7 +320,7 @@ class PostgresDialect extends dialect_1.Dialect {
|
|
|
320
320
|
return tableSQL;
|
|
321
321
|
}
|
|
322
322
|
sqlOrderBy(orderTerms) {
|
|
323
|
-
return `ORDER BY ${orderTerms.map(
|
|
323
|
+
return `ORDER BY ${orderTerms.map(t => `${t} NULLS LAST`).join(',')}`;
|
|
324
324
|
}
|
|
325
325
|
sqlLiteralString(literal) {
|
|
326
326
|
return "'" + literal.replace(/'/g, "''") + "'";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Expr, ExtractUnit, Sampling, TimeValue, TimestampUnit, TypecastFragment } from
|
|
2
|
-
import { Dialect, DialectFieldList, FunctionInfo } from
|
|
1
|
+
import { Expr, ExtractUnit, Sampling, TimeValue, TimestampUnit, TypecastFragment } from '../model/malloy_types';
|
|
2
|
+
import { Dialect, DialectFieldList, FunctionInfo } from './dialect';
|
|
3
3
|
export declare class StandardSQLDialect extends Dialect {
|
|
4
4
|
name: string;
|
|
5
5
|
defaultNumberType: string;
|
|
@@ -38,11 +38,11 @@ export declare class StandardSQLDialect extends Dialect {
|
|
|
38
38
|
sqlNow(): Expr;
|
|
39
39
|
sqlTrunc(sqlTime: TimeValue, units: TimestampUnit): Expr;
|
|
40
40
|
sqlExtract(expr: TimeValue, units: ExtractUnit): Expr;
|
|
41
|
-
sqlAlterTime(op:
|
|
41
|
+
sqlAlterTime(op: '+' | '-', expr: TimeValue, n: Expr, timeframe: TimestampUnit): Expr;
|
|
42
42
|
ignoreInProject(fieldName: string): boolean;
|
|
43
43
|
sqlCast(cast: TypecastFragment): Expr;
|
|
44
44
|
sqlRegexpMatch(expr: Expr, regexp: string): Expr;
|
|
45
|
-
sqlLiteralTime(timeString: string, type:
|
|
45
|
+
sqlLiteralTime(timeString: string, type: 'date' | 'timestamp', timezone: string): string;
|
|
46
46
|
sqlMeasureTime(from: TimeValue, to: TimeValue, units: string): Expr;
|
|
47
47
|
sqlSampleTable(tableSQL: string, sample: Sampling | undefined): string;
|
|
48
48
|
sqlLiteralString(literal: string): string;
|