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


##########
be/src/olap/predicate_creator.h:
##########
@@ -0,0 +1,263 @@
+// 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 <charconv>
+
+#include "olap/column_predicate.h"
+#include "olap/comparison_predicate.h"
+#include "olap/in_list_predicate.h"
+#include "olap/tablet_schema.h"
+#include "util/date_func.h"
+
+namespace doris {
+
+template <typename ConditionType>
+class PredicateCreator {
+public:
+    virtual ColumnPredicate* create(const TabletColumn& column, int index,
+                                    const ConditionType& conditions, bool 
opposite,
+                                    MemPool* pool) = 0;
+    virtual ~PredicateCreator() = default;
+};
+
+template <typename CppType, PredicateType PT, typename ConditionType>
+class IntergerPredicateCreator : public PredicateCreator<ConditionType> {
+public:
+    ColumnPredicate* create(const TabletColumn& column, int index, const 
ConditionType& conditions,
+                            bool opposite, MemPool* pool) override {
+        if constexpr (PredicateTypeTraits::is_list(PT)) {
+            phmap::flat_hash_set<CppType> values;
+            for (auto condition : conditions) {

Review Comment:
   const auto& condition



##########
be/src/olap/predicate_creator.h:
##########
@@ -0,0 +1,263 @@
+// 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 <charconv>
+
+#include "olap/column_predicate.h"
+#include "olap/comparison_predicate.h"
+#include "olap/in_list_predicate.h"
+#include "olap/tablet_schema.h"
+#include "util/date_func.h"
+
+namespace doris {
+
+template <typename ConditionType>
+class PredicateCreator {
+public:
+    virtual ColumnPredicate* create(const TabletColumn& column, int index,
+                                    const ConditionType& conditions, bool 
opposite,
+                                    MemPool* pool) = 0;
+    virtual ~PredicateCreator() = default;
+};
+
+template <typename CppType, PredicateType PT, typename ConditionType>
+class IntergerPredicateCreator : public PredicateCreator<ConditionType> {
+public:
+    ColumnPredicate* create(const TabletColumn& column, int index, const 
ConditionType& conditions,
+                            bool opposite, MemPool* pool) override {
+        if constexpr (PredicateTypeTraits::is_list(PT)) {
+            phmap::flat_hash_set<CppType> values;
+            for (auto condition : conditions) {
+                values.insert(convert(condition));
+            }
+            return new InListPredicateBase<CppType, PT>(index, 
std::move(values), opposite);
+        } else if constexpr (PredicateTypeTraits::is_comparison(PT)) {
+            return new ComparisonPredicateBase<CppType, PT>(index, 
convert(conditions), opposite);
+        }
+        return nullptr;
+    }
+
+private:
+    CppType convert(const std::string& condition) {
+        CppType value = 0;
+        std::from_chars(condition.data(), condition.data() + condition.size(), 
value);
+        return value;
+    }
+};
+
+template <typename CppType, PredicateType PT, typename ConditionType>
+class DecimalPredicateCreator : public PredicateCreator<ConditionType> {
+public:
+    ColumnPredicate* create(const TabletColumn& column, int index, const 
ConditionType& conditions,
+                            bool opposite, MemPool* pool) override {
+        if constexpr (PredicateTypeTraits::is_list(PT)) {
+            phmap::flat_hash_set<CppType> values;
+            for (auto condition : conditions) {
+                values.insert(convert(column, condition));
+            }
+            return new InListPredicateBase<CppType, PT>(index, 
std::move(values), opposite);
+        } else if constexpr (PredicateTypeTraits::is_comparison(PT)) {
+            return new ComparisonPredicateBase<CppType, PT>(index, 
convert(column, conditions),
+                                                            opposite);
+        }
+        return nullptr;
+    }
+
+private:
+    CppType convert(const TabletColumn& column, const std::string& condition) {
+        StringParser::ParseResult result = 
StringParser::ParseResult::PARSE_SUCCESS;
+        // return CppType value cast from int128_t
+        return StringParser::string_to_decimal<int128_t>(
+                condition.data(), condition.size(), column.precision(), 
column.frac(), &result);
+    }
+};
+
+template <PredicateType PT, typename ConditionType>
+class StringPredicateCreator : public PredicateCreator<ConditionType> {
+public:
+    StringPredicateCreator(bool should_padding) : 
_should_padding(should_padding) {};
+
+    ColumnPredicate* create(const TabletColumn& column, int index, const 
ConditionType& conditions,
+                            bool opposite, MemPool* pool) override {
+        if constexpr (PredicateTypeTraits::is_list(PT)) {
+            phmap::flat_hash_set<StringValue> values;
+            for (auto condition : conditions) {
+                values.insert(convert(column, condition, pool));
+            }
+            return new InListPredicateBase<StringValue, PT>(index, 
std::move(values), opposite);
+        } else if constexpr (PredicateTypeTraits::is_comparison(PT)) {
+            return new ComparisonPredicateBase<StringValue, PT>(
+                    index, convert(column, conditions, pool), opposite);
+        }
+        return nullptr;
+    }
+
+private:
+    bool _should_padding;
+    StringValue convert(const TabletColumn& column, const std::string& 
condition, MemPool* pool) {
+        size_t length = condition.length();
+        if (_should_padding) {
+            length = std::max(static_cast<size_t>(column.length()), length);
+        }
+
+        char* buffer = reinterpret_cast<char*>(pool->allocate(length));
+        memset(buffer, 0, length);
+        memory_copy(buffer, condition.data(), condition.length());
+
+        return StringValue(buffer, length);
+    }
+};
+
+template <typename CppType, PredicateType PT, typename ConditionType>
+struct CustomPredicateCreator : public PredicateCreator<ConditionType> {
+public:
+    CustomPredicateCreator(std::function<CppType(const std::string& 
condition)> convert)
+            : _convert(convert) {};

Review Comment:
   pass the reference of `convert`?



##########
be/src/olap/predicate_creator.h:
##########
@@ -0,0 +1,263 @@
+// 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 <charconv>
+
+#include "olap/column_predicate.h"
+#include "olap/comparison_predicate.h"
+#include "olap/in_list_predicate.h"
+#include "olap/tablet_schema.h"
+#include "util/date_func.h"
+
+namespace doris {
+
+template <typename ConditionType>
+class PredicateCreator {
+public:
+    virtual ColumnPredicate* create(const TabletColumn& column, int index,
+                                    const ConditionType& conditions, bool 
opposite,
+                                    MemPool* pool) = 0;
+    virtual ~PredicateCreator() = default;
+};
+
+template <typename CppType, PredicateType PT, typename ConditionType>
+class IntergerPredicateCreator : public PredicateCreator<ConditionType> {
+public:
+    ColumnPredicate* create(const TabletColumn& column, int index, const 
ConditionType& conditions,
+                            bool opposite, MemPool* pool) override {
+        if constexpr (PredicateTypeTraits::is_list(PT)) {
+            phmap::flat_hash_set<CppType> values;
+            for (auto condition : conditions) {
+                values.insert(convert(condition));
+            }
+            return new InListPredicateBase<CppType, PT>(index, 
std::move(values), opposite);
+        } else if constexpr (PredicateTypeTraits::is_comparison(PT)) {
+            return new ComparisonPredicateBase<CppType, PT>(index, 
convert(conditions), opposite);
+        }
+        return nullptr;

Review Comment:
   maybe need logfatal? 



##########
be/src/olap/predicate_creator.h:
##########
@@ -0,0 +1,263 @@
+// 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 <charconv>
+
+#include "olap/column_predicate.h"
+#include "olap/comparison_predicate.h"
+#include "olap/in_list_predicate.h"
+#include "olap/tablet_schema.h"
+#include "util/date_func.h"
+
+namespace doris {
+
+template <typename ConditionType>
+class PredicateCreator {
+public:
+    virtual ColumnPredicate* create(const TabletColumn& column, int index,
+                                    const ConditionType& conditions, bool 
opposite,
+                                    MemPool* pool) = 0;
+    virtual ~PredicateCreator() = default;
+};
+
+template <typename CppType, PredicateType PT, typename ConditionType>
+class IntergerPredicateCreator : public PredicateCreator<ConditionType> {
+public:
+    ColumnPredicate* create(const TabletColumn& column, int index, const 
ConditionType& conditions,
+                            bool opposite, MemPool* pool) override {
+        if constexpr (PredicateTypeTraits::is_list(PT)) {
+            phmap::flat_hash_set<CppType> values;
+            for (auto condition : conditions) {
+                values.insert(convert(condition));
+            }
+            return new InListPredicateBase<CppType, PT>(index, 
std::move(values), opposite);
+        } else if constexpr (PredicateTypeTraits::is_comparison(PT)) {
+            return new ComparisonPredicateBase<CppType, PT>(index, 
convert(conditions), opposite);
+        }
+        return nullptr;
+    }
+
+private:
+    CppType convert(const std::string& condition) {
+        CppType value = 0;
+        std::from_chars(condition.data(), condition.data() + condition.size(), 
value);
+        return value;
+    }
+};
+
+template <typename CppType, PredicateType PT, typename ConditionType>
+class DecimalPredicateCreator : public PredicateCreator<ConditionType> {
+public:
+    ColumnPredicate* create(const TabletColumn& column, int index, const 
ConditionType& conditions,
+                            bool opposite, MemPool* pool) override {
+        if constexpr (PredicateTypeTraits::is_list(PT)) {
+            phmap::flat_hash_set<CppType> values;
+            for (auto condition : conditions) {

Review Comment:
   same to the up



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