@uwdata/mosaic-sql 0.17.0 → 0.19.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 +47 -0
- 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/list.d.ts +15 -0
- package/dist/src/ast/list.d.ts.map +1 -0
- package/dist/src/ast/list.js +21 -0
- package/dist/src/ast/list.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/src/ast/param.d.ts +20 -0
- 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 +334 -0
- package/dist/src/ast/query.d.ts.map +1 -0
- package/dist/src/ast/query.js +640 -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/unnest.d.ts +19 -0
- package/dist/src/ast/unnest.d.ts.map +1 -0
- package/dist/src/ast/unnest.js +29 -0
- package/dist/src/ast/unnest.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/src/ast/with.d.ts +25 -0
- 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 +40 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +40 -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/src/functions/case.d.ts +13 -0
- 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/src/functions/cte.d.ts +13 -0
- 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/src/functions/list.d.ts +31 -0
- package/dist/src/functions/list.d.ts.map +1 -0
- package/dist/src/functions/list.js +49 -0
- package/dist/src/functions/list.js.map +1 -0
- package/dist/src/functions/literal.d.ts +16 -0
- 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/src/functions/sql-template-tag.d.ts +13 -0
- 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/unnest.d.ts +10 -0
- package/dist/src/functions/unnest.d.ts.map +1 -0
- package/dist/src/functions/unnest.js +12 -0
- package/dist/src/functions/unnest.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/src/functions/window.d.ts +74 -0
- 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 +73 -0
- package/dist/src/index.d.ts.map +1 -0
- package/{src → dist/src}/index.js +8 -8
- 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/src/types.d.ts +49 -0
- 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/src/util/ast.d.ts +62 -0
- 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 +37 -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/src/visit/visitors.d.ts +32 -0
- 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 +13 -7
- package/src/ast/{aggregate.js → aggregate.ts} +49 -60
- 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.js → collate.ts} +8 -14
- 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.js → from.ts} +12 -21
- 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/list.ts +23 -0
- package/src/ast/{literal.js → literal.ts} +6 -9
- package/src/ast/logical-op.ts +50 -0
- package/src/ast/{node.js → node.ts} +10 -13
- package/src/ast/order-by.ts +38 -0
- package/src/ast/{param.js → param.ts} +6 -12
- package/src/ast/{query.js → query.ts} +224 -204
- package/src/ast/sample.ts +47 -0
- package/src/ast/{select.js → select.ts} +10 -16
- package/src/ast/{subquery.js → subquery.ts} +9 -8
- 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/unnest.ts +31 -0
- package/src/ast/verbatim.ts +27 -0
- package/src/ast/{window-frame.js → window-frame.ts} +37 -47
- package/src/ast/window.ts +246 -0
- package/src/ast/{with.js → with.ts} +19 -20
- package/src/{constants.js → constants.ts} +2 -0
- 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.js → collate.ts} +4 -7
- package/src/functions/{column.js → column.ts} +9 -10
- package/src/functions/{cte.js → cte.ts} +9 -6
- package/src/functions/{datetime.js → datetime.ts} +12 -20
- package/src/functions/interval.ts +74 -0
- package/src/functions/list.ts +63 -0
- package/src/functions/{literal.js → literal.ts} +5 -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/unnest.ts +13 -0
- 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 +79 -0
- package/src/load/{create.js → create.ts} +9 -3
- package/src/load/extension.ts +3 -0
- package/src/load/{load.js → load.ts} +25 -10
- 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.js → filter-query.ts} +10 -14
- 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 -39
- 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.js → clone.ts} +10 -10
- package/src/visit/{recurse.js → recurse.ts} +3 -1
- package/src/visit/{rewrite.js → rewrite.ts} +7 -7
- package/src/visit/{visitors.js → visitors.ts} +22 -30
- package/src/visit/walk.ts +46 -0
- 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/logical-op.js +0 -67
- package/src/ast/order-by.js +0 -48
- package/src/ast/sample.js +0 -53
- package/src/ast/verbatim.js +0 -33
- package/src/ast/window.js +0 -260
- package/src/functions/aggregate.js +0 -347
- package/src/functions/interval.js +0 -83
- 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/functions/window-frame.js +0 -61
- package/src/index-types.ts +0 -2
- package/src/load/extension.js +0 -3
- package/src/transforms/bin-date.js +0 -38
- 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 -34
- package/tsconfig.json +0 -8
- package/vitest.config.ts +0 -3
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { ExprValue, StringValue } from '../types.js';
|
|
2
|
+
import { asLiteral } from '../util/ast.js';
|
|
3
|
+
import { argsList, fn } from '../util/function.js';
|
|
4
|
+
|
|
5
|
+
function strFn(name: string, expr: ExprValue, ...args: unknown[]) {
|
|
6
|
+
return fn(name, expr, ...(argsList(args).map(asLiteral)));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Function that returns true if a string contains a regexp pattern,
|
|
11
|
+
* false otherwise.
|
|
12
|
+
* @param string The string match against.
|
|
13
|
+
* @param pattern The regular expression pattern to match.
|
|
14
|
+
* @param options Regular expression options:
|
|
15
|
+
* 'c': case-sensitive matching
|
|
16
|
+
* 'i': case-insensitive matching
|
|
17
|
+
* 'l': match literals instead of regular expression tokens
|
|
18
|
+
* 'm', 'n', 'p': newline sensitive matching
|
|
19
|
+
* 'g': global replace, only available for regexp_replace
|
|
20
|
+
* 's': non-newline sensitive matching
|
|
21
|
+
*/
|
|
22
|
+
export function regexp_matches(
|
|
23
|
+
string: ExprValue,
|
|
24
|
+
pattern: StringValue,
|
|
25
|
+
options?: StringValue
|
|
26
|
+
) {
|
|
27
|
+
return strFn('regexp_matches', string, pattern, options);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Function that returns true if search_string is found within string.
|
|
32
|
+
* @param string The string to match against.
|
|
33
|
+
* @param search_string The substring to search for.
|
|
34
|
+
*/
|
|
35
|
+
export function contains(string: ExprValue, search_string: StringValue) {
|
|
36
|
+
return strFn('contains', string, search_string);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Function that returns true if string begins with search_string.
|
|
41
|
+
* @param string The string to match against.
|
|
42
|
+
* @param search_string The substring to search for.
|
|
43
|
+
*/
|
|
44
|
+
export function prefix(string: ExprValue, search_string: StringValue) {
|
|
45
|
+
return strFn('starts_with', string, search_string);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Function that returns true if string ends with search_string.
|
|
50
|
+
* @param string The string to match against.
|
|
51
|
+
* @param search_string The substring to search for.
|
|
52
|
+
*/
|
|
53
|
+
export function suffix(string: ExprValue, search_string: StringValue) {
|
|
54
|
+
return strFn('ends_with', string, search_string);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Function that converts string to lower case.
|
|
59
|
+
* @param string The string to convert.
|
|
60
|
+
*/
|
|
61
|
+
export function lower(string: ExprValue) {
|
|
62
|
+
return strFn('lower', string);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Function that converts string to upper case.
|
|
67
|
+
* @param string The string to convert.
|
|
68
|
+
*/
|
|
69
|
+
export function upper(string: ExprValue) {
|
|
70
|
+
return strFn('upper', string);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Function that returns the number of characters in string.
|
|
75
|
+
* @param value The string to measure.
|
|
76
|
+
*/
|
|
77
|
+
export function length(value: ExprValue) {
|
|
78
|
+
return strFn('length', value);
|
|
79
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { TableRefNode } from '../ast/table-ref.js';
|
|
2
|
+
import { MaybeArray } from '../types.js';
|
|
2
3
|
import { exprList } from '../util/function.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Returns a named table or view reference.
|
|
6
|
-
* @param
|
|
7
|
+
* @param ids Table and namespace identifiers.
|
|
7
8
|
* For example 'name' or ['schema', 'name'].
|
|
8
|
-
* @returns
|
|
9
|
-
* if the input identifier list is empty.
|
|
9
|
+
* @returns A table reference or undefined if the input list is empty.
|
|
10
10
|
*/
|
|
11
|
-
export function tableRef(...ids) {
|
|
11
|
+
export function tableRef(...ids: MaybeArray<string>[]) {
|
|
12
12
|
const args = exprList(ids, String);
|
|
13
13
|
return args?.length ? new TableRefNode(args) : undefined;
|
|
14
14
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ExprValue } from "../types.js";
|
|
2
|
+
import { asNode } from "../util/ast.js";
|
|
3
|
+
import { UnnestNode } from "../ast/unnest.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Create an Unnest Node to flatten nested structures, either structs or lists.
|
|
7
|
+
* @param value
|
|
8
|
+
* @param recursive
|
|
9
|
+
* @param maxDepth
|
|
10
|
+
*/
|
|
11
|
+
export function unnest(value: ExprValue, recursive = false, maxDepth = 0) {
|
|
12
|
+
return new UnnestNode(asNode(value), recursive, maxDepth);
|
|
13
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ExprValue } from '../types.js';
|
|
2
|
+
import { fn } from '../util/function.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns the first non-null argument.
|
|
6
|
+
* @param expr The input expressions.
|
|
7
|
+
*/
|
|
8
|
+
export function coalesce(...expr: ExprValue[]) {
|
|
9
|
+
return fn('coalesce', ...expr);
|
|
10
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { FrameExclude, FrameExtent, FrameValue } from '../ast/window-frame.js';
|
|
2
|
+
import { CURRENT_ROW, FOLLOWING, GROUPS, PRECEDING, RANGE, ROWS, WindowFrameExprNode, WindowFrameNode } from '../ast/window-frame.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Return an updated window definition with the given rows frame.
|
|
6
|
+
* @param extent The row-based window frame extent.
|
|
7
|
+
* @param exclude The window frame exclusion criteria.
|
|
8
|
+
* @returns A window frame node.
|
|
9
|
+
*/
|
|
10
|
+
export function frameRows(extent: FrameExtent, exclude?: FrameExclude) {
|
|
11
|
+
return new WindowFrameNode(ROWS, extent, exclude);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Return an updated window definition with the given range frame.
|
|
16
|
+
* @param extent The range-based window frame extent.
|
|
17
|
+
* @param exclude The window frame exclusion criteria.
|
|
18
|
+
* @returns A window frame node.
|
|
19
|
+
*/
|
|
20
|
+
export function frameRange(extent: FrameExtent, exclude?: FrameExclude) {
|
|
21
|
+
return new WindowFrameNode(RANGE, extent, exclude);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Return an updated window definition with the given groups frame.
|
|
26
|
+
* @param extent The group-based window frame extent.
|
|
27
|
+
* @param exclude The window frame exclusion criteria.
|
|
28
|
+
* @returns A window frame node.
|
|
29
|
+
*/
|
|
30
|
+
export function frameGroups(extent: FrameExtent, exclude?: FrameExclude) {
|
|
31
|
+
return new WindowFrameNode(GROUPS, extent, exclude);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A `PRECEDING` frame value expression.
|
|
36
|
+
* @param value The frame value.
|
|
37
|
+
* @returns A preceding value.
|
|
38
|
+
*/
|
|
39
|
+
export function preceding(value: FrameValue) {
|
|
40
|
+
return new WindowFrameExprNode(PRECEDING, value);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* A `FOLLOWING` frame value expression.
|
|
45
|
+
* @param value The frame value.
|
|
46
|
+
* @returns A following value.
|
|
47
|
+
*/
|
|
48
|
+
export function following(value: FrameValue) {
|
|
49
|
+
return new WindowFrameExprNode(FOLLOWING, value);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* A `CURRENT ROW` frame value expression.
|
|
54
|
+
* @returns A current row value.
|
|
55
|
+
*/
|
|
56
|
+
export function currentRow() {
|
|
57
|
+
return new WindowFrameExprNode(CURRENT_ROW);
|
|
58
|
+
}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
* @import { WindowNode } from '../ast/window.js'
|
|
3
|
-
* @import { ExprValue, NumberValue } from '../types.js'
|
|
4
|
-
*/
|
|
1
|
+
import type { ExprValue, NumberValue } from '../types.js';
|
|
5
2
|
import { winFn } from '../util/function.js';
|
|
6
3
|
|
|
7
4
|
/**
|
|
8
5
|
* Create a window function that returns the number of the current row
|
|
9
6
|
* within the partition, counting from 1.
|
|
10
|
-
* @returns {WindowNode}
|
|
11
7
|
*/
|
|
12
8
|
export function row_number() {
|
|
13
9
|
return winFn('row_number');
|
|
@@ -16,7 +12,6 @@ export function row_number() {
|
|
|
16
12
|
/**
|
|
17
13
|
* Create a window function that returns the rank of the current row with gaps.
|
|
18
14
|
* This is the same as the row_number of its first peer.
|
|
19
|
-
* @returns {WindowNode}
|
|
20
15
|
*/
|
|
21
16
|
export function rank() {
|
|
22
17
|
return winFn('rank');
|
|
@@ -25,7 +20,6 @@ export function rank() {
|
|
|
25
20
|
/**
|
|
26
21
|
* Create a window function that returns the rank of the current row without
|
|
27
22
|
* gaps. The function counts peer groups.
|
|
28
|
-
* @returns {WindowNode}
|
|
29
23
|
*/
|
|
30
24
|
export function dense_rank() {
|
|
31
25
|
return winFn('dense_rank');
|
|
@@ -34,7 +28,6 @@ export function dense_rank() {
|
|
|
34
28
|
/**
|
|
35
29
|
* Create a window function that returns the relative rank of the current row.
|
|
36
30
|
* Computed as (rank() - 1) / (total partition rows - 1).
|
|
37
|
-
* @returns {WindowNode}
|
|
38
31
|
*/
|
|
39
32
|
export function percent_rank() {
|
|
40
33
|
return winFn('percent_rank');
|
|
@@ -43,7 +36,6 @@ export function percent_rank() {
|
|
|
43
36
|
/**
|
|
44
37
|
* Create a window function that returns the cumulative distribution. Computed
|
|
45
38
|
* as (number of preceding or peer partition rows) / total partition rows.
|
|
46
|
-
* @returns {WindowNode}
|
|
47
39
|
*/
|
|
48
40
|
export function cume_dist() {
|
|
49
41
|
return winFn('cume_dist');
|
|
@@ -52,11 +44,9 @@ export function cume_dist() {
|
|
|
52
44
|
/**
|
|
53
45
|
* Create a window function that returns an integer ranging from 1 to the
|
|
54
46
|
* argument value, dividing the partition as equally as possible.
|
|
55
|
-
* @param
|
|
56
|
-
* quantile buckets.
|
|
57
|
-
* @returns {WindowNode}
|
|
47
|
+
* @param num_buckets The number of quantile buckets.
|
|
58
48
|
*/
|
|
59
|
-
export function ntile(num_buckets) {
|
|
49
|
+
export function ntile(num_buckets: NumberValue) {
|
|
60
50
|
return winFn('ntile', num_buckets);
|
|
61
51
|
}
|
|
62
52
|
|
|
@@ -66,13 +56,11 @@ export function ntile(num_buckets) {
|
|
|
66
56
|
* If there is no such row, instead return default (which must be of the same
|
|
67
57
|
* type as the expression). Both offset and default are evaluated with respect
|
|
68
58
|
* to the current row. If omitted, offset defaults to 1 and default to null.
|
|
69
|
-
* @param
|
|
70
|
-
* @param
|
|
71
|
-
*
|
|
72
|
-
* @param {*} [defaultValue] The default value (default `null`).
|
|
73
|
-
* @returns {WindowNode}
|
|
59
|
+
* @param expr The expression to evaluate.
|
|
60
|
+
* @param offset The row offset (default `1`).
|
|
61
|
+
* @param defaultValue The default value (default `null`).
|
|
74
62
|
*/
|
|
75
|
-
export function lag(expr, offset, defaultValue){
|
|
63
|
+
export function lag(expr: ExprValue, offset?: NumberValue, defaultValue?: unknown) {
|
|
76
64
|
return winFn('lag', expr, offset, defaultValue);
|
|
77
65
|
}
|
|
78
66
|
|
|
@@ -82,43 +70,38 @@ export function lag(expr, offset, defaultValue){
|
|
|
82
70
|
* If there is no such row, instead return default (which must be of the same
|
|
83
71
|
* type as the expression). Both offset and default are evaluated with respect
|
|
84
72
|
* to the current row. If omitted, offset defaults to 1 and default to null.
|
|
85
|
-
* @param
|
|
86
|
-
* @param
|
|
87
|
-
*
|
|
88
|
-
* @param {*} [defaultValue] The default value (default `null`).
|
|
89
|
-
* @returns {WindowNode}
|
|
73
|
+
* @param expr The expression to evaluate.
|
|
74
|
+
* @param offset The row offset (default `1`).
|
|
75
|
+
* @param defaultValue The default value (default `null`).
|
|
90
76
|
*/
|
|
91
|
-
export function lead(expr, offset, defaultValue){
|
|
77
|
+
export function lead(expr: ExprValue, offset?: NumberValue, defaultValue?: unknown) {
|
|
92
78
|
return winFn('lead', expr, offset, defaultValue);
|
|
93
79
|
}
|
|
94
80
|
|
|
95
81
|
/**
|
|
96
82
|
* Create a window function that returns the expression evaluated at the row
|
|
97
83
|
* that is the first row of the window frame.
|
|
98
|
-
* @param
|
|
99
|
-
* @returns {WindowNode}
|
|
84
|
+
* @param expr The expression to evaluate.
|
|
100
85
|
*/
|
|
101
|
-
export function first_value(expr) {
|
|
86
|
+
export function first_value(expr: ExprValue) {
|
|
102
87
|
return winFn('first_value', expr);
|
|
103
88
|
}
|
|
104
89
|
|
|
105
90
|
/**
|
|
106
91
|
* Create a window function that returns the expression evaluated at the row
|
|
107
92
|
* that is the last row of the window frame.
|
|
108
|
-
* @param
|
|
109
|
-
* @returns {WindowNode}
|
|
93
|
+
* @param expr The expression to evaluate.
|
|
110
94
|
*/
|
|
111
|
-
export function last_value(expr) {
|
|
95
|
+
export function last_value(expr: ExprValue) {
|
|
112
96
|
return winFn('last_value', expr);
|
|
113
97
|
}
|
|
114
98
|
|
|
115
99
|
/**
|
|
116
100
|
* Create a window function that returns the expression evaluated at the
|
|
117
101
|
* nth row of the window frame (counting from 1), or null if no such row.
|
|
118
|
-
* @param
|
|
119
|
-
* @param
|
|
120
|
-
* @returns {WindowNode}
|
|
102
|
+
* @param expr The expression to evaluate.
|
|
103
|
+
* @param nth The 1-based window frame index.
|
|
121
104
|
*/
|
|
122
|
-
export function nth_value(expr, nth) {
|
|
105
|
+
export function nth_value(expr: ExprValue, nth: NumberValue) {
|
|
123
106
|
return winFn('nth_value', expr, nth);
|
|
124
107
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export { AggregateNode, aggregateNames, isAggregateFunction } from './ast/aggregate.js';
|
|
2
|
+
export { BetweenOpNode, NotBetweenOpNode } from './ast/between-op.js'
|
|
3
|
+
export { BinaryOpNode } from './ast/binary-op.js';
|
|
4
|
+
export { CaseNode, WhenNode } from './ast/case.js';
|
|
5
|
+
export { CastNode } from './ast/cast.js';
|
|
6
|
+
export { CollateNode } from './ast/collate.js';
|
|
7
|
+
export { ColumnParamNode, isColumnParam } from './ast/column-param.js';
|
|
8
|
+
export { ColumnRefNode, ColumnNameRefNode, isColumnRef } from './ast/column-ref.js';
|
|
9
|
+
export { FragmentNode } from './ast/fragment.js';
|
|
10
|
+
export { FromClauseNode } from './ast/from.js';
|
|
11
|
+
export { FunctionNode } from './ast/function.js';
|
|
12
|
+
export { InOpNode } from './ast/in-op.js';
|
|
13
|
+
export { IntervalNode } from './ast/interval.js';
|
|
14
|
+
export { ListNode } from './ast/list.js';
|
|
15
|
+
export { LiteralNode } from './ast/literal.js';
|
|
16
|
+
export { AndNode, OrNode } from './ast/logical-op.js';
|
|
17
|
+
export { SQLNode, ExprNode, isNode } from './ast/node.js';
|
|
18
|
+
export { OrderByNode } from './ast/order-by.js';
|
|
19
|
+
export { ParamNode } from './ast/param.js';
|
|
20
|
+
export { DescribeQuery, Query, SelectQuery, SetOperation, isDescribeQuery, isQuery, isSelectQuery } from './ast/query.js';
|
|
21
|
+
export { SampleClauseNode } from './ast/sample.js';
|
|
22
|
+
export { ScalarSubqueryNode } from './ast/subquery.js';
|
|
23
|
+
export { SelectClauseNode } from './ast/select.js';
|
|
24
|
+
export { TableRefNode, isTableRef } from './ast/table-ref.js';
|
|
25
|
+
export { UnaryOpNode, UnaryPostfixOpNode } from './ast/unary-op.js';
|
|
26
|
+
export { UnnestNode } from './ast/unnest.js';
|
|
27
|
+
export { VerbatimNode } from './ast/verbatim.js';
|
|
28
|
+
export { WindowClauseNode, WindowDefNode, WindowFunctionNode, WindowNode } from './ast/window.js';
|
|
29
|
+
export { WindowFrameNode, WindowFrameExprNode, type FrameExclude, type FrameExtent, type FrameScope, type FrameType, type FrameValue } from './ast/window-frame.js';
|
|
30
|
+
export { WithClauseNode } from './ast/with.js';
|
|
31
|
+
|
|
32
|
+
export { argmax, argmin, arrayAgg, avg, corr, count, covariance, covarPop, entropy, first, geomean, kurtosis, mad, max, median, min, mode, last, product, quantile, regrAvgX, regrAvgY, regrCount, regrIntercept, regrR2, regrSXX, regrSXY, regrSYY, regrSlope, skewness, stddev, stddevPop, stringAgg, sum, variance, varPop } from './functions/aggregate.js';
|
|
33
|
+
export { cond } from './functions/case.js';
|
|
34
|
+
export { cast, float32, float64, int32 } from './functions/cast.js';
|
|
35
|
+
export { collate } from './functions/collate.js';
|
|
36
|
+
export { column } from './functions/column.js';
|
|
37
|
+
export { cte } from './functions/cte.js';
|
|
38
|
+
export { dateBin, dateMonth, dateMonthDay, dateDay, epoch_ms } from './functions/datetime.js';
|
|
39
|
+
export { days, hours, interval, microseconds, minutes, milliseconds, months, seconds, years } from './functions/interval.js';
|
|
40
|
+
export { list, listContains, listHasAll, listHasAny } from './functions/list.js';
|
|
41
|
+
export { literal, verbatim } from './functions/literal.js';
|
|
42
|
+
export { abs, ceil, exp, floor, greatest, isFinite, isInfinite, isNaN, least, ln, log, round, sign, sqrt, trunc } from './functions/numeric.js';
|
|
43
|
+
export { and, or, not, isNull, isNotNull, bitNot, bitAnd, bitOr, bitLeft, bitRight, add, sub, mul, div, idiv, mod, pow, eq, neq, lt, gt, lte, gte, isDistinct, isNotDistinct, isBetween, isNotBetween, isIn } from './functions/operators.js';
|
|
44
|
+
export { asc, desc } from './functions/order-by.js';
|
|
45
|
+
export { geojson, x, y, centroid, centroidX, centroidY } from './functions/spatial.js';
|
|
46
|
+
export { sql } from './functions/sql-template-tag.js';
|
|
47
|
+
export { regexp_matches, contains, prefix, suffix, lower, upper, length } from './functions/string.js';
|
|
48
|
+
export { unnest } from './functions/unnest.js';
|
|
49
|
+
export { coalesce } from './functions/util.js';
|
|
50
|
+
export { cume_dist, dense_rank, first_value, lag, last_value, lead, nth_value, ntile, percent_rank, rank, row_number } from './functions/window.js';
|
|
51
|
+
export { currentRow, following, frameGroups, frameRange, frameRows, preceding } from './functions/window-frame.js';
|
|
52
|
+
|
|
53
|
+
export { deepClone } from './visit/clone.js';
|
|
54
|
+
export { rewrite } from './visit/rewrite.js';
|
|
55
|
+
export { collectAggregates, collectColumns, collectParams, isAggregateExpression } from './visit/visitors.js';
|
|
56
|
+
export { walk, type VisitorCallback, type VisitorResult } from './visit/walk.js';
|
|
57
|
+
|
|
58
|
+
export { createTable, createSchema } from './load/create.js';
|
|
59
|
+
export { loadExtension } from './load/extension.js';
|
|
60
|
+
export { loadCSV, loadJSON, loadObjects, loadParquet, loadSpatial } from './load/load.js';
|
|
61
|
+
|
|
62
|
+
export { bin1d } from './transforms/bin-1d.js';
|
|
63
|
+
export { bin2d } from './transforms/bin-2d.js';
|
|
64
|
+
export { binDate } from './transforms/bin-date.js';
|
|
65
|
+
export { binHistogram } from './transforms/bin-histogram.js';
|
|
66
|
+
export { binLinear1d } from './transforms/bin-linear-1d.js';
|
|
67
|
+
export { binLinear2d } from './transforms/bin-linear-2d.js';
|
|
68
|
+
export { filterQuery } from './transforms/filter-query.js';
|
|
69
|
+
export { lineDensity } from './transforms/line-density.js';
|
|
70
|
+
export { m4 } from './transforms/m4.js';
|
|
71
|
+
export { scaleTransform, type Scale, type ScaleDomain, type ScaleOptions, type ScaleTransform, type ScaleType } from './transforms/scales.js';
|
|
72
|
+
|
|
73
|
+
export { asLiteral, asNode, asTableRef, asVerbatim, over } from './util/ast.js';
|
|
74
|
+
export { isParamLike } from './util/type-check.js';
|
|
75
|
+
|
|
76
|
+
export { binSpec, binStep, type BinOptions } from './transforms/util/bin-step.js';
|
|
77
|
+
export { timeInterval, type TimeUnit } from './transforms/util/time-interval.js';
|
|
78
|
+
|
|
79
|
+
export * from './types.js';
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
export
|
|
1
|
+
export interface CreateTableOptions {
|
|
2
|
+
replace?: boolean;
|
|
3
|
+
temp?: boolean;
|
|
4
|
+
view?: boolean;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function createTable(name: string, query: string, {
|
|
2
8
|
replace = false,
|
|
3
9
|
temp = false,
|
|
4
10
|
view = false
|
|
5
|
-
} = {}) {
|
|
11
|
+
}: CreateTableOptions = {}) {
|
|
6
12
|
return 'CREATE'
|
|
7
13
|
+ (replace ? ' OR REPLACE ' : ' ')
|
|
8
14
|
+ (temp ? 'TEMP ' : '')
|
|
@@ -11,7 +17,7 @@ export function createTable(name, query, {
|
|
|
11
17
|
+ name + ' AS ' + query;
|
|
12
18
|
}
|
|
13
19
|
|
|
14
|
-
export function createSchema(name, {
|
|
20
|
+
export function createSchema(name: string, {
|
|
15
21
|
strict = false
|
|
16
22
|
} = {}) {
|
|
17
23
|
return 'CREATE SCHEMA '
|
|
@@ -1,7 +1,18 @@
|
|
|
1
|
-
import { createTable } from './create.js';
|
|
1
|
+
import { createTable, CreateTableOptions } from './create.js';
|
|
2
2
|
import { sqlFrom } from './sql-from.js';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
type Options =
|
|
5
|
+
& { select?: string[]; }
|
|
6
|
+
& CreateTableOptions
|
|
7
|
+
& Record<string, unknown>;
|
|
8
|
+
|
|
9
|
+
export function load(
|
|
10
|
+
method: string,
|
|
11
|
+
tableName: string,
|
|
12
|
+
fileName: string,
|
|
13
|
+
options: Options = {},
|
|
14
|
+
defaults: Record<string, unknown> = {}
|
|
15
|
+
) {
|
|
5
16
|
const { select = ['*'], where, view, temp, replace, ...file } = options;
|
|
6
17
|
const params = parameters({ ...defaults, ...file });
|
|
7
18
|
const read = `${method}('${fileName}'${params ? ', ' + params : ''})`;
|
|
@@ -10,15 +21,15 @@ export function load(method, tableName, fileName, options = {}, defaults = {}) {
|
|
|
10
21
|
return createTable(tableName, query, { view, temp, replace });
|
|
11
22
|
}
|
|
12
23
|
|
|
13
|
-
export function loadCSV(tableName, fileName, options) {
|
|
24
|
+
export function loadCSV(tableName: string, fileName: string, options?: Options) {
|
|
14
25
|
return load('read_csv', tableName, fileName, options, { auto_detect: true, sample_size: -1 });
|
|
15
26
|
}
|
|
16
27
|
|
|
17
|
-
export function loadJSON(tableName, fileName, options) {
|
|
28
|
+
export function loadJSON(tableName: string, fileName: string, options?: Options) {
|
|
18
29
|
return load('read_json', tableName, fileName, options, { auto_detect: true, format: 'auto' });
|
|
19
30
|
}
|
|
20
31
|
|
|
21
|
-
export function loadParquet(tableName, fileName, options) {
|
|
32
|
+
export function loadParquet(tableName: string, fileName: string, options?: Options) {
|
|
22
33
|
return load('read_parquet', tableName, fileName, options);
|
|
23
34
|
}
|
|
24
35
|
|
|
@@ -28,7 +39,7 @@ export function loadParquet(tableName, fileName, options) {
|
|
|
28
39
|
* Supports GeoJSON, TopoJSON, and other common spatial formats.
|
|
29
40
|
* For TopoJSON, wet the layer option to indicate the feature to extract.
|
|
30
41
|
*/
|
|
31
|
-
export function loadSpatial(tableName, fileName, options = {}) {
|
|
42
|
+
export function loadSpatial(tableName: string, fileName: string, options: Options = {}) {
|
|
32
43
|
// nested options map to the open_options argument of st_read
|
|
33
44
|
const { options: opt, ...rest } = options;
|
|
34
45
|
if (opt) {
|
|
@@ -45,7 +56,11 @@ export function loadSpatial(tableName, fileName, options = {}) {
|
|
|
45
56
|
return load('st_read', tableName, fileName, rest);
|
|
46
57
|
}
|
|
47
58
|
|
|
48
|
-
export function loadObjects(
|
|
59
|
+
export function loadObjects(
|
|
60
|
+
tableName: string,
|
|
61
|
+
data: (Record<string,unknown>)[],
|
|
62
|
+
options: Options = {}
|
|
63
|
+
) {
|
|
49
64
|
const { select = ['*'], ...opt } = options;
|
|
50
65
|
const values = sqlFrom(data);
|
|
51
66
|
const query = select.length === 1 && select[0] === '*'
|
|
@@ -54,13 +69,13 @@ export function loadObjects(tableName, data, options = {}) {
|
|
|
54
69
|
return createTable(tableName, query, opt);
|
|
55
70
|
}
|
|
56
71
|
|
|
57
|
-
function parameters(options) {
|
|
72
|
+
function parameters(options: Record<string, unknown>) {
|
|
58
73
|
return Object.entries(options)
|
|
59
74
|
.map(([key, value]) => `${key}=${toDuckDBValue(value)}`)
|
|
60
75
|
.join(', ');
|
|
61
76
|
}
|
|
62
77
|
|
|
63
|
-
function toDuckDBValue(value) {
|
|
78
|
+
function toDuckDBValue(value: unknown): string {
|
|
64
79
|
switch (typeof value) {
|
|
65
80
|
case 'boolean':
|
|
66
81
|
return String(value);
|
|
@@ -80,6 +95,6 @@ function toDuckDBValue(value) {
|
|
|
80
95
|
+ '}';
|
|
81
96
|
}
|
|
82
97
|
default:
|
|
83
|
-
return value
|
|
98
|
+
return `${value}`;
|
|
84
99
|
}
|
|
85
100
|
}
|
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
import { asLiteral } from '../util/ast.js';
|
|
2
2
|
|
|
3
|
+
type SQLFromOptions = {
|
|
4
|
+
columns?: string[] | Record<string, string>;
|
|
5
|
+
} & Record<string,string>;
|
|
6
|
+
|
|
3
7
|
/**
|
|
4
8
|
* Create a SQL query that embeds the given data for loading.
|
|
5
|
-
* @param
|
|
6
|
-
* @param
|
|
9
|
+
* @param data The dataset as an array of objects.
|
|
10
|
+
* @param options Loading options.
|
|
7
11
|
* @param {string[]|object} [options.columns] The columns to include.
|
|
8
12
|
* If not specified, the keys of the first data object are used.
|
|
9
13
|
* @returns {string} SQL query string to load data.
|
|
10
14
|
*/
|
|
11
|
-
export function sqlFrom(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
export function sqlFrom(
|
|
16
|
+
data: (Record<string, unknown>)[],
|
|
17
|
+
{
|
|
18
|
+
columns = Object.keys(data?.[0] || {})
|
|
19
|
+
}: SQLFromOptions = {}
|
|
20
|
+
) {
|
|
21
|
+
let keys: string[] = [];
|
|
15
22
|
if (Array.isArray(columns)) {
|
|
16
23
|
keys = columns;
|
|
17
|
-
columns = keys.reduce((m, k) => (m[k] = k, m), {});
|
|
24
|
+
columns = keys.reduce((m, k) => (m[k] = k, m), {} as Record<string, string>);
|
|
18
25
|
} else if (columns) {
|
|
19
26
|
keys = Object.keys(columns);
|
|
20
27
|
}
|
|
@@ -1,23 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
* @import { ExprValue } from '../types.js'
|
|
3
|
-
*/
|
|
1
|
+
import type { ExprValue } from '../types.js';
|
|
4
2
|
import { float64 } from '../functions/cast.js';
|
|
5
3
|
import { mul, sub } from '../functions/operators.js';
|
|
6
4
|
|
|
7
5
|
/**
|
|
8
6
|
* Compute binned values over a one-dimensional extent.
|
|
9
|
-
* @param
|
|
7
|
+
* @param x The expression to bin.
|
|
10
8
|
* The expression must return numeric values. For example, to bin
|
|
11
9
|
* datetime values, the input expression might map them to numeric
|
|
12
10
|
* values such as milliseconds since the epoch.
|
|
13
|
-
* @param
|
|
14
|
-
* @param
|
|
15
|
-
* @param
|
|
11
|
+
* @param lo The low value of the bin extent.
|
|
12
|
+
* @param hi The high value of the bin extent.
|
|
13
|
+
* @param bins The integer number of bins to use within the
|
|
16
14
|
* defined binning extent.
|
|
17
|
-
* @param
|
|
15
|
+
* @param reverse Flag indicating if bins should be
|
|
18
16
|
* produced in reverse order from *hi* to *lo* (default `false`).
|
|
19
17
|
*/
|
|
20
|
-
export function bin1d(
|
|
18
|
+
export function bin1d(
|
|
19
|
+
x: ExprValue,
|
|
20
|
+
lo: number,
|
|
21
|
+
hi: number,
|
|
22
|
+
bins: number,
|
|
23
|
+
reverse: boolean = false
|
|
24
|
+
) {
|
|
21
25
|
const diff = reverse ? sub(hi, float64(x)) : sub(float64(x), lo);
|
|
22
26
|
const scale = hi === lo ? 0 : bins / (hi - lo);
|
|
23
27
|
return scale ? mul(diff, float64(scale)) : diff;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* @import { ExprValue } from '../types.js'
|
|
4
|
-
*/
|
|
1
|
+
import type { SelectQuery } from '../ast/query.js';
|
|
2
|
+
import type { ExprValue } from '../types.js';
|
|
5
3
|
import { int32 } from '../functions/cast.js';
|
|
6
4
|
import { floor } from '../functions/numeric.js';
|
|
7
5
|
import { add, mul } from '../functions/operators.js';
|
|
@@ -12,17 +10,23 @@ import { add, mul } from '../functions/operators.js';
|
|
|
12
10
|
* in units of grid indices, but can contain fractional components. The
|
|
13
11
|
* resulting query performs grouping and aggregation over the binned domain,
|
|
14
12
|
* and uses a 2D integer bin index of the form (xbin + num_xbins * ybin).
|
|
15
|
-
* @param
|
|
13
|
+
* @param q The input query. The FROM and WHERE clauses should
|
|
16
14
|
* be added to the query separately, either before or after this method.
|
|
17
|
-
* @param
|
|
18
|
-
* @param
|
|
19
|
-
* @param
|
|
20
|
-
*
|
|
21
|
-
* @param
|
|
22
|
-
* @
|
|
23
|
-
* @returns {SelectQuery} The input query, with binning expressions added.
|
|
15
|
+
* @param xp The x bin expression.
|
|
16
|
+
* @param yp The y bin expression.
|
|
17
|
+
* @param aggs Named aggregate expressions over bins.
|
|
18
|
+
* @param {xn The number of bins along the x dimension
|
|
19
|
+
* @param groupby Group by expressions.
|
|
20
|
+
* @returns The input query, with binning expressions added.
|
|
24
21
|
*/
|
|
25
|
-
export function bin2d(
|
|
22
|
+
export function bin2d(
|
|
23
|
+
q: SelectQuery,
|
|
24
|
+
xp: ExprValue,
|
|
25
|
+
yp: ExprValue,
|
|
26
|
+
aggs: Record<string, ExprValue>,
|
|
27
|
+
xn: number,
|
|
28
|
+
groupby: string[]
|
|
29
|
+
) {
|
|
26
30
|
return q
|
|
27
31
|
.select({
|
|
28
32
|
index: add(int32(floor(xp)), mul(int32(floor(yp)), xn)),
|