This is an automated email from the ASF dual-hosted git repository. yiguolei pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new c583d3e27c [fix][vectorized] Fix bug of VInPredicate on date type (#10663) c583d3e27c is described below commit c583d3e27c6a63aa2301bb7c0d5adce28c4df6c8 Author: Xin Liao <liaoxin...@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 | 4 +-- .../data/datatype/date/test_date_in_predicate.out | 8 +++++ .../datatype/date/test_date_in_predicate.groovy | 38 ++++++++++++++++++++++ 5 files changed, 83 insertions(+), 8 deletions(-) diff --git a/be/src/exprs/create_predicate_function.h b/be/src/exprs/create_predicate_function.h index 364634057f..ebd268b8cf 100644 --- a/be/src/exprs/create_predicate_function.h +++ b/be/src/exprs/create_predicate_function.h @@ -32,15 +32,23 @@ public: }; }; +template <bool is_vec> class HybridSetTraits { public: using BasePtr = HybridSetBase*; template <PrimitiveType type> static BasePtr get_function() { - 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(PrimitiveType type) { return create_predicate_function<BloomFilterTraits>(type); } -} // 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 3c0254013a..b2ed96592d 100644 --- a/be/src/runtime/primitive_type.h +++ b/be/src/runtime/primitive_type.h @@ -206,4 +206,20 @@ struct PredicatePrimitiveTypeTraits<TYPE_DATETIMEV2> { 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 diff --git a/be/src/vec/functions/in.cpp b/be/src/vec/functions/in.cpp index 942a0d8062..9fdb161eff 100644 --- a/be/src/vec/functions/in.cpp +++ b/be/src/vec/functions/in.cpp @@ -67,7 +67,7 @@ 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))); + 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) { @@ -136,7 +136,7 @@ public: } std::unique_ptr<HybridSetBase> hybrid_set( - create_set(convert_type_to_primitive(context->get_arg_type(0)->type))); + 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-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org