This is an automated email from the ASF dual-hosted git repository.
gabriellee 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 7cf7706eb1 [Bug](runtimefilter) Fix wrong runtime filter on datetime
(#16102)
7cf7706eb1 is described below
commit 7cf7706eb1b6bb0c0361e85cef9944e887a05ebb
Author: Gabriel <[email protected]>
AuthorDate: Sat Jan 28 18:16:06 2023 +0800
[Bug](runtimefilter) Fix wrong runtime filter on datetime (#16102)
---
be/src/exprs/bloom_filter_func.h | 19 +++++----
be/src/exprs/minmax_predicate.h | 5 ++-
be/src/runtime/datetime_value.h | 2 +-
be/src/vec/runtime/vdatetime_value.cpp | 2 +-
be/src/vec/runtime/vdatetime_value.h | 2 +-
.../datatype_p0/date/test_date_runtime_filter.out | 26 ++++++++++++
.../date/test_date_runtime_filter.groovy | 49 ++++++++++++++++++++++
7 files changed, 94 insertions(+), 11 deletions(-)
diff --git a/be/src/exprs/bloom_filter_func.h b/be/src/exprs/bloom_filter_func.h
index 84a61ef2e2..3d8f565aa3 100644
--- a/be/src/exprs/bloom_filter_func.h
+++ b/be/src/exprs/bloom_filter_func.h
@@ -314,9 +314,13 @@ struct FixedStringFindOp : public StringFindOp {
struct DateTimeFindOp : public CommonFindOp<DateTimeValue> {
bool find_olap_engine(const BloomFilterAdaptor& bloom_filter, const void*
data) const {
- DateTimeValue value;
+ vectorized::VecDateTimeValue value;
value.from_olap_datetime(*reinterpret_cast<const uint64_t*>(data));
- return bloom_filter.test(Slice((char*)&value, sizeof(DateTimeValue)));
+ return bloom_filter.test(Slice((char*)&value,
sizeof(vectorized::VecDateTimeValue)));
+ }
+
+ void insert(BloomFilterAdaptor& bloom_filter, const void* data) const {
+ bloom_filter.add_bytes((char*)data,
sizeof(vectorized::VecDateTimeValue));
}
};
@@ -328,13 +332,14 @@ struct DateFindOp : public CommonFindOp<DateTimeValue> {
uint24_t date = *static_cast<const uint24_t*>(data);
uint64_t value = uint32_t(date);
- DateTimeValue date_value;
+ vectorized::VecDateTimeValue date_value;
date_value.from_olap_date(value);
- date_value.to_datetime();
- char data_bytes[sizeof(date_value)];
- memcpy(&data_bytes, &date_value, sizeof(date_value));
- return bloom_filter.test(Slice(data_bytes, sizeof(DateTimeValue)));
+ return bloom_filter.test(Slice((char*)&date_value,
sizeof(vectorized::VecDateTimeValue)));
+ }
+
+ void insert(BloomFilterAdaptor& bloom_filter, const void* data) const {
+ bloom_filter.add_bytes((char*)data,
sizeof(vectorized::VecDateTimeValue));
}
};
diff --git a/be/src/exprs/minmax_predicate.h b/be/src/exprs/minmax_predicate.h
index 4394c36d69..65d9ee005f 100644
--- a/be/src/exprs/minmax_predicate.h
+++ b/be/src/exprs/minmax_predicate.h
@@ -49,7 +49,10 @@ public:
}
T val_data;
- if constexpr (sizeof(T) >= sizeof(int128_t)) {
+ if constexpr (std::is_same_v<T, DateTimeValue>) {
+ reinterpret_cast<const
vectorized::VecDateTimeValue*>(data)->convert_vec_dt_to_dt(
+ &val_data);
+ } else if constexpr (sizeof(T) >= sizeof(int128_t)) {
// use dereference operator on unalign address maybe lead
segmentation fault
memcpy(&val_data, data, sizeof(T));
} else {
diff --git a/be/src/runtime/datetime_value.h b/be/src/runtime/datetime_value.h
index 3486692ddd..856bd3f854 100644
--- a/be/src/runtime/datetime_value.h
+++ b/be/src/runtime/datetime_value.h
@@ -615,7 +615,7 @@ public:
private:
// Used to make sure sizeof DateTimeValue
friend class UnusedClass;
- friend void
doris::vectorized::VecDateTimeValue::convert_vec_dt_to_dt(DateTimeValue* dt);
+ friend void
doris::vectorized::VecDateTimeValue::convert_vec_dt_to_dt(DateTimeValue* dt)
const;
friend void
doris::vectorized::VecDateTimeValue::convert_dt_to_vec_dt(DateTimeValue* dt);
void from_packed_time(int64_t packed_time) {
diff --git a/be/src/vec/runtime/vdatetime_value.cpp
b/be/src/vec/runtime/vdatetime_value.cpp
index 8111569c6b..69eae65d99 100644
--- a/be/src/vec/runtime/vdatetime_value.cpp
+++ b/be/src/vec/runtime/vdatetime_value.cpp
@@ -1749,7 +1749,7 @@ void
VecDateTimeValue::create_from_date_v2(DateV2Value<T>& value, TimeType type)
}
void VecDateTimeValue::convert_vec_dt_to_dt(
- doris::DateTimeValue* dt) { //use convert VecDateTimeValue to
DateTimeValue
+ doris::DateTimeValue* dt) const { //use convert VecDateTimeValue to
DateTimeValue
dt->_neg = this->_neg;
dt->_type = this->_type;
dt->_hour = this->_hour;
diff --git a/be/src/vec/runtime/vdatetime_value.h
b/be/src/vec/runtime/vdatetime_value.h
index 93438e179c..a49209492a 100644
--- a/be/src/vec/runtime/vdatetime_value.h
+++ b/be/src/vec/runtime/vdatetime_value.h
@@ -629,7 +629,7 @@ public:
_day > 0;
}
- void convert_vec_dt_to_dt(doris::DateTimeValue* dt);
+ void convert_vec_dt_to_dt(doris::DateTimeValue* dt) const;
void convert_dt_to_vec_dt(doris::DateTimeValue* dt);
int64_t to_datetime_int64() const;
diff --git a/regression-test/data/datatype_p0/date/test_date_runtime_filter.out
b/regression-test/data/datatype_p0/date/test_date_runtime_filter.out
new file mode 100644
index 0000000000..a6051c0236
--- /dev/null
+++ b/regression-test/data/datatype_p0/date/test_date_runtime_filter.out
@@ -0,0 +1,26 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !sql1 --
+1 2000-01-01 2000-01-01T11:11:11
+2 2000-02-02 2000-02-02T11:11:11
+3 2000-03-02 2000-03-02T11:11:11
+
+-- !sql2 --
+1 2000-01-01 2000-01-01T11:11:11 1 2000-01-01
2000-01-01T11:11:11
+2 2000-02-02 2000-02-02T11:11:11 2 2000-02-02
2000-02-02T11:11:11
+3 2000-03-02 2000-03-02T11:11:11 3 2000-03-02
2000-03-02T11:11:11
+
+-- !sql2 --
+1 2000-01-01 2000-01-01T11:11:11 1 2000-01-01
2000-01-01T11:11:11
+2 2000-02-02 2000-02-02T11:11:11 2 2000-02-02
2000-02-02T11:11:11
+3 2000-03-02 2000-03-02T11:11:11 3 2000-03-02
2000-03-02T11:11:11
+
+-- !sql2 --
+1 2000-01-01 2000-01-01T11:11:11 1 2000-01-01
2000-01-01T11:11:11
+2 2000-02-02 2000-02-02T11:11:11 2 2000-02-02
2000-02-02T11:11:11
+3 2000-03-02 2000-03-02T11:11:11 3 2000-03-02
2000-03-02T11:11:11
+
+-- !sql2 --
+1 2000-01-01 2000-01-01T11:11:11 1 2000-01-01
2000-01-01T11:11:11
+2 2000-02-02 2000-02-02T11:11:11 2 2000-02-02
2000-02-02T11:11:11
+3 2000-03-02 2000-03-02T11:11:11 3 2000-03-02
2000-03-02T11:11:11
+
diff --git
a/regression-test/suites/datatype_p0/date/test_date_runtime_filter.groovy
b/regression-test/suites/datatype_p0/date/test_date_runtime_filter.groovy
new file mode 100644
index 0000000000..f1526c1517
--- /dev/null
+++ b/regression-test/suites/datatype_p0/date/test_date_runtime_filter.groovy
@@ -0,0 +1,49 @@
+
+// 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_runtime_filter") {
+ def tbName = "test_date_runtime_filter"
+ sql "DROP TABLE IF EXISTS ${tbName}"
+ sql """
+ CREATE TABLE IF NOT EXISTS ${tbName} (
+ c0 int,
+ c2 date,
+ c3 datetime
+ )
+ DISTRIBUTED BY HASH(c0) BUCKETS 5 properties("replication_num" =
"1");
+ """
+ sql "insert into ${tbName} values(1, '2000-01-01', '2000-01-01 11:11:11')"
+ sql "insert into ${tbName} values(2, '2000-02-02', '2000-02-02 11:11:11')"
+ sql "insert into ${tbName} values(3, '2000-03-02', '2000-03-02 11:11:11')"
+
+ qt_sql1 "select * from ${tbName} ORDER BY c2"
+
+ sql " set runtime_filter_type = 1; "
+ qt_sql2 "select * from ${tbName} a, ${tbName} b WHERE a.c3 = b.c3 ORDER BY
a.c2"
+
+ sql " set runtime_filter_type = 2; "
+ qt_sql2 "select * from ${tbName} a, ${tbName} b WHERE a.c3 = b.c3 ORDER BY
a.c2"
+
+ sql " set runtime_filter_type = 4; "
+ qt_sql2 "select * from ${tbName} a, ${tbName} b WHERE a.c3 = b.c3 ORDER BY
a.c2"
+
+ sql " set runtime_filter_type = 8; "
+ qt_sql2 "select * from ${tbName} a, ${tbName} b WHERE a.c3 = b.c3 ORDER BY
a.c2"
+
+ sql "DROP TABLE ${tbName}"
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]