From fe56ca36983cf4a044aefbeac4ffe6a3c9aec75d Mon Sep 17 00:00:00 2001 From: fotiniAlvanaki <78495594+fotiniAlvanaki@users.noreply.github.com> Date: Thu, 16 Oct 2025 12:56:33 +0100 Subject: [PATCH] SERVER-111398 : Mark query_execution_sbe owned headers in src/mongo/db/query/stage_builder/sbe for modularity (#42615) GitOrigin-RevId: da23e5b21c98c3b8a2e57cfdf91c46b783dab979 --- .../db/query/stage_builder/sbe/abt_lower.h | 1 + .../query/stage_builder/sbe/abt_lower_defs.h | 1 + .../db/query/stage_builder/sbe/analysis.h | 2 +- .../db/query/stage_builder/sbe/builder.h | 10 +- .../db/query/stage_builder/sbe/builder_data.h | 3 +- .../query/stage_builder/sbe/builder_state.h | 3 +- .../stage_builder/sbe/expression_const_eval.h | 1 + .../stage_builder/sbe/gen_abt_helpers.cpp | 12 +- .../query/stage_builder/sbe/gen_abt_helpers.h | 4 +- .../query/stage_builder/sbe/gen_accumulator.h | 1 + .../query/stage_builder/sbe/gen_coll_scan.cpp | 4 - .../query/stage_builder/sbe/gen_coll_scan.h | 1 + .../stage_builder/sbe/gen_expression.cpp | 5 - .../query/stage_builder/sbe/gen_expression.h | 1 + .../sbe/gen_extract_field_paths.h | 1 + .../db/query/stage_builder/sbe/gen_filter.h | 1 + .../query/stage_builder/sbe/gen_helpers.cpp | 4 - .../db/query/stage_builder/sbe/gen_helpers.h | 2 +- .../query/stage_builder/sbe/gen_index_scan.h | 1 + .../query/stage_builder/sbe/gen_projection.h | 1 + .../stage_builder/sbe/gen_window_function.h | 223 +++++++++--------- src/mongo/db/query/stage_builder/sbe/sbexpr.h | 3 +- .../query/stage_builder/sbe/sbexpr_helpers.h | 1 + .../db/query/stage_builder/sbe/type_checker.h | 1 + .../query/stage_builder/sbe/type_signature.h | 1 + .../query/stage_builder/sbe/value_lifetime.h | 1 + .../db/query/stage_builder/sbe/vectorizer.h | 1 + 27 files changed, 135 insertions(+), 155 deletions(-) diff --git a/src/mongo/db/query/stage_builder/sbe/abt_lower.h b/src/mongo/db/query/stage_builder/sbe/abt_lower.h index 482b40f08d0..45ff7542b92 100644 --- a/src/mongo/db/query/stage_builder/sbe/abt_lower.h +++ b/src/mongo/db/query/stage_builder/sbe/abt_lower.h @@ -33,6 +33,7 @@ #include "mongo/db/exec/sbe/expressions/runtime_environment.h" #include "mongo/db/query/stage_builder/sbe/abt/reference_tracker.h" #include "mongo/db/query/stage_builder/sbe/abt_lower_defs.h" +#include "mongo/util/modules.h" namespace mongo::stage_builder::abt_lower { diff --git a/src/mongo/db/query/stage_builder/sbe/abt_lower_defs.h b/src/mongo/db/query/stage_builder/sbe/abt_lower_defs.h index e2873b72b87..816fcc0fdd5 100644 --- a/src/mongo/db/query/stage_builder/sbe/abt_lower_defs.h +++ b/src/mongo/db/query/stage_builder/sbe/abt_lower_defs.h @@ -31,6 +31,7 @@ #include "mongo/db/exec/sbe/values/slot.h" #include "mongo/db/query/stage_builder/sbe/abt/syntax/syntax.h" +#include "mongo/util/modules.h" namespace mongo::stage_builder::abt_lower { diff --git a/src/mongo/db/query/stage_builder/sbe/analysis.h b/src/mongo/db/query/stage_builder/sbe/analysis.h index f917c131ebe..198d2520ae9 100644 --- a/src/mongo/db/query/stage_builder/sbe/analysis.h +++ b/src/mongo/db/query/stage_builder/sbe/analysis.h @@ -31,11 +31,11 @@ #include "mongo/db/query/stage_builder/sbe/gen_helpers.h" #include "mongo/util/field_set.h" +#include "mongo/util/modules.h" #include "mongo/util/string_map.h" #include #include -#include #include #include #include diff --git a/src/mongo/db/query/stage_builder/sbe/builder.h b/src/mongo/db/query/stage_builder/sbe/builder.h index 5f15ebd52cb..53bc212e605 100644 --- a/src/mongo/db/query/stage_builder/sbe/builder.h +++ b/src/mongo/db/query/stage_builder/sbe/builder.h @@ -30,11 +30,6 @@ #pragma once #include "mongo/base/string_data.h" -#include "mongo/bson/ordering.h" -#include "mongo/db/exec/plan_stats.h" -#include "mongo/db/exec/sbe/expressions/expression.h" -#include "mongo/db/exec/sbe/stages/collection_helpers.h" -#include "mongo/db/exec/sbe/stages/plan_stats.h" #include "mongo/db/exec/sbe/stages/stages.h" #include "mongo/db/exec/sbe/values/value.h" #include "mongo/db/exec/trial_period_utils.h" @@ -45,14 +40,12 @@ #include "mongo/db/query/compiler/physical_model/query_solution/query_solution.h" #include "mongo/db/query/multiple_collection_accessor.h" #include "mongo/db/query/plan_yield_policy_sbe.h" -#include "mongo/db/query/shard_filterer_factory_interface.h" #include "mongo/db/query/stage_builder/sbe/analysis.h" #include "mongo/db/query/stage_builder/sbe/builder_data.h" #include "mongo/db/query/stage_builder/sbe/gen_helpers.h" -#include "mongo/db/query/stage_builder/sbe/type_signature.h" #include "mongo/db/query/stage_builder/stage_builder.h" -#include "mongo/db/storage/key_string/key_string.h" #include "mongo/util/assert_util.h" +#include "mongo/util/modules.h" #include "mongo/util/str.h" #include @@ -63,7 +56,6 @@ #include #include #include -#include #include #include diff --git a/src/mongo/db/query/stage_builder/sbe/builder_data.h b/src/mongo/db/query/stage_builder/sbe/builder_data.h index 6d1bca81955..eb4568a60b3 100644 --- a/src/mongo/db/query/stage_builder/sbe/builder_data.h +++ b/src/mongo/db/query/stage_builder/sbe/builder_data.h @@ -34,14 +34,13 @@ #include "mongo/db/exec/sbe/expressions/runtime_environment.h" #include "mongo/db/exec/sbe/in_list.h" #include "mongo/db/exec/sbe/values/slot.h" -#include "mongo/db/matcher/expression.h" #include "mongo/db/namespace_string.h" #include "mongo/db/query/collation/collator_interface.h" #include "mongo/db/query/compiler/metadata/index_entry.h" #include "mongo/db/query/compiler/optimizer/index_bounds_builder/interval_evaluation_tree.h" #include "mongo/db/query/plan_cache/plan_cache_debug_info.h" #include "mongo/stdx/unordered_map.h" -#include "mongo/util/string_listset.h" +#include "mongo/util/modules.h" namespace mongo::stage_builder { diff --git a/src/mongo/db/query/stage_builder/sbe/builder_state.h b/src/mongo/db/query/stage_builder/sbe/builder_state.h index 2cfbafb0991..b71bb2b6755 100644 --- a/src/mongo/db/query/stage_builder/sbe/builder_state.h +++ b/src/mongo/db/query/stage_builder/sbe/builder_state.h @@ -31,8 +31,7 @@ #include "mongo/db/exec/sbe/values/slot.h" #include "mongo/db/query/plan_yield_policy_sbe.h" - -#include +#include "mongo/util/modules.h" #include #include diff --git a/src/mongo/db/query/stage_builder/sbe/expression_const_eval.h b/src/mongo/db/query/stage_builder/sbe/expression_const_eval.h index f2b8dac489e..92212ee4b8d 100644 --- a/src/mongo/db/query/stage_builder/sbe/expression_const_eval.h +++ b/src/mongo/db/query/stage_builder/sbe/expression_const_eval.h @@ -35,6 +35,7 @@ #include "mongo/db/query/stage_builder/sbe/abt/reference_tracker.h" #include "mongo/db/query/stage_builder/sbe/abt/syntax/expr.h" #include "mongo/db/query/stage_builder/sbe/abt/syntax/syntax.h" +#include "mongo/util/modules.h" #include #include diff --git a/src/mongo/db/query/stage_builder/sbe/gen_abt_helpers.cpp b/src/mongo/db/query/stage_builder/sbe/gen_abt_helpers.cpp index 76d9ae5fe4a..0742e02898f 100644 --- a/src/mongo/db/query/stage_builder/sbe/gen_abt_helpers.cpp +++ b/src/mongo/db/query/stage_builder/sbe/gen_abt_helpers.cpp @@ -29,19 +29,9 @@ #include "mongo/db/query/stage_builder/sbe/gen_abt_helpers.h" -#include "mongo/bson/bsontypes.h" -#include "mongo/db/query/algebra/polyvalue.h" -#include "mongo/db/query/bson_typemask.h" -#include "mongo/db/query/stage_builder/sbe/abt_defs.h" -#include "mongo/util/assert_util.h" +#include "mongo/db/query/query_feature_flags_gen.h" -#include #include -#include -#include -#include -#include - namespace mongo::stage_builder { abt::ABT makeVariable(abt::ProjectionName var) { diff --git a/src/mongo/db/query/stage_builder/sbe/gen_abt_helpers.h b/src/mongo/db/query/stage_builder/sbe/gen_abt_helpers.h index e0a99b428a4..8fc49e3afa5 100644 --- a/src/mongo/db/query/stage_builder/sbe/gen_abt_helpers.h +++ b/src/mongo/db/query/stage_builder/sbe/gen_abt_helpers.h @@ -29,14 +29,12 @@ #pragma once -#include "mongo/base/error_codes.h" #include "mongo/base/string_data.h" -#include "mongo/db/exec/sbe/values/slot.h" #include "mongo/db/exec/sbe/values/value.h" #include "mongo/db/query/stage_builder/sbe/abt/comparison_op.h" #include "mongo/db/query/stage_builder/sbe/abt/syntax/expr.h" #include "mongo/db/query/stage_builder/sbe/abt/syntax/syntax.h" -#include "mongo/db/query/stage_builder/sbe/sbexpr.h" +#include "mongo/util/modules.h" #include #include diff --git a/src/mongo/db/query/stage_builder/sbe/gen_accumulator.h b/src/mongo/db/query/stage_builder/sbe/gen_accumulator.h index 281f71f4767..1c1c4d04738 100644 --- a/src/mongo/db/query/stage_builder/sbe/gen_accumulator.h +++ b/src/mongo/db/query/stage_builder/sbe/gen_accumulator.h @@ -33,6 +33,7 @@ #include "mongo/db/pipeline/accumulation_statement.h" #include "mongo/db/query/stage_builder/sbe/gen_helpers.h" #include "mongo/db/query/stage_builder/sbe/sbexpr.h" +#include "mongo/util/modules.h" #include #include diff --git a/src/mongo/db/query/stage_builder/sbe/gen_coll_scan.cpp b/src/mongo/db/query/stage_builder/sbe/gen_coll_scan.cpp index 2fd09d2f483..b0e0411ba7d 100644 --- a/src/mongo/db/query/stage_builder/sbe/gen_coll_scan.cpp +++ b/src/mongo/db/query/stage_builder/sbe/gen_coll_scan.cpp @@ -30,8 +30,6 @@ #include "mongo/db/query/stage_builder/sbe/gen_coll_scan.h" -#include "mongo/base/error_codes.h" -#include "mongo/base/string_data.h" #include "mongo/db/exec/collection_scan_common.h" #include "mongo/db/exec/sbe/expressions/runtime_environment.h" #include "mongo/db/exec/sbe/stages/scan.h" @@ -44,11 +42,9 @@ #include "mongo/db/query/stage_builder/sbe/builder.h" #include "mongo/db/query/stage_builder/sbe/gen_filter.h" #include "mongo/db/query/stage_builder/sbe/sbexpr_helpers.h" -#include "mongo/db/repl/optime.h" #include "mongo/db/storage/record_store.h" #include "mongo/db/storage/recovery_unit.h" #include "mongo/util/assert_util.h" -#include "mongo/util/str.h" #include #include diff --git a/src/mongo/db/query/stage_builder/sbe/gen_coll_scan.h b/src/mongo/db/query/stage_builder/sbe/gen_coll_scan.h index 7fde1c0a2bd..284c69b3cd9 100644 --- a/src/mongo/db/query/stage_builder/sbe/gen_coll_scan.h +++ b/src/mongo/db/query/stage_builder/sbe/gen_coll_scan.h @@ -32,6 +32,7 @@ #include "mongo/db/local_catalog/collection.h" #include "mongo/db/query/compiler/physical_model/query_solution/query_solution.h" #include "mongo/db/query/stage_builder/sbe/gen_helpers.h" +#include "mongo/util/modules.h" #include #include diff --git a/src/mongo/db/query/stage_builder/sbe/gen_expression.cpp b/src/mongo/db/query/stage_builder/sbe/gen_expression.cpp index f0b090b4b38..d413fb951fe 100644 --- a/src/mongo/db/query/stage_builder/sbe/gen_expression.cpp +++ b/src/mongo/db/query/stage_builder/sbe/gen_expression.cpp @@ -50,14 +50,10 @@ #include "mongo/db/pipeline/expression_walker.h" #include "mongo/db/pipeline/field_path.h" #include "mongo/db/pipeline/variables.h" -#include "mongo/db/query/algebra/polyvalue.h" #include "mongo/db/query/bson_typemask.h" #include "mongo/db/query/datetime/date_time_support.h" #include "mongo/db/query/expression_walker.h" #include "mongo/db/query/stage_builder/sbe/abt/comparison_op.h" -#include "mongo/db/query/stage_builder/sbe/abt/syntax/expr.h" -#include "mongo/db/query/stage_builder/sbe/abt/syntax/syntax.h" -#include "mongo/db/query/stage_builder/sbe/abt_defs.h" #include "mongo/db/query/stage_builder/sbe/builder.h" #include "mongo/db/query/stage_builder/sbe/gen_helpers.h" #include "mongo/db/query/stage_builder/sbe/sbexpr_helpers.h" @@ -70,7 +66,6 @@ #include #include #include -#include #include #include #include diff --git a/src/mongo/db/query/stage_builder/sbe/gen_expression.h b/src/mongo/db/query/stage_builder/sbe/gen_expression.h index 9cc3e6518ca..02183c6b493 100644 --- a/src/mongo/db/query/stage_builder/sbe/gen_expression.h +++ b/src/mongo/db/query/stage_builder/sbe/gen_expression.h @@ -32,6 +32,7 @@ #include "mongo/db/exec/sbe/values/value.h" #include "mongo/db/pipeline/expression.h" #include "mongo/db/query/stage_builder/sbe/sbexpr.h" +#include "mongo/util/modules.h" #include diff --git a/src/mongo/db/query/stage_builder/sbe/gen_extract_field_paths.h b/src/mongo/db/query/stage_builder/sbe/gen_extract_field_paths.h index 4083c147b3a..53072908dca 100644 --- a/src/mongo/db/query/stage_builder/sbe/gen_extract_field_paths.h +++ b/src/mongo/db/query/stage_builder/sbe/gen_extract_field_paths.h @@ -29,6 +29,7 @@ #include "mongo/db/query/stage_builder/sbe/builder.h" #include "mongo/db/query/stage_builder/sbe/gen_helpers.h" +#include "mongo/util/modules.h" namespace mongo::stage_builder { diff --git a/src/mongo/db/query/stage_builder/sbe/gen_filter.h b/src/mongo/db/query/stage_builder/sbe/gen_filter.h index b08f4413d26..97a88dbbefd 100644 --- a/src/mongo/db/query/stage_builder/sbe/gen_filter.h +++ b/src/mongo/db/query/stage_builder/sbe/gen_filter.h @@ -35,6 +35,7 @@ #include "mongo/db/matcher/expression_leaf.h" #include "mongo/db/matcher/expression_visitor.h" #include "mongo/db/query/stage_builder/sbe/gen_helpers.h" +#include "mongo/util/modules.h" #include diff --git a/src/mongo/db/query/stage_builder/sbe/gen_helpers.cpp b/src/mongo/db/query/stage_builder/sbe/gen_helpers.cpp index 8fcca214607..44a34b32acb 100644 --- a/src/mongo/db/query/stage_builder/sbe/gen_helpers.cpp +++ b/src/mongo/db/query/stage_builder/sbe/gen_helpers.cpp @@ -35,9 +35,7 @@ #include #include // IWYU pragma: no_include "ext/alloc_traits.h" -#include "mongo/bson/bsonobjbuilder.h" #include "mongo/bson/bsontypes.h" -#include "mongo/db/exec/sbe/expressions/expression.h" #include "mongo/db/index/index_access_method.h" #include "mongo/db/index/multikey_paths.h" #include "mongo/db/index/preallocated_container_pool.h" @@ -65,9 +63,7 @@ #include "mongo/logv2/log.h" #include "mongo/util/decorable.h" #include "mongo/util/shared_buffer_fragment.h" -#include "mongo/util/stacktrace.h" #include "mongo/util/str.h" -#include "mongo/util/time_support.h" #include diff --git a/src/mongo/db/query/stage_builder/sbe/gen_helpers.h b/src/mongo/db/query/stage_builder/sbe/gen_helpers.h index 2306bd60839..8442b19335d 100644 --- a/src/mongo/db/query/stage_builder/sbe/gen_helpers.h +++ b/src/mongo/db/query/stage_builder/sbe/gen_helpers.h @@ -45,13 +45,13 @@ #include "mongo/db/query/compiler/logical_model/projection/projection_ast.h" #include "mongo/db/query/compiler/logical_model/sort_pattern/sort_pattern.h" #include "mongo/db/query/compiler/physical_model/query_solution/stage_types.h" -#include "mongo/db/query/stage_builder/sbe/abt/comparison_op.h" #include "mongo/db/query/stage_builder/sbe/builder_state.h" #include "mongo/db/query/stage_builder/sbe/sbexpr.h" #include "mongo/db/repl/oplog.h" #include "mongo/db/storage/index_entry_comparison.h" #include "mongo/db/storage/key_string/key_string.h" #include "mongo/util/assert_util.h" +#include "mongo/util/modules.h" #include "mongo/util/string_map.h" #include diff --git a/src/mongo/db/query/stage_builder/sbe/gen_index_scan.h b/src/mongo/db/query/stage_builder/sbe/gen_index_scan.h index a9872212dfc..813df308cc2 100644 --- a/src/mongo/db/query/stage_builder/sbe/gen_index_scan.h +++ b/src/mongo/db/query/stage_builder/sbe/gen_index_scan.h @@ -39,6 +39,7 @@ #include "mongo/db/query/compiler/physical_model/query_solution/stage_types.h" #include "mongo/db/query/stage_builder/sbe/gen_helpers.h" #include "mongo/db/storage/key_string/key_string.h" +#include "mongo/util/modules.h" #include #include diff --git a/src/mongo/db/query/stage_builder/sbe/gen_projection.h b/src/mongo/db/query/stage_builder/sbe/gen_projection.h index acb88251833..76fa3b000c1 100644 --- a/src/mongo/db/query/stage_builder/sbe/gen_projection.h +++ b/src/mongo/db/query/stage_builder/sbe/gen_projection.h @@ -33,6 +33,7 @@ #include "mongo/db/exec/sbe/values/value.h" #include "mongo/db/query/compiler/logical_model/projection/projection.h" #include "mongo/db/query/stage_builder/sbe/analysis.h" +#include "mongo/util/modules.h" namespace mongo::stage_builder { class PlanStageSlots; diff --git a/src/mongo/db/query/stage_builder/sbe/gen_window_function.h b/src/mongo/db/query/stage_builder/sbe/gen_window_function.h index f0bc7159e32..0103888647d 100644 --- a/src/mongo/db/query/stage_builder/sbe/gen_window_function.h +++ b/src/mongo/db/query/stage_builder/sbe/gen_window_function.h @@ -1,111 +1,112 @@ -/** - * Copyright (C) 2023-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#pragma once - -#include "mongo/db/pipeline/window_function/window_function_statement.h" -#include "mongo/db/query/stage_builder/sbe/gen_accumulator.h" -#include "mongo/db/query/stage_builder/sbe/gen_helpers.h" - -namespace mongo::stage_builder { -struct WindowOpInfo; - -class WindowOp { -public: - WindowOp(std::string opName); - - WindowOp(StringData opName) : WindowOp(std::string{opName}) {} - - WindowOp(const WindowFunctionStatement& wf); - - StringData getOpName() const { - return _opName; - } - - /** - * This method returns the number of agg expressions that need to be generated for this - * WindowOp. - */ - size_t getNumAggs() const; - - /** - * Given one or more input expressions ('input' / 'inputs'), these methods generate the - * arg expressions needed for this WindowOp. - */ - AccumInputsPtr buildAddRemoveExprs(StageBuilderState& state, AccumInputsPtr inputs) const; - - /** - * Given a vector of named arg expressions ('args' / 'argNames'), this method generates the - * accumulate expressions for this WindowOp. - */ - SbExpr::Vector buildAddAggs(StageBuilderState& state, AccumInputsPtr inputs) const; - - /** - * Given a vector of named arg expressions ('args' / 'argNames'), this method generates the - * accumulate expressions for this WindowOp. - */ - SbExpr::Vector buildRemoveAggs(StageBuilderState& state, AccumInputsPtr inputs) const; - - /** - * Given a map of input expressions ('argExprs'), these methods generate the initialize - * expressions for this WindowOp. - */ - SbExpr::Vector buildInitialize(StageBuilderState& state, AccumInputsPtr inputs) const; - - /** - * Given a map of input expressions ('argExprs'), this method generates the finalize - * expression for this WindowOp. - */ - SbExpr buildFinalize(StageBuilderState& state, - AccumInputsPtr inputs, - const SbSlotVector& aggSlots) const; - -private: - // Static helper method for looking up the info for this WindowOp in the global map. - // This method should only be used by WindowOp's constructors. - static const WindowOpInfo* lookupOpInfo(const std::string& opName); - - // Non-static checked helper method for retrieving the value of '_opInfo'. This method will - // raise a tassert if '_opInfo' is null. - const WindowOpInfo* getOpInfo() const { - uassert(8859901, - str::stream() << "Unrecognized WindowOp name: " << _opName, - _opInfo != nullptr); - - return _opInfo; - } - - // Name of the specific accumulation op. This name is used to retrieve info about the op - // from the global map. - std::string _opName; - - // Info about the specific accumulation op named by '_opName'. - const WindowOpInfo* _opInfo = nullptr; -}; -} // namespace mongo::stage_builder +/** + * Copyright (C) 2023-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * . + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the Server Side Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#pragma once + +#include "mongo/db/pipeline/window_function/window_function_statement.h" +#include "mongo/db/query/stage_builder/sbe/gen_accumulator.h" +#include "mongo/db/query/stage_builder/sbe/gen_helpers.h" +#include "mongo/util/modules.h" + +namespace mongo::stage_builder { +struct WindowOpInfo; + +class WindowOp { +public: + WindowOp(std::string opName); + + WindowOp(StringData opName) : WindowOp(std::string{opName}) {} + + WindowOp(const WindowFunctionStatement& wf); + + StringData getOpName() const { + return _opName; + } + + /** + * This method returns the number of agg expressions that need to be generated for this + * WindowOp. + */ + size_t getNumAggs() const; + + /** + * Given one or more input expressions ('input' / 'inputs'), these methods generate the + * arg expressions needed for this WindowOp. + */ + AccumInputsPtr buildAddRemoveExprs(StageBuilderState& state, AccumInputsPtr inputs) const; + + /** + * Given a vector of named arg expressions ('args' / 'argNames'), this method generates the + * accumulate expressions for this WindowOp. + */ + SbExpr::Vector buildAddAggs(StageBuilderState& state, AccumInputsPtr inputs) const; + + /** + * Given a vector of named arg expressions ('args' / 'argNames'), this method generates the + * accumulate expressions for this WindowOp. + */ + SbExpr::Vector buildRemoveAggs(StageBuilderState& state, AccumInputsPtr inputs) const; + + /** + * Given a map of input expressions ('argExprs'), these methods generate the initialize + * expressions for this WindowOp. + */ + SbExpr::Vector buildInitialize(StageBuilderState& state, AccumInputsPtr inputs) const; + + /** + * Given a map of input expressions ('argExprs'), this method generates the finalize + * expression for this WindowOp. + */ + SbExpr buildFinalize(StageBuilderState& state, + AccumInputsPtr inputs, + const SbSlotVector& aggSlots) const; + +private: + // Static helper method for looking up the info for this WindowOp in the global map. + // This method should only be used by WindowOp's constructors. + static const WindowOpInfo* lookupOpInfo(const std::string& opName); + + // Non-static checked helper method for retrieving the value of '_opInfo'. This method will + // raise a tassert if '_opInfo' is null. + const WindowOpInfo* getOpInfo() const { + uassert(8859901, + str::stream() << "Unrecognized WindowOp name: " << _opName, + _opInfo != nullptr); + + return _opInfo; + } + + // Name of the specific accumulation op. This name is used to retrieve info about the op + // from the global map. + std::string _opName; + + // Info about the specific accumulation op named by '_opName'. + const WindowOpInfo* _opInfo = nullptr; +}; +} // namespace mongo::stage_builder diff --git a/src/mongo/db/query/stage_builder/sbe/sbexpr.h b/src/mongo/db/query/stage_builder/sbe/sbexpr.h index 8c6d280354e..fbea4d39473 100644 --- a/src/mongo/db/query/stage_builder/sbe/sbexpr.h +++ b/src/mongo/db/query/stage_builder/sbe/sbexpr.h @@ -32,11 +32,10 @@ #include "mongo/db/exec/sbe/expressions/expression.h" #include "mongo/db/exec/sbe/stages/hash_agg_accumulator.h" #include "mongo/db/exec/sbe/values/slot.h" -#include "mongo/db/pipeline/accumulator.h" -#include "mongo/db/query/stage_builder/sbe/abt/syntax/expr.h" #include "mongo/db/query/stage_builder/sbe/abt/syntax/syntax.h" #include "mongo/db/query/stage_builder/sbe/abt_defs.h" #include "mongo/db/query/stage_builder/sbe/type_signature.h" +#include "mongo/util/modules.h" #include #include diff --git a/src/mongo/db/query/stage_builder/sbe/sbexpr_helpers.h b/src/mongo/db/query/stage_builder/sbe/sbexpr_helpers.h index 48cd08372fc..c4e79824512 100644 --- a/src/mongo/db/query/stage_builder/sbe/sbexpr_helpers.h +++ b/src/mongo/db/query/stage_builder/sbe/sbexpr_helpers.h @@ -35,6 +35,7 @@ #include "mongo/db/exec/sbe/values/cell_interface.h" #include "mongo/db/query/stage_builder/sbe/builder_state.h" #include "mongo/db/query/stage_builder/sbe/sbexpr.h" +#include "mongo/util/modules.h" namespace mongo::stage_builder { inline void makeSbExprOptSbSlotVecHelper(SbExprOptSlotVector& result) {} diff --git a/src/mongo/db/query/stage_builder/sbe/type_checker.h b/src/mongo/db/query/stage_builder/sbe/type_checker.h index e6589e254dc..fa7002a4e68 100644 --- a/src/mongo/db/query/stage_builder/sbe/type_checker.h +++ b/src/mongo/db/query/stage_builder/sbe/type_checker.h @@ -33,6 +33,7 @@ #include "mongo/db/query/stage_builder/sbe/abt/syntax/syntax.h" #include "mongo/db/query/stage_builder/sbe/type_signature.h" #include "mongo/stdx/unordered_map.h" +#include "mongo/util/modules.h" #include #include diff --git a/src/mongo/db/query/stage_builder/sbe/type_signature.h b/src/mongo/db/query/stage_builder/sbe/type_signature.h index e297b3b285e..52ee06bb0f6 100644 --- a/src/mongo/db/query/stage_builder/sbe/type_signature.h +++ b/src/mongo/db/query/stage_builder/sbe/type_signature.h @@ -30,6 +30,7 @@ #pragma once #include "mongo/db/exec/sbe/values/value.h" +#include "mongo/util/modules.h" namespace mongo::stage_builder { diff --git a/src/mongo/db/query/stage_builder/sbe/value_lifetime.h b/src/mongo/db/query/stage_builder/sbe/value_lifetime.h index 0aa28bea3ca..4039b65712f 100644 --- a/src/mongo/db/query/stage_builder/sbe/value_lifetime.h +++ b/src/mongo/db/query/stage_builder/sbe/value_lifetime.h @@ -32,6 +32,7 @@ #include "mongo/db/query/stage_builder/sbe/abt/syntax/expr.h" #include "mongo/db/query/stage_builder/sbe/abt/syntax/syntax.h" #include "mongo/stdx/unordered_map.h" +#include "mongo/util/modules.h" namespace mongo::stage_builder { diff --git a/src/mongo/db/query/stage_builder/sbe/vectorizer.h b/src/mongo/db/query/stage_builder/sbe/vectorizer.h index 7889ad0497d..2709eeb31c1 100644 --- a/src/mongo/db/query/stage_builder/sbe/vectorizer.h +++ b/src/mongo/db/query/stage_builder/sbe/vectorizer.h @@ -34,6 +34,7 @@ #include "mongo/db/query/stage_builder/sbe/sbexpr.h" #include "mongo/db/query/stage_builder/sbe/type_signature.h" #include "mongo/stdx/unordered_map.h" +#include "mongo/util/modules.h" #include