@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
package/src/util/ast.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { ColumnRefNode } from '../ast/column-ref.js';
|
|
2
|
+
import type { TableRefNode } from '../ast/table-ref.js';
|
|
3
|
+
import { ExprNode, type SQLNode } from '../ast/node.js';
|
|
4
|
+
import { ParamNode } from '../ast/param.js';
|
|
5
|
+
import { WindowDefNode } from '../ast/window.js';
|
|
6
|
+
import { column } from '../functions/column.js';
|
|
7
|
+
import { literal, verbatim } from '../functions/literal.js';
|
|
8
|
+
import { tableRef } from '../functions/table-ref.js';
|
|
9
|
+
import { parseIdentifier } from './string.js';
|
|
10
|
+
import { isArray, isParamLike, isString } from './type-check.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Interpret a value as a SQL AST node. String values are assumed to be
|
|
14
|
+
* column references. All other primitive values are interpreted as
|
|
15
|
+
* SQL literals. Dynamic parameters are interpreted as param AST nodes,
|
|
16
|
+
* while existing AST nodes are left as-is.
|
|
17
|
+
* @param value The value to interpret as a SQL AST node.
|
|
18
|
+
*/
|
|
19
|
+
export function asNode(value: unknown): ExprNode {
|
|
20
|
+
return isString(value)
|
|
21
|
+
? parseColumnRef(value)
|
|
22
|
+
: asLiteral(value);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Interpret a value as a verbatim SQL AST node. String values will be
|
|
27
|
+
* passed through to queries as verbatim text. All other primitive values
|
|
28
|
+
* are interpreted as SQL literals. Dynamic parameters are interpreted
|
|
29
|
+
* as param AST nodes, while existing AST nodes are left as-is.
|
|
30
|
+
* @param value The value to interpret as a verbatim AST node.
|
|
31
|
+
*/
|
|
32
|
+
export function asVerbatim(value: unknown): ExprNode {
|
|
33
|
+
return isString(value)
|
|
34
|
+
? verbatim(value)
|
|
35
|
+
: asLiteral(value);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Interpret a value as a literal AST node. All other primitive values
|
|
40
|
+
* are interpreted as SQL literals. Dynamic parameters are interpreted
|
|
41
|
+
* as param AST nodes, while existing AST nodes are left as-is.
|
|
42
|
+
* @param value The value to interpret as a literal AST node.
|
|
43
|
+
*/
|
|
44
|
+
export function asLiteral(value: unknown): ExprNode {
|
|
45
|
+
return value instanceof ExprNode ? value
|
|
46
|
+
: isParamLike(value) ? new ParamNode(value)
|
|
47
|
+
: literal(value);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Interpret a value as a table reference AST node. String values are parsed
|
|
52
|
+
* assuming dot ('.') delimiters (as in `schema.table`). Array values are
|
|
53
|
+
* interpreted as pre-parsed name paths (as in `['schema', 'table']`). Any
|
|
54
|
+
* other values are left as-is.
|
|
55
|
+
* @param value The value to interpret as a table reference AST node.
|
|
56
|
+
*/
|
|
57
|
+
export function asTableRef(value?: string | string[] | TableRefNode): TableRefNode | undefined {
|
|
58
|
+
return getTableRef(value);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Try to interpret a value as a table reference AST node. String values are
|
|
63
|
+
* parsed assuming dot ('.') delimiters (as in `schema.table`). Array values
|
|
64
|
+
* are interpreted as pre-parsed name paths (as in `['schema', 'table']`). Any
|
|
65
|
+
* other values are left as-is.
|
|
66
|
+
* @param value The value to interpret as a table reference.
|
|
67
|
+
*/
|
|
68
|
+
export function maybeTableRef(value: string | string[] | SQLNode): SQLNode {
|
|
69
|
+
return getTableRef(value)!;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function getTableRef<T>(value?: string | string[] | T): TableRefNode | T | undefined {
|
|
73
|
+
return isString(value) ? parseTableRef(value)
|
|
74
|
+
: isArray(value) ? tableRef(value)!
|
|
75
|
+
: value;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Parse a string as a column reference, potentially with
|
|
80
|
+
* dot ('.') delimited table, schema, and database references.
|
|
81
|
+
* @param ref The column reference string.
|
|
82
|
+
*/
|
|
83
|
+
export function parseColumnRef(ref: string): ColumnRefNode {
|
|
84
|
+
const ids = parseIdentifier(ref);
|
|
85
|
+
return column(ids.pop()!, tableRef(ids));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Parse a string as a table reference, potentially with
|
|
90
|
+
* dot ('.') delimited schema and database references.
|
|
91
|
+
* @param ref The table reference string.
|
|
92
|
+
*/
|
|
93
|
+
export function parseTableRef(ref: string): TableRefNode {
|
|
94
|
+
return tableRef(parseIdentifier(ref))!;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Create a new window definition node. The return value is an empty
|
|
99
|
+
* window definition. Use chained calls such as `partitionby` and `orderby`
|
|
100
|
+
* to specify the window settings.
|
|
101
|
+
*/
|
|
102
|
+
export function over() {
|
|
103
|
+
return new WindowDefNode();
|
|
104
|
+
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* @import { WindowFunctionName } from '../types.js'
|
|
4
|
-
*/
|
|
1
|
+
import type { ExprNode, SQLNode } from '../ast/node.js';
|
|
2
|
+
import type { WindowFunctionName } from '../types.js';
|
|
5
3
|
import { AggregateNode } from '../ast/aggregate.js';
|
|
6
4
|
import { FunctionNode } from '../ast/function.js';
|
|
7
5
|
import { WindowFunctionNode, WindowNode } from '../ast/window.js';
|
|
@@ -9,31 +7,31 @@ import { asNode } from './ast.js';
|
|
|
9
7
|
|
|
10
8
|
/**
|
|
11
9
|
* Test if an AST node is a specific function call.
|
|
12
|
-
* @param
|
|
13
|
-
* @param
|
|
14
|
-
* @returns {node is FunctionNode}
|
|
10
|
+
* @param node The SQL AST node to test.
|
|
11
|
+
* @param name The function name.
|
|
15
12
|
*/
|
|
16
|
-
export function isFunctionCall(
|
|
13
|
+
export function isFunctionCall(
|
|
14
|
+
node: SQLNode,
|
|
15
|
+
name: string
|
|
16
|
+
): node is FunctionNode {
|
|
17
17
|
return node instanceof FunctionNode && node.name === name;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Create a new function call AST node.
|
|
22
|
-
* @param
|
|
23
|
-
* @param
|
|
24
|
-
* @returns {FunctionNode}
|
|
22
|
+
* @param name The function name.
|
|
23
|
+
* @param args The function arguments.
|
|
25
24
|
*/
|
|
26
|
-
export function fn(name, ...args) {
|
|
25
|
+
export function fn(name: string, ...args: unknown[]): FunctionNode {
|
|
27
26
|
return new FunctionNode(name, argsList(args).map(asNode));
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
/**
|
|
31
30
|
* Create a new aggregate function AST node.
|
|
32
|
-
* @param
|
|
33
|
-
* @param
|
|
34
|
-
* @returns {AggregateNode}
|
|
31
|
+
* @param name The function name.
|
|
32
|
+
* @param args The function arguments.
|
|
35
33
|
*/
|
|
36
|
-
export function aggFn(name, ...args) {
|
|
34
|
+
export function aggFn(name: string, ...args: unknown[]): AggregateNode {
|
|
37
35
|
return new AggregateNode(name, argsList(args).map(asNode));
|
|
38
36
|
}
|
|
39
37
|
|
|
@@ -41,40 +39,51 @@ export function aggFn(name, ...args) {
|
|
|
41
39
|
* Create a new window AST node. The output node has an empty window
|
|
42
40
|
* definition. Use chained calls such as `partitionby` and `orderby`
|
|
43
41
|
* to specify the window settings.
|
|
44
|
-
* @param
|
|
45
|
-
* @param
|
|
46
|
-
* @returns {WindowNode}
|
|
42
|
+
* @param name The function name.
|
|
43
|
+
* @param args The function arguments.
|
|
47
44
|
*/
|
|
48
|
-
export function winFn(
|
|
45
|
+
export function winFn(
|
|
46
|
+
name: WindowFunctionName,
|
|
47
|
+
...args: unknown[]
|
|
48
|
+
): WindowNode {
|
|
49
49
|
return new WindowNode(
|
|
50
50
|
new WindowFunctionNode(name, argsList(args).map(asNode))
|
|
51
51
|
);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Process a list of expression inputs. Nested arrays are flattened,
|
|
56
|
+
* null results are removed, and each input is cast to a SQL AST node.
|
|
57
|
+
* @param list The list of expression inputs.
|
|
58
|
+
* @param cast A function that casts an input value
|
|
59
|
+
* to a desired type. By default, `asNode` is used to coerce
|
|
60
|
+
* inputs to AST nodes as needed.
|
|
61
|
+
*/
|
|
62
|
+
export function exprList<T>(
|
|
63
|
+
list: unknown[],
|
|
64
|
+
cast: ((x: unknown) => T)
|
|
65
|
+
): T[] {
|
|
66
|
+
return list.flat().filter(x => x != null).map(x => cast(x));
|
|
67
|
+
}
|
|
68
|
+
|
|
54
69
|
/**
|
|
55
70
|
* Process a list of expression inputs. Nested arrays are flattened,
|
|
56
71
|
* null results are removed, and each input is cast (as needed) to
|
|
57
72
|
* be a proper SQL AST node. By default, strings are assumed to be
|
|
58
73
|
* column names, while other primitive values map to SQL literals.
|
|
59
74
|
* Use an alternative *cast* function to change this behavior.
|
|
60
|
-
* @param
|
|
61
|
-
* @param {function} [cast] A function that casts an input value
|
|
62
|
-
* to a desired type. By default, `asNode` is used to coerce
|
|
63
|
-
* inputs to AST nodes as needed.
|
|
64
|
-
* @returns {ReturnType<cast>[]}
|
|
75
|
+
* @param list The list of expression inputs.
|
|
65
76
|
*/
|
|
66
|
-
export function
|
|
67
|
-
return list
|
|
77
|
+
export function nodeList(list: unknown[]): ExprNode[] {
|
|
78
|
+
return exprList(list, asNode);
|
|
68
79
|
}
|
|
69
80
|
|
|
70
81
|
/**
|
|
71
82
|
* Process a list of function arguments, stripping any undefined
|
|
72
83
|
* values from the end of the list.
|
|
73
|
-
* @
|
|
74
|
-
* @param {T[]} list The input function arguments.
|
|
75
|
-
* @returns {T[]} The prepared argument list.
|
|
84
|
+
* @param list The input function arguments.
|
|
76
85
|
*/
|
|
77
|
-
export function argsList(list) {
|
|
86
|
+
export function argsList<T>(list: T[]): T[] {
|
|
78
87
|
const n = list.length;
|
|
79
88
|
let i = n;
|
|
80
89
|
for (; i > 0 && list[i - 1] === undefined; --i);
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
// TODO: handle case where identifiers are already quoted?
|
|
2
|
-
export function parseIdentifier(id) {
|
|
2
|
+
export function parseIdentifier(id: string) {
|
|
3
3
|
return id.split('.');
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
export function quoteIdentifier(value) {
|
|
6
|
+
export function quoteIdentifier(value: unknown) {
|
|
7
7
|
return `"${value}"`;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export function unquote(s) {
|
|
10
|
+
export function unquote(s?: string) {
|
|
11
11
|
return s && isDoubleQuoted(s) ? s.slice(1, -1) : s;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
function isDoubleQuoted(s) {
|
|
14
|
+
function isDoubleQuoted(s: string) {
|
|
15
15
|
return s[0] === '"' && s[s.length-1] === '"';
|
|
16
16
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ParamLike } from '../types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Check if a value is a string.
|
|
5
|
+
* @param value The value to check.
|
|
6
|
+
*/
|
|
7
|
+
export function isString(value: unknown): value is string {
|
|
8
|
+
return typeof value === 'string';
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Check if a value is an array.
|
|
13
|
+
* @param value The value to check.
|
|
14
|
+
*/
|
|
15
|
+
export function isArray(value: unknown): value is Array<unknown> {
|
|
16
|
+
return Array.isArray(value);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Check if a value is a dynamic parameter.
|
|
21
|
+
* @param value The value to check.
|
|
22
|
+
*/
|
|
23
|
+
export function isParamLike(value: unknown): value is ParamLike {
|
|
24
|
+
if (value) {
|
|
25
|
+
const v = value as Record<string,unknown>;
|
|
26
|
+
return typeof v?.addEventListener === 'function'
|
|
27
|
+
&& v.dynamic !== false
|
|
28
|
+
&& 'value' in v;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { isNode } from '../ast/node.js';
|
|
2
|
+
import { recurse } from './recurse.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Create a deep clone of the given SQL AST node and all children nodes.
|
|
6
|
+
* @param node The node to deeply clone.
|
|
7
|
+
* @returns The cloned node.
|
|
8
|
+
*/
|
|
9
|
+
export function deepClone<T>(node: T): T {
|
|
10
|
+
const clone = shallowClone(node);
|
|
11
|
+
|
|
12
|
+
if (isNode(node)) {
|
|
13
|
+
const props = recurse[node.type];
|
|
14
|
+
const n = props?.length ?? 0;
|
|
15
|
+
for (let i = 0; i < n; ++i) {
|
|
16
|
+
const key = props[i];
|
|
17
|
+
// @ts-expect-error allow assignment
|
|
18
|
+
const value = node[key];
|
|
19
|
+
// @ts-expect-error allow assignment
|
|
20
|
+
clone[key] = Array.isArray(value)
|
|
21
|
+
? value.map(v => deepClone(v))
|
|
22
|
+
: deepClone(value);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return clone;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Create a shallow clone of the given SQL AST node.
|
|
31
|
+
* @param node The node to clone.
|
|
32
|
+
* @returns The cloned node.
|
|
33
|
+
*/
|
|
34
|
+
function shallowClone<T>(node: T): T {
|
|
35
|
+
/** @type {T} */
|
|
36
|
+
let clone;
|
|
37
|
+
|
|
38
|
+
if (!node || typeof node !== 'object') {
|
|
39
|
+
return node;
|
|
40
|
+
} else if (isNode(node)) {
|
|
41
|
+
clone = node.clone();
|
|
42
|
+
} else if (node instanceof Date) {
|
|
43
|
+
// @ts-expect-error node is known to be Date
|
|
44
|
+
return new Date(+node);
|
|
45
|
+
} else if (Array.isArray(node)) {
|
|
46
|
+
// @ts-expect-error allow slice
|
|
47
|
+
return node.slice();
|
|
48
|
+
} else {
|
|
49
|
+
return { ...node };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return clone;
|
|
53
|
+
}
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
BINARY_OPERATOR,
|
|
5
5
|
CASE,
|
|
6
6
|
CAST,
|
|
7
|
+
COLLATE,
|
|
7
8
|
COLUMN_PARAM,
|
|
8
9
|
COLUMN_REF,
|
|
9
10
|
DESCRIBE_QUERY,
|
|
@@ -16,23 +17,29 @@ import {
|
|
|
16
17
|
NOT_BETWEEN_OPERATOR,
|
|
17
18
|
ORDER_BY,
|
|
18
19
|
PARAM,
|
|
20
|
+
SCALAR_SUBQUERY,
|
|
19
21
|
SELECT_CLAUSE,
|
|
20
22
|
SELECT_QUERY,
|
|
21
23
|
SET_OPERATION,
|
|
22
24
|
UNARY_OPERATOR,
|
|
25
|
+
UNARY_POSTFIX_OPERATOR,
|
|
23
26
|
WHEN,
|
|
24
27
|
WINDOW,
|
|
25
28
|
WINDOW_CLAUSE,
|
|
26
29
|
WINDOW_DEF,
|
|
27
|
-
|
|
30
|
+
WINDOW_EXTENT_EXPR,
|
|
31
|
+
WINDOW_FRAME,
|
|
32
|
+
WINDOW_FUNCTION,
|
|
33
|
+
WITH_CLAUSE
|
|
28
34
|
} from '../constants.js';
|
|
29
35
|
|
|
30
|
-
export const recurse = {
|
|
31
|
-
[AGGREGATE]: ['args', 'filter'],
|
|
36
|
+
export const recurse: Record<string, string[]> = {
|
|
37
|
+
[AGGREGATE]: ['args', 'order', 'filter'],
|
|
32
38
|
[BETWEEN_OPERATOR]: ['expr', 'extent'],
|
|
33
39
|
[BINARY_OPERATOR]: ['left', 'right'],
|
|
34
40
|
[CASE]: ['expr', '_when', '_else'],
|
|
35
41
|
[CAST]: ['expr'],
|
|
42
|
+
[COLLATE]: ['expr'],
|
|
36
43
|
[COLUMN_PARAM]: ['param', 'table'],
|
|
37
44
|
[COLUMN_REF]: ['table'],
|
|
38
45
|
[DESCRIBE_QUERY]: ['query'],
|
|
@@ -45,13 +52,18 @@ export const recurse = {
|
|
|
45
52
|
[NOT_BETWEEN_OPERATOR]: ['expr', 'extent'],
|
|
46
53
|
[ORDER_BY]: ['expr'],
|
|
47
54
|
[PARAM]: ['value'],
|
|
55
|
+
[SCALAR_SUBQUERY]: ['subquery'],
|
|
48
56
|
[SELECT_CLAUSE]: ['expr'],
|
|
49
57
|
[SELECT_QUERY]: ['_with', '_select', '_from', '_where', '_sample', '_groupby', '_having', '_window', '_qualify', '_orderby'],
|
|
50
|
-
[SET_OPERATION]: ['
|
|
58
|
+
[SET_OPERATION]: ['queries', '_orderby'],
|
|
51
59
|
[UNARY_OPERATOR]: ['expr'],
|
|
60
|
+
[UNARY_POSTFIX_OPERATOR]: ['expr'],
|
|
52
61
|
[WHEN]: ['when', 'then'],
|
|
53
62
|
[WINDOW]: ['func', 'def'],
|
|
54
63
|
[WINDOW_CLAUSE]: ['def'],
|
|
55
|
-
[WINDOW_DEF]: ['partition', 'order', '
|
|
56
|
-
[
|
|
64
|
+
[WINDOW_DEF]: ['partition', 'order', 'framedef'],
|
|
65
|
+
[WINDOW_EXTENT_EXPR]: ['expr'],
|
|
66
|
+
[WINDOW_FRAME]: ['extent'],
|
|
67
|
+
[WINDOW_FUNCTION]: ['args'],
|
|
68
|
+
[WITH_CLAUSE]: ['query']
|
|
57
69
|
};
|
|
@@ -1,32 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
import { isNode } from '../ast/node.js';
|
|
1
|
+
import { type ExprNode, isNode } from '../ast/node.js';
|
|
3
2
|
import { recurse } from './recurse.js';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Rewrite a SQL expression, based on a map of nodes to replace.
|
|
7
6
|
* This method copies nodes as needed; it does not modify the input node.
|
|
8
|
-
* @param
|
|
9
|
-
* @param
|
|
10
|
-
* When encountered, key nodes are replaced by value nodes.
|
|
11
|
-
* @returns {ExprNode}
|
|
7
|
+
* @param node The root AST node of the expression.
|
|
8
|
+
* @param map The rewrite map. When encountered, key nodes are replaced by value nodes.
|
|
12
9
|
*/
|
|
13
|
-
export function rewrite(node, map) {
|
|
10
|
+
export function rewrite(node: ExprNode, map: Map<ExprNode, ExprNode>) {
|
|
14
11
|
if (map.has(node)) {
|
|
15
12
|
return map.get(node);
|
|
16
13
|
} else if (isNode(node)) {
|
|
17
14
|
const props = recurse[node.type];
|
|
18
15
|
const n = props?.length ?? 0;
|
|
19
16
|
if (n > 0) {
|
|
20
|
-
node =
|
|
17
|
+
node = node.clone();
|
|
21
18
|
for (let i = 0; i < n; ++i) {
|
|
22
19
|
const prop = props[i];
|
|
20
|
+
// @ts-expect-error lookup valid property
|
|
23
21
|
const child = node[prop];
|
|
24
22
|
if (Array.isArray(child)) {
|
|
23
|
+
// @ts-expect-error rewrite known property
|
|
24
|
+
const a = (node[prop] = child.slice());
|
|
25
25
|
const m = child.length;
|
|
26
26
|
for (let j = 0; j < m; ++j) {
|
|
27
|
-
|
|
27
|
+
a[j] = rewrite(child[j], map);
|
|
28
28
|
}
|
|
29
29
|
} else if (child) {
|
|
30
|
+
// @ts-expect-error rewrite known property
|
|
30
31
|
node[prop] = rewrite(child, map);
|
|
31
32
|
}
|
|
32
33
|
}
|
|
@@ -34,12 +35,3 @@ export function rewrite(node, map) {
|
|
|
34
35
|
}
|
|
35
36
|
return node;
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
-
// TODO: consider typed node.clone() methods
|
|
39
|
-
function cloneNode(node) {
|
|
40
|
-
const clone = new node.constructor();
|
|
41
|
-
for (const key in node) {
|
|
42
|
-
clone[key] = node[key];
|
|
43
|
-
}
|
|
44
|
-
return clone;
|
|
45
|
-
}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* @import { ParamLike } from '../types.js'
|
|
7
|
-
*/
|
|
1
|
+
import { type AggregateNode, aggregateNames } from '../ast/aggregate.js';
|
|
2
|
+
import type { ColumnRefNode } from '../ast/column-ref.js';
|
|
3
|
+
import type { SQLNode } from '../ast/node.js';
|
|
4
|
+
import type { ParamNode } from '../ast/param.js';
|
|
5
|
+
import type { ParamLike } from '../types.js';
|
|
8
6
|
import { AGGREGATE, COLUMN_PARAM, COLUMN_REF, FRAGMENT, PARAM, VERBATIM, WINDOW } from '../constants.js';
|
|
9
|
-
import { aggregateNames } from '../ast/aggregate.js';
|
|
10
7
|
import { walk } from './walk.js';
|
|
11
8
|
|
|
12
9
|
// regexp to match valid aggregate function names
|
|
@@ -17,7 +14,7 @@ const aggrRegExp = new RegExp(`^(${aggregateNames.join('|')})$`);
|
|
|
17
14
|
// function call tokens will have a pattern like "name(".
|
|
18
15
|
const funcRegExp = /(\\'|\\"|"(?:\\"|[^"])*"|'(?:\\'|[^'])*'|\w+\()/g;
|
|
19
16
|
|
|
20
|
-
function hasVerbatimAggregate(s) {
|
|
17
|
+
function hasVerbatimAggregate(s: string) {
|
|
21
18
|
return s
|
|
22
19
|
.split(funcRegExp)
|
|
23
20
|
.some(tok => tok.endsWith('(') && aggrRegExp.test(tok.slice(0, -1)));
|
|
@@ -27,12 +24,12 @@ function hasVerbatimAggregate(s) {
|
|
|
27
24
|
* Indicate if the input AST contains an aggregate expression.
|
|
28
25
|
* The string content of verbatim nodes is analyzed to try to identify
|
|
29
26
|
* unparsed aggregate functions calls within SQL strings.
|
|
30
|
-
* @param
|
|
31
|
-
* @returns
|
|
27
|
+
* @param root The root of the AST to search.
|
|
28
|
+
* @returns Return 0 if no aggregate functions are found.
|
|
32
29
|
* Sets bit 1 if an AggregateFunction instance is found.
|
|
33
30
|
* Sets bit 2 if an aggregate embedded in verbatim text is found.
|
|
34
31
|
*/
|
|
35
|
-
export function isAggregateExpression(root) {
|
|
32
|
+
export function isAggregateExpression(root: SQLNode) {
|
|
36
33
|
let agg = 0;
|
|
37
34
|
walk(root, (node) => {
|
|
38
35
|
switch (node.type) {
|
|
@@ -64,14 +61,13 @@ export function isAggregateExpression(root) {
|
|
|
64
61
|
|
|
65
62
|
/**
|
|
66
63
|
* Collect all aggregate function nodes.
|
|
67
|
-
* @param
|
|
68
|
-
* @returns {AggregateNode[]}
|
|
64
|
+
* @param root The root of the AST to search.
|
|
69
65
|
*/
|
|
70
|
-
export function collectAggregates(root) {
|
|
71
|
-
const aggs = new Set();
|
|
66
|
+
export function collectAggregates(root: SQLNode) {
|
|
67
|
+
const aggs = new Set<AggregateNode>();
|
|
72
68
|
walk(root, (node) => {
|
|
73
69
|
if (node.type === AGGREGATE) {
|
|
74
|
-
aggs.add(node);
|
|
70
|
+
aggs.add(node as AggregateNode);
|
|
75
71
|
}
|
|
76
72
|
});
|
|
77
73
|
return Array.from(aggs);
|
|
@@ -81,14 +77,14 @@ export function collectAggregates(root) {
|
|
|
81
77
|
* Collect all unique column references.
|
|
82
78
|
* Multiple references to the same column are de-duplicated, even if
|
|
83
79
|
* they are not object-equal node instances.
|
|
84
|
-
* @param
|
|
85
|
-
* @returns {ColumnRefNode[]}
|
|
80
|
+
* @param root The root of the AST to search.
|
|
86
81
|
*/
|
|
87
|
-
export function collectColumns(root) {
|
|
88
|
-
const cols = {};
|
|
82
|
+
export function collectColumns(root: SQLNode) {
|
|
83
|
+
const cols: Record<string, ColumnRefNode> = {};
|
|
89
84
|
walk(root, (node) => {
|
|
90
85
|
if (node.type === COLUMN_REF || node.type === COLUMN_PARAM) {
|
|
91
|
-
|
|
86
|
+
// key on string-coerced node
|
|
87
|
+
cols[`${node}`] = (node as ColumnRefNode);
|
|
92
88
|
}
|
|
93
89
|
});
|
|
94
90
|
return Object.values(cols);
|
|
@@ -96,17 +92,13 @@ export function collectColumns(root) {
|
|
|
96
92
|
|
|
97
93
|
/**
|
|
98
94
|
* Collect all unique dynamic parameter instances.
|
|
99
|
-
* @param
|
|
100
|
-
* @returns {ParamLike[]}
|
|
95
|
+
* @param root The root of the AST to search.
|
|
101
96
|
*/
|
|
102
|
-
export function collectParams(root) {
|
|
103
|
-
const params = new Set
|
|
97
|
+
export function collectParams(root: SQLNode) {
|
|
98
|
+
const params = new Set<ParamLike>;
|
|
104
99
|
walk(root, (node) => {
|
|
105
100
|
if (node.type === PARAM) {
|
|
106
|
-
params.add(
|
|
107
|
-
/** @type {ParamNode} */
|
|
108
|
-
(node).param
|
|
109
|
-
);
|
|
101
|
+
params.add((node as ParamNode).param);
|
|
110
102
|
}
|
|
111
103
|
});
|
|
112
104
|
return Array.from(params);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { SQLNode } from '../ast/node.js';
|
|
2
|
+
import { isNode } from '../ast/node.js';
|
|
3
|
+
import { recurse } from './recurse.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* SQL AST traversal visitor callback result.
|
|
7
|
+
* A falsy value (including `undefined`, `null`, `false`, and `0`) indicates
|
|
8
|
+
* that traversal should continue.
|
|
9
|
+
* A negative number values indicates that traversal should stop immediately.
|
|
10
|
+
* Any other truthy value indicates that traversal should not recurse on the
|
|
11
|
+
* current node, but should otherwise continue.
|
|
12
|
+
*/
|
|
13
|
+
export type VisitorResult = boolean | number | null | undefined | void;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* SQL AST traversal callback function.
|
|
17
|
+
*/
|
|
18
|
+
export type VisitorCallback = (node: SQLNode) => VisitorResult;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Perform a traversal of a SQL expression AST.
|
|
22
|
+
* @param node Root node for AST traversal.
|
|
23
|
+
* @param visit Visitor callback function.
|
|
24
|
+
*/
|
|
25
|
+
export function walk(node: unknown, visit: VisitorCallback): VisitorResult {
|
|
26
|
+
if (!isNode(node)) return;
|
|
27
|
+
const result = visit(node);
|
|
28
|
+
if (result) return result;
|
|
29
|
+
|
|
30
|
+
const props = recurse[node.type];
|
|
31
|
+
const n = props?.length ?? 0;
|
|
32
|
+
for (let i = 0; i < n; ++i) {
|
|
33
|
+
// @ts-expect-error lookup of valid property
|
|
34
|
+
const value = node[props[i]];
|
|
35
|
+
if (Array.isArray(value)) {
|
|
36
|
+
const m = value.length;
|
|
37
|
+
for (let j = 0; j < m; ++j) {
|
|
38
|
+
if (value[j] && Number(walk(value[j], visit)) < 0) {
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
} else if (value && Number(walk(value, visit)) < 0) {
|
|
43
|
+
return -1;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
export class AggregateNode extends ExprNode {
|
|
2
|
-
/**
|
|
3
|
-
* Instantiate an aggregate function node.
|
|
4
|
-
* @param {string} name The aggregate function name.
|
|
5
|
-
* @param {ExprNode[]} args The aggregate function arguments.
|
|
6
|
-
* @param {boolean} [distinct] The distinct flag.
|
|
7
|
-
* @param {ExprNode} [filter] Filter expression.
|
|
8
|
-
*/
|
|
9
|
-
constructor(name: string, args: ExprNode[], distinct?: boolean, filter?: ExprNode);
|
|
10
|
-
/**
|
|
11
|
-
* The aggregate function name.
|
|
12
|
-
* @type {string}
|
|
13
|
-
* @readonly
|
|
14
|
-
*/
|
|
15
|
-
readonly name: string;
|
|
16
|
-
/**
|
|
17
|
-
* The aggregate function arguments.
|
|
18
|
-
* @type {ExprNode[]}
|
|
19
|
-
* @readonly
|
|
20
|
-
*/
|
|
21
|
-
readonly args: ExprNode[];
|
|
22
|
-
/**
|
|
23
|
-
* The distinct flag.
|
|
24
|
-
* @type {boolean}
|
|
25
|
-
* @readonly
|
|
26
|
-
*/
|
|
27
|
-
readonly isDistinct: boolean;
|
|
28
|
-
/**
|
|
29
|
-
* Filter criteria.
|
|
30
|
-
* @type {ExprNode}
|
|
31
|
-
* @readonly
|
|
32
|
-
*/
|
|
33
|
-
readonly filter: ExprNode;
|
|
34
|
-
/**
|
|
35
|
-
* Return a new derived aggregate over distinct values.
|
|
36
|
-
* @param {boolean} [isDistinct=true] The distinct flag.
|
|
37
|
-
* @returns {AggregateNode} A new aggregate node.
|
|
38
|
-
*/
|
|
39
|
-
distinct(isDistinct?: boolean): AggregateNode;
|
|
40
|
-
/**
|
|
41
|
-
* Return a new derived aggregate function that filters values.
|
|
42
|
-
* @param {ExprNode | string} filter The filter expression.
|
|
43
|
-
* @returns {AggregateNode} A new aggregate node.
|
|
44
|
-
*/
|
|
45
|
-
where(filter: ExprNode | string): AggregateNode;
|
|
46
|
-
/**
|
|
47
|
-
* Return a new window function over this aggregate.
|
|
48
|
-
* @returns {WindowNode} A new window node.
|
|
49
|
-
*/
|
|
50
|
-
window(): WindowNode;
|
|
51
|
-
/**
|
|
52
|
-
* Return a new window function over this aggregate with the given partitions.
|
|
53
|
-
* @param {...ExprVarArgs} expr The partition by criteria.
|
|
54
|
-
* @returns {WindowNode} A new window node.
|
|
55
|
-
*/
|
|
56
|
-
partitionby(...expr: ExprVarArgs[]): WindowNode;
|
|
57
|
-
/**
|
|
58
|
-
* Return a new window function over this aggregate with the given ordering.
|
|
59
|
-
* @param {...ExprVarArgs} expr The order by criteria.
|
|
60
|
-
* @returns {WindowNode} A new window node.
|
|
61
|
-
*/
|
|
62
|
-
orderby(...expr: ExprVarArgs[]): WindowNode;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* An array of known aggregate function names.
|
|
66
|
-
* From https://duckdb.org/docs/sql/functions/aggregates.html.
|
|
67
|
-
*/
|
|
68
|
-
export const aggregateNames: string[];
|
|
69
|
-
import { ExprNode } from './node.js';
|
|
70
|
-
import { WindowNode } from './window.js';
|
|
71
|
-
import type { ExprVarArgs } from '../types.js';
|