You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2022/07/08 03:19:58 UTC

[doris] 04/07: [fix][vectorized] Fix bug of VInPredicate on date type (#10663)

This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch dev-1.0.1-v20220707
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 199bb616c6d7b0bc0a953c2799527d757dc3df51
Author: Xin Liao <li...@126.com>
AuthorDate: Thu Jul 7 22:15:33 2022 +0800

    [fix][vectorized] Fix bug of VInPredicate on date type (#10663)
---
 be/src/exprs/create_predicate_function.h           | 25 ++++++++++----
 be/src/runtime/primitive_type.h                    | 16 +++++++++
 be/src/vec/functions/in.cpp                        |  8 ++---
 .../data/datatype/date/test_date_in_predicate.out  |  8 +++++
 .../datatype/date/test_date_in_predicate.groovy    | 38 ++++++++++++++++++++++
 5 files changed, 85 insertions(+), 10 deletions(-)

diff --git a/be/src/exprs/create_predicate_function.h b/be/src/exprs/create_predicate_function.h
index 27aef88c92..bd7c8bc6e0 100644
--- a/be/src/exprs/create_predicate_function.h
+++ b/be/src/exprs/create_predicate_function.h
@@ -33,15 +33,23 @@ public:
     };
 };
 
+template <bool is_vec>
 class HybridSetTraits {
 public:
     using BasePtr = HybridSetBase*;
     template <PrimitiveType type>
     static BasePtr get_function([[maybe_unused]] MemTracker* tracker) {
-        using CppType = typename PrimitiveTypeTraits<type>::CppType;
-        using Set = std::conditional_t<std::is_same_v<CppType, StringValue>, StringValueSet,
-                                       HybridSet<CppType>>;
-        return new (std::nothrow) Set();
+        if constexpr (is_vec) {
+            using CppType = typename VecPrimitiveTypeTraits<type>::CppType;
+            using Set = std::conditional_t<std::is_same_v<CppType, StringValue>, StringValueSet,
+                                           HybridSet<CppType>>;
+            return new (std::nothrow) Set();
+        } else {
+            using CppType = typename PrimitiveTypeTraits<type>::CppType;
+            using Set = std::conditional_t<std::is_same_v<CppType, StringValue>, StringValueSet,
+                                           HybridSet<CppType>>;
+            return new (std::nothrow) Set();
+        }
     };
 };
 
@@ -114,11 +122,16 @@ inline auto create_minmax_filter(PrimitiveType type) {
 }
 
 inline auto create_set(PrimitiveType type) {
-    return create_predicate_function<HybridSetTraits>(type);
+    return create_predicate_function<HybridSetTraits<false>>(type);
+}
+
+// used for VInPredicate
+inline auto vec_create_set(PrimitiveType type) {
+    return create_predicate_function<HybridSetTraits<true>>(type);
 }
 
 inline auto create_bloom_filter(MemTracker* tracker, PrimitiveType type) {
     return create_predicate_function<BloomFilterTraits>(type, tracker);
 }
 
-} // namespace doris
\ No newline at end of file
+} // namespace doris
diff --git a/be/src/runtime/primitive_type.h b/be/src/runtime/primitive_type.h
index 03d13b2069..7b4789b0b4 100644
--- a/be/src/runtime/primitive_type.h
+++ b/be/src/runtime/primitive_type.h
@@ -372,6 +372,22 @@ struct PredicatePrimitiveTypeTraits<TYPE_DATETIME> {
     using PredicateFieldType = uint64_t;
 };
 
+// used for VInPredicate. VInPredicate should use vectorized data type
+template <PrimitiveType type>
+struct VecPrimitiveTypeTraits {
+    using CppType = typename PrimitiveTypeTraits<type>::CppType;
+};
+
+template <>
+struct VecPrimitiveTypeTraits<TYPE_DATE> {
+    using CppType = vectorized::VecDateTimeValue;
+};
+
+template <>
+struct VecPrimitiveTypeTraits<TYPE_DATETIME> {
+    using CppType = vectorized::VecDateTimeValue;
+};
+
 } // namespace doris
 
 #endif
diff --git a/be/src/vec/functions/in.cpp b/be/src/vec/functions/in.cpp
index 65232c442e..216165b826 100644
--- a/be/src/vec/functions/in.cpp
+++ b/be/src/vec/functions/in.cpp
@@ -67,8 +67,8 @@ public:
         }
         auto* state = new InState();
         context->set_function_state(scope, state);
-        state->hybrid_set.reset(create_set(convert_type_to_primitive(
-                context->get_arg_type(0)->type)));
+        state->hybrid_set.reset(
+                vec_create_set(convert_type_to_primitive(context->get_arg_type(0)->type)));
 
         DCHECK(context->get_num_args() > 1);
         for (int i = 1; i < context->get_num_args(); ++i) {
@@ -135,8 +135,8 @@ public:
                     continue;
                 }
 
-                std::unique_ptr<HybridSetBase> hybrid_set(create_set(convert_type_to_primitive(
-                context->get_arg_type(0)->type)));
+                std::unique_ptr<HybridSetBase> hybrid_set(
+                        vec_create_set(convert_type_to_primitive(context->get_arg_type(0)->type)));
                 bool null_in_set = false;
 
                 for (const auto& set_column : set_columns) {
diff --git a/regression-test/data/datatype/date/test_date_in_predicate.out b/regression-test/data/datatype/date/test_date_in_predicate.out
new file mode 100644
index 0000000000..db4eb25976
--- /dev/null
+++ b/regression-test/data/datatype/date/test_date_in_predicate.out
@@ -0,0 +1,8 @@
+-- This file is automatically generated. You should know what you did if you want to edit this
+-- !sql1 --
+2	test2	2000-02-02
+
+-- !sql2 --
+1	test1	2000-01-01
+3	test3	2000-03-02
+
diff --git a/regression-test/suites/datatype/date/test_date_in_predicate.groovy b/regression-test/suites/datatype/date/test_date_in_predicate.groovy
new file mode 100644
index 0000000000..6fc5c1dbac
--- /dev/null
+++ b/regression-test/suites/datatype/date/test_date_in_predicate.groovy
@@ -0,0 +1,38 @@
+
+// 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.
+
+suite("test_date_in_predicate", "datatype") {
+    def tbName = "test_date_in_predicate"
+    sql "DROP TABLE IF EXISTS ${tbName}"
+    sql """
+            CREATE TABLE IF NOT EXISTS ${tbName} (
+                c0 int,
+                c1 char(10),
+                c2 date
+            )
+            UNIQUE KEY(c0)
+            DISTRIBUTED BY HASH(c0) BUCKETS 5 properties("replication_num" = "1");
+        """
+    sql "insert into ${tbName} values(1, 'test1', '2000-01-01')"
+    sql "insert into ${tbName} values(2, 'test2', '2000-02-02')"
+    sql "insert into ${tbName} values(3, 'test3', '2000-03-02')"
+
+    qt_sql1 "select * from ${tbName} where c2 in ('2000-02-02')"
+    qt_sql2 "select * from ${tbName} where c2 not in ('2000-02-02')"
+    sql "DROP TABLE ${tbName}"
+}


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