@quereus/quereus 0.7.3 → 0.7.5
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/dist/src/schema/manager.d.ts.map +1 -1
- package/dist/src/schema/manager.js +19 -18
- package/package.json +3 -3
- package/dist/src/common/constants.js.map +0 -1
- package/dist/src/common/datatype.js.map +0 -1
- package/dist/src/common/errors.js.map +0 -1
- package/dist/src/common/json-types.js.map +0 -1
- package/dist/src/common/logger.js.map +0 -1
- package/dist/src/common/type-inference.js.map +0 -1
- package/dist/src/common/types.js.map +0 -1
- package/dist/src/core/database-options.js.map +0 -1
- package/dist/src/core/database.js.map +0 -1
- package/dist/src/core/param.js.map +0 -1
- package/dist/src/core/statement.js.map +0 -1
- package/dist/src/func/builtins/aggregate.js.map +0 -1
- package/dist/src/func/builtins/builtin-window-functions.js.map +0 -1
- package/dist/src/func/builtins/conversion.js.map +0 -1
- package/dist/src/func/builtins/datetime.js.map +0 -1
- package/dist/src/func/builtins/explain.js.map +0 -1
- package/dist/src/func/builtins/generation.js.map +0 -1
- package/dist/src/func/builtins/index.js.map +0 -1
- package/dist/src/func/builtins/json-helpers.js.map +0 -1
- package/dist/src/func/builtins/json-tvf.js.map +0 -1
- package/dist/src/func/builtins/json.js.map +0 -1
- package/dist/src/func/builtins/scalar.js.map +0 -1
- package/dist/src/func/builtins/schema.js.map +0 -1
- package/dist/src/func/builtins/string.js.map +0 -1
- package/dist/src/func/builtins/timespan.js.map +0 -1
- package/dist/src/func/context.js.map +0 -1
- package/dist/src/func/registration.js.map +0 -1
- package/dist/src/index.js.map +0 -1
- package/dist/src/parser/ast.js.map +0 -1
- package/dist/src/parser/index.js.map +0 -1
- package/dist/src/parser/lexer.js.map +0 -1
- package/dist/src/parser/parser.js.map +0 -1
- package/dist/src/parser/utils.js.map +0 -1
- package/dist/src/parser/visitor.js.map +0 -1
- package/dist/src/planner/analysis/binding-collector.js.map +0 -1
- package/dist/src/planner/analysis/const-evaluator.js.map +0 -1
- package/dist/src/planner/analysis/const-pass.js.map +0 -1
- package/dist/src/planner/analysis/constraint-extractor.js.map +0 -1
- package/dist/src/planner/analysis/predicate-normalizer.js.map +0 -1
- package/dist/src/planner/building/alter-table.js.map +0 -1
- package/dist/src/planner/building/block.js.map +0 -1
- package/dist/src/planner/building/constraint-builder.js.map +0 -1
- package/dist/src/planner/building/create-assertion.js.map +0 -1
- package/dist/src/planner/building/create-view.js.map +0 -1
- package/dist/src/planner/building/ddl.js.map +0 -1
- package/dist/src/planner/building/declare-schema.js.map +0 -1
- package/dist/src/planner/building/delete.js.map +0 -1
- package/dist/src/planner/building/drop-assertion.js.map +0 -1
- package/dist/src/planner/building/drop-table.js.map +0 -1
- package/dist/src/planner/building/drop-view.js.map +0 -1
- package/dist/src/planner/building/expression.js.map +0 -1
- package/dist/src/planner/building/function-call.js.map +0 -1
- package/dist/src/planner/building/insert.js.map +0 -1
- package/dist/src/planner/building/pragma.js.map +0 -1
- package/dist/src/planner/building/schema-resolution.js.map +0 -1
- package/dist/src/planner/building/select-aggregates.js.map +0 -1
- package/dist/src/planner/building/select-compound.js.map +0 -1
- package/dist/src/planner/building/select-context.js.map +0 -1
- package/dist/src/planner/building/select-modifiers.js.map +0 -1
- package/dist/src/planner/building/select-projections.js.map +0 -1
- package/dist/src/planner/building/select-window.js.map +0 -1
- package/dist/src/planner/building/select.js.map +0 -1
- package/dist/src/planner/building/table-function.js.map +0 -1
- package/dist/src/planner/building/table.js.map +0 -1
- package/dist/src/planner/building/transaction.js.map +0 -1
- package/dist/src/planner/building/update.js.map +0 -1
- package/dist/src/planner/building/with.js.map +0 -1
- package/dist/src/planner/cache/correlation-detector.js.map +0 -1
- package/dist/src/planner/cache/materialization-advisory.js.map +0 -1
- package/dist/src/planner/cache/reference-graph.js.map +0 -1
- package/dist/src/planner/cost/index.js.map +0 -1
- package/dist/src/planner/debug/logger-utils.js.map +0 -1
- package/dist/src/planner/debug.js.map +0 -1
- package/dist/src/planner/framework/characteristics.js.map +0 -1
- package/dist/src/planner/framework/context.js.map +0 -1
- package/dist/src/planner/framework/pass.js.map +0 -1
- package/dist/src/planner/framework/physical-utils.js.map +0 -1
- package/dist/src/planner/framework/registry.js.map +0 -1
- package/dist/src/planner/framework/trace.js.map +0 -1
- package/dist/src/planner/nodes/add-constraint-node.js.map +0 -1
- package/dist/src/planner/nodes/aggregate-function.js.map +0 -1
- package/dist/src/planner/nodes/aggregate-node.js.map +0 -1
- package/dist/src/planner/nodes/array-index-node.js.map +0 -1
- package/dist/src/planner/nodes/block.js.map +0 -1
- package/dist/src/planner/nodes/cache-node.js.map +0 -1
- package/dist/src/planner/nodes/constraint-check-node.js.map +0 -1
- package/dist/src/planner/nodes/create-assertion-node.js.map +0 -1
- package/dist/src/planner/nodes/create-index-node.js.map +0 -1
- package/dist/src/planner/nodes/create-table-node.js.map +0 -1
- package/dist/src/planner/nodes/create-view-node.js.map +0 -1
- package/dist/src/planner/nodes/cte-node.js.map +0 -1
- package/dist/src/planner/nodes/cte-reference-node.js.map +0 -1
- package/dist/src/planner/nodes/declarative-schema.js.map +0 -1
- package/dist/src/planner/nodes/delete-node.js.map +0 -1
- package/dist/src/planner/nodes/distinct-node.js.map +0 -1
- package/dist/src/planner/nodes/dml-executor-node.js.map +0 -1
- package/dist/src/planner/nodes/drop-assertion-node.js.map +0 -1
- package/dist/src/planner/nodes/drop-table-node.js.map +0 -1
- package/dist/src/planner/nodes/drop-view-node.js.map +0 -1
- package/dist/src/planner/nodes/filter.js.map +0 -1
- package/dist/src/planner/nodes/function.js.map +0 -1
- package/dist/src/planner/nodes/insert-node.js.map +0 -1
- package/dist/src/planner/nodes/internal-recursive-cte-ref-node.js.map +0 -1
- package/dist/src/planner/nodes/join-node.js.map +0 -1
- package/dist/src/planner/nodes/limit-offset.js.map +0 -1
- package/dist/src/planner/nodes/plan-node-type.js.map +0 -1
- package/dist/src/planner/nodes/plan-node.js.map +0 -1
- package/dist/src/planner/nodes/pragma.js.map +0 -1
- package/dist/src/planner/nodes/project-node.js.map +0 -1
- package/dist/src/planner/nodes/recursive-cte-node.js.map +0 -1
- package/dist/src/planner/nodes/reference.js.map +0 -1
- package/dist/src/planner/nodes/remote-query-node.js.map +0 -1
- package/dist/src/planner/nodes/retrieve-node.js.map +0 -1
- package/dist/src/planner/nodes/returning-node.js.map +0 -1
- package/dist/src/planner/nodes/scalar.js.map +0 -1
- package/dist/src/planner/nodes/sequencing-node.js.map +0 -1
- package/dist/src/planner/nodes/set-operation-node.js.map +0 -1
- package/dist/src/planner/nodes/single-row.js.map +0 -1
- package/dist/src/planner/nodes/sink-node.js.map +0 -1
- package/dist/src/planner/nodes/sort.js.map +0 -1
- package/dist/src/planner/nodes/stream-aggregate.js.map +0 -1
- package/dist/src/planner/nodes/subquery.js.map +0 -1
- package/dist/src/planner/nodes/table-access-nodes.js.map +0 -1
- package/dist/src/planner/nodes/table-function-call.js.map +0 -1
- package/dist/src/planner/nodes/transaction-node.js.map +0 -1
- package/dist/src/planner/nodes/update-node.js.map +0 -1
- package/dist/src/planner/nodes/values-node.js.map +0 -1
- package/dist/src/planner/nodes/view-reference-node.js.map +0 -1
- package/dist/src/planner/nodes/window-function.js.map +0 -1
- package/dist/src/planner/nodes/window-node.js.map +0 -1
- package/dist/src/planner/optimizer-tuning.js.map +0 -1
- package/dist/src/planner/optimizer.js.map +0 -1
- package/dist/src/planner/planning-context.js.map +0 -1
- package/dist/src/planner/resolve.js.map +0 -1
- package/dist/src/planner/rules/access/rule-select-access-path.js.map +0 -1
- package/dist/src/planner/rules/aggregate/rule-aggregate-streaming.js.map +0 -1
- package/dist/src/planner/rules/cache/rule-cte-optimization.js.map +0 -1
- package/dist/src/planner/rules/cache/rule-materialization-advisory.js.map +0 -1
- package/dist/src/planner/rules/cache/rule-mutating-subquery-cache.js.map +0 -1
- package/dist/src/planner/rules/join/rule-join-greedy-commute.js.map +0 -1
- package/dist/src/planner/rules/join/rule-join-key-inference.js.map +0 -1
- package/dist/src/planner/rules/join/rule-quickpick-enumeration.js.map +0 -1
- package/dist/src/planner/rules/predicate/rule-predicate-pushdown.js.map +0 -1
- package/dist/src/planner/rules/retrieve/rule-grow-retrieve.js.map +0 -1
- package/dist/src/planner/scopes/aliased.js.map +0 -1
- package/dist/src/planner/scopes/base.js.map +0 -1
- package/dist/src/planner/scopes/empty.js.map +0 -1
- package/dist/src/planner/scopes/global.js.map +0 -1
- package/dist/src/planner/scopes/multi.js.map +0 -1
- package/dist/src/planner/scopes/param.js.map +0 -1
- package/dist/src/planner/scopes/registered.js.map +0 -1
- package/dist/src/planner/scopes/scope.js.map +0 -1
- package/dist/src/planner/stats/basic-estimates.js.map +0 -1
- package/dist/src/planner/stats/index.js.map +0 -1
- package/dist/src/planner/type-utils.js.map +0 -1
- package/dist/src/planner/util/key-utils.js.map +0 -1
- package/dist/src/planner/validation/determinism-validator.js.map +0 -1
- package/dist/src/planner/validation/plan-validator.js.map +0 -1
- package/dist/src/runtime/async-util.js.map +0 -1
- package/dist/src/runtime/cache/shared-cache.js.map +0 -1
- package/dist/src/runtime/context-helpers.js.map +0 -1
- package/dist/src/runtime/deferred-constraint-queue.js.map +0 -1
- package/dist/src/runtime/emission-context.js.map +0 -1
- package/dist/src/runtime/emit/add-constraint.js.map +0 -1
- package/dist/src/runtime/emit/aggregate.js.map +0 -1
- package/dist/src/runtime/emit/array-index.js.map +0 -1
- package/dist/src/runtime/emit/between.js.map +0 -1
- package/dist/src/runtime/emit/binary.js.map +0 -1
- package/dist/src/runtime/emit/block.js.map +0 -1
- package/dist/src/runtime/emit/cache.js.map +0 -1
- package/dist/src/runtime/emit/case.js.map +0 -1
- package/dist/src/runtime/emit/cast.js.map +0 -1
- package/dist/src/runtime/emit/collate.js.map +0 -1
- package/dist/src/runtime/emit/column-reference.js.map +0 -1
- package/dist/src/runtime/emit/constraint-check.js.map +0 -1
- package/dist/src/runtime/emit/create-assertion.js.map +0 -1
- package/dist/src/runtime/emit/create-index.js.map +0 -1
- package/dist/src/runtime/emit/create-table.js.map +0 -1
- package/dist/src/runtime/emit/create-view.js.map +0 -1
- package/dist/src/runtime/emit/cte-reference.js.map +0 -1
- package/dist/src/runtime/emit/cte.js.map +0 -1
- package/dist/src/runtime/emit/delete.js.map +0 -1
- package/dist/src/runtime/emit/distinct.js.map +0 -1
- package/dist/src/runtime/emit/dml-executor.js.map +0 -1
- package/dist/src/runtime/emit/drop-assertion.js.map +0 -1
- package/dist/src/runtime/emit/drop-table.js.map +0 -1
- package/dist/src/runtime/emit/drop-view.js.map +0 -1
- package/dist/src/runtime/emit/filter.js.map +0 -1
- package/dist/src/runtime/emit/insert.js.map +0 -1
- package/dist/src/runtime/emit/internal-recursive-cte-ref.js.map +0 -1
- package/dist/src/runtime/emit/join.js.map +0 -1
- package/dist/src/runtime/emit/limit-offset.js.map +0 -1
- package/dist/src/runtime/emit/literal.js.map +0 -1
- package/dist/src/runtime/emit/parameter.js.map +0 -1
- package/dist/src/runtime/emit/pragma.js.map +0 -1
- package/dist/src/runtime/emit/project.js.map +0 -1
- package/dist/src/runtime/emit/recursive-cte.js.map +0 -1
- package/dist/src/runtime/emit/remote-query.js.map +0 -1
- package/dist/src/runtime/emit/retrieve.js.map +0 -1
- package/dist/src/runtime/emit/returning.js.map +0 -1
- package/dist/src/runtime/emit/scalar-function.js.map +0 -1
- package/dist/src/runtime/emit/scan.js.map +0 -1
- package/dist/src/runtime/emit/schema-declarative.js.map +0 -1
- package/dist/src/runtime/emit/sequencing.js.map +0 -1
- package/dist/src/runtime/emit/set-operation.js.map +0 -1
- package/dist/src/runtime/emit/sink.js.map +0 -1
- package/dist/src/runtime/emit/sort.js.map +0 -1
- package/dist/src/runtime/emit/subquery.js.map +0 -1
- package/dist/src/runtime/emit/table-valued-function.js.map +0 -1
- package/dist/src/runtime/emit/temporal-arithmetic.js.map +0 -1
- package/dist/src/runtime/emit/transaction.js.map +0 -1
- package/dist/src/runtime/emit/unary.js.map +0 -1
- package/dist/src/runtime/emit/update.js.map +0 -1
- package/dist/src/runtime/emit/values.js.map +0 -1
- package/dist/src/runtime/emit/window-function.js.map +0 -1
- package/dist/src/runtime/emit/window.js.map +0 -1
- package/dist/src/runtime/emitters.js.map +0 -1
- package/dist/src/runtime/register.js.map +0 -1
- package/dist/src/runtime/scheduler.js.map +0 -1
- package/dist/src/runtime/types.js.map +0 -1
- package/dist/src/runtime/utils.js.map +0 -1
- package/dist/src/schema/assertion.js.map +0 -1
- package/dist/src/schema/catalog.js.map +0 -1
- package/dist/src/schema/change-events.js.map +0 -1
- package/dist/src/schema/column.js.map +0 -1
- package/dist/src/schema/declared-schema-manager.js.map +0 -1
- package/dist/src/schema/function.js.map +0 -1
- package/dist/src/schema/manager.js.map +0 -1
- package/dist/src/schema/schema-differ.js.map +0 -1
- package/dist/src/schema/schema-hasher.js.map +0 -1
- package/dist/src/schema/schema.js.map +0 -1
- package/dist/src/schema/table.js.map +0 -1
- package/dist/src/schema/view.js.map +0 -1
- package/dist/src/schema/window-function.js.map +0 -1
- package/dist/src/types/builtin-types.js.map +0 -1
- package/dist/src/types/index.js.map +0 -1
- package/dist/src/types/json-type.js.map +0 -1
- package/dist/src/types/logical-type.js.map +0 -1
- package/dist/src/types/plugin-interface.js.map +0 -1
- package/dist/src/types/registry.js.map +0 -1
- package/dist/src/types/temporal-types.js.map +0 -1
- package/dist/src/types/validation.js.map +0 -1
- package/dist/src/util/affinity.js.map +0 -1
- package/dist/src/util/ast-stringify.js.map +0 -1
- package/dist/src/util/cached.js.map +0 -1
- package/dist/src/util/coercion.js.map +0 -1
- package/dist/src/util/comparison.js.map +0 -1
- package/dist/src/util/environment.js.map +0 -1
- package/dist/src/util/hash.js.map +0 -1
- package/dist/src/util/latches.js.map +0 -1
- package/dist/src/util/mutation-statement.js.map +0 -1
- package/dist/src/util/patterns.js.map +0 -1
- package/dist/src/util/plan-formatter.js.map +0 -1
- package/dist/src/util/plugin-helper.js.map +0 -1
- package/dist/src/util/row-descriptor.js.map +0 -1
- package/dist/src/util/serialization.js.map +0 -1
- package/dist/src/util/sql-literal.js.map +0 -1
- package/dist/src/util/working-table-iterable.js.map +0 -1
- package/dist/src/vtab/best-access-plan.js.map +0 -1
- package/dist/src/vtab/connection.js.map +0 -1
- package/dist/src/vtab/filter-info.js.map +0 -1
- package/dist/src/vtab/index-info.js.map +0 -1
- package/dist/src/vtab/manifest.js.map +0 -1
- package/dist/src/vtab/memory/connection.js.map +0 -1
- package/dist/src/vtab/memory/index.js.map +0 -1
- package/dist/src/vtab/memory/layer/base-cursor.js.map +0 -1
- package/dist/src/vtab/memory/layer/base.js.map +0 -1
- package/dist/src/vtab/memory/layer/connection.js.map +0 -1
- package/dist/src/vtab/memory/layer/interface.js.map +0 -1
- package/dist/src/vtab/memory/layer/manager.js.map +0 -1
- package/dist/src/vtab/memory/layer/safe-iterate.js.map +0 -1
- package/dist/src/vtab/memory/layer/scan-plan.js.map +0 -1
- package/dist/src/vtab/memory/layer/transaction-cursor.js.map +0 -1
- package/dist/src/vtab/memory/layer/transaction.js.map +0 -1
- package/dist/src/vtab/memory/module.js.map +0 -1
- package/dist/src/vtab/memory/table.js.map +0 -1
- package/dist/src/vtab/memory/types.js.map +0 -1
- package/dist/src/vtab/memory/utils/logging.js.map +0 -1
- package/dist/src/vtab/memory/utils/primary-key.js.map +0 -1
- package/dist/src/vtab/module.js.map +0 -1
- package/dist/src/vtab/table.js.map +0 -1
- package/src/common/constants.ts +0 -60
- package/src/common/datatype.ts +0 -85
- package/src/common/errors.ts +0 -189
- package/src/common/json-types.ts +0 -16
- package/src/common/logger.ts +0 -97
- package/src/common/type-inference.ts +0 -39
- package/src/common/types.ts +0 -151
- package/src/core/database-options.ts +0 -258
- package/src/core/database.ts +0 -1461
- package/src/core/param.ts +0 -56
- package/src/core/statement.ts +0 -528
- package/src/func/builtins/aggregate.ts +0 -269
- package/src/func/builtins/builtin-window-functions.ts +0 -166
- package/src/func/builtins/conversion.ts +0 -226
- package/src/func/builtins/datetime.ts +0 -500
- package/src/func/builtins/explain.ts +0 -779
- package/src/func/builtins/generation.ts +0 -43
- package/src/func/builtins/index.ts +0 -167
- package/src/func/builtins/json-helpers.ts +0 -237
- package/src/func/builtins/json-tvf.ts +0 -224
- package/src/func/builtins/json.ts +0 -588
- package/src/func/builtins/scalar.ts +0 -423
- package/src/func/builtins/schema.ts +0 -213
- package/src/func/builtins/string.ts +0 -306
- package/src/func/builtins/timespan.ts +0 -179
- package/src/func/context.ts +0 -258
- package/src/func/registration.ts +0 -201
- package/src/index.ts +0 -172
- package/src/parser/ast.ts +0 -581
- package/src/parser/index.ts +0 -65
- package/src/parser/lexer.ts +0 -806
- package/src/parser/parser.ts +0 -3352
- package/src/parser/utils.ts +0 -10
- package/src/parser/visitor.ts +0 -188
- package/src/planner/analysis/README.md +0 -93
- package/src/planner/analysis/binding-collector.ts +0 -83
- package/src/planner/analysis/const-evaluator.ts +0 -63
- package/src/planner/analysis/const-pass.ts +0 -282
- package/src/planner/analysis/constraint-extractor.ts +0 -764
- package/src/planner/analysis/predicate-normalizer.ts +0 -237
- package/src/planner/building/alter-table.ts +0 -49
- package/src/planner/building/block.ts +0 -93
- package/src/planner/building/constraint-builder.ts +0 -178
- package/src/planner/building/create-assertion.ts +0 -7
- package/src/planner/building/create-view.ts +0 -29
- package/src/planner/building/ddl.ts +0 -24
- package/src/planner/building/declare-schema.ts +0 -22
- package/src/planner/building/delete.ts +0 -218
- package/src/planner/building/drop-assertion.ts +0 -11
- package/src/planner/building/drop-table.ts +0 -13
- package/src/planner/building/drop-view.ts +0 -19
- package/src/planner/building/expression.ts +0 -205
- package/src/planner/building/function-call.ts +0 -129
- package/src/planner/building/insert.ts +0 -435
- package/src/planner/building/pragma.ts +0 -34
- package/src/planner/building/schema-resolution.ts +0 -176
- package/src/planner/building/select-aggregates.ts +0 -318
- package/src/planner/building/select-compound.ts +0 -119
- package/src/planner/building/select-context.ts +0 -85
- package/src/planner/building/select-modifiers.ts +0 -236
- package/src/planner/building/select-projections.ts +0 -177
- package/src/planner/building/select-window.ts +0 -259
- package/src/planner/building/select.ts +0 -567
- package/src/planner/building/table-function.ts +0 -49
- package/src/planner/building/table.ts +0 -40
- package/src/planner/building/transaction.ts +0 -23
- package/src/planner/building/update.ts +0 -331
- package/src/planner/building/with.ts +0 -180
- package/src/planner/cache/correlation-detector.ts +0 -83
- package/src/planner/cache/materialization-advisory.ts +0 -265
- package/src/planner/cache/reference-graph.ts +0 -196
- package/src/planner/cost/index.ts +0 -169
- package/src/planner/debug/logger-utils.ts +0 -68
- package/src/planner/debug.ts +0 -480
- package/src/planner/framework/README.md +0 -132
- package/src/planner/framework/characteristics.ts +0 -503
- package/src/planner/framework/context.ts +0 -239
- package/src/planner/framework/pass.ts +0 -354
- package/src/planner/framework/physical-utils.ts +0 -210
- package/src/planner/framework/registry.ts +0 -261
- package/src/planner/framework/trace.ts +0 -259
- package/src/planner/nodes/add-constraint-node.ts +0 -62
- package/src/planner/nodes/aggregate-function.ts +0 -155
- package/src/planner/nodes/aggregate-node.ts +0 -267
- package/src/planner/nodes/array-index-node.ts +0 -50
- package/src/planner/nodes/block.ts +0 -80
- package/src/planner/nodes/cache-node.ts +0 -103
- package/src/planner/nodes/constraint-check-node.ts +0 -138
- package/src/planner/nodes/create-assertion-node.ts +0 -51
- package/src/planner/nodes/create-index-node.ts +0 -41
- package/src/planner/nodes/create-table-node.ts +0 -35
- package/src/planner/nodes/create-view-node.ts +0 -44
- package/src/planner/nodes/cte-node.ts +0 -168
- package/src/planner/nodes/cte-reference-node.ts +0 -125
- package/src/planner/nodes/declarative-schema.ts +0 -221
- package/src/planner/nodes/delete-node.ts +0 -102
- package/src/planner/nodes/distinct-node.ts +0 -107
- package/src/planner/nodes/dml-executor-node.ts +0 -104
- package/src/planner/nodes/drop-assertion-node.ts +0 -50
- package/src/planner/nodes/drop-table-node.ts +0 -36
- package/src/planner/nodes/drop-view-node.ts +0 -37
- package/src/planner/nodes/filter.ts +0 -144
- package/src/planner/nodes/function.ts +0 -98
- package/src/planner/nodes/insert-node.ts +0 -126
- package/src/planner/nodes/internal-recursive-cte-ref-node.ts +0 -61
- package/src/planner/nodes/join-node.ts +0 -336
- package/src/planner/nodes/limit-offset.ts +0 -144
- package/src/planner/nodes/plan-node-type.ts +0 -95
- package/src/planner/nodes/plan-node.ts +0 -503
- package/src/planner/nodes/pragma.ts +0 -98
- package/src/planner/nodes/project-node.ts +0 -337
- package/src/planner/nodes/recursive-cte-node.ts +0 -158
- package/src/planner/nodes/reference.ts +0 -334
- package/src/planner/nodes/remote-query-node.ts +0 -73
- package/src/planner/nodes/retrieve-node.ts +0 -86
- package/src/planner/nodes/returning-node.ts +0 -269
- package/src/planner/nodes/scalar.ts +0 -772
- package/src/planner/nodes/sequencing-node.ts +0 -113
- package/src/planner/nodes/set-operation-node.ts +0 -87
- package/src/planner/nodes/single-row.ts +0 -85
- package/src/planner/nodes/sink-node.ts +0 -61
- package/src/planner/nodes/sort.ts +0 -166
- package/src/planner/nodes/stream-aggregate.ts +0 -293
- package/src/planner/nodes/subquery.ts +0 -268
- package/src/planner/nodes/table-access-nodes.ts +0 -323
- package/src/planner/nodes/table-function-call.ts +0 -134
- package/src/planner/nodes/transaction-node.ts +0 -55
- package/src/planner/nodes/update-node.ts +0 -138
- package/src/planner/nodes/values-node.ts +0 -244
- package/src/planner/nodes/view-reference-node.ts +0 -97
- package/src/planner/nodes/window-function.ts +0 -73
- package/src/planner/nodes/window-node.ts +0 -199
- package/src/planner/optimizer-tuning.ts +0 -105
- package/src/planner/optimizer.ts +0 -332
- package/src/planner/planning-context.ts +0 -190
- package/src/planner/resolve.ts +0 -101
- package/src/planner/rules/README.md +0 -96
- package/src/planner/rules/access/rule-select-access-path.ts +0 -399
- package/src/planner/rules/aggregate/rule-aggregate-streaming.ts +0 -162
- package/src/planner/rules/cache/rule-cte-optimization.ts +0 -79
- package/src/planner/rules/cache/rule-materialization-advisory.ts +0 -77
- package/src/planner/rules/cache/rule-mutating-subquery-cache.ts +0 -104
- package/src/planner/rules/join/rule-join-greedy-commute.ts +0 -48
- package/src/planner/rules/join/rule-join-key-inference.ts +0 -35
- package/src/planner/rules/join/rule-quickpick-enumeration.ts +0 -267
- package/src/planner/rules/predicate/rule-predicate-pushdown.ts +0 -144
- package/src/planner/rules/retrieve/rule-grow-retrieve.ts +0 -337
- package/src/planner/scopes/aliased.ts +0 -50
- package/src/planner/scopes/base.ts +0 -10
- package/src/planner/scopes/empty.ts +0 -12
- package/src/planner/scopes/global.ts +0 -73
- package/src/planner/scopes/multi.ts +0 -40
- package/src/planner/scopes/param.ts +0 -95
- package/src/planner/scopes/registered.ts +0 -67
- package/src/planner/scopes/scope.ts +0 -16
- package/src/planner/stats/basic-estimates.ts +0 -107
- package/src/planner/stats/index.ts +0 -158
- package/src/planner/type-utils.ts +0 -87
- package/src/planner/util/key-utils.ts +0 -46
- package/src/planner/validation/determinism-validator.ts +0 -104
- package/src/planner/validation/plan-validator.ts +0 -335
- package/src/runtime/async-util.ts +0 -283
- package/src/runtime/cache/shared-cache.ts +0 -169
- package/src/runtime/context-helpers.ts +0 -191
- package/src/runtime/deferred-constraint-queue.ts +0 -196
- package/src/runtime/emission-context.ts +0 -319
- package/src/runtime/emit/add-constraint.ts +0 -78
- package/src/runtime/emit/aggregate.ts +0 -581
- package/src/runtime/emit/array-index.ts +0 -25
- package/src/runtime/emit/between.ts +0 -51
- package/src/runtime/emit/binary.ts +0 -357
- package/src/runtime/emit/block.ts +0 -23
- package/src/runtime/emit/cache.ts +0 -64
- package/src/runtime/emit/case.ts +0 -87
- package/src/runtime/emit/cast.ts +0 -151
- package/src/runtime/emit/collate.ts +0 -9
- package/src/runtime/emit/column-reference.ts +0 -17
- package/src/runtime/emit/constraint-check.ts +0 -290
- package/src/runtime/emit/create-assertion.ts +0 -82
- package/src/runtime/emit/create-index.ts +0 -15
- package/src/runtime/emit/create-table.ts +0 -15
- package/src/runtime/emit/create-view.ts +0 -52
- package/src/runtime/emit/cte-reference.ts +0 -38
- package/src/runtime/emit/cte.ts +0 -39
- package/src/runtime/emit/delete.ts +0 -24
- package/src/runtime/emit/distinct.ts +0 -40
- package/src/runtime/emit/dml-executor.ts +0 -198
- package/src/runtime/emit/drop-assertion.ts +0 -45
- package/src/runtime/emit/drop-table.ts +0 -27
- package/src/runtime/emit/drop-view.ts +0 -49
- package/src/runtime/emit/filter.ts +0 -30
- package/src/runtime/emit/insert.ts +0 -42
- package/src/runtime/emit/internal-recursive-cte-ref.ts +0 -37
- package/src/runtime/emit/join.ts +0 -148
- package/src/runtime/emit/limit-offset.ts +0 -73
- package/src/runtime/emit/literal.ts +0 -17
- package/src/runtime/emit/parameter.ts +0 -59
- package/src/runtime/emit/pragma.ts +0 -56
- package/src/runtime/emit/project.ts +0 -46
- package/src/runtime/emit/recursive-cte.ts +0 -111
- package/src/runtime/emit/remote-query.ts +0 -47
- package/src/runtime/emit/retrieve.ts +0 -15
- package/src/runtime/emit/returning.ts +0 -41
- package/src/runtime/emit/scalar-function.ts +0 -69
- package/src/runtime/emit/scan.ts +0 -106
- package/src/runtime/emit/schema-declarative.ts +0 -215
- package/src/runtime/emit/sequencing.ts +0 -24
- package/src/runtime/emit/set-operation.ts +0 -141
- package/src/runtime/emit/sink.ts +0 -27
- package/src/runtime/emit/sort.ts +0 -75
- package/src/runtime/emit/subquery.ts +0 -203
- package/src/runtime/emit/table-valued-function.ts +0 -106
- package/src/runtime/emit/temporal-arithmetic.ts +0 -302
- package/src/runtime/emit/transaction.ts +0 -205
- package/src/runtime/emit/unary.ts +0 -101
- package/src/runtime/emit/update.ts +0 -66
- package/src/runtime/emit/values.ts +0 -66
- package/src/runtime/emit/window-function.ts +0 -42
- package/src/runtime/emit/window.ts +0 -458
- package/src/runtime/emitters.ts +0 -183
- package/src/runtime/register.ts +0 -150
- package/src/runtime/scheduler.ts +0 -488
- package/src/runtime/types.ts +0 -242
- package/src/runtime/utils.ts +0 -177
- package/src/schema/assertion.ts +0 -21
- package/src/schema/catalog.ts +0 -269
- package/src/schema/change-events.ts +0 -80
- package/src/schema/column.ts +0 -51
- package/src/schema/declared-schema-manager.ts +0 -82
- package/src/schema/function.ts +0 -188
- package/src/schema/manager.ts +0 -1034
- package/src/schema/schema-differ.ts +0 -214
- package/src/schema/schema-hasher.ts +0 -26
- package/src/schema/schema.ts +0 -222
- package/src/schema/table.ts +0 -409
- package/src/schema/view.ts +0 -19
- package/src/schema/window-function.ts +0 -56
- package/src/types/builtin-types.ts +0 -350
- package/src/types/index.ts +0 -17
- package/src/types/json-type.ts +0 -152
- package/src/types/logical-type.ts +0 -91
- package/src/types/plugin-interface.ts +0 -10
- package/src/types/registry.ts +0 -204
- package/src/types/temporal-types.ts +0 -290
- package/src/types/validation.ts +0 -120
- package/src/util/affinity.ts +0 -151
- package/src/util/ast-stringify.ts +0 -887
- package/src/util/cached.ts +0 -25
- package/src/util/coercion.ts +0 -113
- package/src/util/comparison.ts +0 -510
- package/src/util/environment.ts +0 -52
- package/src/util/hash.ts +0 -90
- package/src/util/latches.ts +0 -47
- package/src/util/mutation-statement.ts +0 -135
- package/src/util/patterns.ts +0 -56
- package/src/util/plan-formatter.ts +0 -48
- package/src/util/plugin-helper.ts +0 -110
- package/src/util/row-descriptor.ts +0 -105
- package/src/util/serialization.ts +0 -47
- package/src/util/sql-literal.ts +0 -22
- package/src/util/working-table-iterable.ts +0 -38
- package/src/vtab/best-access-plan.ts +0 -244
- package/src/vtab/connection.ts +0 -36
- package/src/vtab/filter-info.ts +0 -23
- package/src/vtab/index-info.ts +0 -84
- package/src/vtab/manifest.ts +0 -86
- package/src/vtab/memory/connection.ts +0 -73
- package/src/vtab/memory/index.ts +0 -191
- package/src/vtab/memory/layer/base-cursor.ts +0 -124
- package/src/vtab/memory/layer/base.ts +0 -275
- package/src/vtab/memory/layer/connection.ts +0 -203
- package/src/vtab/memory/layer/interface.ts +0 -47
- package/src/vtab/memory/layer/manager.ts +0 -909
- package/src/vtab/memory/layer/safe-iterate.ts +0 -49
- package/src/vtab/memory/layer/scan-plan.ts +0 -84
- package/src/vtab/memory/layer/transaction-cursor.ts +0 -162
- package/src/vtab/memory/layer/transaction.ts +0 -229
- package/src/vtab/memory/module.ts +0 -667
- package/src/vtab/memory/table.ts +0 -251
- package/src/vtab/memory/types.ts +0 -23
- package/src/vtab/memory/utils/logging.ts +0 -36
- package/src/vtab/memory/utils/primary-key.ts +0 -163
- package/src/vtab/module.ts +0 -162
- package/src/vtab/table.ts +0 -177
|
@@ -1,458 +0,0 @@
|
|
|
1
|
-
import type { WindowNode } from '../../planner/nodes/window-node.js';
|
|
2
|
-
import type { Instruction, RuntimeContext, InstructionRun } from '../types.js';
|
|
3
|
-
import type { OutputValue, Row, SqlValue } from '../../common/types.js';
|
|
4
|
-
import type { EmissionContext } from '../emission-context.js';
|
|
5
|
-
import { emitPlanNode, emitCallFromPlan } from '../emitters.js';
|
|
6
|
-
import { resolveWindowFunction } from '../../schema/window-function.js';
|
|
7
|
-
import { QuereusError } from '../../common/errors.js';
|
|
8
|
-
import { StatusCode } from '../../common/types.js';
|
|
9
|
-
import { compareSqlValues, createOrderByComparatorFast, resolveCollation } from '../../util/comparison.js';
|
|
10
|
-
import { createLogger } from '../../common/logger.js';
|
|
11
|
-
import { buildRowDescriptor } from '../../util/row-descriptor.js';
|
|
12
|
-
import { RowDescriptor } from '../../planner/nodes/plan-node.js';
|
|
13
|
-
import { withRowContext, withAsyncRowContext } from '../context-helpers.js';
|
|
14
|
-
|
|
15
|
-
const log = createLogger('runtime:emit:window');
|
|
16
|
-
|
|
17
|
-
export function emitWindow(plan: WindowNode, ctx: EmissionContext): Instruction {
|
|
18
|
-
// Get schemas for all window functions in this node
|
|
19
|
-
const functionSchemas = plan.functions.map(func => {
|
|
20
|
-
const schema = resolveWindowFunction(func.functionName);
|
|
21
|
-
if (!schema) {
|
|
22
|
-
throw new QuereusError(`Window function ${func.functionName} not found`, StatusCode.INTERNAL);
|
|
23
|
-
}
|
|
24
|
-
return schema;
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
// Emit callbacks for partition expressions
|
|
28
|
-
const partitionCallbacks = plan.partitionExpressions.map(exprPlan =>
|
|
29
|
-
emitCallFromPlan(exprPlan, ctx)
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
// Emit callbacks for ORDER BY expressions (if any)
|
|
33
|
-
const orderByCallbacks = plan.orderByExpressions.map(exprPlan =>
|
|
34
|
-
emitCallFromPlan(exprPlan, ctx)
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
// Emit callbacks for window function arguments
|
|
38
|
-
const functionArgCallbacks = plan.functionArguments.map(argPlan =>
|
|
39
|
-
argPlan ? emitCallFromPlan(argPlan, ctx) : null
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
// Create row descriptors
|
|
43
|
-
const sourceRowDescriptor = buildRowDescriptor(plan.source.getAttributes());
|
|
44
|
-
const outputRowDescriptor = buildRowDescriptor(plan.getAttributes());
|
|
45
|
-
|
|
46
|
-
async function* run(
|
|
47
|
-
rctx: RuntimeContext,
|
|
48
|
-
source: AsyncIterable<Row>,
|
|
49
|
-
...callbacks: Array<(ctx: RuntimeContext) => OutputValue>
|
|
50
|
-
): AsyncIterable<Row> {
|
|
51
|
-
log('Starting window function execution');
|
|
52
|
-
|
|
53
|
-
// Extract callbacks in order: partitions, orderBy, function args
|
|
54
|
-
const partitionCallbackList = callbacks.slice(0, partitionCallbacks.length);
|
|
55
|
-
const orderByCallbackList = callbacks.slice(
|
|
56
|
-
partitionCallbacks.length,
|
|
57
|
-
partitionCallbacks.length + orderByCallbacks.length
|
|
58
|
-
);
|
|
59
|
-
const funcArgCallbackList = callbacks.slice(
|
|
60
|
-
partitionCallbacks.length + orderByCallbacks.length
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
// Collect all rows (window functions require materialization for frame evaluation)
|
|
64
|
-
const allRows: Row[] = [];
|
|
65
|
-
for await (const row of source) {
|
|
66
|
-
allRows.push(row);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (plan.windowSpec.partitionBy.length === 0) {
|
|
70
|
-
// No partitioning - process as single partition
|
|
71
|
-
yield* processPartition(
|
|
72
|
-
allRows, plan, functionSchemas, rctx,
|
|
73
|
-
sourceRowDescriptor, outputRowDescriptor,
|
|
74
|
-
partitionCallbackList, orderByCallbackList, funcArgCallbackList
|
|
75
|
-
);
|
|
76
|
-
} else {
|
|
77
|
-
// With partitioning - group by partition keys
|
|
78
|
-
const partitions = await groupByPartitions(
|
|
79
|
-
allRows, partitionCallbackList, rctx, sourceRowDescriptor
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
for (const partitionRows of partitions.values()) {
|
|
83
|
-
yield* processPartition(
|
|
84
|
-
partitionRows, plan, functionSchemas, rctx,
|
|
85
|
-
sourceRowDescriptor, outputRowDescriptor,
|
|
86
|
-
partitionCallbackList, orderByCallbackList, funcArgCallbackList
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// Collect all callbacks
|
|
93
|
-
const allCallbacks = [
|
|
94
|
-
...partitionCallbacks,
|
|
95
|
-
...orderByCallbacks,
|
|
96
|
-
...functionArgCallbacks.filter(cb => cb !== null)
|
|
97
|
-
];
|
|
98
|
-
|
|
99
|
-
const sourceInstruction = emitPlanNode(plan.source, ctx);
|
|
100
|
-
|
|
101
|
-
return {
|
|
102
|
-
params: [sourceInstruction, ...allCallbacks],
|
|
103
|
-
run: run as InstructionRun,
|
|
104
|
-
note: `window(${plan.functions.map(f => f.functionName).join(', ')})`
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
async function groupByPartitions(
|
|
109
|
-
rows: Row[],
|
|
110
|
-
partitionCallbacks: Array<(ctx: RuntimeContext) => OutputValue>,
|
|
111
|
-
rctx: RuntimeContext,
|
|
112
|
-
sourceRowDescriptor: RowDescriptor
|
|
113
|
-
): Promise<Map<string, Row[]>> {
|
|
114
|
-
const partitions = new Map<string, Row[]>();
|
|
115
|
-
|
|
116
|
-
for (const row of rows) {
|
|
117
|
-
const partitionKey = await withAsyncRowContext(rctx, sourceRowDescriptor, () => row, async () => {
|
|
118
|
-
// Evaluate partition expressions
|
|
119
|
-
const partitionValues = await Promise.all(partitionCallbacks.map(callback =>
|
|
120
|
-
callback(rctx)
|
|
121
|
-
));
|
|
122
|
-
|
|
123
|
-
// Create partition key
|
|
124
|
-
return partitionValues.map(val =>
|
|
125
|
-
val === null ? 'NULL' : String(val)
|
|
126
|
-
).join('|');
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
if (!partitions.has(partitionKey)) {
|
|
130
|
-
partitions.set(partitionKey, []);
|
|
131
|
-
}
|
|
132
|
-
partitions.get(partitionKey)!.push(row);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return partitions;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
async function* processPartition(
|
|
139
|
-
partitionRows: Row[],
|
|
140
|
-
plan: WindowNode,
|
|
141
|
-
functionSchemas: any[],
|
|
142
|
-
rctx: RuntimeContext,
|
|
143
|
-
sourceRowDescriptor: RowDescriptor,
|
|
144
|
-
outputRowDescriptor: RowDescriptor,
|
|
145
|
-
partitionCallbacks: Array<(ctx: RuntimeContext) => OutputValue>,
|
|
146
|
-
orderByCallbacks: Array<(ctx: RuntimeContext) => OutputValue>,
|
|
147
|
-
funcArgCallbacks: Array<(ctx: RuntimeContext) => OutputValue | null>
|
|
148
|
-
): AsyncIterable<Row> {
|
|
149
|
-
// Sort rows according to ORDER BY specification
|
|
150
|
-
const sortedRows = await sortRows(
|
|
151
|
-
partitionRows, plan.windowSpec.orderBy, orderByCallbacks,
|
|
152
|
-
rctx, sourceRowDescriptor
|
|
153
|
-
);
|
|
154
|
-
|
|
155
|
-
// Process each row in the sorted partition
|
|
156
|
-
for (let currentIndex = 0; currentIndex < sortedRows.length; currentIndex++) {
|
|
157
|
-
const currentRow = sortedRows[currentIndex];
|
|
158
|
-
const outputRow = [...currentRow];
|
|
159
|
-
|
|
160
|
-
// Set up context for current row
|
|
161
|
-
const outputValues = await withRowContext(rctx, sourceRowDescriptor, () => currentRow, async () => {
|
|
162
|
-
const values: SqlValue[] = [];
|
|
163
|
-
// Compute each window function
|
|
164
|
-
for (let funcIndex = 0; funcIndex < plan.functions.length; funcIndex++) {
|
|
165
|
-
const func = plan.functions[funcIndex];
|
|
166
|
-
const schema = functionSchemas[funcIndex];
|
|
167
|
-
const argCallback = funcArgCallbacks[funcIndex];
|
|
168
|
-
|
|
169
|
-
let value: SqlValue;
|
|
170
|
-
|
|
171
|
-
if (schema.kind === 'ranking') {
|
|
172
|
-
value = await computeRankingFunction(
|
|
173
|
-
func.functionName, sortedRows, currentIndex,
|
|
174
|
-
orderByCallbacks, rctx, sourceRowDescriptor
|
|
175
|
-
);
|
|
176
|
-
} else if (schema.kind === 'aggregate') {
|
|
177
|
-
value = await computeAggregateFunction(
|
|
178
|
-
schema, argCallback, sortedRows, currentIndex,
|
|
179
|
-
plan.windowSpec.frame, plan.windowSpec.orderBy.length > 0,
|
|
180
|
-
rctx, sourceRowDescriptor
|
|
181
|
-
);
|
|
182
|
-
} else {
|
|
183
|
-
throw new QuereusError(
|
|
184
|
-
`Window function type ${schema.kind} not yet implemented`,
|
|
185
|
-
StatusCode.UNSUPPORTED
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
values.push(value);
|
|
190
|
-
}
|
|
191
|
-
return values;
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
// Add computed values to output row
|
|
195
|
-
outputRow.push(...outputValues);
|
|
196
|
-
|
|
197
|
-
// Yield the output row
|
|
198
|
-
yield await withRowContext(rctx, outputRowDescriptor, () => outputRow as Row, () => outputRow as Row);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
async function sortRows(
|
|
203
|
-
rows: Row[],
|
|
204
|
-
orderBy: any[],
|
|
205
|
-
orderByCallbacks: Array<(ctx: RuntimeContext) => OutputValue>,
|
|
206
|
-
rctx: RuntimeContext,
|
|
207
|
-
sourceRowDescriptor: RowDescriptor
|
|
208
|
-
): Promise<Row[]> {
|
|
209
|
-
if (orderBy.length === 0) {
|
|
210
|
-
return rows; // No sorting needed
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// Pre-create optimized comparators for all ORDER BY expressions with resolved collations
|
|
214
|
-
const orderByComparators = orderBy.map(orderClause => {
|
|
215
|
-
// TODO: Extract actual collation from order clause expression
|
|
216
|
-
// For now, use BINARY collation (most common case)
|
|
217
|
-
const collationFunc = resolveCollation('BINARY');
|
|
218
|
-
return createOrderByComparatorFast(
|
|
219
|
-
orderClause.direction,
|
|
220
|
-
orderClause.nulls,
|
|
221
|
-
collationFunc
|
|
222
|
-
);
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
// Pre-evaluate ORDER BY values for all rows to avoid async in sort
|
|
226
|
-
const rowsWithValues = await Promise.all(rows.map(async (row) => {
|
|
227
|
-
const values = await Promise.all(orderByCallbacks.map(async (callback) => {
|
|
228
|
-
return await withAsyncRowContext(rctx, sourceRowDescriptor, () => row, async () => {
|
|
229
|
-
const result = callback(rctx);
|
|
230
|
-
return await Promise.resolve(result);
|
|
231
|
-
});
|
|
232
|
-
}));
|
|
233
|
-
return { row, values };
|
|
234
|
-
}));
|
|
235
|
-
|
|
236
|
-
// Now sort using the pre-evaluated values
|
|
237
|
-
rowsWithValues.sort((a, b) => {
|
|
238
|
-
// Compare each ORDER BY expression in sequence
|
|
239
|
-
for (let i = 0; i < orderBy.length; i++) {
|
|
240
|
-
const comparator = orderByComparators[i];
|
|
241
|
-
const valueA = a.values[i] as SqlValue;
|
|
242
|
-
const valueB = b.values[i] as SqlValue;
|
|
243
|
-
|
|
244
|
-
// Use pre-created optimized comparator
|
|
245
|
-
const comparison = comparator(valueA, valueB);
|
|
246
|
-
|
|
247
|
-
// If not equal, return comparison result
|
|
248
|
-
if (comparison !== 0) {
|
|
249
|
-
return comparison;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
// Equal, continue to next ORDER BY expression
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
return 0; // All ORDER BY expressions are equal
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
// Extract just the rows in sorted order
|
|
259
|
-
return rowsWithValues.map(item => item.row);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
async function computeRankingFunction(
|
|
263
|
-
functionName: string,
|
|
264
|
-
sortedRows: Row[],
|
|
265
|
-
currentIndex: number,
|
|
266
|
-
orderByCallbacks: Array<(ctx: RuntimeContext) => any>,
|
|
267
|
-
rctx: RuntimeContext,
|
|
268
|
-
sourceRowDescriptor: RowDescriptor
|
|
269
|
-
): Promise<number> {
|
|
270
|
-
switch (functionName.toLowerCase()) {
|
|
271
|
-
case 'row_number':
|
|
272
|
-
return currentIndex + 1;
|
|
273
|
-
|
|
274
|
-
case 'rank': {
|
|
275
|
-
// Find rank by counting how many rows come before this one in sort order
|
|
276
|
-
let rank = 1;
|
|
277
|
-
const currentRow = sortedRows[currentIndex];
|
|
278
|
-
|
|
279
|
-
for (let i = 0; i < currentIndex; i++) {
|
|
280
|
-
const prevRow = sortedRows[i];
|
|
281
|
-
if (!(await areRowsEqualInOrderBy(
|
|
282
|
-
prevRow, currentRow, orderByCallbacks, rctx, sourceRowDescriptor
|
|
283
|
-
))) {
|
|
284
|
-
rank = i + 2; // Rank is 1-based and accounts for ties
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
return rank;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
case 'dense_rank': {
|
|
291
|
-
// Count distinct values that come before this one
|
|
292
|
-
let denseRank = 1;
|
|
293
|
-
const currentRow = sortedRows[currentIndex];
|
|
294
|
-
const seenValues = new Set<string>();
|
|
295
|
-
|
|
296
|
-
for (let i = 0; i < currentIndex; i++) {
|
|
297
|
-
const prevRow = sortedRows[i];
|
|
298
|
-
if (!(await areRowsEqualInOrderBy(
|
|
299
|
-
prevRow, currentRow, orderByCallbacks, rctx, sourceRowDescriptor
|
|
300
|
-
))) {
|
|
301
|
-
// Create a key for this distinct set of ORDER BY values
|
|
302
|
-
const key = await getOrderByKey(prevRow, orderByCallbacks, rctx, sourceRowDescriptor);
|
|
303
|
-
if (!seenValues.has(key)) {
|
|
304
|
-
seenValues.add(key);
|
|
305
|
-
denseRank++;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
return denseRank;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
default:
|
|
313
|
-
throw new QuereusError(
|
|
314
|
-
`Ranking function ${functionName} not implemented`,
|
|
315
|
-
StatusCode.UNSUPPORTED
|
|
316
|
-
);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
async function computeAggregateFunction(
|
|
321
|
-
schema: any,
|
|
322
|
-
argCallback: ((ctx: RuntimeContext) => any) | null,
|
|
323
|
-
sortedRows: Row[],
|
|
324
|
-
currentIndex: number,
|
|
325
|
-
frame: any,
|
|
326
|
-
hasOrderBy: boolean,
|
|
327
|
-
rctx: RuntimeContext,
|
|
328
|
-
sourceRowDescriptor: RowDescriptor
|
|
329
|
-
): Promise<SqlValue> {
|
|
330
|
-
// Determine frame bounds
|
|
331
|
-
const frameBounds = getFrameBounds(frame, sortedRows.length, currentIndex, hasOrderBy);
|
|
332
|
-
|
|
333
|
-
let accumulator: any = null;
|
|
334
|
-
let rowCount = 0;
|
|
335
|
-
|
|
336
|
-
// Process rows within the frame
|
|
337
|
-
for (let i = frameBounds.start; i <= frameBounds.end; i++) {
|
|
338
|
-
const frameRow = sortedRows[i];
|
|
339
|
-
|
|
340
|
-
await withAsyncRowContext(rctx, sourceRowDescriptor, () => frameRow, async () => {
|
|
341
|
-
let argValue: SqlValue = null;
|
|
342
|
-
|
|
343
|
-
// Get argument value if callback exists
|
|
344
|
-
if (argCallback) {
|
|
345
|
-
const result = argCallback(rctx);
|
|
346
|
-
argValue = await Promise.resolve(result);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
// Apply aggregate step function
|
|
350
|
-
if (schema.step) {
|
|
351
|
-
accumulator = schema.step(accumulator, argValue);
|
|
352
|
-
rowCount++;
|
|
353
|
-
}
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
// Apply final function
|
|
358
|
-
return schema.final ? schema.final(accumulator, rowCount) : accumulator;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
function getFrameBounds(
|
|
362
|
-
frame: any,
|
|
363
|
-
totalRows: number,
|
|
364
|
-
currentIndex: number,
|
|
365
|
-
hasOrderBy: boolean = true
|
|
366
|
-
): { start: number; end: number } {
|
|
367
|
-
if (!frame) {
|
|
368
|
-
if (!hasOrderBy) {
|
|
369
|
-
// No ORDER BY: default frame is entire partition (all rows)
|
|
370
|
-
return { start: 0, end: totalRows - 1 };
|
|
371
|
-
} else {
|
|
372
|
-
// With ORDER BY: default frame is RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
|
|
373
|
-
return { start: 0, end: currentIndex };
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
let start: number;
|
|
378
|
-
let end: number;
|
|
379
|
-
|
|
380
|
-
// Calculate start bound
|
|
381
|
-
if (frame.start.type === 'unboundedPreceding') {
|
|
382
|
-
start = 0;
|
|
383
|
-
} else if (frame.start.type === 'currentRow') {
|
|
384
|
-
start = currentIndex;
|
|
385
|
-
} else if (frame.start.type === 'preceding') {
|
|
386
|
-
// TODO: Evaluate frame.start.value expression
|
|
387
|
-
const offset = 1; // For now, hard-coded for the test
|
|
388
|
-
start = Math.max(0, currentIndex - offset);
|
|
389
|
-
} else if (frame.start.type === 'following') {
|
|
390
|
-
const offset = 1; // TODO: Evaluate frame.start.value expression
|
|
391
|
-
start = Math.min(totalRows - 1, currentIndex + offset);
|
|
392
|
-
} else {
|
|
393
|
-
start = 0;
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
// Calculate end bound
|
|
397
|
-
if (frame.end === null) {
|
|
398
|
-
// Single bound frame - end is current row
|
|
399
|
-
end = currentIndex;
|
|
400
|
-
} else if (frame.end.type === 'unboundedFollowing') {
|
|
401
|
-
end = totalRows - 1;
|
|
402
|
-
} else if (frame.end.type === 'currentRow') {
|
|
403
|
-
end = currentIndex;
|
|
404
|
-
} else if (frame.end.type === 'preceding') {
|
|
405
|
-
const offset = 1; // TODO: Evaluate frame.end.value expression
|
|
406
|
-
end = Math.max(0, currentIndex - offset);
|
|
407
|
-
} else if (frame.end.type === 'following') {
|
|
408
|
-
const offset = 1; // TODO: Evaluate frame.end.value expression
|
|
409
|
-
end = Math.min(totalRows - 1, currentIndex + offset);
|
|
410
|
-
} else {
|
|
411
|
-
end = currentIndex;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
return { start, end };
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
async function areRowsEqualInOrderBy(
|
|
418
|
-
rowA: Row,
|
|
419
|
-
rowB: Row,
|
|
420
|
-
orderByCallbacks: Array<(ctx: RuntimeContext) => any>,
|
|
421
|
-
rctx: RuntimeContext,
|
|
422
|
-
sourceRowDescriptor: RowDescriptor
|
|
423
|
-
): Promise<boolean> {
|
|
424
|
-
for (const callback of orderByCallbacks) {
|
|
425
|
-
// Get value for row A
|
|
426
|
-
const valueA = await withAsyncRowContext(rctx, sourceRowDescriptor, () => rowA, async () => {
|
|
427
|
-
const result = callback(rctx);
|
|
428
|
-
return await Promise.resolve(result);
|
|
429
|
-
});
|
|
430
|
-
|
|
431
|
-
// Get value for row B
|
|
432
|
-
const valueB = await withAsyncRowContext(rctx, sourceRowDescriptor, () => rowB, async () => {
|
|
433
|
-
const result = callback(rctx);
|
|
434
|
-
return await Promise.resolve(result);
|
|
435
|
-
});
|
|
436
|
-
|
|
437
|
-
// If any ORDER BY expression differs, rows are not equal
|
|
438
|
-
if (compareSqlValues(valueA, valueB) !== 0) {
|
|
439
|
-
return false;
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
return true; // All ORDER BY expressions are equal
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
async function getOrderByKey(
|
|
447
|
-
row: Row,
|
|
448
|
-
orderByCallbacks: Array<(ctx: RuntimeContext) => any>,
|
|
449
|
-
rctx: RuntimeContext,
|
|
450
|
-
sourceRowDescriptor: RowDescriptor
|
|
451
|
-
): Promise<string> {
|
|
452
|
-
return await withAsyncRowContext(rctx, sourceRowDescriptor, () => row, async () => {
|
|
453
|
-
const values = await Promise.all(orderByCallbacks.map(callback =>
|
|
454
|
-
Promise.resolve(callback(rctx))
|
|
455
|
-
));
|
|
456
|
-
return values.map(val => val === null ? 'NULL' : String(val)).join('|');
|
|
457
|
-
});
|
|
458
|
-
}
|
package/src/runtime/emitters.ts
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import { QuereusError } from "../common/errors.js";
|
|
3
|
-
import type { PlanNode } from "../planner/nodes/plan-node.js";
|
|
4
|
-
import type { PlanNodeType } from "../planner/nodes/plan-node-type.js";
|
|
5
|
-
import type { Instruction, InstructionRun, RuntimeContext } from "./types.js";
|
|
6
|
-
import { StatusCode, type OutputValue } from '../common/types.js';
|
|
7
|
-
import { createLogger } from '../common/logger.js';
|
|
8
|
-
import { Scheduler } from "./scheduler.js";
|
|
9
|
-
import type { EmissionContext } from "./emission-context.js";
|
|
10
|
-
import { isAsyncIterable } from "./utils.js";
|
|
11
|
-
|
|
12
|
-
const log = createLogger('emitters');
|
|
13
|
-
|
|
14
|
-
export type EmitterFunc = (plan: PlanNode, ctx: EmissionContext) => Instruction;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Metadata about an emitter's execution characteristics
|
|
18
|
-
* Used by optimizer to make decisions about physical properties
|
|
19
|
-
*/
|
|
20
|
-
export interface EmitterMeta {
|
|
21
|
-
/** Whether this emitter preserves input ordering */
|
|
22
|
-
preservesOrdering?: boolean;
|
|
23
|
-
|
|
24
|
-
/** Column indexes that must be ordered for this emitter to work efficiently */
|
|
25
|
-
requiresOrdering?: number[];
|
|
26
|
-
|
|
27
|
-
/** Whether this emitter can handle streaming input efficiently */
|
|
28
|
-
supportsStreaming?: boolean;
|
|
29
|
-
|
|
30
|
-
/** Whether this emitter produces deterministic output */
|
|
31
|
-
isDeterministic?: boolean;
|
|
32
|
-
|
|
33
|
-
/** Estimated CPU cost factor relative to other operations */
|
|
34
|
-
cpuCostFactor?: number;
|
|
35
|
-
|
|
36
|
-
/** Estimated memory usage factor */
|
|
37
|
-
memoryCostFactor?: number;
|
|
38
|
-
|
|
39
|
-
/** Free-text description for debugging */
|
|
40
|
-
note?: string;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Emitter registration with metadata
|
|
45
|
-
*/
|
|
46
|
-
interface EmitterRegistration {
|
|
47
|
-
emitter: EmitterFunc;
|
|
48
|
-
meta: EmitterMeta;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const emitters: Map<PlanNodeType, EmitterRegistration> = new Map();
|
|
52
|
-
|
|
53
|
-
export function registerEmitter(nodeType: PlanNodeType, emitter: EmitterFunc, meta: EmitterMeta = {}): void {
|
|
54
|
-
emitters.set(nodeType, { emitter, meta });
|
|
55
|
-
log(`Registered emitter for ${nodeType} with meta: %O`, meta);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Get emitter metadata for a node type
|
|
60
|
-
*/
|
|
61
|
-
export function getEmitterMeta(nodeType: PlanNodeType): EmitterMeta | undefined {
|
|
62
|
-
const registration = emitters.get(nodeType);
|
|
63
|
-
return registration?.meta;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Wraps an instruction's run function with plan node stack tracking for debugging.
|
|
68
|
-
* Only adds overhead when tracing is enabled.
|
|
69
|
-
*/
|
|
70
|
-
function instrumentRunForTracing(plan: PlanNode, originalRun: InstructionRun): InstructionRun {
|
|
71
|
-
return function (ctx: RuntimeContext, ...args: any[]) {
|
|
72
|
-
const stack = (ctx.planStack = ctx.planStack || []);
|
|
73
|
-
stack.push(plan);
|
|
74
|
-
|
|
75
|
-
let result: any;
|
|
76
|
-
try {
|
|
77
|
-
result = originalRun(ctx, ...args);
|
|
78
|
-
} catch (err) {
|
|
79
|
-
// Synchronous error – pop immediately and re-throw
|
|
80
|
-
stack.pop();
|
|
81
|
-
throw err;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// If the result is an async iterable, defer the pop until iteration completes
|
|
85
|
-
if (isAsyncIterable(result)) {
|
|
86
|
-
const iterable = result as AsyncIterable<unknown>;
|
|
87
|
-
// Wrap iterable to pop stack in a finally block once iteration ends
|
|
88
|
-
return (async function* () {
|
|
89
|
-
try {
|
|
90
|
-
for await (const item of iterable) {
|
|
91
|
-
yield item;
|
|
92
|
-
}
|
|
93
|
-
} finally {
|
|
94
|
-
stack.pop();
|
|
95
|
-
}
|
|
96
|
-
})();
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// If the result is a promise, pop once it settles
|
|
100
|
-
if (result && typeof (result as Promise<unknown>).then === 'function') {
|
|
101
|
-
return (result as Promise<unknown>).finally(() => {
|
|
102
|
-
stack.pop();
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Synchronous return value – pop immediately
|
|
107
|
-
stack.pop();
|
|
108
|
-
return result;
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export function emitPlanNode(plan: PlanNode, ctx: EmissionContext): Instruction {
|
|
113
|
-
const registration = emitters.get(plan.nodeType);
|
|
114
|
-
if (!registration) {
|
|
115
|
-
throw new QuereusError(`No emitter registered for ${plan.nodeType}`, StatusCode.ERROR);
|
|
116
|
-
}
|
|
117
|
-
const instruction = registration.emitter(plan, ctx);
|
|
118
|
-
// Wrap with instrumentation for tracing
|
|
119
|
-
if (ctx.tracePlanStack) {
|
|
120
|
-
instruction.run = instrumentRunForTracing(plan, instruction.run);
|
|
121
|
-
}
|
|
122
|
-
return instruction;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Compiles any plan node into a callable instruction that can be used as a function.
|
|
127
|
-
* This enables the scheduler to create separate programs for functions and pass them
|
|
128
|
-
* as callbacks to other instructions.
|
|
129
|
-
*/
|
|
130
|
-
export function emitCall(root: Instruction): Instruction {
|
|
131
|
-
const program = new Scheduler(root);
|
|
132
|
-
|
|
133
|
-
function run(_ctx: RuntimeContext): OutputValue {
|
|
134
|
-
return (innerCtx: RuntimeContext) => program.run(innerCtx);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return {
|
|
138
|
-
params: [],
|
|
139
|
-
run,
|
|
140
|
-
note: `callback(${root.note})`,
|
|
141
|
-
programs: [program]
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Helper function to emit a plan node and wrap it as a callable instruction.
|
|
147
|
-
* This is useful for emitters that need to create sub-instructions.
|
|
148
|
-
*/
|
|
149
|
-
export function emitCallFromPlan(plan: PlanNode, emissionCtx: EmissionContext): Instruction {
|
|
150
|
-
const instruction = emitPlanNode(plan, emissionCtx);
|
|
151
|
-
return emitCall(instruction);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Creates an instruction that validates its schema dependencies before execution.
|
|
156
|
-
* This should be used for instructions that captured schema objects during emission.
|
|
157
|
-
*/
|
|
158
|
-
export function createValidatedInstruction(
|
|
159
|
-
params: Instruction[],
|
|
160
|
-
run: InstructionRun,
|
|
161
|
-
emissionCtx: EmissionContext,
|
|
162
|
-
note?: string
|
|
163
|
-
): Instruction {
|
|
164
|
-
// Only add validation if we actually captured schema objects
|
|
165
|
-
if (emissionCtx.getCapturedObjectCount() === 0) {
|
|
166
|
-
return { params, run, note };
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// Wrap the run function to validate schema before execution
|
|
170
|
-
const validatedRun: InstructionRun = (ctx: RuntimeContext, ...args: any[]) => {
|
|
171
|
-
// Validate schema objects are still available
|
|
172
|
-
emissionCtx.validateCapturedSchemaObjects();
|
|
173
|
-
// If validation passes, run the original instruction
|
|
174
|
-
return run(ctx, ...args);
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
return {
|
|
178
|
-
params,
|
|
179
|
-
run: validatedRun,
|
|
180
|
-
note: note ? `validated(${note})` : 'validated',
|
|
181
|
-
emissionContext: emissionCtx
|
|
182
|
-
};
|
|
183
|
-
}
|