HappenLee commented on code in PR #25290:
URL: https://github.com/apache/doris/pull/25290#discussion_r1356015097


##########
be/src/exprs/minmax_predicate.h:
##########
@@ -128,11 +128,158 @@ class MinMaxNumFunc : public MinMaxFuncBase {
         return Status::OK();
     }
 
-private:
+protected:
     T _max = type_limit<T>::min();
     T _min = type_limit<T>::max();
     // we use _empty to avoid compare twice
     bool _empty = true;
 };
 
+template <class T>
+class MinNumFunc : public MinMaxNumFunc<T> {
+public:
+    MinNumFunc() = default;
+    ~MinNumFunc() override = default;
+
+    void insert(const void* data) override {
+        if (data == nullptr) {
+            return;
+        }
+
+        T val_data = *reinterpret_cast<const T*>(data);
+
+        if (this->_empty) {
+            this->_min = val_data;
+            this->_empty = false;
+            return;
+        }
+        if (val_data < this->_min) {
+            this->_min = val_data;
+        }
+    }
+
+    void insert_fixed_len(const char* data, const int* offsets, int number) 
override {
+        if (!number) {
+            return;
+        }
+        if (this->_empty) {
+            this->_min = *((T*)data + offsets[0]);
+        }
+        for (int i = this->_empty; i < number; i++) {
+            this->_min = std::min(this->_min, *((T*)data + offsets[i]));
+        }
+        this->_empty = false;
+    }
+
+    bool find(void* data) override {
+        if (data == nullptr) {
+            return false;
+        }
+
+        T val_data = *reinterpret_cast<T*>(data);
+        return val_data >= this->_min;
+    }
+
+    Status merge(MinMaxFuncBase* minmax_func, ObjectPool* pool) override {
+        if constexpr (std::is_same_v<T, StringRef>) {
+            MinNumFunc<T>* other_minmax = 
static_cast<MinNumFunc<T>*>(minmax_func);
+            if (other_minmax->_min < this->_min) {
+                auto& other_min = other_minmax->_min;
+                auto str = pool->add(new std::string(other_min.data, 
other_min.size));
+                this->_min.data = str->data();
+                this->_min.size = str->length();
+            }
+        } else {
+            MinNumFunc<T>* other_minmax = 
static_cast<MinNumFunc<T>*>(minmax_func);
+            if (other_minmax->_min < this->_min) {
+                this->_min = other_minmax->_min;
+            }
+        }
+
+        return Status::OK();
+    }
+
+    //min filter the max is useless, so return nullptr directly
+    void* get_max() override { return nullptr; }
+
+    Status assign(void* min_data, void* max_data) override {
+        this->_min = *(T*)min_data;
+        return Status::OK();
+    }
+};
+
+template <class T>
+class MaxNumFunc : public MinMaxNumFunc<T> {
+public:
+    MaxNumFunc() = default;
+    ~MaxNumFunc() override = default;
+
+    void insert(const void* data) override {
+        if (data == nullptr) {
+            return;
+        }
+
+        T val_data = *reinterpret_cast<const T*>(data);
+
+        if (this->_empty) {
+            this->_max = val_data;
+            this->_empty = false;
+            return;
+        }
+        if (val_data > this->_max) {
+            this->_max = val_data;
+        }
+    }
+
+    void insert_fixed_len(const char* data, const int* offsets, int number) 
override {
+        if (!number) {
+            return;
+        }
+        if (this->_empty) {
+            this->_max = *((T*)data + offsets[0]);
+        }
+        for (int i = this->_empty; i < number; i++) {
+            this->_max = std::max(this->_max, *((T*)data + offsets[i]));
+        }
+        this->_empty = false;
+    }
+
+    bool find(void* data) override {
+        if (data == nullptr) {
+            return false;
+        }
+
+        T val_data = *reinterpret_cast<T*>(data);
+        return val_data <= this->_max;
+    }
+
+    Status merge(MinMaxFuncBase* minmax_func, ObjectPool* pool) override {
+        if constexpr (std::is_same_v<T, StringRef>) {
+            MinMaxNumFunc<T>* other_minmax = 
static_cast<MinMaxNumFunc<T>*>(minmax_func);

Review Comment:
   assert_cast to  MaxNumFunc<T>*



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to