github-actions[bot] commented on code in PR #62589: URL: https://github.com/apache/doris/pull/62589#discussion_r3108102326
########## be/src/exec/runtime_filter/runtime_filter_partition_pruner.cpp: ########## @@ -0,0 +1,371 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "exec/runtime_filter/runtime_filter_partition_pruner.h" + +#include <gen_cpp/PlanNodes_types.h> + +#include <optional> +#include <utility> + +#include "exprs/hybrid_set.h" +#include "exprs/vexpr.h" +#include "exprs/vexpr_context.h" +#include "exprs/vliteral.h" +#include "exprs/vslot_ref.h" +#include "runtime/descriptors.h" + +namespace doris { + +// Helper to extract a typed value from a ColumnPtr's first row. +// Must be a template function so that `if constexpr` properly discards +// the inapplicable branch during instantiation. +template <PrimitiveType PT> +static typename PrimitiveTypeTraits<PT>::CppType extract_value_from_column(const ColumnPtr& col) { + using CppType = typename PrimitiveTypeTraits<PT>::CppType; + auto data = col->get_data_at(0); + if constexpr (is_string_type(PT)) { + return CppType(data.data, data.size); + } else { + return *reinterpret_cast<const CppType*>(data.data); + } +} + +// NOLINTBEGIN(readability-function-cognitive-complexity,readability-function-size) +// Complexity is inflated by macro expansion for each PrimitiveType case. +void RuntimeFilterPartitionPruner::parse_boundaries( + const std::vector<TPartitionBoundary>& boundaries, + const phmap::flat_hash_map<int, SlotDescriptor*>& slot_descs) { + for (const auto& tb : boundaries) { + if (!tb.__isset.partition_id || !tb.__isset.slot_id) { + continue; + } + SlotId slot_id = tb.slot_id; + + auto slot_it = slot_descs.find(slot_id); + if (slot_it == slot_descs.end()) { + continue; + } + SlotDescriptor* slot = slot_it->second; + PrimitiveType ptype = slot->type()->get_primitive_type(); + int precision = cast_set<int>(slot->type()->get_precision()); + int scale = cast_set<int>(slot->type()->get_scale()); + bool is_nullable = slot->is_nullable(); + + ParsedBoundary boundary; + boundary.partition_id = tb.partition_id; + boundary.slot_id = slot_id; + boundary.is_nullable = is_nullable; + + bool parsed_ok = false; + +#define BUILD_BOUNDARY_CVR(NAME) \ + case TYPE_##NAME: { \ + using CppType = typename PrimitiveTypeTraits<TYPE_##NAME>::CppType; \ + bool is_list = tb.__isset.list_values && !tb.list_values.empty(); \ + bool is_range = tb.__isset.range_start || tb.__isset.range_end; \ + if (!is_list && !is_range) break; \ + ColumnValueRange<TYPE_##NAME> cvr(slot->col_name(), is_nullable, precision, scale); \ + /* Returns nullopt if `node` is a NULL literal; the caller then sets contain_null */ \ + /* on the CVR instead of trying to extract a typed value (which would dereference */ \ + /* a null data pointer for the non-string branch). */ \ + auto parse_texpr_node = \ + [&](const TExprNode& node) -> std::optional<std::pair<CppType, ColumnPtr>> { \ + if (node.node_type == TExprNodeType::NULL_LITERAL) { \ + return std::nullopt; \ + } \ + VLiteral literal(node); \ + auto col_ptr = literal.get_column_ptr(); \ + auto val = extract_value_from_column<TYPE_##NAME>(col_ptr); \ + return std::make_optional(std::pair<CppType, ColumnPtr> {val, col_ptr}); \ + }; \ + if (is_list) { \ + auto empty_cvr = ColumnValueRange<TYPE_##NAME>::create_empty_column_value_range( \ + is_nullable, precision, scale); \ + bool list_has_null = false; \ + bool list_has_value = false; \ + for (const auto& node : tb.list_values) { \ + auto parsed = parse_texpr_node(node); \ + if (!parsed) { \ + list_has_null = true; \ + continue; \ + } \ + auto& [val, col_ptr] = *parsed; \ + boundary.literal_columns.push_back(std::move(col_ptr)); \ + static_cast<void>(empty_cvr.add_fixed_value(val)); \ + list_has_value = true; \ + } \ + if (list_has_value) { \ + cvr.intersection(empty_cvr); \ + } \ + if (list_has_null && is_nullable) { \ + cvr.set_contain_null(true); \ Review Comment: When a LIST boundary contains both NULL and concrete values, `cvr.intersection(empty_cvr)` first materializes the concrete fixed-value set, but `set_contain_null(true)` immediately calls `set_empty_value_range()` and discards those fixed values. That turns a partition like `{NULL, 5}` into a NULL-only boundary, so `_try_prune_by_single_rf()` can later prune it even when the runtime filter contains `5`. Please preserve both the concrete values and the NULL marker here instead of resetting the CVR. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
