mrhhsg commented on code in PR #63389:
URL: https://github.com/apache/doris/pull/63389#discussion_r3456575398


##########
be/src/exprs/expr_zonemap_filter.h:
##########
@@ -0,0 +1,125 @@
+// 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.
+
+#pragma once
+
+#include <compare>
+#include <optional>
+#include <vector>
+
+#include "common/check.h"
+#include "common/status.h"
+#include "core/data_type/data_type.h"
+#include "core/data_type/data_type_nullable.h"
+#include "core/data_type/define_primitive_type.h"
+#include "core/field.h"
+#include "exprs/vexpr_fwd.h"
+#include "storage/index/zone_map/zonemap_eval_context.h"
+#include "storage/index/zone_map/zonemap_filter_result.h"
+
+namespace doris {
+class HybridSetBase;
+class RuntimeState;
+class TExprNode;
+} // namespace doris
+
+namespace doris::expr_zonemap {
+
+struct InZonemapMaterializedSet {
+    bool contains_null = false;
+    std::vector<Field> values;
+    Field min_value;
+    Field max_value;
+};
+
+struct SlotLiteral {
+    int slot_index;
+    DataTypePtr slot_type;
+    Field literal;
+    DataTypePtr literal_type;
+    bool literal_on_left;
+};
+
+std::optional<SlotLiteral> extract_slot_and_literal(const VExprSPtrs& args);
+
+TExprNode create_texpr_node_from_hybrid_set_value(const void* data, const 
PrimitiveType& type,
+                                                  int precision, int scale);
+
+Status materialize_hybrid_set_for_zonemap_filter(HybridSetBase& set, const 
DataTypePtr& data_type,
+                                                 InZonemapMaterializedSet* 
result);
+
+inline bool field_types_compatible(PrimitiveType lhs, PrimitiveType rhs) {
+    return lhs == rhs || (is_string_type(lhs) && is_string_type(rhs));
+}
+
+inline bool data_types_compatible(const DataTypePtr& lhs, const DataTypePtr& 
rhs) {
+    if (lhs == nullptr || rhs == nullptr) {
+        return false;
+    }
+    const auto lhs_type = remove_nullable(lhs);
+    const auto rhs_type = remove_nullable(rhs);
+    const auto lhs_primitive_type = lhs_type->get_primitive_type();
+    const auto rhs_primitive_type = rhs_type->get_primitive_type();
+    if (is_string_type(lhs_primitive_type) && 
is_string_type(rhs_primitive_type)) {
+        return true;
+    }
+    return lhs_type->equals(*rhs_type);
+}
+
+inline DataTypePtr fetch_compatible_slot_type(const ZoneMapEvalContext& ctx, 
int slot_index,
+                                              const DataTypePtr& 
expr_slot_type) {
+    const auto* slot_type = ctx.data_type(slot_index);
+    if (slot_type == nullptr || *slot_type == nullptr) {
+        return nullptr;
+    }
+    DORIS_CHECK(data_types_compatible(*slot_type, expr_slot_type));
+    return *slot_type;
+}
+
+inline bool field_less(const Field& lhs, const Field& rhs) {
+    return (lhs <=> rhs) == std::strong_ordering::less;

Review Comment:
   我倾向于:不放到 field.h,先继续留在 expr_zonemap_filter.h 更合适。
   理由:
   1. 当前使用范围很窄
        field_less / field_greater / field_less_equal / field_greater_equal 
目前只被 expr-zonemap 相关路径使用:
         - expr_zonemap_filter.cpp
         - functions_comparison.h
         - function_string.cpp
   
   2. field.h 已经有通用能力
        Field 本身已经提供:
   ```cpp
        std::strong_ordering operator<=>(const Field& rhs) const;
   ```
   
   这几个 helper 只是对 <=> 的 zonemap 使用场景包装。放进 field.h 会扩大 core API 
surface,但没有明显复用收益。
   
   3. field.h 是很基础的 core header
        它被大量模块包含,最好避免加入只服务 expr-zonemap 的便捷函数,尤其是名字比较泛的 field_less,放在 doris 全局 
namespace 下会显得比较突兀。
   
   4. 语义上这些 helper 属于 zonemap pruning
        它们服务的是 min/max 区间判断、literal 与 zone map 边界比较,和 
range_stats_usable_for_zonemap()、fetch_compatible_slot_type() 属于同一组 evaluator 
helper。



-- 
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]

Reply via email to