@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
|
@@ -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,75 @@
|
|
|
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 { LiteralNode } from './ast/literal.js';
|
|
15
|
+
export { AndNode, OrNode } from './ast/logical-op.js';
|
|
16
|
+
export { SQLNode, ExprNode, isNode } from './ast/node.js';
|
|
17
|
+
export { OrderByNode } from './ast/order-by.js';
|
|
18
|
+
export { ParamNode } from './ast/param.js';
|
|
19
|
+
export { DescribeQuery, Query, SelectQuery, SetOperation, isDescribeQuery, isQuery, isSelectQuery } from './ast/query.js';
|
|
20
|
+
export { SampleClauseNode } from './ast/sample.js';
|
|
21
|
+
export { ScalarSubqueryNode } from './ast/subquery.js';
|
|
22
|
+
export { SelectClauseNode } from './ast/select.js';
|
|
23
|
+
export { TableRefNode, isTableRef } from './ast/table-ref.js';
|
|
24
|
+
export { UnaryOpNode, UnaryPostfixOpNode } from './ast/unary-op.js';
|
|
25
|
+
export { VerbatimNode } from './ast/verbatim.js';
|
|
26
|
+
export { WindowClauseNode, WindowDefNode, WindowFunctionNode, WindowNode } from './ast/window.js';
|
|
27
|
+
export { WindowFrameNode, WindowFrameExprNode, type FrameExclude, type FrameExtent, type FrameScope, type FrameType, type FrameValue } from './ast/window-frame.js';
|
|
28
|
+
export { WithClauseNode } from './ast/with.js';
|
|
29
|
+
|
|
30
|
+
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';
|
|
31
|
+
export { cond } from './functions/case.js';
|
|
32
|
+
export { cast, float32, float64, int32 } from './functions/cast.js';
|
|
33
|
+
export { collate } from './functions/collate.js';
|
|
34
|
+
export { column } from './functions/column.js';
|
|
35
|
+
export { cte } from './functions/cte.js';
|
|
36
|
+
export { dateBin, dateMonth, dateMonthDay, dateDay, epoch_ms } from './functions/datetime.js';
|
|
37
|
+
export { days, hours, interval, microseconds, minutes, milliseconds, months, seconds, years } from './functions/interval.js';
|
|
38
|
+
export { literal, verbatim } from './functions/literal.js';
|
|
39
|
+
export { abs, ceil, exp, floor, greatest, isFinite, isInfinite, isNaN, least, ln, log, round, sign, sqrt, trunc } from './functions/numeric.js';
|
|
40
|
+
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';
|
|
41
|
+
export { asc, desc } from './functions/order-by.js';
|
|
42
|
+
export { geojson, x, y, centroid, centroidX, centroidY } from './functions/spatial.js';
|
|
43
|
+
export { sql } from './functions/sql-template-tag.js';
|
|
44
|
+
export { regexp_matches, contains, prefix, suffix, lower, upper, length } from './functions/string.js';
|
|
45
|
+
export { coalesce } from './functions/util.js';
|
|
46
|
+
export { cume_dist, dense_rank, first_value, lag, last_value, lead, nth_value, ntile, percent_rank, rank, row_number } from './functions/window.js';
|
|
47
|
+
export { currentRow, following, frameGroups, frameRange, frameRows, preceding } from './functions/window-frame.js';
|
|
48
|
+
|
|
49
|
+
export { deepClone } from './visit/clone.js';
|
|
50
|
+
export { rewrite } from './visit/rewrite.js';
|
|
51
|
+
export { collectAggregates, collectColumns, collectParams, isAggregateExpression } from './visit/visitors.js';
|
|
52
|
+
export { walk, type VisitorCallback, type VisitorResult } from './visit/walk.js';
|
|
53
|
+
|
|
54
|
+
export { createTable, createSchema } from './load/create.js';
|
|
55
|
+
export { loadExtension } from './load/extension.js';
|
|
56
|
+
export { loadCSV, loadJSON, loadObjects, loadParquet, loadSpatial } from './load/load.js';
|
|
57
|
+
|
|
58
|
+
export { bin1d } from './transforms/bin-1d.js';
|
|
59
|
+
export { bin2d } from './transforms/bin-2d.js';
|
|
60
|
+
export { binDate } from './transforms/bin-date.js';
|
|
61
|
+
export { binHistogram } from './transforms/bin-histogram.js';
|
|
62
|
+
export { binLinear1d } from './transforms/bin-linear-1d.js';
|
|
63
|
+
export { binLinear2d } from './transforms/bin-linear-2d.js';
|
|
64
|
+
export { filterQuery } from './transforms/filter-query.js';
|
|
65
|
+
export { lineDensity } from './transforms/line-density.js';
|
|
66
|
+
export { m4 } from './transforms/m4.js';
|
|
67
|
+
export { scaleTransform, type Scale, type ScaleDomain, type ScaleOptions, type ScaleTransform, type ScaleType } from './transforms/scales.js';
|
|
68
|
+
|
|
69
|
+
export { asLiteral, asNode, asTableRef, asVerbatim, over } from './util/ast.js';
|
|
70
|
+
export { isParamLike } from './util/type-check.js';
|
|
71
|
+
|
|
72
|
+
export { binSpec, binStep, type BinOptions } from './transforms/util/bin-step.js';
|
|
73
|
+
export { timeInterval, type TimeUnit } from './transforms/util/time-interval.js';
|
|
74
|
+
|
|
75
|
+
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,25 +21,25 @@ 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
|
|
|
25
36
|
/**
|
|
26
37
|
* Load geometry data within a spatial file format.
|
|
27
38
|
* This method requires that the DuckDB spatial extension is loaded.
|
|
28
|
-
* Supports GeoJSON, TopoJSON, and other
|
|
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)),
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ExprNode } from '../ast/node.js';
|
|
2
|
+
import type { ExprValue } from '../types.js';
|
|
3
|
+
import { dateBin } from '../functions/datetime.js';
|
|
4
|
+
import { interval } from '../functions/interval.js';
|
|
5
|
+
import { add } from '../functions/operators.js';
|
|
6
|
+
import { timeInterval, type DateTimeValue, type TimeUnit } from './util/time-interval.js';
|
|
7
|
+
|
|
8
|
+
export interface BinDateOptions {
|
|
9
|
+
/**
|
|
10
|
+
* A string indicating a time interval unit,
|
|
11
|
+
* such as 'year', 'day', or 'hour'.
|
|
12
|
+
*/
|
|
13
|
+
interval?: TimeUnit;
|
|
14
|
+
/**
|
|
15
|
+
* The number of time interval steps to take, such as 2 years or 3 months.
|
|
16
|
+
*/
|
|
17
|
+
step?: number;
|
|
18
|
+
/**
|
|
19
|
+
* The number of bin steps (default 0) by which to offset the result.
|
|
20
|
+
*/
|
|
21
|
+
offset?: number;
|
|
22
|
+
/**
|
|
23
|
+
* The desired number of binning steps. This value is a hint,
|
|
24
|
+
* it does not guarantee an exact number of steps.
|
|
25
|
+
*/
|
|
26
|
+
steps?: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Return a SQL expression for date/time bins.
|
|
31
|
+
* @param field The column or expression to bin.
|
|
32
|
+
* @param extent The min/max extent over which to bin.
|
|
33
|
+
* @param options Datetime binning options.
|
|
34
|
+
*/
|
|
35
|
+
export function binDate(
|
|
36
|
+
field: ExprValue,
|
|
37
|
+
extent: [DateTimeValue, DateTimeValue],
|
|
38
|
+
options: BinDateOptions = {}
|
|
39
|
+
): ExprNode {
|
|
40
|
+
const { offset = 0 } = options;
|
|
41
|
+
|
|
42
|
+
// use interval if provided, otherwise determine from extent
|
|
43
|
+
const { unit, step = 1 } = options.interval
|
|
44
|
+
? { unit: options.interval, step: options.step }
|
|
45
|
+
: timeInterval(extent[0], extent[1], options.steps || 40);
|
|
46
|
+
const bin = dateBin(field, unit, step);
|
|
47
|
+
return offset ? add(bin, interval(unit, offset * step)) : bin;
|
|
48
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { ExprNode } from '../ast/node.js';
|
|
2
|
+
import type { ExprValue } from '../types.js';
|
|
3
|
+
import { float64 } from '../functions/cast.js';
|
|
4
|
+
import { floor } from '../functions/numeric.js';
|
|
5
|
+
import { add, div, mul, sub } from '../functions/operators.js';
|
|
6
|
+
import { binSpec } from './util/bin-step.js';
|
|
7
|
+
import { Scale, scaleTransform } from './scales.js';
|
|
8
|
+
|
|
9
|
+
export interface BinHistogramOptions {
|
|
10
|
+
/** An exact binning step to use. */
|
|
11
|
+
step?: number;
|
|
12
|
+
/**
|
|
13
|
+
* The desired number of binning steps. This value is a hint,
|
|
14
|
+
* it does not guarantee an exact number of steps.
|
|
15
|
+
*/
|
|
16
|
+
steps?: number;
|
|
17
|
+
/**
|
|
18
|
+
* A minimum binning step value. No generated
|
|
19
|
+
* step can be less than this value.
|
|
20
|
+
*/
|
|
21
|
+
minstep?: number;
|
|
22
|
+
/**
|
|
23
|
+
* A boolean flag (default true) indicating if bin extents should be
|
|
24
|
+
* snapped to "nice" numbers such as multiples of 5 or 10.
|
|
25
|
+
*/
|
|
26
|
+
nice?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The number of bin steps (default 0) by which to offset the result.
|
|
29
|
+
*/
|
|
30
|
+
offset?: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Return a SQL expression for histogram bins.
|
|
35
|
+
* @param field The column or expression to bin.
|
|
36
|
+
* @param extent The min/max extent over which to bin.
|
|
37
|
+
* @param options Binning options.
|
|
38
|
+
* @param transform Scale transforms to apply to create
|
|
39
|
+
* (potentially non-linear) binning intervals.
|
|
40
|
+
* @returns The resulting SQL expression
|
|
41
|
+
*/
|
|
42
|
+
export function binHistogram(
|
|
43
|
+
field: ExprValue,
|
|
44
|
+
extent: [number, number],
|
|
45
|
+
options: BinHistogramOptions = {},
|
|
46
|
+
transform: Scale<number> = scaleTransform({ type: 'linear' })!
|
|
47
|
+
): ExprNode {
|
|
48
|
+
const [min, max] = extent;
|
|
49
|
+
const { offset = 0 } = options;
|
|
50
|
+
const { apply, sqlApply, sqlInvert } = transform;
|
|
51
|
+
const b = binSpec(apply(min), apply(max), options);
|
|
52
|
+
const col = sqlApply(field);
|
|
53
|
+
const alpha = (b.max - b.min) / b.steps;
|
|
54
|
+
|
|
55
|
+
let expr = b.min === 0 ? col : sub(col, b.min);
|
|
56
|
+
if (alpha !== 1) expr = div(expr, float64(alpha));
|
|
57
|
+
expr = floor(offset ? add(offset, expr) : expr);
|
|
58
|
+
if (alpha !== 1) expr = mul(alpha, expr);
|
|
59
|
+
if (b.min !== 0) expr = add(b.min, expr);
|
|
60
|
+
return sqlInvert(expr);
|
|
61
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*/
|
|
1
|
+
import type { ExprNode } from '../ast/node.js';
|
|
2
|
+
import type { SelectQuery } from '../ast/query.js';
|
|
3
|
+
import type { ExprValue } from '../types.js';
|
|
5
4
|
import { Query } from '../ast/query.js';
|
|
6
5
|
import { sum } from '../functions/aggregate.js';
|
|
7
6
|
import { int32 } from '../functions/cast.js';
|
|
@@ -10,14 +9,20 @@ import { add, mul, neq, sub } from '../functions/operators.js';
|
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
11
|
* Perform linear binning in one dimension.
|
|
13
|
-
* @param
|
|
14
|
-
* @param
|
|
15
|
-
* @param
|
|
16
|
-
* @param
|
|
17
|
-
* @returns {Query}
|
|
12
|
+
* @param query The base query to bin.
|
|
13
|
+
* @param x The expression to bin.
|
|
14
|
+
* @param weight The expression to weight by.
|
|
15
|
+
* @param groupby Group by expressions.
|
|
18
16
|
*/
|
|
19
|
-
export function binLinear1d(
|
|
20
|
-
|
|
17
|
+
export function binLinear1d(
|
|
18
|
+
query: SelectQuery,
|
|
19
|
+
x: ExprValue,
|
|
20
|
+
weight: ExprValue | undefined = undefined,
|
|
21
|
+
groupby: string[] = []
|
|
22
|
+
) {
|
|
23
|
+
const w = weight
|
|
24
|
+
? ((x: ExprNode) => mul(x, weight))
|
|
25
|
+
: ((x: ExprNode) => x);
|
|
21
26
|
const p0 = floor(x);
|
|
22
27
|
const p1 = add(p0, 1);
|
|
23
28
|
return Query
|