@uwdata/mosaic-sql 0.17.0 → 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 +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/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 +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/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 +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/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/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/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 +69 -0
- package/dist/src/index.d.ts.map +1 -0
- package/{src → dist/src}/index.js +4 -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 +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/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/{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} +159 -203
- 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/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/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/{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/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} +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} +1 -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
- /package/src/{constants.js → constants.ts} +0 -0
|
@@ -1,22 +1,12 @@
|
|
|
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';
|
|
8
7
|
import { floor } from '../functions/numeric.js';
|
|
9
8
|
import { add, mul, neq, sub } from '../functions/operators.js';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Identity function.
|
|
13
|
-
* @template T
|
|
14
|
-
* @param {T} x
|
|
15
|
-
* @returns {T}
|
|
16
|
-
*/
|
|
17
|
-
function identity(x) {
|
|
18
|
-
return x;
|
|
19
|
-
}
|
|
9
|
+
import { identity } from '../util/identity.js';
|
|
20
10
|
|
|
21
11
|
/**
|
|
22
12
|
* Compute densities over a 2D domain using linear binning. The weight of
|
|
@@ -24,30 +14,28 @@ function identity(x) {
|
|
|
24
14
|
* a better base for subsequent kernel density estimation. This method takes
|
|
25
15
|
* expressions for the (non-truncated) x and y bin values; these expressions
|
|
26
16
|
* should be in units of grid indices, but can contain fractional components.
|
|
27
|
-
* @param
|
|
17
|
+
* @param q The input query. The FROM and WHERE clauses should
|
|
28
18
|
* be added to the query separately, before this method is invoked.
|
|
29
|
-
* @param
|
|
30
|
-
* @param
|
|
31
|
-
* @param
|
|
32
|
-
* @param
|
|
33
|
-
* @param
|
|
34
|
-
* @returns
|
|
35
|
-
*
|
|
19
|
+
* @param xp The x grid bin expression
|
|
20
|
+
* @param yp The y grid bin expression
|
|
21
|
+
* @param weight Point weights.
|
|
22
|
+
* @param xn The number of x grid bins.
|
|
23
|
+
* @param groupby Group by expressions.
|
|
24
|
+
* @returns A linear binning query for bin `index` and aggregate `density`
|
|
25
|
+
* columns, in addition to any group by expressions.
|
|
36
26
|
*/
|
|
37
|
-
export function binLinear2d(
|
|
38
|
-
|
|
39
|
-
|
|
27
|
+
export function binLinear2d(
|
|
28
|
+
q: SelectQuery,
|
|
29
|
+
xp: ExprValue,
|
|
30
|
+
yp: ExprValue,
|
|
31
|
+
weight: ExprValue | undefined,
|
|
32
|
+
xn: number,
|
|
33
|
+
groupby: string[] = []
|
|
34
|
+
) {
|
|
35
|
+
const w = weight ? (x: ExprNode) => mul(x, weight) : identity;
|
|
40
36
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
* @param {ExprValue} w
|
|
44
|
-
*/
|
|
45
|
-
const subq = (i, w) => q.clone().select({ xp, yp, i, w });
|
|
46
|
-
/**
|
|
47
|
-
* @param {ExprValue} x
|
|
48
|
-
* @param {ExprValue} y
|
|
49
|
-
*/
|
|
50
|
-
const index = (x, y) => add(x, mul(y, xn));
|
|
37
|
+
const subq = (i: ExprValue, w: ExprValue) => q.clone().select({ xp, yp, i, w });
|
|
38
|
+
const index = (x: ExprValue, y: ExprValue) => add(x, mul(y, xn));
|
|
51
39
|
|
|
52
40
|
const xu = int32(floor(xp));
|
|
53
41
|
const yu = int32(floor(yp));
|
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* @import { FilterExpr } from '../types.js'
|
|
5
|
-
*/
|
|
6
|
-
import { isSelectQuery } from '../ast/query.js';
|
|
7
|
-
import { isTableRef } from '../ast/table-ref.js';
|
|
1
|
+
import type { FilterExpr } from '../types.js';
|
|
2
|
+
import { isSelectQuery, type Query } from '../ast/query.js';
|
|
3
|
+
import { isTableRef, type TableRefNode } from '../ast/table-ref.js';
|
|
8
4
|
import { deepClone } from '../visit/clone.js';
|
|
9
5
|
import { walk } from '../visit/walk.js';
|
|
10
6
|
|
|
11
7
|
/**
|
|
12
8
|
* Returns a generator function that clones the given query and adds
|
|
13
9
|
* a WHERE clause for the specified table reference.
|
|
14
|
-
* @param
|
|
15
|
-
* @param
|
|
16
|
-
* @returns
|
|
10
|
+
* @param query The query to clone and extend.
|
|
11
|
+
* @param tableRef The table to filter.
|
|
12
|
+
* @returns The generator function.
|
|
17
13
|
*/
|
|
18
|
-
export function filterQuery(query, tableRef) {
|
|
19
|
-
return (filter) => {
|
|
14
|
+
export function filterQuery(query: Query, tableRef: TableRefNode) {
|
|
15
|
+
return (filter: FilterExpr) => {
|
|
20
16
|
const clone = deepClone(query);
|
|
21
17
|
walk(clone, (node) => {
|
|
22
18
|
if (
|
|
@@ -32,12 +28,12 @@ export function filterQuery(query, tableRef) {
|
|
|
32
28
|
};
|
|
33
29
|
}
|
|
34
30
|
|
|
35
|
-
function arrayEquals(a, b) {
|
|
31
|
+
function arrayEquals(a: unknown[], b: unknown[]) {
|
|
36
32
|
if (a === b) return true;
|
|
37
33
|
if (a == null || b == null) return false;
|
|
38
34
|
if (a.length !== b.length) return false;
|
|
39
35
|
|
|
40
|
-
for (
|
|
36
|
+
for (let i = 0; i < a.length; ++i) {
|
|
41
37
|
if (a[i] !== b[i]) return false;
|
|
42
38
|
}
|
|
43
39
|
return true;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* @import { ExprValue } from '../types.js'
|
|
4
|
-
*/
|
|
5
|
-
import { Query } from '../ast/query.js';
|
|
1
|
+
import type { ExprValue } from '../types.js';
|
|
2
|
+
import { Query, type SelectQuery } from '../ast/query.js';
|
|
6
3
|
import { count, max, sum } from '../functions/aggregate.js';
|
|
7
4
|
import { int32 } from '../functions/cast.js';
|
|
8
5
|
import { abs, floor, greatest, round, sign } from '../functions/numeric.js';
|
|
@@ -18,24 +15,29 @@ import { over } from '../util/ast.js';
|
|
|
18
15
|
* pairs, perform line rasterization in-database, normalize arc lengths,
|
|
19
16
|
* and then sum results for all line series to produce a density map.
|
|
20
17
|
* Based on Moritz and Fisher's work: https://arxiv.org/abs/1808.06019
|
|
21
|
-
* @param
|
|
22
|
-
* @param
|
|
18
|
+
* @param q The base query over the data.
|
|
19
|
+
* @param x Bin expression for x dimension.
|
|
23
20
|
* Provides gridded x coordinates, potentially with a fractional component.
|
|
24
|
-
* @param
|
|
21
|
+
* @param y Bin expression for x dimension.
|
|
25
22
|
* Provides gridded y coordinates, potentially with a fractional component.
|
|
26
|
-
* @param
|
|
23
|
+
* @param z Group by columns that segment data into individual line
|
|
27
24
|
* series. An empty array indicates there is only a single line series.
|
|
28
|
-
* @param
|
|
29
|
-
* @param
|
|
30
|
-
* @param
|
|
25
|
+
* @param xn The number of grid bins for the x dimension.
|
|
26
|
+
* @param yn The number of grid bins for the y dimension.
|
|
27
|
+
* @param groupby Additional group by expressions. Separate
|
|
31
28
|
* line density maps are created for each of these groups.
|
|
32
|
-
* @param
|
|
33
|
-
*
|
|
34
|
-
* @returns {SelectQuery}
|
|
29
|
+
* @param normalize Flag toggling approximate arc-length normalization to
|
|
30
|
+
* improve accuracy and reduce artifacts (default `true`).
|
|
35
31
|
*/
|
|
36
32
|
export function lineDensity(
|
|
37
|
-
q
|
|
38
|
-
|
|
33
|
+
q: SelectQuery,
|
|
34
|
+
x: ExprValue,
|
|
35
|
+
y: ExprValue,
|
|
36
|
+
z: string[],
|
|
37
|
+
xn: number,
|
|
38
|
+
yn: number,
|
|
39
|
+
groupby: string[] = [],
|
|
40
|
+
normalize: boolean = true
|
|
39
41
|
) {
|
|
40
42
|
// select x, y points binned to the grid
|
|
41
43
|
q.select({
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* @import { ExprValue, FromExpr } from '../types.js'
|
|
4
|
-
*/
|
|
1
|
+
import type { ExprValue, FromExpr, SelectExpr } from '../types.js';
|
|
2
|
+
import type { ColumnRefNode } from '../ast/column-ref.js';
|
|
5
3
|
import { Query, isQuery } from '../ast/query.js';
|
|
6
4
|
import { argmax, argmin, max, min } from '../functions/aggregate.js';
|
|
7
5
|
import { int32 } from '../functions/cast.js';
|
|
@@ -15,16 +13,21 @@ import { floor } from '../functions/numeric.js';
|
|
|
15
13
|
* argmin and argmax, following https://arxiv.org/pdf/2306.03714.pdf.
|
|
16
14
|
* This method can bin along either the *x* or *y* dimension, as determined
|
|
17
15
|
* by the caller-provided *bin* expression.
|
|
18
|
-
* @param
|
|
19
|
-
* @param
|
|
16
|
+
* @param input The base query or table.
|
|
17
|
+
* @param bin An expression that maps
|
|
20
18
|
* time-series values to fractional pixel positions.
|
|
21
|
-
* @param
|
|
22
|
-
* @param
|
|
23
|
-
* @param
|
|
24
|
-
*
|
|
25
|
-
* @returns {Query} The resulting M4 query.
|
|
19
|
+
* @param x The x dimension column name.
|
|
20
|
+
* @param y The y dimension column name.
|
|
21
|
+
* @param groups Additional groupby columns, for example for faceted charts.
|
|
22
|
+
* @returns The resulting M4 query.
|
|
26
23
|
*/
|
|
27
|
-
export function m4(
|
|
24
|
+
export function m4(
|
|
25
|
+
input: FromExpr,
|
|
26
|
+
bin: ExprValue,
|
|
27
|
+
x: string,
|
|
28
|
+
y: string,
|
|
29
|
+
groups: ColumnRefNode[] = []
|
|
30
|
+
) {
|
|
28
31
|
const pixel = int32(floor(bin));
|
|
29
32
|
|
|
30
33
|
// Below, we treat input as a CTE when it is a query. In this case,
|
|
@@ -32,10 +35,10 @@ export function m4(input, bin, x, y, groups = []) {
|
|
|
32
35
|
const useCTE = isQuery(input);
|
|
33
36
|
const from = useCTE ? 'input' : input;
|
|
34
37
|
const query = useCTE
|
|
35
|
-
? Query.with(cte(
|
|
38
|
+
? Query.with(cte(String(from), input, true))
|
|
36
39
|
: Query;
|
|
37
40
|
|
|
38
|
-
const q = (sel) => Query
|
|
41
|
+
const q = (sel: SelectExpr) => Query
|
|
39
42
|
.from(from)
|
|
40
43
|
.select(sel)
|
|
41
44
|
.groupby(pixel, groups);
|
|
@@ -1,13 +1,55 @@
|
|
|
1
|
+
import type { ExprValue } from '../types.js';
|
|
1
2
|
import { LiteralNode } from '../ast/literal.js';
|
|
3
|
+
import { ExprNode } from '../ast/node.js';
|
|
2
4
|
import { epoch_ms } from '../functions/datetime.js';
|
|
3
5
|
import { literal } from '../functions/literal.js';
|
|
4
6
|
import { abs, exp, ln, log, sign, sqrt } from '../functions/numeric.js';
|
|
5
7
|
import { add, div, mul, pow, sub } from '../functions/operators.js';
|
|
6
8
|
import { asNode } from '../util/ast.js';
|
|
9
|
+
import { identity } from '../util/identity.js';
|
|
10
|
+
import { DateTimeValue } from './util/time-interval.js';
|
|
7
11
|
|
|
8
|
-
|
|
12
|
+
export interface ScaleTransform<T> {
|
|
13
|
+
apply: (value: T) => number;
|
|
14
|
+
invert: (value: number) => T;
|
|
15
|
+
sqlApply: (value: ExprValue) => ExprNode;
|
|
16
|
+
sqlInvert: (value: ExprNode) => ExprNode;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type ScaleType =
|
|
20
|
+
| 'identity'
|
|
21
|
+
| 'linear'
|
|
22
|
+
| 'log'
|
|
23
|
+
| 'symlog'
|
|
24
|
+
| 'sqrt'
|
|
25
|
+
| 'pow'
|
|
26
|
+
| 'time'
|
|
27
|
+
| 'utc'
|
|
28
|
+
;
|
|
29
|
+
|
|
30
|
+
export type ScaleDomain = [number, number] | [Date, Date];
|
|
31
|
+
|
|
32
|
+
export interface ScaleOptions {
|
|
33
|
+
/** The scale type, such as `'linear'`, `'log'`, etc. */
|
|
34
|
+
type: ScaleType;
|
|
35
|
+
/** The scale domain, as an array of start and end data values. */
|
|
36
|
+
domain?: ScaleDomain;
|
|
37
|
+
/**
|
|
38
|
+
* The scale range, as an array of start and end screen pixels.
|
|
39
|
+
* The range may be omitted for *identity* scales.
|
|
40
|
+
*/
|
|
41
|
+
range?: [number, number];
|
|
42
|
+
/** The base of the logarithm. For `'log'` scales only. */
|
|
43
|
+
base?: number;
|
|
44
|
+
/** The constant parameter. For `'symlog'` scales only. */
|
|
45
|
+
constant?: number;
|
|
46
|
+
/** The exponent parameter. For `'pow'` scales only. */
|
|
47
|
+
exponent?: number;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type Scale<T> = ScaleTransform<T> & ScaleOptions;
|
|
9
51
|
|
|
10
|
-
function scaleLinear() {
|
|
52
|
+
function scaleLinear(): ScaleTransform<number> {
|
|
11
53
|
return {
|
|
12
54
|
apply: identity,
|
|
13
55
|
invert: identity,
|
|
@@ -16,7 +58,7 @@ function scaleLinear() {
|
|
|
16
58
|
};
|
|
17
59
|
}
|
|
18
60
|
|
|
19
|
-
function scaleLog({ base = null } = {}) {
|
|
61
|
+
function scaleLog({ base = null }: {base?: number | null} = { }): ScaleTransform<number> {
|
|
20
62
|
if (base == null || base === Math.E) {
|
|
21
63
|
return {
|
|
22
64
|
apply: Math.log,
|
|
@@ -42,7 +84,7 @@ function scaleLog({ base = null } = {}) {
|
|
|
42
84
|
}
|
|
43
85
|
}
|
|
44
86
|
|
|
45
|
-
function scaleSymlog({ constant = 1 } = {}) {
|
|
87
|
+
function scaleSymlog({ constant = 1 } = {}): ScaleTransform<number> {
|
|
46
88
|
const _ = +constant;
|
|
47
89
|
return {
|
|
48
90
|
apply: x => Math.sign(x) * Math.log1p(Math.abs(x)),
|
|
@@ -52,7 +94,7 @@ function scaleSymlog({ constant = 1 } = {}) {
|
|
|
52
94
|
};
|
|
53
95
|
}
|
|
54
96
|
|
|
55
|
-
function scaleSqrt() {
|
|
97
|
+
function scaleSqrt(): ScaleTransform<number> {
|
|
56
98
|
return {
|
|
57
99
|
apply: x => Math.sign(x) * Math.sqrt(Math.abs(x)),
|
|
58
100
|
invert: x => Math.sign(x) * x * x,
|
|
@@ -61,7 +103,7 @@ function scaleSqrt() {
|
|
|
61
103
|
};
|
|
62
104
|
}
|
|
63
105
|
|
|
64
|
-
function scalePow({ exponent = 1 } = {}) {
|
|
106
|
+
function scalePow({ exponent = 1 } = {}): ScaleTransform<number> {
|
|
65
107
|
const e = +exponent;
|
|
66
108
|
return {
|
|
67
109
|
apply: x => Math.sign(x) * Math.pow(Math.abs(x), e),
|
|
@@ -71,12 +113,12 @@ function scalePow({ exponent = 1 } = {}) {
|
|
|
71
113
|
};
|
|
72
114
|
}
|
|
73
115
|
|
|
74
|
-
function scaleTime() {
|
|
116
|
+
function scaleTime(): ScaleTransform<DateTimeValue> {
|
|
75
117
|
return {
|
|
76
|
-
apply: x =>
|
|
118
|
+
apply: x => Number(x),
|
|
77
119
|
invert: x => new Date(x),
|
|
78
120
|
sqlApply: c => c instanceof Date ? literal(+c)
|
|
79
|
-
: isDateLiteral(c) ? literal(
|
|
121
|
+
: isDateLiteral(c) ? literal(Number(c.value))
|
|
80
122
|
: epoch_ms(c),
|
|
81
123
|
sqlInvert: identity
|
|
82
124
|
};
|
|
@@ -93,16 +135,17 @@ const scales = {
|
|
|
93
135
|
utc: scaleTime
|
|
94
136
|
};
|
|
95
137
|
|
|
96
|
-
export function scaleTransform(options) {
|
|
138
|
+
export function scaleTransform<T>(options: ScaleOptions): Scale<T> {
|
|
97
139
|
const scale = scales[options.type];
|
|
98
|
-
|
|
140
|
+
if (!scale) throw new Error(`Unrecognized scale type: ${options.type}`);
|
|
141
|
+
// @ts-expect-error suppress error, revisit later?
|
|
142
|
+
return { ...options, ...scale(options) };
|
|
99
143
|
}
|
|
100
144
|
|
|
101
145
|
/**
|
|
102
146
|
* Check if a value is a date-valued literal SQL AST node.
|
|
103
|
-
* @param
|
|
104
|
-
* @returns {x is LiteralNode}
|
|
147
|
+
* @param x The value to test.
|
|
105
148
|
*/
|
|
106
|
-
function isDateLiteral(x) {
|
|
149
|
+
function isDateLiteral(x: unknown): x is LiteralNode {
|
|
107
150
|
return x instanceof LiteralNode && x.value instanceof Date;
|
|
108
151
|
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/** Numerical binning options. */
|
|
2
|
+
export interface BinOptions {
|
|
3
|
+
/**
|
|
4
|
+
* An exact binning step to use.
|
|
5
|
+
*/
|
|
6
|
+
step?: number;
|
|
7
|
+
/**
|
|
8
|
+
* The desired number of binning steps. This value is a hint,
|
|
9
|
+
* it does not guarantee an exact number of steps.
|
|
10
|
+
*/
|
|
11
|
+
steps?: number;
|
|
12
|
+
/**
|
|
13
|
+
* A minimum binning step value.
|
|
14
|
+
* No generated step can be less than this value.
|
|
15
|
+
*/
|
|
16
|
+
minstep?: number;
|
|
17
|
+
/**
|
|
18
|
+
* A boolean flag (default true) indicating if bin extents should be snapped
|
|
19
|
+
* to "nice" numbers such as multiples of 5 or 10.
|
|
20
|
+
*/
|
|
21
|
+
nice?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* A number indicating the the logarithm base to use for automatic step size
|
|
24
|
+
* determination. Defaults to base 10.
|
|
25
|
+
*/
|
|
26
|
+
base?: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Generate a numeric binning scheme suitable for a histogram.
|
|
31
|
+
* @param min The minimum value of the extent to bin.
|
|
32
|
+
* @param max The maximum value of the extent to bin.
|
|
33
|
+
* @param options Binning scheme options.
|
|
34
|
+
*/
|
|
35
|
+
export function binSpec(min: number, max: number, options: BinOptions) {
|
|
36
|
+
let {
|
|
37
|
+
step,
|
|
38
|
+
steps = 25,
|
|
39
|
+
} = options;
|
|
40
|
+
const {
|
|
41
|
+
minstep = 0,
|
|
42
|
+
nice = true,
|
|
43
|
+
base
|
|
44
|
+
} = options;
|
|
45
|
+
|
|
46
|
+
if (nice !== false) {
|
|
47
|
+
// use span to determine step size
|
|
48
|
+
const span = max - min;
|
|
49
|
+
const logb = base ? Math.log(base) : Math.LN10;
|
|
50
|
+
step = step || binStep(span, steps, minstep, logb);
|
|
51
|
+
|
|
52
|
+
// adjust min/max relative to step
|
|
53
|
+
let v = Math.log(step);
|
|
54
|
+
const precision = v >= 0 ? 0 : ~~(-v / logb) + 1;
|
|
55
|
+
const eps = Math.pow(10, -precision - 1);
|
|
56
|
+
v = Math.floor(min / step + eps) * step;
|
|
57
|
+
min = min < v ? v - step : v;
|
|
58
|
+
max = Math.ceil(max / step) * step;
|
|
59
|
+
steps = Math.round((max - min) / step);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return { min, max, steps };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Determine a bin step interval.
|
|
67
|
+
* @param span The span from maximum to minimum value.
|
|
68
|
+
* @param steps The approximate number of desired bins.
|
|
69
|
+
* @param minstep The minimum acceptable bin step size.
|
|
70
|
+
* @param logb The log base for determining orders of magnitude for step
|
|
71
|
+
* sizes. Defaults to log base 10 (`Math.LN10`). For example to use log
|
|
72
|
+
* base 2, provide the argument `Math.LN2` instead.
|
|
73
|
+
* @returns The bin step interval (bin size).
|
|
74
|
+
*/
|
|
75
|
+
export function binStep(
|
|
76
|
+
span: number,
|
|
77
|
+
steps: number,
|
|
78
|
+
minstep: number = 0,
|
|
79
|
+
logb: number = Math.LN10
|
|
80
|
+
) {
|
|
81
|
+
let v;
|
|
82
|
+
|
|
83
|
+
const level = Math.ceil(Math.log(steps) / logb);
|
|
84
|
+
let step = Math.max(
|
|
85
|
+
minstep,
|
|
86
|
+
Math.pow(10, Math.round(Math.log(span) / logb) - level)
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
// increase step size if too many bins
|
|
90
|
+
while (Math.ceil(span / step) > steps) { step *= 10; }
|
|
91
|
+
|
|
92
|
+
// decrease step size if allowed
|
|
93
|
+
const div = [5, 2];
|
|
94
|
+
for (let i = 0, n = div.length; i < n; ++i) {
|
|
95
|
+
v = step / div[i];
|
|
96
|
+
if (v >= minstep && span / v <= steps) step = v;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return step;
|
|
100
|
+
}
|
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
/** @import { TimeUnit } from '../../types.js' */
|
|
2
1
|
import { binStep } from './bin-step.js';
|
|
3
2
|
|
|
3
|
+
export type DateTimeValue = Date | number;
|
|
4
|
+
|
|
5
|
+
export type TimeUnit =
|
|
6
|
+
| 'year'
|
|
7
|
+
| 'quarter'
|
|
8
|
+
| 'month'
|
|
9
|
+
| 'day'
|
|
10
|
+
| 'hour'
|
|
11
|
+
| 'minute'
|
|
12
|
+
| 'second'
|
|
13
|
+
| 'millisecond'
|
|
14
|
+
| 'microsecond';
|
|
15
|
+
|
|
4
16
|
const YEAR = 'year';
|
|
5
17
|
const MONTH = 'month';
|
|
6
18
|
const DAY = 'day';
|
|
@@ -18,10 +30,7 @@ const durationWeek = durationDay * 7;
|
|
|
18
30
|
const durationMonth = durationDay * 30;
|
|
19
31
|
const durationYear = durationDay * 365;
|
|
20
32
|
|
|
21
|
-
|
|
22
|
-
* @type {Array<{unit: TimeUnit, step: number, dt: number}>}
|
|
23
|
-
*/
|
|
24
|
-
const units = [
|
|
33
|
+
const units: {unit: TimeUnit, step: number, dt: number}[] = [
|
|
25
34
|
{ unit: SECOND, step: 1, dt: durationSecond },
|
|
26
35
|
{ unit: SECOND, step: 5, dt: durationSecond * 5 },
|
|
27
36
|
{ unit: SECOND, step: 15, dt: durationSecond * 15 },
|
|
@@ -44,18 +53,21 @@ const units = [
|
|
|
44
53
|
/**
|
|
45
54
|
* Determine a time interval for binning based on provided min
|
|
46
55
|
* and max timestamps and approximate step count.
|
|
47
|
-
* @param
|
|
48
|
-
* @param
|
|
49
|
-
* @param
|
|
50
|
-
* @returns {{ unit: TimeUnit, step: number }}
|
|
56
|
+
* @param min The minimum timestamp value.
|
|
57
|
+
* @param max The maximum timestamp value.
|
|
58
|
+
* @param steps The approximate number of bins desired.
|
|
51
59
|
*/
|
|
52
|
-
export function timeInterval(
|
|
60
|
+
export function timeInterval(
|
|
61
|
+
min: DateTimeValue,
|
|
62
|
+
max: DateTimeValue,
|
|
63
|
+
steps: number
|
|
64
|
+
): ({ unit: TimeUnit, step: number }) {
|
|
53
65
|
const span = +max - +min;
|
|
54
66
|
const t = span / steps; // target step size duration
|
|
55
67
|
const i = bisect(units, t, v => v.dt);
|
|
56
|
-
|
|
57
|
-
let unit;
|
|
58
|
-
let step;
|
|
68
|
+
|
|
69
|
+
let unit: TimeUnit;
|
|
70
|
+
let step: number;
|
|
59
71
|
|
|
60
72
|
if (i === units.length) {
|
|
61
73
|
unit = YEAR;
|
|
@@ -72,15 +84,14 @@ export function timeInterval(min, max, steps) {
|
|
|
72
84
|
|
|
73
85
|
/**
|
|
74
86
|
* Perform a binary search.
|
|
75
|
-
* @
|
|
76
|
-
* @param
|
|
77
|
-
* @param
|
|
78
|
-
* @
|
|
79
|
-
* @returns {number} The search result array index.
|
|
87
|
+
* @param a The array to search.
|
|
88
|
+
* @param x The target value.
|
|
89
|
+
* @param value A value accessor.
|
|
90
|
+
* @returns The search result array index.
|
|
80
91
|
*/
|
|
81
|
-
function bisect(a, x, value) {
|
|
82
|
-
const compare1 = (a, b) => a - b;
|
|
83
|
-
const compare2 = (d, x) => compare1(value(d), x);
|
|
92
|
+
function bisect<I, T>(a: I[], x: T, value: (item: I) => T) {
|
|
93
|
+
const compare1 = (a: T, b: T) => Number(a) - Number(b);
|
|
94
|
+
const compare2 = (d: I, x: T) => compare1(value(d), x);
|
|
84
95
|
|
|
85
96
|
let lo = 0;
|
|
86
97
|
let hi = a.length;
|
package/src/types.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { WithClauseNode } from './ast/with.js';
|
|
|
9
9
|
*/
|
|
10
10
|
export interface ParamLike {
|
|
11
11
|
/** The current parameter value. */
|
|
12
|
-
value:
|
|
12
|
+
value: unknown;
|
|
13
13
|
/** Add an event listener callback. */
|
|
14
14
|
addEventListener(type: string, callback: EventCallback): void;
|
|
15
15
|
/** Remove an event listener callback. */
|
|
@@ -19,7 +19,7 @@ export interface ParamLike {
|
|
|
19
19
|
/**
|
|
20
20
|
* Expression value input to SQL builder method.
|
|
21
21
|
*/
|
|
22
|
-
export type ExprValue = ExprNode | ParamLike | string | number | boolean | Date;
|
|
22
|
+
export type ExprValue = ExprNode | ParamLike | string | number | boolean | Date | null;
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* Expression values that may be nested in arrays.
|
|
@@ -39,22 +39,7 @@ export type NumberValue = ExprNode | ParamLike | number;
|
|
|
39
39
|
/**
|
|
40
40
|
* Event listener callback function.
|
|
41
41
|
*/
|
|
42
|
-
export type EventCallback = <T>(value:
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* SQL AST traversal visitor callback result.
|
|
46
|
-
* A falsy value (including `undefined`, `null`, `false`, and `0`) indicates
|
|
47
|
-
* that traversal should continue.
|
|
48
|
-
* A negative number values indicates that traversal should stop immediately.
|
|
49
|
-
* Any other truthy value indicates that traversal should not recurse on the
|
|
50
|
-
* current node, but should otherwise continue.
|
|
51
|
-
*/
|
|
52
|
-
export type VisitorResult = boolean | number | null | undefined | void;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* SQL AST traversal callback function.
|
|
56
|
-
*/
|
|
57
|
-
export type VisitorCallback = (node: SQLNode) => VisitorResult;
|
|
42
|
+
export type EventCallback = <T>(value: unknown) => Promise<T> | undefined;
|
|
58
43
|
|
|
59
44
|
/** Valid window function names. */
|
|
60
45
|
export type WindowFunctionName =
|
|
@@ -74,6 +59,7 @@ export type WindowFunctionName =
|
|
|
74
59
|
export type MaybeArray<T> = T | T[];
|
|
75
60
|
|
|
76
61
|
export type SelectEntry =
|
|
62
|
+
| null
|
|
77
63
|
| string
|
|
78
64
|
| ColumnRefNode
|
|
79
65
|
| [string, ExprNode]
|
|
@@ -96,26 +82,6 @@ export type FromEntry =
|
|
|
96
82
|
|
|
97
83
|
export type FromExpr = MaybeArray<FromEntry>;
|
|
98
84
|
|
|
99
|
-
export type FilterExpr = MaybeArray<string | ExprNode>;
|
|
85
|
+
export type FilterExpr = MaybeArray<string | boolean | ExprNode>;
|
|
100
86
|
export type GroupByExpr = MaybeArray<string | ExprNode>;
|
|
101
87
|
export type OrderByExpr = MaybeArray<string | ExprNode>;
|
|
102
|
-
|
|
103
|
-
export type TimeUnit =
|
|
104
|
-
| 'year'
|
|
105
|
-
| 'quarter'
|
|
106
|
-
| 'month'
|
|
107
|
-
| 'day'
|
|
108
|
-
| 'hour'
|
|
109
|
-
| 'minute'
|
|
110
|
-
| 'second'
|
|
111
|
-
| 'millisecond'
|
|
112
|
-
| 'microsecond';
|
|
113
|
-
|
|
114
|
-
export type FrameValue = ExprNode | number | null;
|
|
115
|
-
|
|
116
|
-
export type FrameExtent = [FrameValue, FrameValue] | ParamLike;
|
|
117
|
-
|
|
118
|
-
export type FrameScope =
|
|
119
|
-
| 'PRECEDING'
|
|
120
|
-
| 'FOLLOWING'
|
|
121
|
-
| 'CURRENT ROW';
|