You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by yi...@apache.org on 2024/07/31 02:27:44 UTC
(doris) branch branch-2.1 updated: [fix](type)support runtime predicate for time type (#38258) (#38465)
This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new 017dad8c540 [fix](type)support runtime predicate for time type (#38258) (#38465)
017dad8c540 is described below
commit 017dad8c54087468ec2a6780d77c575d83a3da85
Author: Mryange <59...@users.noreply.github.com>
AuthorDate: Wed Jul 31 10:27:36 2024 +0800
[fix](type)support runtime predicate for time type (#38258) (#38465)
## Proposed changes
https://github.com/apache/doris/pull/38258
Issue Number: close #xxx
<!--Describe your changes.-->
---
be/src/exec/olap_common.h | 3 ++
be/src/runtime/runtime_predicate.cpp | 10 ++++++
be/src/vec/runtime/time_value.h | 38 ++++++++++++++++++++++
.../time_type/test_time_in_runtimepredicate.out | 12 +++++++
.../time_type/test_time_in_runtimepredicate.groovy | 30 +++++++++++++++++
5 files changed, 93 insertions(+)
diff --git a/be/src/exec/olap_common.h b/be/src/exec/olap_common.h
index 778444346d3..c2199cd6be9 100644
--- a/be/src/exec/olap_common.h
+++ b/be/src/exec/olap_common.h
@@ -44,6 +44,7 @@
#include "vec/io/io_helper.h"
#include "vec/runtime/ipv4_value.h"
#include "vec/runtime/ipv6_value.h"
+#include "vec/runtime/time_value.h"
#include "vec/runtime/vdatetime_value.h"
namespace doris {
@@ -70,6 +71,8 @@ std::string cast_to_string(T value, int scale) {
std::stringstream ss;
ss << buf;
return ss.str();
+ } else if constexpr (primitive_type == TYPE_TIMEV2) {
+ return TimeValue::to_string(value, scale);
} else if constexpr (primitive_type == TYPE_IPV4) {
return IPv4Value::to_string(value);
} else if constexpr (primitive_type == TYPE_IPV6) {
diff --git a/be/src/runtime/runtime_predicate.cpp b/be/src/runtime/runtime_predicate.cpp
index 032a5d505c9..f534ae12371 100644
--- a/be/src/runtime/runtime_predicate.cpp
+++ b/be/src/runtime/runtime_predicate.cpp
@@ -28,6 +28,12 @@
namespace doris::vectorized {
+std::string get_time_value(const Field& field) {
+ using ValueType = typename PrimitiveTypeTraits<TYPE_TIMEV2>::CppType;
+ ValueType value = field.get<ValueType>();
+ return cast_to_string<TYPE_TIMEV2, ValueType>(value, 0);
+}
+
Status RuntimePredicate::init(PrimitiveType type, bool nulls_first, bool is_asc,
const std::string& col_name) {
std::unique_lock<std::shared_mutex> wlock(_rwlock);
@@ -94,6 +100,10 @@ Status RuntimePredicate::init(PrimitiveType type, bool nulls_first, bool is_asc,
_get_value_fn = get_datetime_value;
break;
}
+ case PrimitiveType::TYPE_TIMEV2: {
+ _get_value_fn = get_time_value;
+ break;
+ }
case PrimitiveType::TYPE_DECIMAL32: {
_get_value_fn = get_decimal_value<TYPE_DECIMAL32>;
break;
diff --git a/be/src/vec/runtime/time_value.h b/be/src/vec/runtime/time_value.h
new file mode 100644
index 00000000000..8283e12f8af
--- /dev/null
+++ b/be/src/vec/runtime/time_value.h
@@ -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.
+
+#pragma once
+
+#include <string>
+
+#include "runtime/define_primitive_type.h"
+#include "runtime/primitive_type.h"
+#include "util/date_func.h"
+
+namespace doris {
+
+/// TODO: Due to the "Time type is not supported for OLAP table" issue, a lot of basic content is missing.It will be supplemented later.
+class TimeValue {
+ using TimeType = typename PrimitiveTypeTraits<TYPE_TIMEV2>::CppType;
+
+public:
+ static std::string to_string(TimeType time, int scale) {
+ return timev2_to_buffer_from_double(time, scale);
+ }
+};
+
+} // namespace doris
diff --git a/regression-test/data/datatype_p0/time_type/test_time_in_runtimepredicate.out b/regression-test/data/datatype_p0/time_type/test_time_in_runtimepredicate.out
new file mode 100644
index 00000000000..6f3daa0f45c
--- /dev/null
+++ b/regression-test/data/datatype_p0/time_type/test_time_in_runtimepredicate.out
@@ -0,0 +1,12 @@
+-- This file is automatically generated. You should know what you did if you want to edit this
+-- !sql1 --
+-24:47:22 1
+-02:47:22 1
+-01:47:22 1
+47:12:38 2
+
+-- !sql2 --
+-24:47:22 1
+-02:47:22 1
+-01:47:22 1
+
diff --git a/regression-test/suites/datatype_p0/time_type/test_time_in_runtimepredicate.groovy b/regression-test/suites/datatype_p0/time_type/test_time_in_runtimepredicate.groovy
new file mode 100644
index 00000000000..0496192963c
--- /dev/null
+++ b/regression-test/suites/datatype_p0/time_type/test_time_in_runtimepredicate.groovy
@@ -0,0 +1,30 @@
+
+// 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_time_in_runtimepredicate") {
+ def tbName = "test_time_in_runtimepredicate"
+ sql """ DROP TABLE IF EXISTS test_time_in_runtimepredicate """
+ sql """
+ create table test_time_in_runtimepredicate(a date, b datetime, c int) properties ("replication_allocation" = "tag.location.default: 1");
+ """
+ sql """insert into test_time_in_runtimepredicate values ("2023-12-18", "2023-12-18 01:47:22", 1), ("2023-12-18", "2023-12-18 02:47:22", 2) , ("2023-12-17", "2023-12-18 00:47:22", 3), ("2023-12-20", "2023-12-18 00:47:22", 4) , ("2023-12-20", "2023-12-18 00:47:22", 5);"""
+
+
+ qt_sql1 "select timediff(a, b) as t, count(c) from test_time_in_runtimepredicate group by t order by t;"
+ qt_sql2 "select timediff(a, b) as t, count(c) from test_time_in_runtimepredicate group by t order by t limit 3;"
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org