derive-dashboards 0.7.1 → 0.9.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/CHANGELOG.md +513 -0
- package/README.md +8 -2
- package/dist/adapter/statement.mjs +9 -7
- package/dist/authorize.mjs +27 -6
- package/dist/body.mjs +28 -25
- package/dist/cache.d.mts +2 -2
- package/dist/charts/data/buckets.d.mts +25 -7
- package/dist/charts/data/buckets.mjs +92 -15
- package/dist/charts/data/clean.mjs +254 -12
- package/dist/charts/data/format.d.mts +7 -2
- package/dist/charts/data/format.mjs +68 -70
- package/dist/charts/data/input-error.d.mts +2 -0
- package/dist/charts/data/input-error.mjs +2 -0
- package/dist/charts/data/rows.d.mts +3 -1
- package/dist/charts/data/rows.mjs +4 -2
- package/dist/charts/data/types.d.mts +50 -7
- package/dist/charts/data/words.d.mts +13 -0
- package/dist/charts/data/words.mjs +8 -1
- package/dist/charts/describe.mjs +6 -6
- package/dist/charts/index.d.mts +14 -14
- package/dist/charts/index.mjs +4 -1
- package/dist/charts/kinds/area-marks.mjs +86 -44
- package/dist/charts/kinds/area.d.mts +3 -3
- package/dist/charts/kinds/area.mjs +32 -11
- package/dist/charts/kinds/bars-data.d.mts +3 -3
- package/dist/charts/kinds/bars-data.mjs +12 -6
- package/dist/charts/kinds/bars-layout.mjs +60 -6
- package/dist/charts/kinds/bars-marks.mjs +6 -6
- package/dist/charts/kinds/bars.d.mts +5 -3
- package/dist/charts/kinds/bars.mjs +39 -6
- package/dist/charts/kinds/columns-data.mjs +14 -5
- package/dist/charts/kinds/columns-marks.mjs +52 -23
- package/dist/charts/kinds/columns.d.mts +2 -2
- package/dist/charts/kinds/columns.mjs +36 -10
- package/dist/charts/kinds/course-data.mjs +44 -0
- package/dist/charts/kinds/course-layout.mjs +77 -0
- package/dist/charts/kinds/course-marks.mjs +52 -0
- package/dist/charts/kinds/course-words.mjs +64 -0
- package/dist/charts/kinds/course.d.mts +10 -0
- package/dist/charts/kinds/course.mjs +55 -0
- package/dist/charts/kinds/dumbbell-data.d.mts +4 -4
- package/dist/charts/kinds/dumbbell-data.mjs +3 -3
- package/dist/charts/kinds/dumbbell-layout.mjs +17 -8
- package/dist/charts/kinds/dumbbell.d.mts +5 -3
- package/dist/charts/kinds/dumbbell.mjs +35 -4
- package/dist/charts/kinds/funnel-data.d.mts +3 -3
- package/dist/charts/kinds/funnel-data.mjs +11 -16
- package/dist/charts/kinds/funnel-layout.mjs +7 -6
- package/dist/charts/kinds/funnel.d.mts +5 -4
- package/dist/charts/kinds/funnel.mjs +33 -6
- package/dist/charts/kinds/grid-data.d.mts +3 -3
- package/dist/charts/kinds/grid-data.mjs +55 -13
- package/dist/charts/kinds/grid-layout.mjs +88 -13
- package/dist/charts/kinds/grid-legend.mjs +60 -0
- package/dist/charts/kinds/grid-marks.mjs +81 -32
- package/dist/charts/kinds/grid-time.mjs +19 -5
- package/dist/charts/kinds/grid-words.mjs +57 -35
- package/dist/charts/kinds/grid.d.mts +7 -4
- package/dist/charts/kinds/grid.mjs +51 -9
- package/dist/charts/kinds/histogram-data.mjs +68 -26
- package/dist/charts/kinds/histogram-layout.mjs +4 -3
- package/dist/charts/kinds/histogram-words.mjs +2 -3
- package/dist/charts/kinds/histogram.d.mts +2 -2
- package/dist/charts/kinds/histogram.mjs +17 -1
- package/dist/charts/kinds/line-marks.mjs +19 -11
- package/dist/charts/kinds/line.d.mts +2 -2
- package/dist/charts/kinds/line.mjs +21 -3
- package/dist/charts/kinds/multiples-grid.mjs +57 -27
- package/dist/charts/kinds/multiples-head.mjs +52 -22
- package/dist/charts/kinds/multiples-layout.mjs +106 -52
- package/dist/charts/kinds/multiples-marks.mjs +6 -5
- package/dist/charts/kinds/multiples-words.mjs +53 -38
- package/dist/charts/kinds/multiples.d.mts +2 -2
- package/dist/charts/kinds/multiples.mjs +35 -7
- package/dist/charts/kinds/row-chart.d.mts +7 -0
- package/dist/charts/kinds/row-chart.mjs +47 -10
- package/dist/charts/kinds/row-marks.mjs +5 -5
- package/dist/charts/kinds/scatter-data.d.mts +5 -5
- package/dist/charts/kinds/scatter-data.mjs +6 -6
- package/dist/charts/kinds/scatter-marks.mjs +46 -19
- package/dist/charts/kinds/scatter-words.mjs +8 -8
- package/dist/charts/kinds/scatter.d.mts +5 -3
- package/dist/charts/kinds/scatter.mjs +18 -0
- package/dist/charts/kinds/stat-data.mjs +7 -7
- package/dist/charts/kinds/stat-marks.mjs +2 -2
- package/dist/charts/kinds/stat.d.mts +4 -4
- package/dist/charts/kinds/stat.mjs +19 -0
- package/dist/charts/kinds/time-chart.mjs +13 -4
- package/dist/charts/kinds/time-frame.mjs +50 -19
- package/dist/charts/kinds/time-plan.mjs +29 -2
- package/dist/charts/kinds/time-plot.mjs +1 -1
- package/dist/charts/kinds/time-stops.mjs +58 -29
- package/dist/charts/kinds/waterfall-data.d.mts +3 -3
- package/dist/charts/kinds/waterfall-data.mjs +2 -2
- package/dist/charts/kinds/waterfall.d.mts +5 -4
- package/dist/charts/kinds/waterfall.mjs +29 -2
- package/dist/charts/layout/frame.mjs +5 -3
- package/dist/charts/layout/stack.mjs +43 -22
- package/dist/charts/marks/axes.mjs +12 -6
- package/dist/charts/marks/budget.mjs +14 -0
- package/dist/charts/marks/end-labels.mjs +24 -10
- package/dist/charts/marks/legend.mjs +19 -8
- package/dist/charts/marks/lines.mjs +3 -3
- package/dist/charts/marks/more.mjs +79 -13
- package/dist/charts/marks/notes.mjs +12 -6
- package/dist/charts/marks/series-line.mjs +14 -10
- package/dist/charts/marks/thin.mjs +16 -33
- package/dist/charts/marks/x-axis.mjs +3 -2
- package/dist/charts/scale/calendar.mjs +41 -26
- package/dist/charts/scale/linear.mjs +58 -0
- package/dist/charts/scale/value.d.mts +21 -0
- package/dist/charts/scale/value.mjs +67 -9
- package/dist/charts/scene/lazy.mjs +27 -0
- package/dist/charts/scene/markup.mjs +2 -1
- package/dist/charts/scene/svg.mjs +20 -8
- package/dist/charts/scene/types.d.mts +34 -0
- package/dist/charts/text/measure.mjs +33 -3
- package/dist/charts/theme.d.mts +25 -25
- package/dist/charts/theme.mjs +47 -30
- package/dist/charts-react/Chart.d.mts +20 -0
- package/dist/charts-react/Chart.mjs +9 -67
- package/dist/charts-react/Reader.mjs +50 -96
- package/dist/charts-react/box.mjs +106 -0
- package/dist/charts-react/bucket-names.mjs +9 -24
- package/dist/charts-react/columns-picture.mjs +12 -0
- package/dist/charts-react/exact-sum.mjs +4 -7
- package/dist/charts-react/from-answer.mjs +9 -4
- package/dist/charts-react/index.d.mts +9 -2
- package/dist/charts-react/index.mjs +9 -2
- package/dist/charts-react/kinds/area.d.mts +4 -0
- package/dist/charts-react/kinds/area.mjs +38 -0
- package/dist/charts-react/kinds/bar.d.mts +4 -0
- package/dist/charts-react/kinds/bar.mjs +15 -0
- package/dist/charts-react/kinds/funnel.d.mts +4 -0
- package/dist/charts-react/kinds/funnel.mjs +13 -0
- package/dist/charts-react/kinds/heatmap.d.mts +4 -0
- package/dist/charts-react/kinds/heatmap.mjs +13 -0
- package/dist/charts-react/kinds/line.d.mts +4 -0
- package/dist/charts-react/kinds/line.mjs +20 -0
- package/dist/charts-react/kinds/multiples.d.mts +4 -0
- package/dist/charts-react/kinds/multiples.mjs +33 -0
- package/dist/charts-react/kinds/number.d.mts +5 -0
- package/dist/charts-react/kinds/number.mjs +86 -0
- package/dist/charts-react/plan-bars.mjs +15 -8
- package/dist/charts-react/plan-funnel.mjs +3 -1
- package/dist/charts-react/plan-grid.mjs +14 -5
- package/dist/charts-react/plan-of.mjs +17 -0
- package/dist/charts-react/plan-parts.mjs +16 -5
- package/dist/charts-react/plan-time.mjs +4 -53
- package/dist/charts-react/reader-page.d.mts +1 -1
- package/dist/charts-react/reader-page.mjs +19 -9
- package/dist/charts-react/renderers.d.mts +14 -0
- package/dist/charts-react/renderers.mjs +22 -0
- package/dist/charts-react/table.d.mts +1 -0
- package/dist/charts-react/table.mjs +108 -0
- package/dist/charts-react/tiles.mjs +21 -49
- package/dist/charts-react/useScene.mjs +45 -17
- package/dist/charts-react/words.mjs +19 -0
- package/dist/checks.mjs +97 -19
- package/dist/cli/add.mjs +4 -3
- package/dist/cli/doctor.mjs +2 -2
- package/dist/core/conformance/index.d.mts +5 -2
- package/dist/core/conformance/index.mjs +5 -2
- package/dist/core/conformance/memory/aggregate.mjs +11 -6
- package/dist/core/conformance/memory/rows.d.mts +7 -3
- package/dist/core/conformance/memory/rows.mjs +19 -13
- package/dist/core/conformance/memory/source.mjs +4 -4
- package/dist/core/document/control-fields.d.mts +20 -0
- package/dist/core/document/control-fields.mjs +117 -0
- package/dist/core/document/display-comparisons.d.mts +17 -0
- package/dist/core/document/display-comparisons.mjs +15 -4
- package/dist/core/document/display-entries.d.mts +14 -0
- package/dist/core/document/display-entries.mjs +25 -9
- package/dist/core/document/display-validation.d.mts +5 -1
- package/dist/core/document/display-validation.mjs +14 -7
- package/dist/core/document/display.d.mts +11 -8
- package/dist/core/document/display.mjs +26 -3
- package/dist/core/document/layout.d.mts +8 -9
- package/dist/core/document/layout.mjs +23 -6
- package/dist/core/document/stacked.d.mts +0 -7
- package/dist/core/document/types.mjs +8 -6
- package/dist/core/document/upgrade.d.mts +1 -0
- package/dist/core/document/upgrade.mjs +4 -2
- package/dist/core/engine/access.mjs +3 -3
- package/dist/core/engine/assert.mjs +4 -2
- package/dist/core/engine/bucket.mjs +2 -2
- package/dist/core/engine/checks.mjs +6 -7
- package/dist/core/engine/custom/ask.mjs +22 -2
- package/dist/core/engine/custom/cells.mjs +22 -22
- package/dist/core/engine/custom/level.mjs +12 -13
- package/dist/core/engine/custom/measures.mjs +12 -9
- package/dist/core/engine/custom/reader.mjs +3 -1
- package/dist/core/engine/custom/records.mjs +8 -7
- package/dist/core/engine/custom/unread.mjs +78 -0
- package/dist/core/engine/custom/where.mjs +15 -10
- package/dist/core/engine/index.d.mts +2 -13
- package/dist/core/engine/index.mjs +2 -12
- package/dist/core/engine/measure.mjs +1 -0
- package/dist/core/engine/members.mjs +7 -3
- package/dist/core/engine/nan.mjs +10 -1
- package/dist/core/engine/native.mjs +2 -20
- package/dist/core/engine/numbers.mjs +26 -14
- package/dist/core/engine/postgres.mjs +9 -5
- package/dist/core/engine/prepare.mjs +4 -4
- package/dist/core/engine/rank-sets.mjs +1 -1
- package/dist/core/engine/read.mjs +5 -4
- package/dist/core/engine/reader.d.mts +6 -0
- package/dist/core/engine/record-layout.mjs +3 -3
- package/dist/core/engine/run.mjs +77 -20
- package/dist/core/engine/segmented.d.mts +2 -1
- package/dist/core/engine/segmented.mjs +19 -12
- package/dist/core/engine/series.mjs +1 -1
- package/dist/core/engine/shape.mjs +8 -8
- package/dist/core/engine/sql-partition.mjs +2 -2
- package/dist/core/engine/sql-pass.mjs +3 -2
- package/dist/core/engine/sql-reader.mjs +13 -5
- package/dist/core/engine/sql-reads.mjs +2 -1
- package/dist/core/engine/sql-records.mjs +2 -2
- package/dist/core/engine/sql-split.mjs +1 -1
- package/dist/core/engine/sql-unread.mjs +70 -0
- package/dist/core/engine/time.mjs +2 -1
- package/dist/core/engine/types.d.mts +17 -0
- package/dist/core/engine/version.d.mts +1 -1
- package/dist/core/engine/version.mjs +1 -1
- package/dist/core/error/codes.d.mts +24 -1
- package/dist/core/error/codes.mjs +23 -3
- package/dist/core/error/refusal.d.mts +8 -3
- package/dist/core/error/refusal.mjs +6 -1
- package/dist/core/exact/decimal.d.mts +1 -14
- package/dist/core/exact/decimal.mjs +9 -19
- package/dist/core/exact/stored.d.mts +9 -0
- package/dist/core/exact/stored.mjs +38 -0
- package/dist/core/exact/text.d.mts +16 -1
- package/dist/core/exact/text.mjs +50 -1
- package/dist/core/format/digits.mjs +55 -0
- package/dist/core/format/index.d.mts +16 -0
- package/dist/core/format/index.mjs +27 -0
- package/dist/core/format/number.d.mts +27 -0
- package/dist/core/format/number.mjs +158 -0
- package/dist/core/format/write.d.mts +6 -0
- package/dist/core/format/write.mjs +57 -0
- package/dist/core/index.d.mts +43 -33
- package/dist/core/index.mjs +31 -28
- package/dist/core/model/defaults.d.mts +18 -1
- package/dist/core/model/defaults.mjs +19 -1
- package/dist/core/model/define.d.mts +17 -8
- package/dist/core/model/define.mjs +2 -0
- package/dist/core/model/member.d.mts +5 -3
- package/dist/core/model/member.mjs +33 -6
- package/dist/core/model/storage.mjs +40 -12
- package/dist/core/model/types.d.mts +17 -1
- package/dist/core/model/types.mjs +5 -0
- package/dist/core/model/validate/expr.d.mts +1 -7
- package/dist/core/model/validate/fields.d.mts +2 -0
- package/dist/core/model/validate/fields.mjs +14 -7
- package/dist/core/model/validate/issues.mjs +5 -1
- package/dist/core/model/validate/known-members.mjs +6 -5
- package/dist/core/model/validate/shape.mjs +36 -3
- package/dist/core/model/validate/source.mjs +2 -2
- package/dist/core/oracle/data.d.mts +4 -2
- package/dist/core/oracle/evaluate.d.mts +19 -1
- package/dist/core/oracle/evaluate.mjs +56 -10
- package/dist/core/oracle/expr.mjs +1 -1
- package/dist/core/oracle/facts.mjs +12 -5
- package/dist/core/oracle/measure.mjs +1 -1
- package/dist/core/oracle/request.mjs +39 -4
- package/dist/core/oracle/segmented.d.mts +3 -1
- package/dist/core/oracle/segmented.mjs +19 -13
- package/dist/core/oracle/unread.mjs +32 -0
- package/dist/core/oracle/visibility.mjs +4 -3
- package/dist/core/policy/bind.d.mts +2 -11
- package/dist/core/policy/bind.mjs +1 -1
- package/dist/core/policy/match.mjs +1 -1
- package/dist/core/query/closure.d.mts +7 -2
- package/dist/core/query/closure.mjs +29 -12
- package/dist/core/query/compose-tile.d.mts +3 -2
- package/dist/core/query/compose-tile.mjs +32 -13
- package/dist/core/query/compose.d.mts +0 -5
- package/dist/core/query/drill/internal.d.mts +5 -5
- package/dist/core/query/drill/internal.mjs +11 -0
- package/dist/core/query/drill/links.d.mts +2 -3
- package/dist/core/query/drill/links.mjs +18 -4
- package/dist/core/query/drill/selection.d.mts +8 -2
- package/dist/core/query/drill/selection.mjs +14 -3
- package/dist/core/query/drill/synthetic.mjs +1 -1
- package/dist/core/query/drill/time.mjs +11 -10
- package/dist/core/query/filter.d.mts +1 -6
- package/dist/core/query/filter.mjs +1 -4
- package/dist/core/query/fold.mjs +23 -0
- package/dist/core/query/segments.mjs +42 -3
- package/dist/core/query/to-wire.d.mts +7 -0
- package/dist/core/query/to-wire.mjs +14 -2
- package/dist/core/query/types.d.mts +30 -13
- package/dist/core/result/columns.mjs +23 -13
- package/dist/core/result/number.mjs +3 -3
- package/dist/core/result/status.d.mts +13 -0
- package/dist/core/result/status.mjs +18 -0
- package/dist/core/result/time-axis.d.mts +14 -13
- package/dist/core/result/time-axis.mjs +20 -2
- package/dist/core/result/types.d.mts +33 -3
- package/dist/core/result/whole.d.mts +23 -0
- package/dist/core/result/whole.mjs +27 -0
- package/dist/core/schema/agent-query.d.mts +89 -0
- package/dist/core/schema/agent-query.mjs +115 -0
- package/dist/core/schema/aliases.mjs +1 -52
- package/dist/core/schema/answer-parts.mjs +17 -13
- package/dist/core/schema/answers.d.mts +787 -319
- package/dist/core/schema/commands.d.mts +33 -23
- package/dist/core/schema/commands.mjs +26 -18
- package/dist/core/schema/custom.mjs +46 -45
- package/dist/core/schema/document.d.mts +32 -27
- package/dist/core/schema/document.mjs +61 -81
- package/dist/core/schema/drill-answers.mjs +4 -1
- package/dist/core/schema/drill.d.mts +14 -9
- package/dist/core/schema/drill.mjs +23 -22
- package/dist/core/schema/index.d.mts +5 -3
- package/dist/core/schema/index.mjs +5 -3
- package/dist/core/schema/options.d.mts +92 -0
- package/dist/core/schema/options.mjs +104 -0
- package/dist/core/schema/picks.d.mts +2 -2
- package/dist/core/schema/picks.mjs +7 -6
- package/dist/core/schema/query.d.mts +9 -83
- package/dist/core/schema/query.mjs +49 -73
- package/dist/core/schema/strict.d.mts +3 -0
- package/dist/core/schema/strict.mjs +91 -0
- package/dist/core/schema/union-error.mjs +30 -7
- package/dist/core/schema/view.d.mts +4 -3
- package/dist/core/schema/view.mjs +16 -11
- package/dist/core/store/ddl.d.mts +0 -2
- package/dist/core/store/ddl.mjs +1 -5
- package/dist/core/time/bucket.d.mts +1 -18
- package/dist/core/time/bucket.mjs +12 -8
- package/dist/core/time/compare.mjs +3 -2
- package/dist/core/time/index.d.mts +7 -8
- package/dist/core/time/instant.d.mts +15 -9
- package/dist/core/time/instant.mjs +23 -9
- package/dist/core/time/range.d.mts +3 -15
- package/dist/core/time/range.mjs +17 -7
- package/dist/core/time/stored.d.mts +8 -5
- package/dist/core/time/stored.mjs +51 -15
- package/dist/core/time/temporal.d.mts +1 -5
- package/dist/core/time/temporal.mjs +9 -4
- package/dist/core/time/text-time.d.mts +31 -2
- package/dist/core/time/text-time.mjs +139 -22
- package/dist/core/time/zone.d.mts +6 -1
- package/dist/core/time/zone.mjs +13 -4
- package/dist/core/types/api.d.mts +1 -1
- package/dist/core/types/api.mjs +1 -1
- package/dist/core/types/dashboard.d.mts +185 -0
- package/dist/core/types/dashboard.mjs +26 -0
- package/dist/core/types/drill-api.d.mts +14 -2
- package/dist/core/types/infer.d.mts +0 -4
- package/dist/core/types/options-check.d.mts +42 -0
- package/dist/core/types/options-check.mjs +90 -0
- package/dist/core/types/options.d.mts +14 -8
- package/dist/core/value/casefold.d.mts +1 -3
- package/dist/core/value/stored.d.mts +26 -0
- package/dist/core/value/stored.mjs +28 -0
- package/dist/cursor-seal.mjs +37 -9
- package/dist/dashboard-documents.d.mts +14 -6
- package/dist/dashboard-documents.mjs +32 -12
- package/dist/dashboards.mjs +10 -9
- package/dist/drill-access.mjs +6 -6
- package/dist/drill-change.mjs +18 -20
- package/dist/drill-comparison.mjs +2 -1
- package/dist/drill-crumbs.mjs +63 -28
- package/dist/drill-distinct.mjs +2 -1
- package/dist/drill-explain.mjs +1 -1
- package/dist/drill-items.mjs +1 -1
- package/dist/drill-open.mjs +39 -23
- package/dist/drill-seal.mjs +41 -13
- package/dist/drill-share.mjs +1 -1
- package/dist/drill-summary.mjs +2 -1
- package/dist/drill-targets.mjs +4 -4
- package/dist/drill-views.mjs +4 -3
- package/dist/drill.mjs +1 -1
- package/dist/editing.mjs +5 -3
- package/dist/endpoints/index.d.mts +29 -8
- package/dist/endpoints/index.mjs +4 -1
- package/dist/endpoints/meta.mjs +4 -3
- package/dist/endpoints/query.mjs +5 -2
- package/dist/endpoints/read.mjs +7 -6
- package/dist/endpoints/versions.mjs +2 -1
- package/dist/execute.d.mts +3 -0
- package/dist/execute.mjs +23 -12
- package/dist/grant.d.mts +9 -0
- package/dist/grant.mjs +43 -0
- package/dist/handler.mjs +8 -13
- package/dist/http.d.mts +6 -2
- package/dist/http.mjs +6 -2
- package/dist/index.d.mts +25 -4
- package/dist/index.mjs +91 -40
- package/dist/llms.txt +3 -3
- package/dist/mcp/api.mjs +2 -1
- package/dist/mcp/query.mjs +3 -8
- package/dist/mcp/resolve.mjs +9 -2
- package/dist/node/index.d.mts +36 -0
- package/dist/node/index.mjs +89 -0
- package/dist/node/request.d.mts +12 -0
- package/dist/node/request.mjs +119 -0
- package/dist/node/response.mjs +58 -0
- package/dist/principal.mjs +15 -7
- package/dist/react/Canvas.mjs +90 -69
- package/dist/react/Cell.mjs +2 -1
- package/dist/react/Dashboard.d.mts +15 -1
- package/dist/react/Dashboard.mjs +43 -42
- package/dist/react/DashboardList.mjs +9 -4
- package/dist/react/Editing.d.mts +9 -0
- package/dist/react/Editing.mjs +8 -3
- package/dist/react/Grid.mjs +1 -1
- package/dist/react/Header.mjs +25 -52
- package/dist/react/History.mjs +3 -2
- package/dist/react/LoadFailed.mjs +59 -0
- package/dist/react/Panel.d.mts +1 -1
- package/dist/react/Panel.mjs +1 -1
- package/dist/react/Parts.d.mts +34 -0
- package/dist/react/Parts.mjs +9 -6
- package/dist/react/ReviewPanel.mjs +1 -1
- package/dist/react/RowBody.d.mts +2 -0
- package/dist/react/RowBody.mjs +5 -1
- package/dist/react/Share.mjs +153 -0
- package/dist/react/TabStrip.mjs +37 -0
- package/dist/react/Tile.d.mts +3 -1
- package/dist/react/Tile.mjs +89 -92
- package/dist/react/TileState.mjs +117 -0
- package/dist/react/ago.mjs +45 -0
- package/dist/react/arrange.mjs +1 -1
- package/dist/react/board.mjs +2 -2
- package/dist/react/bucket-name.d.mts +8 -0
- package/dist/react/bucket-name.mjs +13 -0
- package/dist/react/builder/DisplayOptions.mjs +219 -0
- package/dist/react/builder/Preview.mjs +13 -13
- package/dist/react/builder/RangeEditor.mjs +4 -3
- package/dist/react/builder/WidgetBuilder.d.mts +1 -7
- package/dist/react/builder/WidgetBuilder.mjs +12 -3
- package/dist/react/builder/base.d.mts +13 -2
- package/dist/react/builder/base.mjs +70 -12
- package/dist/react/builder/display.d.mts +3 -0
- package/dist/react/builder/display.mjs +256 -0
- package/dist/react/builder/labels.mjs +19 -5
- package/dist/react/builder/options.mjs +11 -6
- package/dist/react/builder/state.mjs +25 -3
- package/dist/react/builder/useBuilder.d.mts +7 -1
- package/dist/react/builder/useBuilder.mjs +6 -9
- package/dist/react/builder/usePreview.mjs +3 -2
- package/dist/react/builder/words.d.mts +16 -1
- package/dist/react/builder/words.mjs +41 -1
- package/dist/react/change-text.mjs +149 -0
- package/dist/react/client.d.mts +9 -0
- package/dist/react/client.mjs +105 -14
- package/dist/react/columns.mjs +9 -1
- package/dist/react/context.d.mts +24 -3
- package/dist/react/context.mjs +23 -7
- package/dist/react/dates-shown.mjs +76 -0
- package/dist/react/draft.mjs +3 -2
- package/dist/react/drill/Bars.mjs +12 -16
- package/dist/react/drill/Comparison.mjs +1 -1
- package/dist/react/drill/DrillPanel.d.mts +1 -1
- package/dist/react/drill/DrillPanel.mjs +2 -1
- package/dist/react/drill/Header.mjs +65 -12
- package/dist/react/drill/Items.d.mts +1 -1
- package/dist/react/drill/Notes.mjs +10 -7
- package/dist/react/drill/PanelStates.mjs +8 -1
- package/dist/react/drill/Trend.mjs +10 -5
- package/dist/react/drill/board.d.mts +1 -1
- package/dist/react/drill/board.mjs +1 -0
- package/dist/react/drill/host.mjs +4 -1
- package/dist/react/drill/lazy.mjs +2 -27
- package/dist/react/drill/props.d.mts +19 -8
- package/dist/react/drill/props.mjs +62 -18
- package/dist/react/drill/state.d.mts +15 -5
- package/dist/react/drill/state.mjs +12 -3
- package/dist/react/drill/words.d.mts +46 -3
- package/dist/react/drill/words.mjs +30 -5
- package/dist/react/english.mjs +33 -8
- package/dist/react/export/ExportButton.mjs +4 -1
- package/dist/react/export/csv.d.mts +7 -2
- package/dist/react/export/csv.mjs +24 -7
- package/dist/react/failure-words.mjs +60 -0
- package/dist/react/filters/bar.d.mts +1 -1
- package/dist/react/filters/bar.mjs +4 -1
- package/dist/react/filters/calendar.mjs +23 -8
- package/dist/react/filters/chip.mjs +7 -3
- package/dist/react/filters/context.d.mts +13 -1
- package/dist/react/filters/context.mjs +1 -1
- package/dist/react/filters/dates-said.mjs +57 -0
- package/dist/react/filters/days.d.mts +3 -4
- package/dist/react/filters/days.mjs +10 -17
- package/dist/react/filters/hooks.d.mts +11 -0
- package/dist/react/filters/hooks.mjs +10 -6
- package/dist/react/filters/menu-search.mjs +17 -9
- package/dist/react/filters/menu.mjs +10 -8
- package/dist/react/filters/phone.mjs +41 -16
- package/dist/react/filters/place.mjs +40 -0
- package/dist/react/filters/popover.mjs +18 -13
- package/dist/react/filters/rules.d.mts +4 -3
- package/dist/react/filters/rules.mjs +3 -3
- package/dist/react/filters/sheet.mjs +7 -3
- package/dist/react/filters/state.mjs +6 -1
- package/dist/react/filters/values.mjs +24 -7
- package/dist/react/filters/words.d.mts +13 -0
- package/dist/react/filters/words.mjs +5 -0
- package/dist/react/format-time.d.mts +17 -6
- package/dist/react/format-time.mjs +152 -33
- package/dist/react/format.d.mts +3 -3
- package/dist/react/format.mjs +35 -122
- package/dist/react/headline.d.mts +12 -0
- package/dist/react/headline.mjs +107 -0
- package/dist/react/index.d.mts +20 -17
- package/dist/react/index.mjs +13 -10
- package/dist/react/lazy.mjs +38 -0
- package/dist/react/messages.d.mts +78 -2
- package/dist/react/now.mjs +38 -0
- package/dist/react/place.mjs +4 -2
- package/dist/react/read.d.mts +1 -0
- package/dist/react/read.mjs +140 -9
- package/dist/react/renderers/exact.mjs +31 -59
- package/dist/react/renderers/index.d.mts +27 -6
- package/dist/react/renderers/index.mjs +154 -92
- package/dist/react/renderers/list-parts.mjs +24 -0
- package/dist/react/renderers/list.d.mts +1 -0
- package/dist/react/renderers/list.mjs +99 -43
- package/dist/react/renderers/more-rows.mjs +75 -0
- package/dist/react/renderers/number-before.mjs +320 -0
- package/dist/react/renderers/number-period.mjs +54 -0
- package/dist/react/renderers/number-whole.mjs +29 -0
- package/dist/react/renderers/props.d.mts +24 -1
- package/dist/react/renderers/props.mjs +8 -0
- package/dist/react/renderers/table-cells.mjs +137 -31
- package/dist/react/renderers/table-fit.mjs +55 -10
- package/dist/react/renderers/table-measure.mjs +29 -9
- package/dist/react/renderers/table-row.mjs +14 -9
- package/dist/react/renderers/table-scale.mjs +2 -3
- package/dist/react/renderers/table-sort.mjs +3 -2
- package/dist/react/renderers/table-whole.mjs +37 -0
- package/dist/react/renderers/table.mjs +73 -53
- package/dist/react/review.d.mts +7 -0
- package/dist/react/review.mjs +35 -8
- package/dist/react/roving.d.mts +6 -0
- package/dist/react/roving.mjs +123 -0
- package/dist/react/says-dates.d.mts +7 -0
- package/dist/react/says-dates.mjs +51 -0
- package/dist/react/series.mjs +5 -6
- package/dist/react/stable.mjs +1 -1
- package/dist/react/tabs/EditTabs.mjs +125 -0
- package/dist/react/tabs/NameField.mjs +72 -0
- package/dist/react/tabs/TabMenu.mjs +175 -0
- package/dist/react/tabs/actions.mjs +37 -0
- package/dist/react/tabs/commands.mjs +76 -0
- package/dist/react/tabs/focus.mjs +22 -0
- package/dist/react/tabs/keys.mjs +28 -0
- package/dist/react/theme-unlayered.css +1 -1
- package/dist/react/theme.css +1 -1
- package/dist/react/tile-store.d.mts +4 -0
- package/dist/react/tile-store.mjs +93 -13
- package/dist/react/touch.d.mts +16 -0
- package/dist/react/touch.mjs +39 -0
- package/dist/react/useBoard.d.mts +6 -0
- package/dist/react/useBoard.mjs +1 -0
- package/dist/react/useDashboard.d.mts +2 -0
- package/dist/react/useDashboard.mjs +5 -2
- package/dist/react/useTiles.d.mts +3 -0
- package/dist/react/useTiles.mjs +73 -17
- package/dist/react/view-grid.mjs +2 -2
- package/dist/react/view.mjs +1 -1
- package/dist/recharts/axes.mjs +1 -1
- package/dist/recharts/axis.mjs +23 -73
- package/dist/recharts/bar.d.mts +2 -1
- package/dist/recharts/bar.mjs +140 -64
- package/dist/recharts/fit.mjs +33 -0
- package/dist/recharts/line.mjs +23 -17
- package/dist/recharts/marks.mjs +2 -1
- package/dist/recharts/parts.mjs +19 -14
- package/dist/recharts/table.mjs +8 -3
- package/dist/refusal.mjs +46 -0
- package/dist/registry/filter-bar.json +1 -1
- package/dist/skills/derive-dashboards/SKILL.md +25 -9
- package/dist/tile-doc.mjs +1 -1
- package/package.json +21 -6
- package/dist/charts-react/plan.d.mts +0 -3
- package/dist/charts-react/plan.mjs +0 -37
- package/dist/charts-react/tiles.d.mts +0 -24
- package/dist/core/policy/match.d.mts +0 -16
- package/dist/core/schema/aliases.d.mts +0 -7
- package/dist/core/time/compare.d.mts +0 -30
- package/dist/react/EditBar.d.mts +0 -16
- package/dist/react/History.d.mts +0 -30
- package/dist/react/ReviewPanel.d.mts +0 -15
- package/dist/react/digits.mjs +0 -46
- package/dist/react/drill/trend-touch.mjs +0 -33
- package/dist/react/renderers/exact.d.mts +0 -6
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OPERAND_LIMIT } from "../exact/stored.mjs";
|
|
2
|
+
import { decimalColumns, readColumns } from "../model/storage.mjs";
|
|
2
3
|
import { exprLinearTerms } from "../model/validate/expr.mjs";
|
|
3
4
|
import { cellOf, divide, exactNum } from "../result/number.mjs";
|
|
4
5
|
import { exprSql } from "./members.mjs";
|
|
@@ -53,18 +54,26 @@ function ratioParts(n, d, rest) {
|
|
|
53
54
|
const width = np.aggs.length;
|
|
54
55
|
return fromParts([...np.aggs, ...dp.aggs], (aggs) => ({ sql: [...np.finish(aggs.slice(0, width)).sql, ...dp.finish(aggs.slice(width)).sql] }), rest);
|
|
55
56
|
}
|
|
57
|
+
const anyOf = (tests) => tests.length === 0 ? sql`FALSE` : sql`(${join(tests, sql` OR `)})`;
|
|
56
58
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
59
|
+
* The worst stored exact value among a group's rows, as a level that merges by max: 2 for a
|
|
60
|
+
* NaN in a decimal column (refused), 1 for a value that is no operand (`minorUnits` gives none:
|
|
61
|
+
* it is unread, and `sqlUnread` counts it), 0 when every value is one. A level reads it as a
|
|
62
|
+
* window over every group, so a NaN in any row is refused and an unread value noted, whichever
|
|
63
|
+
* group it falls in and whatever a LIMIT keeps, with no statement of its own.
|
|
60
64
|
*/
|
|
61
|
-
function
|
|
62
|
-
const columns =
|
|
65
|
+
function storedPart(b, query, alias) {
|
|
66
|
+
const columns = readColumns(b.model, query).flatMap((c) => c.kind === "exact" ? [c] : []);
|
|
63
67
|
if (columns.length === 0) return void 0;
|
|
64
|
-
const
|
|
68
|
+
const nan = decimalColumns(b.model, query).map((c) => b.dialect.notFinite(ident(alias, c)));
|
|
69
|
+
const unread = columns.map((c) => {
|
|
70
|
+
const column = ident(alias, c.column);
|
|
71
|
+
return sql`(${column} IS NOT NULL AND ${minorUnits(b, column, c.numeric)} IS NULL)`;
|
|
72
|
+
});
|
|
73
|
+
const level = sql`CASE WHEN ${anyOf(nan)} THEN 2 WHEN ${anyOf(unread)} THEN 1 ELSE 0 END`;
|
|
65
74
|
return {
|
|
66
|
-
agg: sql`
|
|
67
|
-
merge: "
|
|
75
|
+
agg: sql`max(${level})`,
|
|
76
|
+
merge: "max"
|
|
68
77
|
};
|
|
69
78
|
}
|
|
70
79
|
/** A count of rows: the sum of the parts' counts. */
|
|
@@ -98,12 +107,15 @@ function float(raw) {
|
|
|
98
107
|
const value = typeof raw === "number" ? raw : Number(text(raw) ?? NaN);
|
|
99
108
|
return Number.isFinite(value) ? value : null;
|
|
100
109
|
}
|
|
101
|
-
/**
|
|
110
|
+
/**
|
|
111
|
+
* A stored exact value as a whole number of minor units below `OPERAND_LIMIT`, as the one
|
|
112
|
+
* reader reads it, or null when it is not one: then it is unread, and `sqlUnread` counts it.
|
|
113
|
+
*/
|
|
102
114
|
function minorUnits(b, column, numeric) {
|
|
103
115
|
const value = b.dialect.cast(column, "numeric");
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
return sql`CASE WHEN ${
|
|
116
|
+
const units = numeric.stored === "minor_units" ? value : sql`(${value} * ${keyword(`1${"0".repeat(numeric.scale)}`)})`;
|
|
117
|
+
const limit = keyword(String(OPERAND_LIMIT));
|
|
118
|
+
return sql`CASE WHEN ${units} = trunc(${units}) AND abs(${units}) < ${limit} THEN trunc(${units}) END`;
|
|
107
119
|
}
|
|
108
120
|
function rowExact(b, scope, def) {
|
|
109
121
|
const terms = exprLinearTerms(def.of).map((t) => sql`${keyword(String(t.coefficient))} * ${minorUnits(b, ident(scope.alias, t.column), def.numeric)}`);
|
|
@@ -188,4 +200,4 @@ function floatCols(b, scope, def, where) {
|
|
|
188
200
|
sql: [agg]
|
|
189
201
|
}), { decode });
|
|
190
202
|
}
|
|
191
|
-
export { columnsLess, countCols, exactCols, floatCols, mergeOf, merged,
|
|
203
|
+
export { columnsLess, countCols, exactCols, floatCols, mergeOf, merged, minorUnits, ratioParts, storedPart, text, windowOf };
|
|
@@ -25,8 +25,9 @@ const TYPES = {
|
|
|
25
25
|
timestamp: "timestamp",
|
|
26
26
|
timestamptz: "timestamptz"
|
|
27
27
|
};
|
|
28
|
-
const SHAPE_WITH_OFFSET = "^[0-9]{4}-[0-9]{2}-[0-9]{2}[
|
|
29
|
-
const SHAPE_NAIVE = "^[0-9]{4}-[0-9]{2}-[0-9]{2}[
|
|
28
|
+
const SHAPE_WITH_OFFSET = "^[0-9]{4}-[0-9]{2}-[0-9]{2}[Tt ][0-9]{2}:[0-9]{2}:[0-9]{2}([.][0-9]+)?([Zz]|[+-][0-9]{2}(:[0-9]{2})?)$";
|
|
29
|
+
const SHAPE_NAIVE = "^[0-9]{4}-[0-9]{2}-[0-9]{2}[Tt ][0-9]{2}:[0-9]{2}:[0-9]{2}([.][0-9]+)?$";
|
|
30
|
+
const toMicros = (text) => sql`regexp_replace(${text}, ${"([.][0-9]{6})[0-9]+"}, ${"\\1"})`;
|
|
30
31
|
const digits = (text, from, length) => sql`substr(${text}, ${keyword(String(from))}, ${keyword(String(length))})::int`;
|
|
31
32
|
/** Field ranges of the grammar, in integer arithmetic, so no cast below can raise. */
|
|
32
33
|
function fieldsValid(text) {
|
|
@@ -44,7 +45,10 @@ function fieldsValid(text) {
|
|
|
44
45
|
function offsetValid(text) {
|
|
45
46
|
const tail = sql`right(${text}, 5)`;
|
|
46
47
|
const [hours, minutes] = [digits(tail, 1, 2), digits(tail, 4, 2)];
|
|
47
|
-
|
|
48
|
+
const whole = sql`${digits(sql`right(${text}, 2)`, 1, 2)} <= 14`;
|
|
49
|
+
const full = sql`(${hours} * 60 + ${minutes} <= 840 AND ${minutes} <= 59)`;
|
|
50
|
+
const hoursOnly = sql`left(right(${text}, 3), 1) IN ('+', '-')`;
|
|
51
|
+
return sql`(upper(right(${text}, 1)) = 'Z' OR CASE WHEN ${hoursOnly} THEN ${whole} ELSE ${full} END)`;
|
|
48
52
|
}
|
|
49
53
|
const micros = (value) => sql`(extract(epoch FROM ${value}) * 1000000)::bigint`;
|
|
50
54
|
/** The instant of a naive wall-clock time: both candidate offsets, then the column's rules. */
|
|
@@ -112,9 +116,9 @@ const postgres = {
|
|
|
112
116
|
contains: (text, part) => sql`strpos(${text}, ${part}) > 0`,
|
|
113
117
|
startsWith: (text, part) => sql`starts_with(${text}, ${part})`,
|
|
114
118
|
textMicros: (text) => sql`CASE WHEN ${text} ~ ${SHAPE_WITH_OFFSET} THEN CASE WHEN ${fieldsValid(text)} AND ${offsetValid(text)}
|
|
115
|
-
THEN ${micros(sql`CAST(${text} AS timestamptz)`)} END END`,
|
|
119
|
+
THEN ${micros(sql`CAST(${toMicros(text)} AS timestamptz)`)} END END`,
|
|
116
120
|
naiveMicros: (text, rule) => sql`CASE WHEN ${text} ~ ${SHAPE_NAIVE} THEN CASE WHEN ${fieldsValid(text)}
|
|
117
|
-
THEN ${micros(resolveNaive(sql`CAST(${text} AS timestamp)`, rule))} END END`,
|
|
121
|
+
THEN ${micros(resolveNaive(sql`CAST(${toMicros(text)} AS timestamp)`, rule))} END END`,
|
|
118
122
|
timestamptzMicros: micros,
|
|
119
123
|
dateMicros: (value, zone) => micros(sql`(CAST(${value} AS timestamp) AT TIME ZONE ${zone})`),
|
|
120
124
|
dateEpochDay: (value) => sql`(${value} - ${EPOCH_DATE})`,
|
|
@@ -2,7 +2,7 @@ import { filterMembers, relation, scopeFrom } from "./build.mjs";
|
|
|
2
2
|
import { filterSql, guardSql } from "./filter.mjs";
|
|
3
3
|
import { bound, measureCols, measureFilters, queryMeasures } from "./measure.mjs";
|
|
4
4
|
import { memberSql } from "./members.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { storedPart } from "./numbers.mjs";
|
|
6
6
|
import { ident, join, sql } from "./sql.mjs";
|
|
7
7
|
import { bucketSql } from "./bucket.mjs";
|
|
8
8
|
import { instantOnce, queryTime, rangeSql } from "./time.mjs";
|
|
@@ -108,7 +108,7 @@ function prepareTwoStep(b, query, span, nanOf) {
|
|
|
108
108
|
const dims = (query.dimensions ?? []).map((d) => memberSql(b, rows.scope, d.member));
|
|
109
109
|
const measures = queryMeasures(b, query).map((m) => measureCols(b, rows.scope, m.def, m.line));
|
|
110
110
|
if (!measures.every((m) => m.parts !== void 0)) return void 0;
|
|
111
|
-
const nan =
|
|
111
|
+
const nan = storedPart(b, nanOf, rows.scope.alias);
|
|
112
112
|
return twoStep(b, rows, dims, {
|
|
113
113
|
measures,
|
|
114
114
|
nan,
|
|
@@ -125,9 +125,9 @@ function prepare(b, query, span) {
|
|
|
125
125
|
const dims = (query.dimensions ?? []).map((d) => memberSql(b, rows.scope, d.member));
|
|
126
126
|
const parts = {
|
|
127
127
|
measures: queryMeasures(b, query).map((m) => measureCols(b, rows.scope, m.def, m.line)),
|
|
128
|
-
nan:
|
|
128
|
+
nan: storedPart(b, query, rows.scope.alias),
|
|
129
129
|
bucket: bucketOf(b, query, rows, span)
|
|
130
130
|
};
|
|
131
131
|
return dims.some((m) => isCi(m)) && parts.measures.every((m) => m.parts !== void 0) ? twoStep(b, rows, dims, parts) : oneStep(b, rows, dims, parts);
|
|
132
132
|
}
|
|
133
|
-
export { prepare, prepareTwoStep };
|
|
133
|
+
export { factRows, prepare, prepareTwoStep };
|
|
@@ -111,7 +111,7 @@ function keptOf(rows, ranks, cap) {
|
|
|
111
111
|
const own = rows.filter((row) => Number(row[0]) === setOf(i, n)).toSorted((a, b) => Number(a[1 + n + i]) - Number(b[1 + n + i]));
|
|
112
112
|
const { want } = counts(r.limit, cap);
|
|
113
113
|
truncated ||= cap !== void 0 && own.length > cap && r.limit + 1 > cap;
|
|
114
|
-
return [r.index, own.slice(0, want).map((row) => primitive(row[1 + i]))];
|
|
114
|
+
return [r.index, own.slice(0, want).map((row) => primitive(row[1 + i], `dimension ${i + 1}`))];
|
|
115
115
|
})),
|
|
116
116
|
truncated
|
|
117
117
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { assertPlan } from "./assert.mjs";
|
|
2
2
|
import { withClause } from "./build.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { checkStored } from "./nan.mjs";
|
|
4
4
|
import { seriesGroups, seriesRows } from "./series.mjs";
|
|
5
5
|
import { decodeCells, decodeRow } from "./shape.mjs";
|
|
6
6
|
import { sql } from "./sql.mjs";
|
|
@@ -13,12 +13,13 @@ async function read(pass, body) {
|
|
|
13
13
|
return (await pass.session.run(b.dialect.compile(sql`${withClause(b)}${body}`))).rows;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
|
-
* Runs a statement whose rows end with
|
|
17
|
-
* before any LIMIT)
|
|
16
|
+
* Runs a statement whose rows end with the worst stored exact value's level when `counted` (a
|
|
17
|
+
* window over every group, before any LIMIT): refuses when a decimal column the measures read
|
|
18
|
+
* holds NaN in any row, and notes a value that is no operand.
|
|
18
19
|
*/
|
|
19
20
|
async function readCounted(pass, body, counted) {
|
|
20
21
|
const rows = await read(pass, body);
|
|
21
|
-
if (counted)
|
|
22
|
+
if (counted) checkStored(rows[0]?.at(-1), pass.seen);
|
|
22
23
|
return rows;
|
|
23
24
|
}
|
|
24
25
|
/** How a level's measure columns become cells. */
|
|
@@ -3,6 +3,7 @@ import { Kept } from "../query/segments.mjs";
|
|
|
3
3
|
import { WireQuery } from "../query/types.mjs";
|
|
4
4
|
import { Span } from "../time/range.mjs";
|
|
5
5
|
import { Primitive, SourceName } from "../types/primitives.mjs";
|
|
6
|
+
import { Unread } from "../value/stored.mjs";
|
|
6
7
|
import { AccessPlan } from "./plan.mjs";
|
|
7
8
|
import { RecordPage } from "./record-layout.mjs";
|
|
8
9
|
import { Decoded } from "./shape.mjs";
|
|
@@ -102,6 +103,11 @@ export type Store = {
|
|
|
102
103
|
sources(): SourceName[];
|
|
103
104
|
/** The rows of a records page, `limit` and one more, as cells by column. */
|
|
104
105
|
records(ask: RecordsAsk): Promise<RecordRows>;
|
|
106
|
+
/**
|
|
107
|
+
* The stored values a query's answer leaves out because they do not read as their column's
|
|
108
|
+
* storage, by column (`readColumns`): what the oracle's `unread` counts on the same rows.
|
|
109
|
+
*/
|
|
110
|
+
unread(query: WireQuery): Promise<Unread[]>;
|
|
105
111
|
/** Every limited dimension's kept values in one read, when the store can rank them so. */
|
|
106
112
|
keptBySets?(query: WireQuery): Promise<{
|
|
107
113
|
kept: Kept;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { recordDimensions } from "../model/member.mjs";
|
|
2
|
-
import { formatTextTime } from "../time/instant.mjs";
|
|
2
|
+
import { formatTextTime, wholeMicros } from "../time/instant.mjs";
|
|
3
3
|
import { sourceDef } from "./access.mjs";
|
|
4
4
|
// src/engine/record-layout.ts
|
|
5
5
|
/** The columns a records view shows, from the model's one rule (`recordDimensions`), or the caller's. */
|
|
@@ -17,9 +17,9 @@ function orderOf(def) {
|
|
|
17
17
|
if (def.records?.order !== void 0) return def.records.order;
|
|
18
18
|
return def.time === void 0 ? [] : [[def.time, "desc"]];
|
|
19
19
|
}
|
|
20
|
-
function decode(dim, raw) {
|
|
20
|
+
function decode({ id, dim }, raw) {
|
|
21
21
|
if (raw === null || raw === void 0) return null;
|
|
22
|
-
if (dim.kind === "time") return formatTextTime(
|
|
22
|
+
if (dim.kind === "time") return formatTextTime(wholeMicros(raw, id));
|
|
23
23
|
if (typeof raw === "bigint") return raw.toString();
|
|
24
24
|
if (typeof raw === "string" || typeof raw === "number" || typeof raw === "boolean") return raw;
|
|
25
25
|
return raw instanceof Date ? raw.toISOString() : JSON.stringify(raw);
|
package/dist/core/engine/run.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { answersWhole, withoutGrain } from "../query/fold.mjs";
|
|
1
2
|
import { readsPrevious } from "../result/calc.mjs";
|
|
2
3
|
import { comparisonQuery } from "../time/compare.mjs";
|
|
3
4
|
import { formatTextTime } from "../time/instant.mjs";
|
|
@@ -58,8 +59,78 @@ async function periods(first, before) {
|
|
|
58
59
|
})];
|
|
59
60
|
}
|
|
60
61
|
/**
|
|
62
|
+
* A pass of the query without its grain (`withoutGrain`), over the same span, through the same
|
|
63
|
+
* base: the same access plan, store and session, so `assertPlan` checks each of its statements
|
|
64
|
+
* as it does the query's own. Its totals read the uncut query without its grain, as the
|
|
65
|
+
* query's own read the uncut query.
|
|
66
|
+
*/
|
|
67
|
+
function folded(base, pass) {
|
|
68
|
+
const own = passFor(base, withoutGrain(pass.query));
|
|
69
|
+
return pass.whole === void 0 ? own : {
|
|
70
|
+
...own,
|
|
71
|
+
whole: passFor(base, withoutGrain(pass.whole.query))
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const periodsOf = ([now, before]) => ({
|
|
75
|
+
now: now.answer,
|
|
76
|
+
before: before?.answer
|
|
77
|
+
});
|
|
78
|
+
/** Rows cut to the groups `kept` has, by their dimension cells after `offset`. */
|
|
79
|
+
function cutTo(rows, kept, offset, width) {
|
|
80
|
+
const dimsOf = (row) => canonical(row.slice(offset, offset + width));
|
|
81
|
+
const keys = new Set(kept.map((row) => dimsOf(row)));
|
|
82
|
+
return rows.filter((row) => keys.has(dimsOf(row)));
|
|
83
|
+
}
|
|
84
|
+
/** A fold's answer as the whole of another: its rows, Other and totals; a cut says the answer is cut. */
|
|
85
|
+
function wholeOf(answer, fold) {
|
|
86
|
+
if (fold === void 0) return answer;
|
|
87
|
+
const { rows, other, totals, truncated } = fold;
|
|
88
|
+
return {
|
|
89
|
+
...answer,
|
|
90
|
+
whole: {
|
|
91
|
+
rows,
|
|
92
|
+
...other === void 0 ? {} : { other },
|
|
93
|
+
...totals === void 0 ? {} : { totals }
|
|
94
|
+
},
|
|
95
|
+
...truncated === true ? { truncated } : {}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The answer with its comparison period's rows cut to its groups and, with the fold, its whole
|
|
100
|
+
* and its comparison's whole cut to the whole's groups.
|
|
101
|
+
*/
|
|
102
|
+
function joined(query, own, fold, range) {
|
|
103
|
+
const main = wholeOf(own.now, fold?.now);
|
|
104
|
+
if (own.before === void 0 || range === void 0) return main;
|
|
105
|
+
const offset = query.time?.grain === void 0 ? 0 : 1;
|
|
106
|
+
const width = (query.dimensions ?? []).length;
|
|
107
|
+
const then = fold && wholeBefore(fold, width);
|
|
108
|
+
return {
|
|
109
|
+
...main,
|
|
110
|
+
compare: {
|
|
111
|
+
...cutPeriod(own.before, own.now, offset, width),
|
|
112
|
+
range,
|
|
113
|
+
...then === void 0 ? {} : { whole: then }
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/** A comparison period's rows cut to the groups `now` has, and its totals. */
|
|
118
|
+
function cutPeriod(before, now, offset, width) {
|
|
119
|
+
const rows = cutTo(before.rows, now.rows, offset, width);
|
|
120
|
+
return before.totals === void 0 ? { rows } : {
|
|
121
|
+
rows,
|
|
122
|
+
totals: before.totals
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/** The comparison's whole: its rows cut to the groups the main whole has, and its totals. */
|
|
126
|
+
const wholeBefore = (fold, width) => fold.before && cutPeriod(fold.before, fold.now, 0, width);
|
|
127
|
+
/**
|
|
61
128
|
* `whole`: the query whose rows the totals and `total` refs read, when not `input.query`
|
|
62
|
-
* (the uncut query, for a query whose dimensions have cuts).
|
|
129
|
+
* (the uncut query, for a query whose dimensions have cuts). With `time.whole`, the query
|
|
130
|
+
* without its grain is read after it in the same session, and so is its comparison period.
|
|
131
|
+
* Those reads are separate statements: the engine already reads each kept group over the whole
|
|
132
|
+
* range to rank it and, for a calc that reads the total, the whole itself, but this answer does
|
|
133
|
+
* not reuse them yet (a known gap: one or two more statements per answer that asks for its whole).
|
|
63
134
|
*/
|
|
64
135
|
async function runPlain(input, reader, whole) {
|
|
65
136
|
const base = startBase(input, reader);
|
|
@@ -74,29 +145,15 @@ async function runPlain(input, reader, whole) {
|
|
|
74
145
|
...input,
|
|
75
146
|
query: whole
|
|
76
147
|
}));
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
answer:
|
|
148
|
+
const own = periodsOf(await periods(first, before));
|
|
149
|
+
const fold = answersWhole(input.query) ? periodsOf(await periods(folded(base, first), before && folded(base, before))) : void 0;
|
|
150
|
+
return {
|
|
151
|
+
answer: joined(input.query, own, fold, second?.range),
|
|
81
152
|
sources: base.store.sources(),
|
|
82
153
|
...first.span === void 0 ? {} : { range: {
|
|
83
154
|
from: formatTextTime(first.span.from),
|
|
84
155
|
to: formatTextTime(first.span.to)
|
|
85
156
|
} }
|
|
86
|
-
}
|
|
87
|
-
if (second === void 0 || previous === void 0) return ran(main);
|
|
88
|
-
const offset = input.query.time?.grain === void 0 ? 0 : 1;
|
|
89
|
-
const width = (input.query.dimensions ?? []).length;
|
|
90
|
-
const dimsOf = (row) => canonical(row.slice(offset, offset + width));
|
|
91
|
-
const keys = new Set(main.rows.map((row) => dimsOf(row)));
|
|
92
|
-
const totals = previous.totals === void 0 ? {} : { totals: previous.totals };
|
|
93
|
-
return ran({
|
|
94
|
-
...main,
|
|
95
|
-
compare: {
|
|
96
|
-
rows: previous.rows.filter((row) => keys.has(dimsOf(row))),
|
|
97
|
-
...totals,
|
|
98
|
-
range: second.range
|
|
99
|
-
}
|
|
100
|
-
});
|
|
157
|
+
};
|
|
101
158
|
}
|
|
102
159
|
export { runPlain };
|
|
@@ -6,6 +6,7 @@ import { EngineInput, Ran } from "./types.mjs";
|
|
|
6
6
|
export declare function runQuery(input: EngineInput, session: ReadSession, dialect?: Dialect): Promise<Ran>;
|
|
7
7
|
/**
|
|
8
8
|
* Answers a query through a reader with the answer the oracle gives on the same rows. A
|
|
9
|
-
* dimension with a limit of its own runs as the queries `query/segments` defines.
|
|
9
|
+
* dimension with a limit of its own runs as the queries `query/segments` defines. Stored
|
|
10
|
+
* values that do not read as their column's storage are left out and counted (`unread`).
|
|
10
11
|
*/
|
|
11
12
|
export declare function readQuery(input: EngineInput, reader: Reader): Promise<Ran>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { hasSegments, keptQuery, limitedDimensions, rankQuery, segmentCuts, segmentOtherQuery,
|
|
1
|
+
import { hasSegments, keptQuery, limitedDimensions, rankQuery, segmentCuts, segmentOtherQuery, segmentSplit, uncutQuery, withSegmentOthers } from "../query/segments.mjs";
|
|
2
2
|
import { startBase } from "./context.mjs";
|
|
3
3
|
import { postgres } from "./postgres.mjs";
|
|
4
4
|
import { each } from "./reader.mjs";
|
|
@@ -35,9 +35,22 @@ function splitting(query, kept, reader, queries) {
|
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* Answers a query through a reader with the answer the oracle gives on the same rows. A
|
|
38
|
-
* dimension with a limit of its own runs as the queries `query/segments` defines.
|
|
38
|
+
* dimension with a limit of its own runs as the queries `query/segments` defines. Stored
|
|
39
|
+
* values that do not read as their column's storage are left out and counted (`unread`).
|
|
39
40
|
*/
|
|
40
41
|
async function readQuery(input, reader) {
|
|
42
|
+
const ran = await readRows(input, reader);
|
|
43
|
+
if (ran.answer.unreadable === true) return ran;
|
|
44
|
+
const unread = await startBase(input, reader).store.unread(input.query);
|
|
45
|
+
return unread.length === 0 ? ran : {
|
|
46
|
+
...ran,
|
|
47
|
+
answer: {
|
|
48
|
+
...ran.answer,
|
|
49
|
+
unread
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
async function readRows(input, reader) {
|
|
41
54
|
if (!hasSegments(input.query)) return runPlain(input, reader);
|
|
42
55
|
const { query } = input;
|
|
43
56
|
const rank = (q) => runPlain({
|
|
@@ -63,20 +76,14 @@ async function readQuery(input, reader) {
|
|
|
63
76
|
cuts: segmentCuts(query, kept)
|
|
64
77
|
};
|
|
65
78
|
}
|
|
66
|
-
/** The kept query's answer with Other's rows, now and in the comparison period. */
|
|
79
|
+
/** The kept query's answer with Other's rows, now and in the comparison period, and each whole's. */
|
|
67
80
|
function withSegmentOther(query, main, folded, truncated) {
|
|
68
|
-
const
|
|
69
|
-
const { compare } = main.answer;
|
|
81
|
+
const answer = withSegmentOthers(query, main.answer, folded?.answer);
|
|
70
82
|
return {
|
|
71
83
|
...main,
|
|
72
84
|
answer: {
|
|
73
|
-
...
|
|
74
|
-
...truncated ? { truncated: true } : {}
|
|
75
|
-
...now === void 0 ? {} : { segmentOther: now },
|
|
76
|
-
...compare === void 0 || before === void 0 ? {} : { compare: {
|
|
77
|
-
...compare,
|
|
78
|
-
segmentOther: before
|
|
79
|
-
} }
|
|
85
|
+
...answer,
|
|
86
|
+
...truncated ? { truncated: true } : {}
|
|
80
87
|
}
|
|
81
88
|
};
|
|
82
89
|
}
|
|
@@ -78,7 +78,7 @@ function seriesRows(shape, rows) {
|
|
|
78
78
|
const start = 1 + group + groupOrder(series, p.keys.length).length;
|
|
79
79
|
const after = labelled(p).length + parts(p).length + extra;
|
|
80
80
|
return rows.map((raw) => ({
|
|
81
|
-
rank: Number(primitive(raw[0])),
|
|
81
|
+
rank: Number(primitive(raw[0], "rank")),
|
|
82
82
|
row: decodeRow(layout, raw.slice(start, raw.length - after)),
|
|
83
83
|
group: raw.slice(1, 1 + group)
|
|
84
84
|
}));
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
+
import { answerInvalid } from "../error/refusal.mjs";
|
|
1
2
|
import { valueRow } from "../result/calc.mjs";
|
|
2
3
|
import { comparator, compareKeys } from "../result/order.mjs";
|
|
3
4
|
import { zeroValues } from "../result/zero.mjs";
|
|
4
5
|
import { bucketLabels, epochDayLabel } from "../time/bucket.mjs";
|
|
5
|
-
import { formatTextTime } from "../time/instant.mjs";
|
|
6
|
+
import { formatTextTime, wholeMicros } from "../time/instant.mjs";
|
|
6
7
|
import { canonical } from "../value/canonical.mjs";
|
|
7
8
|
// src/engine/shape.ts
|
|
8
9
|
/** A value from the driver as a plain primitive; big integers arrive as text. */
|
|
9
|
-
function primitive(raw) {
|
|
10
|
+
function primitive(raw, column) {
|
|
10
11
|
if (raw === null || raw === void 0) return null;
|
|
11
12
|
if (typeof raw === "string" || typeof raw === "number" || typeof raw === "boolean") return raw;
|
|
12
13
|
if (typeof raw === "bigint") return raw.toString();
|
|
13
|
-
throw
|
|
14
|
+
throw answerInvalid(column, `the driver returned a ${typeof raw} where a plain value was expected.`);
|
|
14
15
|
}
|
|
15
16
|
function bucketLabel(raw, grain) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return grain === "hour" ? formatTextTime(Number(value)) : epochDayLabel(Number(value));
|
|
17
|
+
if (raw === null || raw === void 0 || grain === void 0) return null;
|
|
18
|
+
return grain === "hour" ? formatTextTime(wholeMicros(raw, "bucket")) : epochDayLabel(Number(primitive(raw, "bucket")));
|
|
19
19
|
}
|
|
20
20
|
function decodeRow(layout, raw) {
|
|
21
21
|
let rest = raw;
|
|
@@ -25,8 +25,8 @@ function decodeRow(layout, raw) {
|
|
|
25
25
|
return part;
|
|
26
26
|
};
|
|
27
27
|
const bucket = layout.bucket ? bucketLabel(next(1)[0], layout.grain) : null;
|
|
28
|
-
const key = next(layout.keys).map((v) => primitive(v));
|
|
29
|
-
const labels = next(layout.labelled.filter(Boolean).length).map((v) => primitive(v));
|
|
28
|
+
const key = next(layout.keys).map((v, i) => primitive(v, `dimension ${i + 1}`));
|
|
29
|
+
const labels = next(layout.labelled.filter(Boolean).length).map((v, i) => primitive(v, `label ${i + 1}`));
|
|
30
30
|
return {
|
|
31
31
|
bucket,
|
|
32
32
|
key,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { checkStored } from "./nan.mjs";
|
|
2
2
|
import { layoutOf, read } from "./read.mjs";
|
|
3
3
|
import { decodeRow } from "./shape.mjs";
|
|
4
4
|
import { ident, join, sql } from "./sql.mjs";
|
|
@@ -34,7 +34,7 @@ async function readPartition(pass, order, limit) {
|
|
|
34
34
|
bucket: false
|
|
35
35
|
});
|
|
36
36
|
for (const raw of await read(pass, partitionSql(pass, order, limit))) {
|
|
37
|
-
if (pass.p.nan !== void 0)
|
|
37
|
+
if (pass.p.nan !== void 0) checkStored(raw.at(-1), pass.seen);
|
|
38
38
|
const group = decodeRow(layout, raw.slice(2, pass.p.nan === void 0 ? void 0 : -1));
|
|
39
39
|
if (Number(raw[0]) === 1) result.total = group;
|
|
40
40
|
else if (raw[1] === null) result.other = group;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { relationBody } from "./filter.mjs";
|
|
2
2
|
// src/engine/sql-pass.ts
|
|
3
3
|
/** One request's statement build, empty, and what the plan check is told. */
|
|
4
|
-
function sqlBase(input, plan, session, dialect) {
|
|
4
|
+
function sqlBase(input, plan, { session, seen }, dialect) {
|
|
5
5
|
return {
|
|
6
6
|
b: {
|
|
7
7
|
model: input.model,
|
|
@@ -18,7 +18,8 @@ function sqlBase(input, plan, session, dialect) {
|
|
|
18
18
|
principal: input.principal,
|
|
19
19
|
expectedLocks: input.locks ?? [],
|
|
20
20
|
expectedRequired: input.required ?? []
|
|
21
|
-
}
|
|
21
|
+
},
|
|
22
|
+
seen
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
25
|
export { sqlBase };
|
|
@@ -4,6 +4,7 @@ import { keptBySets } from "./rank-sets.mjs";
|
|
|
4
4
|
import { sqlBase } from "./sql-pass.mjs";
|
|
5
5
|
import { sqlRecords } from "./sql-records.mjs";
|
|
6
6
|
import { readsOf, splitState } from "./sql-split.mjs";
|
|
7
|
+
import { sqlUnread } from "./sql-unread.mjs";
|
|
7
8
|
// src/engine/sql-reader.ts
|
|
8
9
|
const keyOf = (s) => JSON.stringify([s.text, s.params.map((p) => p instanceof Uint8Array ? { bytes: [...p] } : p)]);
|
|
9
10
|
/**
|
|
@@ -23,20 +24,27 @@ function once(session) {
|
|
|
23
24
|
}
|
|
24
25
|
};
|
|
25
26
|
}
|
|
26
|
-
/**
|
|
27
|
-
|
|
27
|
+
/**
|
|
28
|
+
* The reader on a session that already runs each statement once: a split's is its parent's,
|
|
29
|
+
* and so is what its statements have seen of the stored values.
|
|
30
|
+
*/
|
|
31
|
+
function readerOn(session, dialect, seen, split) {
|
|
28
32
|
return {
|
|
29
33
|
...session.concurrent === true ? { concurrent: true } : {},
|
|
30
34
|
open(input, plan) {
|
|
31
|
-
const base = sqlBase(input, plan,
|
|
35
|
+
const base = sqlBase(input, plan, {
|
|
36
|
+
session,
|
|
37
|
+
seen
|
|
38
|
+
}, dialect);
|
|
32
39
|
return {
|
|
33
40
|
reads: (query, span) => readsOf(base, query, span, split),
|
|
34
41
|
sources: () => [...base.b.relations.keys()].toSorted(),
|
|
35
42
|
records: (ask) => sqlRecords(base, ask),
|
|
43
|
+
unread: (query) => sqlUnread(base, query),
|
|
36
44
|
keptBySets: (query) => keptBySets(base, query, spanOf(input, query))
|
|
37
45
|
};
|
|
38
46
|
},
|
|
39
|
-
split: (s) => readerOn(session, dialect, splitState(s))
|
|
47
|
+
split: (s) => readerOn(session, dialect, seen, splitState(s))
|
|
40
48
|
};
|
|
41
49
|
}
|
|
42
50
|
/**
|
|
@@ -46,6 +54,6 @@ function readerOn(session, dialect, split) {
|
|
|
46
54
|
* statement per level, in the period asked and in its comparison period.
|
|
47
55
|
*/
|
|
48
56
|
function sqlReader(given, dialect = postgres) {
|
|
49
|
-
return readerOn(once(given), dialect);
|
|
57
|
+
return readerOn(once(given), dialect, { unread: false });
|
|
50
58
|
}
|
|
51
59
|
export { sqlReader };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { decimalColumns } from "../model/storage.mjs";
|
|
1
2
|
import { columnsLess } from "./numbers.mjs";
|
|
2
3
|
import { measureLayout, readLevel } from "./read.mjs";
|
|
3
4
|
import { decodeCells } from "./shape.mjs";
|
|
@@ -24,7 +25,7 @@ function sqlReads(pass) {
|
|
|
24
25
|
ranks: (index) => p.measures[index]?.order !== void 0,
|
|
25
26
|
windowTotals: p.measures.every((m) => m.parts !== void 0),
|
|
26
27
|
...pass.b.dialect.groupingSets === true && p.staged === void 0 && !additive ? { partition: (order, limit) => readPartition(pass, order, limit) } : {},
|
|
27
|
-
narrows:
|
|
28
|
+
narrows: decimalColumns(pass.b.model, pass.query).length === 0,
|
|
28
29
|
...additive ? { lessKept } : {}
|
|
29
30
|
};
|
|
30
31
|
}
|
|
@@ -94,8 +94,8 @@ async function sqlRecords(base, ask) {
|
|
|
94
94
|
raw.push(...await read(pass, statement(test, want - raw.length)));
|
|
95
95
|
}
|
|
96
96
|
return {
|
|
97
|
-
rows: raw.map((r) => columns.map((c, i) => decode(c
|
|
98
|
-
at: raw.map((r) => r.slice(columns.length).map((v) => primitive(v)))
|
|
97
|
+
rows: raw.map((r) => columns.map((c, i) => decode(c, r[i]))),
|
|
98
|
+
at: raw.map((r) => r.slice(columns.length).map((v, i) => primitive(v, `order ${i + 1}`)))
|
|
99
99
|
};
|
|
100
100
|
}
|
|
101
101
|
export { sqlRecords };
|
|
@@ -28,7 +28,7 @@ const splitState = (split) => ({
|
|
|
28
28
|
stash: /* @__PURE__ */ new Map()
|
|
29
29
|
});
|
|
30
30
|
/** A level of one period as a key: the whole level, in its canonical form. */
|
|
31
|
-
const levelKey = (span, l) => canonical([span
|
|
31
|
+
const levelKey = (span, l) => canonical([span === void 0 ? null : [String(span.from), String(span.to)], l]);
|
|
32
32
|
/** A grouped level of every row, ranked or not: one the split reads for both queries. */
|
|
33
33
|
const splits = (l) => l.keys && l.restrict === void 0 && l.totals !== true && l.nonEmpty !== true && !(l.bucket && l.take !== void 0);
|
|
34
34
|
/** Other's order: the kept query's without the folded dimension, later dimensions one down. */
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { readColumns } from "../model/storage.mjs";
|
|
2
|
+
import { INSTANTS } from "../time/text-time.mjs";
|
|
3
|
+
import { spanOf } from "./checks.mjs";
|
|
4
|
+
import { instantSql } from "./members.mjs";
|
|
5
|
+
import { minorUnits } from "./numbers.mjs";
|
|
6
|
+
import { factRows } from "./prepare.mjs";
|
|
7
|
+
import { read } from "./read.mjs";
|
|
8
|
+
import { ident, join, sql } from "./sql.mjs";
|
|
9
|
+
import { queryTime } from "./time.mjs";
|
|
10
|
+
// src/engine/sql-unread.ts
|
|
11
|
+
/** Whether the database's own type reads a storage: then every stored value is an instant. */
|
|
12
|
+
const typed = (storage) => storage === "timestamptz" || storage === "date";
|
|
13
|
+
/** A row whose time is set but is no instant: it does not parse, its rule excludes it, or it is out of range. */
|
|
14
|
+
function unreadSql(column, instant) {
|
|
15
|
+
const [from, last] = [String(INSTANTS.from), String(INSTANTS.to - INSTANTS.from - 1n)];
|
|
16
|
+
const known = sql`(${instant} - CAST(${from} AS bigint)) BETWEEN 0 AND CAST(${last} AS bigint)`;
|
|
17
|
+
return sql`${column} IS NOT NULL AND NOT COALESCE(${known}, FALSE)`;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The time values that do not read, over the rows the query reads without its range (an
|
|
21
|
+
* unread time is in no range). A `timestamptz` or `date` column is read by the database's own
|
|
22
|
+
* type, so it has none.
|
|
23
|
+
*/
|
|
24
|
+
async function timeUnread(base, query) {
|
|
25
|
+
const time = queryTime(base.b, query);
|
|
26
|
+
if (time === void 0 || typed(time.storage)) return [];
|
|
27
|
+
const rows = factRows(base.b, query);
|
|
28
|
+
const test = unreadSql(ident("f", time.column), instantSql(base.b, "f", time));
|
|
29
|
+
const body = sql`SELECT count(*) FROM ${rows.from} WHERE ${rows.where} AND ${test}`;
|
|
30
|
+
const [row] = await read(base, body);
|
|
31
|
+
const count = Number(row?.[0] ?? 0);
|
|
32
|
+
return count === 0 ? [] : [{
|
|
33
|
+
source: query.source,
|
|
34
|
+
column: time.column,
|
|
35
|
+
count
|
|
36
|
+
}];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The exact values that are set but are no operand (`minorUnits` gives none: past the scale or
|
|
40
|
+
* the operand bound), over the rows the query aggregates, in one statement. Only when a read
|
|
41
|
+
* noted one (`storedPart`): an answer whose values all read runs no statement for this.
|
|
42
|
+
*/
|
|
43
|
+
async function exactUnread(base, query) {
|
|
44
|
+
const columns = readColumns(base.b.model, query).flatMap((c) => c.kind === "exact" ? [c] : []);
|
|
45
|
+
if (columns.length === 0 || !base.seen.unread) return [];
|
|
46
|
+
const rows = factRows(base.b, query, spanOf(base.input, query));
|
|
47
|
+
const counts = columns.map((c) => {
|
|
48
|
+
const column = ident("f", c.column);
|
|
49
|
+
const units = minorUnits(base.b, column, c.numeric);
|
|
50
|
+
return sql`count(*) FILTER (WHERE ${column} IS NOT NULL AND ${units} IS NULL)`;
|
|
51
|
+
});
|
|
52
|
+
const [row] = await read(base, sql`SELECT ${join(counts)} FROM ${rows.from} WHERE ${rows.where}`);
|
|
53
|
+
return columns.flatMap((c, i) => {
|
|
54
|
+
const count = Number(row?.[i] ?? 0);
|
|
55
|
+
return count === 0 ? [] : [{
|
|
56
|
+
source: query.source,
|
|
57
|
+
column: c.column,
|
|
58
|
+
count
|
|
59
|
+
}];
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The values a query's answer leaves out because they do not read as their column's storage,
|
|
64
|
+
* by column, in the order every engine counts them (`readColumns`): its time, then its exact
|
|
65
|
+
* columns.
|
|
66
|
+
*/
|
|
67
|
+
async function sqlUnread(base, query) {
|
|
68
|
+
return [...await timeUnread(base, query), ...await exactUnread(base, query)];
|
|
69
|
+
}
|
|
70
|
+
export { sqlUnread };
|
|
@@ -47,6 +47,7 @@ function rangeSql(b, dim, span, at) {
|
|
|
47
47
|
return sql`${column} >= CAST(${from} AS timestamptz) AND ${column} < CAST(${to} AS timestamptz)`;
|
|
48
48
|
}
|
|
49
49
|
const instant = at ?? instantSql(b, alias, dim);
|
|
50
|
-
|
|
50
|
+
const [from, to] = [String(span.from), String(span.to)];
|
|
51
|
+
return sql`${instant} >= CAST(${from} AS bigint) AND ${instant} < CAST(${to} AS bigint)`;
|
|
51
52
|
}
|
|
52
53
|
export { bucketSql, instantOnce, queryTime, rangeSql };
|