@uwdata/mosaic-sql 0.16.2 → 0.18.0
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/LICENSE +1 -1
- package/README.md +0 -2
- package/dist/src/ast/aggregate.d.ts +82 -0
- package/dist/src/ast/aggregate.d.ts.map +1 -0
- package/dist/src/ast/aggregate.js +180 -0
- package/dist/src/ast/aggregate.js.map +1 -0
- package/dist/src/ast/between-op.d.ts +46 -0
- package/dist/src/ast/between-op.d.ts.map +1 -0
- package/dist/src/ast/between-op.js +60 -0
- package/dist/src/ast/between-op.js.map +1 -0
- package/dist/src/ast/binary-op.d.ts +21 -0
- package/dist/src/ast/binary-op.d.ts.map +1 -0
- package/dist/src/ast/binary-op.js +29 -0
- package/dist/src/ast/binary-op.js.map +1 -0
- package/dist/src/ast/case.d.ts +53 -0
- package/dist/src/ast/case.d.ts.map +1 -0
- package/dist/src/ast/case.js +75 -0
- package/dist/src/ast/case.js.map +1 -0
- package/dist/src/ast/cast.d.ts +18 -0
- package/dist/src/ast/cast.d.ts.map +1 -0
- package/dist/src/ast/cast.js +26 -0
- package/dist/src/ast/cast.js.map +1 -0
- package/dist/src/ast/collate.d.ts +18 -0
- package/dist/src/ast/collate.d.ts.map +1 -0
- package/dist/src/ast/collate.js +25 -0
- package/dist/src/ast/collate.js.map +1 -0
- package/dist/src/ast/column-param.d.ts +23 -0
- package/dist/src/ast/column-param.d.ts.map +1 -0
- package/dist/src/ast/column-param.js +29 -0
- package/dist/src/ast/column-param.js.map +1 -0
- package/dist/src/ast/column-ref.d.ts +40 -0
- package/dist/src/ast/column-ref.d.ts.map +1 -0
- package/dist/src/ast/column-ref.js +58 -0
- package/dist/src/ast/column-ref.js.map +1 -0
- package/dist/src/ast/fragment.d.ts +20 -0
- package/dist/src/ast/fragment.d.ts.map +1 -0
- package/dist/src/ast/fragment.js +26 -0
- package/dist/src/ast/fragment.js.map +1 -0
- package/dist/src/ast/from.d.ts +22 -0
- package/dist/src/ast/from.d.ts.map +1 -0
- package/dist/src/ast/from.js +37 -0
- package/dist/src/ast/from.js.map +1 -0
- package/dist/src/ast/function.d.ts +18 -0
- package/dist/src/ast/function.d.ts.map +1 -0
- package/dist/src/ast/function.js +26 -0
- package/dist/src/ast/function.js.map +1 -0
- package/dist/src/ast/in-op.d.ts +18 -0
- package/dist/src/ast/in-op.d.ts.map +1 -0
- package/dist/src/ast/in-op.js +25 -0
- package/dist/src/ast/in-op.js.map +1 -0
- package/dist/src/ast/interval.d.ts +18 -0
- package/dist/src/ast/interval.d.ts.map +1 -0
- package/dist/src/ast/interval.js +25 -0
- package/dist/src/ast/interval.js.map +1 -0
- package/dist/src/ast/literal.d.ts +16 -0
- package/dist/src/ast/literal.d.ts.map +1 -0
- package/dist/src/ast/literal.js +53 -0
- package/dist/src/ast/literal.js.map +1 -0
- package/dist/src/ast/logical-op.d.ts +32 -0
- package/dist/src/ast/logical-op.d.ts.map +1 -0
- package/dist/src/ast/logical-op.js +46 -0
- package/dist/src/ast/logical-op.js.map +1 -0
- package/dist/src/ast/node.d.ts +25 -0
- package/dist/src/ast/node.d.ts.map +1 -0
- package/dist/src/ast/node.js +36 -0
- package/dist/src/ast/node.js.map +1 -0
- package/dist/src/ast/order-by.d.ts +21 -0
- package/dist/src/ast/order-by.d.ts.map +1 -0
- package/dist/src/ast/order-by.js +36 -0
- package/dist/src/ast/order-by.js.map +1 -0
- package/dist/{types → src}/ast/param.d.ts +11 -11
- package/dist/src/ast/param.d.ts.map +1 -0
- package/dist/src/ast/param.js +28 -0
- package/dist/src/ast/param.js.map +1 -0
- package/dist/src/ast/query.d.ts +294 -0
- package/dist/src/ast/query.d.ts.map +1 -0
- package/dist/src/ast/query.js +584 -0
- package/dist/src/ast/query.js.map +1 -0
- package/dist/src/ast/sample.d.ts +27 -0
- package/dist/src/ast/sample.d.ts.map +1 -0
- package/dist/src/ast/sample.js +38 -0
- package/dist/src/ast/sample.js.map +1 -0
- package/dist/src/ast/select.d.ts +19 -0
- package/dist/src/ast/select.d.ts.map +1 -0
- package/dist/src/ast/select.js +35 -0
- package/dist/src/ast/select.js.map +1 -0
- package/dist/src/ast/subquery.d.ts +16 -0
- package/dist/src/ast/subquery.d.ts.map +1 -0
- package/dist/src/ast/subquery.js +21 -0
- package/dist/src/ast/subquery.js.map +1 -0
- package/dist/src/ast/table-ref.d.ts +24 -0
- package/dist/src/ast/table-ref.d.ts.map +1 -0
- package/dist/src/ast/table-ref.js +35 -0
- package/dist/src/ast/table-ref.js.map +1 -0
- package/dist/src/ast/unary-op.d.ts +40 -0
- package/dist/src/ast/unary-op.d.ts.map +1 -0
- package/dist/src/ast/unary-op.js +52 -0
- package/dist/src/ast/unary-op.js.map +1 -0
- package/dist/src/ast/verbatim.d.ts +18 -0
- package/dist/src/ast/verbatim.d.ts.map +1 -0
- package/dist/src/ast/verbatim.js +25 -0
- package/dist/src/ast/verbatim.js.map +1 -0
- package/dist/src/ast/window-frame.d.ts +54 -0
- package/dist/src/ast/window-frame.d.ts.map +1 -0
- package/dist/src/ast/window-frame.js +79 -0
- package/dist/src/ast/window-frame.js.map +1 -0
- package/dist/src/ast/window.d.ts +128 -0
- package/dist/src/ast/window.d.ts.map +1 -0
- package/dist/src/ast/window.js +194 -0
- package/dist/src/ast/window.js.map +1 -0
- package/dist/{types → src}/ast/with.d.ts +15 -22
- package/dist/src/ast/with.d.ts.map +1 -0
- package/dist/src/ast/with.js +36 -0
- package/dist/src/ast/with.js.map +1 -0
- package/dist/src/constants.d.ts +38 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +38 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/functions/aggregate.d.ts +236 -0
- package/dist/src/functions/aggregate.d.ts.map +1 -0
- package/dist/src/functions/aggregate.js +308 -0
- package/dist/src/functions/aggregate.js.map +1 -0
- package/dist/{types → src}/functions/case.d.ts +7 -7
- package/dist/src/functions/case.d.ts.map +1 -0
- package/dist/src/functions/case.js +17 -0
- package/dist/src/functions/case.js.map +1 -0
- package/dist/src/functions/cast.d.ts +23 -0
- package/dist/src/functions/cast.d.ts.map +1 -0
- package/dist/src/functions/cast.js +32 -0
- package/dist/src/functions/cast.js.map +1 -0
- package/dist/src/functions/collate.d.ts +10 -0
- package/dist/src/functions/collate.d.ts.map +1 -0
- package/dist/src/functions/collate.js +12 -0
- package/dist/src/functions/collate.js.map +1 -0
- package/dist/src/functions/column.d.ts +10 -0
- package/dist/src/functions/column.d.ts.map +1 -0
- package/dist/src/functions/column.js +17 -0
- package/dist/src/functions/column.js.map +1 -0
- package/dist/{types → src}/functions/cte.d.ts +7 -7
- package/dist/src/functions/cte.d.ts.map +1 -0
- package/dist/src/functions/cte.js +14 -0
- package/dist/src/functions/cte.js.map +1 -0
- package/dist/src/functions/datetime.d.ts +32 -0
- package/dist/src/functions/datetime.d.ts.map +1 -0
- package/dist/src/functions/datetime.js +45 -0
- package/dist/src/functions/datetime.js.map +1 -0
- package/dist/src/functions/interval.d.ts +48 -0
- package/dist/src/functions/interval.d.ts.map +1 -0
- package/dist/src/functions/interval.js +66 -0
- package/dist/src/functions/interval.js.map +1 -0
- package/dist/{types → src}/functions/literal.d.ts +8 -8
- package/dist/src/functions/literal.d.ts.map +1 -0
- package/dist/src/functions/literal.js +20 -0
- package/dist/src/functions/literal.js.map +1 -0
- package/dist/src/functions/numeric.d.ts +80 -0
- package/dist/src/functions/numeric.d.ts.map +1 -0
- package/dist/src/functions/numeric.js +110 -0
- package/dist/src/functions/numeric.js.map +1 -0
- package/dist/src/functions/operators.d.ts +169 -0
- package/dist/src/functions/operators.d.ts.map +1 -0
- package/dist/src/functions/operators.js +235 -0
- package/dist/src/functions/operators.js.map +1 -0
- package/dist/src/functions/order-by.d.ts +15 -0
- package/dist/src/functions/order-by.d.ts.map +1 -0
- package/dist/src/functions/order-by.js +19 -0
- package/dist/src/functions/order-by.js.map +1 -0
- package/dist/src/functions/spatial.d.ts +32 -0
- package/dist/src/functions/spatial.d.ts.map +1 -0
- package/dist/src/functions/spatial.js +44 -0
- package/dist/src/functions/spatial.js.map +1 -0
- package/dist/{types → src}/functions/sql-template-tag.d.ts +8 -10
- package/dist/src/functions/sql-template-tag.d.ts.map +1 -0
- package/dist/src/functions/sql-template-tag.js +44 -0
- package/dist/src/functions/sql-template-tag.js.map +1 -0
- package/dist/src/functions/string.d.ts +49 -0
- package/dist/src/functions/string.d.ts.map +1 -0
- package/dist/src/functions/string.js +67 -0
- package/dist/src/functions/string.js.map +1 -0
- package/dist/src/functions/table-ref.d.ts +10 -0
- package/dist/src/functions/table-ref.d.ts.map +1 -0
- package/dist/src/functions/table-ref.js +13 -0
- package/dist/src/functions/table-ref.js.map +1 -0
- package/dist/src/functions/util.d.ts +7 -0
- package/dist/src/functions/util.d.ts.map +1 -0
- package/dist/src/functions/util.js +9 -0
- package/dist/src/functions/util.js.map +1 -0
- package/dist/src/functions/window-frame.d.ts +41 -0
- package/dist/src/functions/window-frame.d.ts.map +1 -0
- package/dist/src/functions/window-frame.js +52 -0
- package/dist/src/functions/window-frame.js.map +1 -0
- package/dist/{types → src}/functions/window.d.ts +24 -39
- package/dist/src/functions/window.d.ts.map +1 -0
- package/dist/src/functions/window.js +96 -0
- package/dist/src/functions/window.js.map +1 -0
- package/dist/src/index.d.ts +69 -0
- package/dist/src/index.d.ts.map +1 -0
- package/{src → dist/src}/index.js +16 -12
- package/dist/src/index.js.map +1 -0
- package/dist/src/load/create.d.ts +10 -0
- package/dist/src/load/create.d.ts.map +1 -0
- package/dist/src/load/create.js +14 -0
- package/dist/src/load/create.js.map +1 -0
- package/dist/src/load/extension.d.ts +2 -0
- package/dist/src/load/extension.d.ts.map +1 -0
- package/dist/src/load/extension.js +4 -0
- package/dist/src/load/extension.js.map +1 -0
- package/dist/src/load/load.d.ts +18 -0
- package/dist/src/load/load.d.ts.map +1 -0
- package/dist/src/load/load.js +80 -0
- package/dist/src/load/load.js.map +1 -0
- package/dist/src/load/sql-from.d.ts +14 -0
- package/dist/src/load/sql-from.d.ts.map +1 -0
- package/dist/src/load/sql-from.js +29 -0
- package/dist/src/load/sql-from.js.map +1 -0
- package/dist/src/transforms/bin-1d.d.ts +16 -0
- package/dist/src/transforms/bin-1d.d.ts.map +1 -0
- package/dist/src/transforms/bin-1d.js +21 -0
- package/dist/src/transforms/bin-1d.js.map +1 -0
- package/dist/src/transforms/bin-2d.d.ts +19 -0
- package/dist/src/transforms/bin-2d.d.ts.map +1 -0
- package/dist/src/transforms/bin-2d.js +27 -0
- package/dist/src/transforms/bin-2d.js.map +1 -0
- package/dist/src/transforms/bin-date.d.ts +31 -0
- package/dist/src/transforms/bin-date.d.ts.map +1 -0
- package/dist/src/transforms/bin-date.js +20 -0
- package/dist/src/transforms/bin-date.js.map +1 -0
- package/dist/src/transforms/bin-histogram.d.ts +37 -0
- package/dist/src/transforms/bin-histogram.d.ts.map +1 -0
- package/dist/src/transforms/bin-histogram.js +32 -0
- package/dist/src/transforms/bin-histogram.js.map +1 -0
- package/dist/src/transforms/bin-linear-1d.d.ts +11 -0
- package/dist/src/transforms/bin-linear-1d.d.ts.map +1 -0
- package/dist/src/transforms/bin-linear-1d.js +25 -0
- package/dist/src/transforms/bin-linear-1d.js.map +1 -0
- package/dist/src/transforms/bin-linear-2d.d.ts +20 -0
- package/dist/src/transforms/bin-linear-2d.d.ts.map +1 -0
- package/dist/src/transforms/bin-linear-2d.js +49 -0
- package/dist/src/transforms/bin-linear-2d.js.map +1 -0
- package/dist/src/transforms/filter-query.d.ts +12 -0
- package/dist/src/transforms/filter-query.d.ts.map +1 -0
- package/dist/src/transforms/filter-query.js +39 -0
- package/dist/src/transforms/filter-query.js.map +1 -0
- package/dist/src/transforms/line-density.d.ts +24 -0
- package/dist/src/transforms/line-density.d.ts.map +1 -0
- package/dist/src/transforms/line-density.js +98 -0
- package/dist/src/transforms/line-density.js.map +1 -0
- package/dist/src/transforms/m4.d.ts +19 -0
- package/dist/src/transforms/m4.d.ts.map +1 -0
- package/dist/src/transforms/m4.js +38 -0
- package/dist/src/transforms/m4.js.map +1 -0
- package/dist/src/transforms/scales.d.ts +30 -0
- package/dist/src/transforms/scales.d.ts.map +1 -0
- package/dist/src/transforms/scales.js +103 -0
- package/dist/src/transforms/scales.js.map +1 -0
- package/dist/src/transforms/util/bin-step.d.ts +50 -0
- package/dist/src/transforms/util/bin-step.d.ts.map +1 -0
- package/dist/src/transforms/util/bin-step.js +53 -0
- package/dist/src/transforms/util/bin-step.js.map +1 -0
- package/dist/src/transforms/util/time-interval.d.ts +14 -0
- package/dist/src/transforms/util/time-interval.d.ts.map +1 -0
- package/dist/src/transforms/util/time-interval.js +88 -0
- package/dist/src/transforms/util/time-interval.js.map +1 -0
- package/dist/{types → src}/types.d.ts +6 -19
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/{types → src}/util/ast.d.ts +26 -25
- package/dist/src/util/ast.d.ts.map +1 -0
- package/{src → dist/src}/util/ast.js +36 -41
- package/dist/src/util/ast.js.map +1 -0
- package/dist/src/util/function.d.ts +56 -0
- package/dist/src/util/function.d.ts.map +1 -0
- package/dist/src/util/function.js +73 -0
- package/dist/src/util/function.js.map +1 -0
- package/dist/src/util/identity.d.ts +6 -0
- package/dist/src/util/identity.d.ts.map +1 -0
- package/dist/src/util/identity.js +8 -0
- package/dist/src/util/identity.js.map +1 -0
- package/dist/src/util/string.d.ts +4 -0
- package/dist/src/util/string.d.ts.map +1 -0
- package/dist/src/util/string.js +14 -0
- package/dist/src/util/string.js.map +1 -0
- package/dist/src/util/type-check.d.ts +17 -0
- package/dist/src/util/type-check.d.ts.map +1 -0
- package/dist/src/util/type-check.js +28 -0
- package/dist/src/util/type-check.js.map +1 -0
- package/dist/src/visit/clone.d.ts +7 -0
- package/dist/src/visit/clone.d.ts.map +1 -0
- package/dist/src/visit/clone.js +52 -0
- package/dist/src/visit/clone.js.map +1 -0
- package/dist/src/visit/recurse.d.ts +2 -0
- package/dist/src/visit/recurse.d.ts.map +1 -0
- package/dist/src/visit/recurse.js +36 -0
- package/dist/src/visit/recurse.js.map +1 -0
- package/dist/src/visit/rewrite.d.ts +9 -0
- package/dist/src/visit/rewrite.d.ts.map +1 -0
- package/dist/src/visit/rewrite.js +39 -0
- package/dist/src/visit/rewrite.js.map +1 -0
- package/dist/{types → src}/visit/visitors.d.ts +14 -16
- package/dist/src/visit/visitors.d.ts.map +1 -0
- package/dist/src/visit/visitors.js +95 -0
- package/dist/src/visit/visitors.js.map +1 -0
- package/dist/src/visit/walk.d.ts +21 -0
- package/dist/src/visit/walk.d.ts.map +1 -0
- package/dist/src/visit/walk.js +32 -0
- package/dist/src/visit/walk.js.map +1 -0
- package/package.json +12 -10
- package/src/ast/aggregate.ts +198 -0
- package/src/ast/{between-op.js → between-op.ts} +19 -26
- package/src/ast/binary-op.ts +31 -0
- package/src/ast/{case.js → case.ts} +29 -44
- package/src/ast/{cast.js → cast.ts} +8 -14
- package/src/ast/collate.ts +27 -0
- package/src/ast/column-param.ts +34 -0
- package/src/ast/{column-ref.js → column-ref.ts} +16 -25
- package/src/ast/fragment.ts +28 -0
- package/src/ast/from.ts +40 -0
- package/src/ast/{function.js → function.ts} +8 -14
- package/src/ast/{in-op.js → in-op.ts} +8 -14
- package/src/ast/{interval.js → interval.ts} +8 -14
- package/src/ast/{literal.js → literal.ts} +6 -9
- package/src/ast/logical-op.ts +50 -0
- package/src/ast/node.ts +39 -0
- package/src/ast/order-by.ts +38 -0
- package/src/ast/{param.js → param.ts} +6 -12
- package/src/ast/{query.js → query.ts} +193 -205
- package/src/ast/sample.ts +47 -0
- package/src/ast/{select.js → select.ts} +10 -16
- package/src/ast/subquery.ts +24 -0
- package/src/ast/{table-ref.js → table-ref.ts} +7 -12
- package/src/ast/{unary-op.js → unary-op.ts} +16 -23
- package/src/ast/{verbatim.js → verbatim.ts} +9 -8
- package/src/ast/window-frame.ts +97 -0
- package/src/ast/window.ts +246 -0
- package/src/ast/{with.js → with.ts} +19 -20
- package/src/{constants.js → constants.ts} +5 -6
- package/src/functions/aggregate.ts +344 -0
- package/src/functions/{case.js → case.ts} +5 -8
- package/src/functions/{cast.js → cast.ts} +9 -13
- package/src/functions/collate.ts +13 -0
- package/src/functions/{column.js → column.ts} +9 -10
- package/src/functions/{cte.js → cte.ts} +9 -6
- package/src/functions/datetime.ts +50 -0
- package/src/functions/interval.ts +74 -0
- package/src/functions/{literal.js → literal.ts} +6 -7
- package/src/functions/numeric.ts +125 -0
- package/src/functions/operators.ts +272 -0
- package/src/functions/order-by.ts +21 -0
- package/src/functions/spatial.ts +50 -0
- package/src/functions/{sql-template-tag.js → sql-template-tag.ts} +16 -13
- package/src/functions/string.ts +79 -0
- package/src/functions/{table-ref.js → table-ref.ts} +4 -4
- package/src/functions/util.ts +10 -0
- package/src/functions/window-frame.ts +58 -0
- package/src/functions/{window.js → window.ts} +18 -35
- package/src/index.ts +75 -0
- package/src/load/{create.js → create.ts} +9 -3
- package/src/load/extension.ts +3 -0
- package/src/load/{load.js → load.ts} +26 -11
- package/src/load/{sql-from.js → sql-from.ts} +14 -7
- package/src/transforms/{bin-1d.js → bin-1d.ts} +13 -9
- package/src/transforms/{bin-2d.js → bin-2d.ts} +17 -13
- package/src/transforms/bin-date.ts +48 -0
- package/src/transforms/bin-histogram.ts +61 -0
- package/src/transforms/{bin-linear-1d.js → bin-linear-1d.ts} +16 -11
- package/src/transforms/{bin-linear-2d.js → bin-linear-2d.ts} +23 -35
- package/src/transforms/filter-query.ts +40 -0
- package/src/transforms/{line-density.js → line-density.ts} +19 -17
- package/src/transforms/{m4.js → m4.ts} +17 -14
- package/src/transforms/{scales.js → scales.ts} +57 -14
- package/src/transforms/util/bin-step.ts +100 -0
- package/src/transforms/util/{time-interval.js → time-interval.ts} +32 -21
- package/src/types.ts +5 -30
- package/src/util/ast.ts +104 -0
- package/src/util/{function.js → function.ts} +40 -31
- package/src/util/identity.ts +7 -0
- package/src/util/{string.js → string.ts} +4 -4
- package/src/util/type-check.ts +31 -0
- package/src/visit/clone.ts +53 -0
- package/src/visit/{recurse.js → recurse.ts} +18 -6
- package/src/visit/{rewrite.js → rewrite.ts} +10 -18
- package/src/visit/{visitors.js → visitors.ts} +22 -30
- package/src/visit/walk.ts +46 -0
- package/dist/types/ast/aggregate.d.ts +0 -71
- package/dist/types/ast/between-op.d.ts +0 -46
- package/dist/types/ast/binary-op.d.ts +0 -28
- package/dist/types/ast/case.d.ts +0 -67
- package/dist/types/ast/cast.d.ts +0 -21
- package/dist/types/ast/column-param.d.ts +0 -23
- package/dist/types/ast/column-ref.d.ts +0 -40
- package/dist/types/ast/fragment.d.ts +0 -14
- package/dist/types/ast/from.d.ts +0 -21
- package/dist/types/ast/function.d.ts +0 -21
- package/dist/types/ast/in-op.d.ts +0 -21
- package/dist/types/ast/interval.d.ts +0 -21
- package/dist/types/ast/literal.d.ts +0 -15
- package/dist/types/ast/logical-op.d.ts +0 -46
- package/dist/types/ast/node.d.ts +0 -24
- package/dist/types/ast/order-by.d.ts +0 -29
- package/dist/types/ast/query.d.ts +0 -320
- package/dist/types/ast/sample.d.ts +0 -42
- package/dist/types/ast/select.d.ts +0 -22
- package/dist/types/ast/table-ref.d.ts +0 -25
- package/dist/types/ast/unary-op.d.ts +0 -39
- package/dist/types/ast/verbatim.d.ts +0 -9
- package/dist/types/ast/window.d.ts +0 -180
- package/dist/types/constants.d.ts +0 -38
- package/dist/types/functions/aggregate.d.ts +0 -236
- package/dist/types/functions/cast.d.ts +0 -26
- package/dist/types/functions/column.d.ts +0 -11
- package/dist/types/functions/datetime.d.ts +0 -45
- package/dist/types/functions/numeric.d.ts +0 -95
- package/dist/types/functions/operators.d.ts +0 -200
- package/dist/types/functions/order-by.d.ts +0 -18
- package/dist/types/functions/spatial.d.ts +0 -38
- package/dist/types/functions/string.d.ts +0 -57
- package/dist/types/functions/table-ref.d.ts +0 -9
- package/dist/types/functions/util.d.ts +0 -8
- package/dist/types/index-types.d.ts +0 -2
- package/dist/types/index.d.ts +0 -59
- package/dist/types/load/create.d.ts +0 -8
- package/dist/types/load/extension.d.ts +0 -1
- package/dist/types/load/load.d.ts +0 -12
- package/dist/types/load/sql-from.d.ts +0 -11
- package/dist/types/transforms/bin-1d.d.ts +0 -15
- package/dist/types/transforms/bin-2d.d.ts +0 -19
- package/dist/types/transforms/bin-date.d.ts +0 -44
- package/dist/types/transforms/bin-histogram.d.ts +0 -51
- package/dist/types/transforms/bin-linear-1d.d.ts +0 -12
- package/dist/types/transforms/bin-linear-2d.d.ts +0 -19
- package/dist/types/transforms/line-density.d.ts +0 -24
- package/dist/types/transforms/m4.d.ts +0 -21
- package/dist/types/transforms/scales.d.ts +0 -1
- package/dist/types/transforms/util/bin-step.d.ts +0 -61
- package/dist/types/transforms/util/time-interval.d.ts +0 -13
- package/dist/types/util/function.d.ts +0 -56
- package/dist/types/util/string.d.ts +0 -3
- package/dist/types/util/type-check.d.ts +0 -22
- package/dist/types/visit/recurse.d.ts +0 -28
- package/dist/types/visit/rewrite.d.ts +0 -10
- package/dist/types/visit/walk.d.ts +0 -10
- package/jsconfig.json +0 -11
- package/src/ast/aggregate.js +0 -167
- package/src/ast/binary-op.js +0 -40
- package/src/ast/column-param.js +0 -40
- package/src/ast/fragment.js +0 -26
- package/src/ast/from.js +0 -40
- package/src/ast/logical-op.js +0 -67
- package/src/ast/node.js +0 -29
- package/src/ast/order-by.js +0 -48
- package/src/ast/sample.js +0 -53
- package/src/ast/window.js +0 -294
- package/src/functions/aggregate.js +0 -347
- package/src/functions/datetime.js +0 -68
- package/src/functions/numeric.js +0 -143
- package/src/functions/operators.js +0 -301
- package/src/functions/order-by.js +0 -27
- package/src/functions/spatial.js +0 -59
- package/src/functions/string.js +0 -85
- package/src/functions/util.js +0 -14
- package/src/index-types.ts +0 -2
- package/src/load/extension.js +0 -3
- package/src/transforms/bin-date.js +0 -37
- package/src/transforms/bin-histogram.js +0 -52
- package/src/transforms/util/bin-step.js +0 -79
- package/src/util/type-check.js +0 -33
- package/src/visit/walk.js +0 -35
- package/tsconfig.json +0 -12
- package/vitest.config.ts +0 -3
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { SAMPLE_CLAUSE } from '../constants.js';
|
|
2
|
+
import { SQLNode } from './node.js';
|
|
3
|
+
|
|
4
|
+
export type SampleMethod = 'reservoir' | 'bernoulli' | 'system';
|
|
5
|
+
|
|
6
|
+
export class SampleClauseNode extends SQLNode {
|
|
7
|
+
/** The sample size as either a row count or percentage. */
|
|
8
|
+
readonly size: number;
|
|
9
|
+
/** Flag if the sampling unit is rows (`false`) or percentage (`true`). */
|
|
10
|
+
readonly perc: boolean;
|
|
11
|
+
/** The sampling method. */
|
|
12
|
+
readonly method?: SampleMethod;
|
|
13
|
+
/** The random seed. */
|
|
14
|
+
readonly seed?: number;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Instantiate a sample clause node.
|
|
18
|
+
* @param size The sample size as either a row count or percentage.
|
|
19
|
+
* @param perc Flag indicating if the sampling unit is
|
|
20
|
+
* rows (`false`) or a percentage (`true`).
|
|
21
|
+
* @param method The sampling method. If unspecified,
|
|
22
|
+
* a default method is applied based on the sampling unit.
|
|
23
|
+
* @param seed The random seed.
|
|
24
|
+
*/
|
|
25
|
+
constructor(
|
|
26
|
+
size: number,
|
|
27
|
+
perc: boolean = false,
|
|
28
|
+
method?: SampleMethod,
|
|
29
|
+
seed?: number
|
|
30
|
+
) {
|
|
31
|
+
super(SAMPLE_CLAUSE);
|
|
32
|
+
this.size = size;
|
|
33
|
+
this.perc = perc;
|
|
34
|
+
this.method = method;
|
|
35
|
+
this.seed = seed;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Generate a SQL query string for this node.
|
|
40
|
+
*/
|
|
41
|
+
toString() {
|
|
42
|
+
const { size, perc, method, seed } = this;
|
|
43
|
+
const m = method ? `${method} ` : '';
|
|
44
|
+
const s = seed != null ? ` REPEATABLE (${seed})` : '';
|
|
45
|
+
return `${m}(${size}${perc ? '%' : ' ROWS'})${s}`;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -1,34 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
import type { ExprNode } from './node.js';
|
|
2
2
|
import { SELECT_CLAUSE } from '../constants.js';
|
|
3
3
|
import { quoteIdentifier } from '../util/string.js';
|
|
4
4
|
import { ColumnRefNode } from './column-ref.js';
|
|
5
5
|
import { SQLNode } from './node.js';
|
|
6
6
|
|
|
7
7
|
export class SelectClauseNode extends SQLNode {
|
|
8
|
+
/** The select expression. */
|
|
9
|
+
readonly expr: ExprNode;
|
|
10
|
+
/** The output name. */
|
|
11
|
+
readonly alias: string;
|
|
12
|
+
|
|
8
13
|
/**
|
|
9
14
|
* Instantiate a select node.
|
|
10
|
-
* @param
|
|
11
|
-
* @param
|
|
15
|
+
* @param expr The select expression.
|
|
16
|
+
* @param alias The output name.
|
|
12
17
|
*/
|
|
13
|
-
constructor(expr, alias) {
|
|
18
|
+
constructor(expr: ExprNode, alias: string) {
|
|
14
19
|
super(SELECT_CLAUSE);
|
|
15
|
-
/**
|
|
16
|
-
* The select expression.
|
|
17
|
-
* @type {ExprNode}
|
|
18
|
-
* @readonly
|
|
19
|
-
*/
|
|
20
20
|
this.expr = expr;
|
|
21
|
-
/**
|
|
22
|
-
* The output name.
|
|
23
|
-
* @type {string}
|
|
24
|
-
* @readonly
|
|
25
|
-
*/
|
|
26
21
|
this.alias = alias;
|
|
27
22
|
}
|
|
28
23
|
|
|
29
24
|
/**
|
|
30
25
|
* Generate a SQL query string for this node.
|
|
31
|
-
* @returns {string}
|
|
32
26
|
*/
|
|
33
27
|
toString() {
|
|
34
28
|
const { expr, alias } = this;
|
|
@@ -38,7 +32,7 @@ export class SelectClauseNode extends SQLNode {
|
|
|
38
32
|
}
|
|
39
33
|
}
|
|
40
34
|
|
|
41
|
-
function isColumnRefFor(expr, name) {
|
|
35
|
+
function isColumnRefFor(expr: unknown, name: string): expr is ColumnRefNode {
|
|
42
36
|
return expr instanceof ColumnRefNode
|
|
43
37
|
&& expr.table == null
|
|
44
38
|
&& expr.column === name;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Query } from './query.js';
|
|
2
|
+
import { SCALAR_SUBQUERY } from '../constants.js';
|
|
3
|
+
import { ExprNode } from './node.js';
|
|
4
|
+
|
|
5
|
+
export class ScalarSubqueryNode extends ExprNode {
|
|
6
|
+
/** The scalar subquery. */
|
|
7
|
+
readonly subquery: Query;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Instantiate a scalar subquery node.
|
|
11
|
+
* @param subquery The scalar subquery.
|
|
12
|
+
*/
|
|
13
|
+
constructor(subquery: Query) {
|
|
14
|
+
super(SCALAR_SUBQUERY);
|
|
15
|
+
this.subquery = subquery;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Generate a SQL query string for this node.
|
|
20
|
+
*/
|
|
21
|
+
toString() {
|
|
22
|
+
return `(${this.subquery})`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -4,31 +4,27 @@ import { ExprNode } from './node.js';
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Check if a value is a table reference node.
|
|
7
|
-
* @param
|
|
8
|
-
* @returns {value is TableRefNode}
|
|
7
|
+
* @param value The value to check.
|
|
9
8
|
*/
|
|
10
|
-
export function isTableRef(value) {
|
|
9
|
+
export function isTableRef(value: unknown): value is TableRefNode {
|
|
11
10
|
return value instanceof TableRefNode;
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
export class TableRefNode extends ExprNode {
|
|
14
|
+
/** The table name, including namespaces. */
|
|
15
|
+
readonly table: string[];
|
|
16
|
+
|
|
15
17
|
/**
|
|
16
18
|
* Instantiate a table reference node.
|
|
17
|
-
* @param
|
|
19
|
+
* @param table The table name.
|
|
18
20
|
*/
|
|
19
|
-
constructor(table) {
|
|
21
|
+
constructor(table: string | string[]) {
|
|
20
22
|
super(TABLE_REF);
|
|
21
|
-
/**
|
|
22
|
-
* The table name, including namespaces.
|
|
23
|
-
* @type {string[]}
|
|
24
|
-
* @readonly
|
|
25
|
-
*/
|
|
26
23
|
this.table = [table].flat();
|
|
27
24
|
}
|
|
28
25
|
|
|
29
26
|
/**
|
|
30
27
|
* The table name without database or schema namespaces.
|
|
31
|
-
* @returns {string}
|
|
32
28
|
*/
|
|
33
29
|
get name() {
|
|
34
30
|
return this.table[this.table.length - 1];
|
|
@@ -36,7 +32,6 @@ export class TableRefNode extends ExprNode {
|
|
|
36
32
|
|
|
37
33
|
/**
|
|
38
34
|
* Generate a SQL query string for this node.
|
|
39
|
-
* @returns {string}
|
|
40
35
|
*/
|
|
41
36
|
toString() {
|
|
42
37
|
return this.table.map(t => quoteIdentifier(t)).join('.');
|
|
@@ -2,25 +2,20 @@ import { UNARY_OPERATOR, UNARY_POSTFIX_OPERATOR } from '../constants.js';
|
|
|
2
2
|
import { ExprNode } from './node.js';
|
|
3
3
|
|
|
4
4
|
class AbstractUnaryOpNode extends ExprNode {
|
|
5
|
+
/** The operator type. */
|
|
6
|
+
readonly op: string;
|
|
7
|
+
/** The input expression. */
|
|
8
|
+
readonly expr: ExprNode;
|
|
9
|
+
|
|
5
10
|
/**
|
|
6
11
|
* Instantiate an abstract unary operator node.
|
|
7
|
-
* @param
|
|
8
|
-
* @param
|
|
9
|
-
* @param
|
|
12
|
+
* @param type The node type.
|
|
13
|
+
* @param op The operator type.
|
|
14
|
+
* @param expr The input expression.
|
|
10
15
|
*/
|
|
11
|
-
constructor(type, op, expr) {
|
|
16
|
+
constructor(type: string, op: string, expr: ExprNode) {
|
|
12
17
|
super(type);
|
|
13
|
-
/**
|
|
14
|
-
* The operator type.
|
|
15
|
-
* @type {string}
|
|
16
|
-
* @readonly
|
|
17
|
-
*/
|
|
18
18
|
this.op = op;
|
|
19
|
-
/**
|
|
20
|
-
* The input expression.
|
|
21
|
-
* @type {ExprNode}
|
|
22
|
-
* @readonly
|
|
23
|
-
*/
|
|
24
19
|
this.expr = expr;
|
|
25
20
|
}
|
|
26
21
|
}
|
|
@@ -28,35 +23,33 @@ class AbstractUnaryOpNode extends ExprNode {
|
|
|
28
23
|
export class UnaryOpNode extends AbstractUnaryOpNode {
|
|
29
24
|
/**
|
|
30
25
|
* Instantiate a unary operator node.
|
|
31
|
-
* @param
|
|
32
|
-
* @param
|
|
26
|
+
* @param op The operator type.
|
|
27
|
+
* @param expr The input expression.
|
|
33
28
|
*/
|
|
34
|
-
constructor(op, expr) {
|
|
29
|
+
constructor(op: string, expr: ExprNode) {
|
|
35
30
|
super(UNARY_OPERATOR, op, expr);
|
|
36
31
|
}
|
|
37
32
|
|
|
38
33
|
/**
|
|
39
34
|
* Generate a SQL query string for this node.
|
|
40
|
-
* @returns {string}
|
|
41
35
|
*/
|
|
42
36
|
toString() {
|
|
43
37
|
return `(${this.op} ${this.expr})`;
|
|
44
38
|
}
|
|
45
39
|
}
|
|
46
40
|
|
|
47
|
-
export class
|
|
41
|
+
export class UnaryPostfixOpNode extends AbstractUnaryOpNode {
|
|
48
42
|
/**
|
|
49
43
|
* Instantiate a unary operator node.
|
|
50
|
-
* @param
|
|
51
|
-
* @param
|
|
44
|
+
* @param op The operator type.
|
|
45
|
+
* @param expr The input expression.
|
|
52
46
|
*/
|
|
53
|
-
constructor(op, expr) {
|
|
47
|
+
constructor(op: string, expr: ExprNode) {
|
|
54
48
|
super(UNARY_POSTFIX_OPERATOR, op, expr);
|
|
55
49
|
}
|
|
56
50
|
|
|
57
51
|
/**
|
|
58
52
|
* Generate a SQL query string for this node.
|
|
59
|
-
* @returns {string}
|
|
60
53
|
*/
|
|
61
54
|
toString() {
|
|
62
55
|
return `(${this.expr} ${this.op})`;
|
|
@@ -2,23 +2,24 @@ import { VERBATIM } from '../constants.js';
|
|
|
2
2
|
import { ExprNode } from './node.js';
|
|
3
3
|
|
|
4
4
|
export class VerbatimNode extends ExprNode {
|
|
5
|
+
/** The verbatim content to include. */
|
|
6
|
+
readonly value: string;
|
|
7
|
+
/** A type hint for analyzing verbatim content. */
|
|
8
|
+
readonly hint?: string;
|
|
9
|
+
|
|
5
10
|
/**
|
|
6
11
|
* Instantiate a raw node with verbatim content.
|
|
7
|
-
* @param
|
|
12
|
+
* @param value The verbatim content to include.
|
|
13
|
+
* @param hint A type hint for analyzing verbatim content.
|
|
8
14
|
*/
|
|
9
|
-
constructor(value) {
|
|
15
|
+
constructor(value: string, hint?: string) {
|
|
10
16
|
super(VERBATIM);
|
|
11
|
-
/**
|
|
12
|
-
* The verbatim content to include.
|
|
13
|
-
* @type {string}
|
|
14
|
-
* @readonly
|
|
15
|
-
*/
|
|
16
17
|
this.value = value;
|
|
18
|
+
this.hint = hint;
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
/**
|
|
20
22
|
* Generate a SQL query string for this node.
|
|
21
|
-
* @returns {string}
|
|
22
23
|
*/
|
|
23
24
|
toString() {
|
|
24
25
|
return this.value;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { WINDOW_EXTENT_EXPR, WINDOW_FRAME } from '../constants.js';
|
|
2
|
+
import { type ParamLike } from '../types.js';
|
|
3
|
+
import { isParamLike } from '../util/type-check.js';
|
|
4
|
+
import { type ExprNode, isNode, SQLNode } from './node.js';
|
|
5
|
+
import { ParamNode } from './param.js';
|
|
6
|
+
|
|
7
|
+
export type FrameValue = ExprNode | number | null;
|
|
8
|
+
export type FrameExtent = [FrameValue, FrameValue] | ParamLike;
|
|
9
|
+
export type FrameScope = 'PRECEDING' | 'FOLLOWING' | 'CURRENT ROW';
|
|
10
|
+
export type FrameType = 'ROWS' | 'RANGE' | 'GROUPS';
|
|
11
|
+
export type FrameExclude = 'NO OTHERS' | 'CURRENT ROW' | 'TIES' | 'GROUP';
|
|
12
|
+
|
|
13
|
+
export const ROWS = 'ROWS';
|
|
14
|
+
export const RANGE = 'RANGE';
|
|
15
|
+
export const GROUPS = 'GROUPS';
|
|
16
|
+
export const PRECEDING = 'PRECEDING';
|
|
17
|
+
export const FOLLOWING = 'FOLLOWING';
|
|
18
|
+
export const CURRENT_ROW = 'CURRENT ROW';
|
|
19
|
+
export const UNBOUNDED = 'UNBOUNDED';
|
|
20
|
+
|
|
21
|
+
export class WindowFrameNode extends SQLNode {
|
|
22
|
+
/** The frame type, one of ROWS, RANGE, or GROUPS. */
|
|
23
|
+
readonly frameType: FrameType;
|
|
24
|
+
/** The window frame extent. */
|
|
25
|
+
readonly extent: [unknown, unknown] | ParamNode;
|
|
26
|
+
/** The window frame exclusion criteria. */
|
|
27
|
+
readonly exclude?: FrameExclude;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Instantiate a window frame definition node.
|
|
31
|
+
* @param frameType The frame type, one of ROWS, RANGE, or GROUPS.
|
|
32
|
+
* @param extent The window frame extent.
|
|
33
|
+
* @param exclude The window frame exclusion criteria.
|
|
34
|
+
*/
|
|
35
|
+
constructor(
|
|
36
|
+
frameType: FrameType,
|
|
37
|
+
extent: FrameExtent,
|
|
38
|
+
exclude?: FrameExclude
|
|
39
|
+
) {
|
|
40
|
+
super(WINDOW_FRAME);
|
|
41
|
+
this.frameType = frameType;
|
|
42
|
+
this.extent = isParamLike(extent) ? new ParamNode(extent) : extent;
|
|
43
|
+
this.exclude = exclude;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Generate a SQL query string for this node.
|
|
48
|
+
*/
|
|
49
|
+
toString() {
|
|
50
|
+
const { frameType, exclude, extent } = this;
|
|
51
|
+
const [prev, next] = isNode(extent)
|
|
52
|
+
? extent.value as [unknown, unknown]
|
|
53
|
+
: extent;
|
|
54
|
+
const a = asFrameExpr(prev, PRECEDING);
|
|
55
|
+
const b = asFrameExpr(next, FOLLOWING);
|
|
56
|
+
return `${frameType} BETWEEN ${a} AND ${b}${exclude ? ` ${exclude}` : ''}`;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function asFrameExpr(value: unknown, scope: string) {
|
|
61
|
+
return value instanceof WindowFrameExprNode ? value
|
|
62
|
+
: value != null && typeof value !== 'number' ? `${value} ${scope}`
|
|
63
|
+
: value === 0 ? CURRENT_ROW
|
|
64
|
+
: !(value && Number.isFinite(value)) ? `${UNBOUNDED} ${scope}`
|
|
65
|
+
: `${Math.abs(value)} ${scope}`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export class WindowFrameExprNode extends SQLNode {
|
|
69
|
+
/** The window frame extent. */
|
|
70
|
+
readonly scope: FrameScope;
|
|
71
|
+
/**
|
|
72
|
+
* The window frame extent expression. This value should be null
|
|
73
|
+
* in the case of current row or unbounded extent values.
|
|
74
|
+
*/
|
|
75
|
+
readonly expr: FrameValue | null;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Instantiate a window frame definition node.
|
|
79
|
+
* @param scope The frame scope, one of PRECEDING, FOLLOWING, or CURRENT ROW.
|
|
80
|
+
* @param expr The window frame extent expression.
|
|
81
|
+
*/
|
|
82
|
+
constructor(scope: FrameScope, expr: FrameValue | null = null) {
|
|
83
|
+
super(WINDOW_EXTENT_EXPR);
|
|
84
|
+
this.scope = scope;
|
|
85
|
+
this.expr = expr;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Generate a SQL query string for this node.
|
|
90
|
+
*/
|
|
91
|
+
toString() {
|
|
92
|
+
const { scope, expr } = this;
|
|
93
|
+
return scope === CURRENT_ROW
|
|
94
|
+
? scope
|
|
95
|
+
: `${expr ?? UNBOUNDED} ${scope}`;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import type { ExprVarArgs, OrderByExpr, WindowFunctionName } from '../types.js';
|
|
2
|
+
import type { AggregateNode } from './aggregate.js';
|
|
3
|
+
import type { WindowFrameNode } from './window-frame.js';
|
|
4
|
+
import { WINDOW, WINDOW_CLAUSE, WINDOW_DEF, WINDOW_FUNCTION } from '../constants.js';
|
|
5
|
+
import { nodeList } from '../util/function.js';
|
|
6
|
+
import { quoteIdentifier } from '../util/string.js';
|
|
7
|
+
import { ExprNode, SQLNode } from './node.js';
|
|
8
|
+
|
|
9
|
+
export class WindowClauseNode extends SQLNode {
|
|
10
|
+
/** The window name. */
|
|
11
|
+
readonly name: string;
|
|
12
|
+
/** The window definition. */
|
|
13
|
+
readonly def: WindowDefNode;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Instantiate a window clause node.
|
|
17
|
+
* @param name The window name.
|
|
18
|
+
* @param def The window definition.
|
|
19
|
+
*/
|
|
20
|
+
constructor(name: string, def: WindowDefNode) {
|
|
21
|
+
super(WINDOW_CLAUSE);
|
|
22
|
+
this.name = name;
|
|
23
|
+
this.def = def;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Generate a SQL query string for this node.
|
|
28
|
+
*/
|
|
29
|
+
toString() {
|
|
30
|
+
return `${quoteIdentifier(this.name)} AS ${this.def}`;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class WindowNode extends ExprNode {
|
|
35
|
+
readonly func: WindowFunctionNode | AggregateNode;
|
|
36
|
+
readonly def: WindowDefNode
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Instantiate a window node.
|
|
40
|
+
* @param func The window function call.
|
|
41
|
+
* @param over The window definition or name.
|
|
42
|
+
*/
|
|
43
|
+
constructor(
|
|
44
|
+
func: WindowFunctionNode | AggregateNode,
|
|
45
|
+
over: WindowDefNode = new WindowDefNode()
|
|
46
|
+
) {
|
|
47
|
+
super(WINDOW);
|
|
48
|
+
this.func = func;
|
|
49
|
+
this.def = over;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Return an updated window over a named window definition.
|
|
54
|
+
* @param name The window definition name.
|
|
55
|
+
* @returns A new window node.
|
|
56
|
+
*/
|
|
57
|
+
over(name: string) {
|
|
58
|
+
return new WindowNode(this.func, this.def.over(name));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Return an updated window with the given partitions.
|
|
63
|
+
* @param expr The partition by criteria.
|
|
64
|
+
* @returns A new window node.
|
|
65
|
+
*/
|
|
66
|
+
partitionby(...expr: ExprVarArgs[]) {
|
|
67
|
+
return new WindowNode(this.func, this.def.partitionby(...expr));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Return an updated window with the given ordering.
|
|
72
|
+
* @param expr The order by criteria.
|
|
73
|
+
* @returns A new window node.
|
|
74
|
+
*/
|
|
75
|
+
orderby(...expr: ExprVarArgs[]) {
|
|
76
|
+
return new WindowNode(this.func, this.def.orderby(...expr));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Return an updated window with the given frame definition.
|
|
81
|
+
* @param framedef The frame definition.
|
|
82
|
+
* @returns A new window node.
|
|
83
|
+
*/
|
|
84
|
+
frame(framedef: WindowFrameNode) {
|
|
85
|
+
return new WindowNode(this.func, this.def.frame(framedef));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Generate a SQL query string for this node.
|
|
90
|
+
*/
|
|
91
|
+
toString() {
|
|
92
|
+
return `${this.func} OVER ${this.def}`;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export class WindowFunctionNode extends ExprNode {
|
|
97
|
+
/** The window function name. */
|
|
98
|
+
readonly name: string;
|
|
99
|
+
/** The window function arguments. */
|
|
100
|
+
readonly args: ExprNode[];
|
|
101
|
+
/** Flag to ignore null values. */
|
|
102
|
+
readonly ignoreNulls: boolean;
|
|
103
|
+
/** Order by expression for window arguments. */
|
|
104
|
+
readonly order: ExprNode[];
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Instantiate a window function call node.
|
|
108
|
+
* @param name The window function name.
|
|
109
|
+
* @param args The window function arguments.
|
|
110
|
+
* @param ignoreNulls Flag to ignore null values.
|
|
111
|
+
* @param argOrder Order expressions for window arguments.
|
|
112
|
+
* Note that this argument ordering is distinct from the window ordering.
|
|
113
|
+
*/
|
|
114
|
+
constructor(
|
|
115
|
+
name: WindowFunctionName,
|
|
116
|
+
args: ExprNode[] = [],
|
|
117
|
+
ignoreNulls: boolean = false,
|
|
118
|
+
argOrder: OrderByExpr = []
|
|
119
|
+
) {
|
|
120
|
+
super(WINDOW_FUNCTION);
|
|
121
|
+
this.name = name;
|
|
122
|
+
this.args = args;
|
|
123
|
+
this.ignoreNulls = ignoreNulls;
|
|
124
|
+
this.order = nodeList([argOrder]);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Generate a SQL query string for this node.
|
|
129
|
+
*/
|
|
130
|
+
toString() {
|
|
131
|
+
const { name, args, ignoreNulls, order } = this;
|
|
132
|
+
const arg = [
|
|
133
|
+
args.join(', '),
|
|
134
|
+
order.length ? `ORDER BY ${order.join(', ')}` : '',
|
|
135
|
+
ignoreNulls ? 'IGNORE NULLS' : ''
|
|
136
|
+
].filter(x => x).join(' ');
|
|
137
|
+
return `${name}(${arg})`;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export class WindowDefNode extends SQLNode {
|
|
142
|
+
/** The base window definition name. */
|
|
143
|
+
readonly name?: string;
|
|
144
|
+
/** The partition by criteria. */
|
|
145
|
+
readonly partition?: ExprNode[];
|
|
146
|
+
/** The order by criteria. */
|
|
147
|
+
readonly order?: ExprNode[];
|
|
148
|
+
/** The window frame definition. */
|
|
149
|
+
readonly framedef?: WindowFrameNode;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Instantiate a window definition node.
|
|
153
|
+
* @param name The base window definition name.
|
|
154
|
+
* @param partition The partition by criteria.
|
|
155
|
+
* @param order The order by criteria.
|
|
156
|
+
* @param framedef The window frame definition.
|
|
157
|
+
*/
|
|
158
|
+
constructor(
|
|
159
|
+
name?: string,
|
|
160
|
+
partition?: ExprNode[],
|
|
161
|
+
order?: ExprNode[],
|
|
162
|
+
framedef?: WindowFrameNode
|
|
163
|
+
) {
|
|
164
|
+
super(WINDOW_DEF);
|
|
165
|
+
this.name = name;
|
|
166
|
+
this.partition = partition;
|
|
167
|
+
this.order = order;
|
|
168
|
+
this.framedef = framedef;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Return an updated window definition with the given base name.
|
|
173
|
+
* @param name The base window definition name.
|
|
174
|
+
* @returns A new window definition node.
|
|
175
|
+
*/
|
|
176
|
+
over(name: string) {
|
|
177
|
+
return deriveDef(this, { name });
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Return an updated window definition with the given partitions.
|
|
182
|
+
* @param expr The partition by criteria.
|
|
183
|
+
* @returns A new window definition node.
|
|
184
|
+
*/
|
|
185
|
+
partitionby(...expr: ExprVarArgs[]) {
|
|
186
|
+
return deriveDef(this, { partition: nodeList(expr) });
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Return an updated window definition with the given ordering.
|
|
191
|
+
* @param expr The order by criteria.
|
|
192
|
+
* @returns A new window definition node.
|
|
193
|
+
*/
|
|
194
|
+
orderby(...expr: ExprVarArgs[]) {
|
|
195
|
+
return deriveDef(this, { order: nodeList(expr) });
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Return an updated window definition with the given frame definition.
|
|
200
|
+
* @param framedef The frame definition.
|
|
201
|
+
* @return A new window definition node.
|
|
202
|
+
*/
|
|
203
|
+
frame(framedef: WindowFrameNode) {
|
|
204
|
+
return deriveDef(this, { framedef });
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Generate a SQL query string for this node.
|
|
209
|
+
*/
|
|
210
|
+
toString() {
|
|
211
|
+
const { name, partition, order, framedef } = this;
|
|
212
|
+
const base = name && quoteIdentifier(name);
|
|
213
|
+
const def = [
|
|
214
|
+
base,
|
|
215
|
+
partition?.length && `PARTITION BY ${partition.join(', ')}`,
|
|
216
|
+
order?.length && `ORDER BY ${order.join(', ')}`,
|
|
217
|
+
framedef
|
|
218
|
+
].filter(x => x);
|
|
219
|
+
return base && def.length < 2 ? base : `(${def.join(' ')})`;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
interface DeriveDefOptions {
|
|
224
|
+
/** The base window definition name. */
|
|
225
|
+
name?: string;
|
|
226
|
+
/** The partition by criteria. */
|
|
227
|
+
partition?: ExprNode[];
|
|
228
|
+
/** The order by criteria. */
|
|
229
|
+
order?: ExprNode[];
|
|
230
|
+
/** The window frame definition. */
|
|
231
|
+
framedef?: WindowFrameNode;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Derive a new window definition node from an existing one.
|
|
236
|
+
* @param def The existing window definition.
|
|
237
|
+
* @param options An options object with new definition properties.
|
|
238
|
+
*/
|
|
239
|
+
function deriveDef(def: WindowDefNode, options: DeriveDefOptions) {
|
|
240
|
+
return new WindowDefNode(
|
|
241
|
+
options.name ?? def.name,
|
|
242
|
+
options.partition ?? def.partition,
|
|
243
|
+
options.order ?? def.order,
|
|
244
|
+
options.framedef ?? def.framedef
|
|
245
|
+
);
|
|
246
|
+
}
|
|
@@ -1,39 +1,38 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Query } from './query.js';
|
|
2
2
|
import { WITH_CLAUSE } from '../constants.js';
|
|
3
3
|
import { SQLNode } from './node.js';
|
|
4
4
|
|
|
5
5
|
export class WithClauseNode extends SQLNode {
|
|
6
|
+
/** The common table expression (CTE) name. */
|
|
7
|
+
readonly name: string;
|
|
8
|
+
/** The common table expression (CTE) query. */
|
|
9
|
+
readonly query: Query;
|
|
10
|
+
/** The common table expression (CTE) materialization flag. */
|
|
11
|
+
readonly materialized: boolean | null;
|
|
12
|
+
|
|
6
13
|
/**
|
|
7
14
|
* Instantiate a with clause node for a common table expression (CTE).
|
|
8
|
-
* @param
|
|
9
|
-
* @param
|
|
10
|
-
* @param
|
|
15
|
+
* @param name The common table expression (CTE) name.
|
|
16
|
+
* @param query The common table expression (CTE) query.
|
|
17
|
+
* @param materialized The common table expression (CTE)
|
|
11
18
|
* materialization flag. If `true`, forces materialization of the CTE.
|
|
12
19
|
* If `false`, materialization is not performed. Otherwise (for example, if
|
|
13
20
|
* `undefined` or `null`), materialization is decided by the database.
|
|
14
21
|
*/
|
|
15
|
-
constructor(
|
|
22
|
+
constructor(
|
|
23
|
+
name: string,
|
|
24
|
+
query: Query,
|
|
25
|
+
materialized: boolean | null = null
|
|
26
|
+
) {
|
|
16
27
|
super(WITH_CLAUSE);
|
|
17
|
-
/**
|
|
18
|
-
* The common table expression (CTE) name.
|
|
19
|
-
* @type {string}
|
|
20
|
-
* @readonly
|
|
21
|
-
*/
|
|
22
28
|
this.name = name;
|
|
23
|
-
/**
|
|
24
|
-
* The common table expression (CTE) query.
|
|
25
|
-
* @type {Query}
|
|
26
|
-
* @readonly
|
|
27
|
-
*/
|
|
28
29
|
this.query = query;
|
|
29
|
-
/**
|
|
30
|
-
* The common table expression (CTE) materialization flag.
|
|
31
|
-
* @type {boolean | null}
|
|
32
|
-
* @readonly
|
|
33
|
-
*/
|
|
34
30
|
this.materialized = materialized;
|
|
35
31
|
}
|
|
36
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Generate a SQL query string for this node.
|
|
35
|
+
*/
|
|
37
36
|
toString() {
|
|
38
37
|
const flag = this.materialized;
|
|
39
38
|
const mat = flag === true ? ' MATERIALIZED'
|