BiteTheDDDDt commented on code in PR #64165:
URL: https://github.com/apache/doris/pull/64165#discussion_r3378641579


##########
be/src/runtime/scan_filter_profile.cpp:
##########
@@ -0,0 +1,599 @@
+// 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 "runtime/scan_filter_profile.h"
+
+#include <fmt/format.h>
+#include <glog/logging.h>
+
+#include <algorithm>
+#include <sstream>
+
+#include "runtime/runtime_profile.h"
+
+namespace doris {
+
+namespace {
+
+constexpr const char* SCAN_FILTER_INFO = "ScanFilterInfo";
+constexpr const char* KEY_RANGE_INFO = "KeyRangeInfo";
+constexpr const char* RUNTIME_FILTER_PARTITION_PRUNING = 
"RuntimeFilterPartitionPruning";
+
+bool is_index_stage(ScanFilterStage stage) {
+    return stage == ScanFilterStage::INDEX_INVERTED ||
+           stage == ScanFilterStage::INDEX_BLOOM_FILTER ||
+           stage == ScanFilterStage::INDEX_ZONE_MAP || stage == 
ScanFilterStage::INDEX_DICT ||
+           stage == ScanFilterStage::INDEX_ANN;
+}
+
+bool is_exec_stage(ScanFilterStage stage) {
+    return stage == ScanFilterStage::EXEC_VECTOR || stage == 
ScanFilterStage::EXEC_SHORT_CIRCUIT ||
+           stage == ScanFilterStage::EXEC_COMMON_EXPR || stage == 
ScanFilterStage::EXEC_RESIDUAL;
+}
+
+std::string join_ids(const std::vector<int32_t>& ids) {
+    std::stringstream ss;
+    for (size_t i = 0; i < ids.size(); ++i) {
+        if (i != 0) {
+            ss << ",";
+        }
+        ss << ids[i];
+    }
+    return ss.str();
+}
+
+void set_counter(RuntimeProfile* profile, const std::string& name, TUnit::type 
type,
+                 const std::string& parent, int64_t level, int64_t value) {
+    auto* counter = profile->add_counter(name, type, parent, level);
+    counter->set(value);
+}
+
+void set_root_counter(RuntimeProfile* profile, const std::string& name, 
TUnit::type type,
+                      int64_t level, int64_t value) {
+    set_counter(profile, name, type, RuntimeProfile::ROOT_COUNTER, level, 
value);
+}
+
+RuntimeProfile* get_or_create_child(RuntimeProfile* profile, const 
std::string& name) {
+    auto* child = profile->get_child(name);
+    if (child != nullptr) {
+        return child;
+    }
+    return profile->create_child(name, true, false);
+}
+
+void add_info_string_if_not_empty(RuntimeProfile* profile, const std::string& 
key,
+                                  const std::string& value) {
+    if (!value.empty()) {
+        profile->add_info_string(key, value);
+    }
+}
+
+int stage_display_order(ScanFilterStage stage) {
+    switch (stage) {
+    case ScanFilterStage::KEY_RANGE:
+        return 1;
+    case ScanFilterStage::INDEX_INVERTED:
+        return 2;
+    case ScanFilterStage::INDEX_ANN:
+        return 3;
+    case ScanFilterStage::INDEX_DICT:
+        return 4;
+    case ScanFilterStage::INDEX_BLOOM_FILTER:
+        return 5;
+    case ScanFilterStage::INDEX_ZONE_MAP:
+        return 6;
+    case ScanFilterStage::EXEC_VECTOR:
+        return 7;
+    case ScanFilterStage::EXEC_SHORT_CIRCUIT:
+        return 8;
+    case ScanFilterStage::EXEC_COMMON_EXPR:
+        return 9;
+    case ScanFilterStage::EXEC_RESIDUAL:
+        return 10;
+    case ScanFilterStage::NUM_STAGES:
+        break;
+    }
+    return 99;
+}
+
+const char* stage_profile_name(ScanFilterStage stage) {
+    return scan_filter_stage_name(stage);
+}
+
+const char* scan_filter_source_name(ScanFilterKind kind) {
+    switch (kind) {
+    case ScanFilterKind::NORMAL:
+        return "Conjunct";
+    case ScanFilterKind::RUNTIME_FILTER:
+        return "RuntimeFilter";
+    case ScanFilterKind::TOPN_FILTER:
+        return "TopNFilter";
+    case ScanFilterKind::UNKNOWN:
+        return "Unknown";
+    }
+    return "Unknown";
+}
+
+bool contains_id(const std::vector<int32_t>& ids, int32_t id) {
+    return std::find(ids.begin(), ids.end(), id) != ids.end();
+}
+
+bool has_runtime_filter_partition_pruning_stats(
+        const ScanRuntimeFilterPartitionPruningStats& stats) {
+    return stats.total_partitions > 0 || stats.pruned_partitions > 0 || 
stats.pruned_tablets > 0;
+}
+
+constexpr std::array<ScanFilterStage, 
static_cast<size_t>(ScanFilterStage::NUM_STAGES)>
+ordered_stages() {
+    return {ScanFilterStage::KEY_RANGE,          
ScanFilterStage::INDEX_INVERTED,
+            ScanFilterStage::INDEX_ANN,          ScanFilterStage::INDEX_DICT,
+            ScanFilterStage::INDEX_BLOOM_FILTER, 
ScanFilterStage::INDEX_ZONE_MAP,
+            ScanFilterStage::EXEC_VECTOR,        
ScanFilterStage::EXEC_SHORT_CIRCUIT,
+            ScanFilterStage::EXEC_COMMON_EXPR,   
ScanFilterStage::EXEC_RESIDUAL};
+}
+
+struct SummaryStats {
+    bool participated = false;
+    bool has_filtering_stage = false;
+    bool has_time = false;
+    int first_stage = 99;

Review Comment:
   有几次出现这个magic number 99了,要么统一声明一下,要么想办法别用这个



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