From 1121965ce4c043db12dad76ef107add66735a234 Mon Sep 17 00:00:00 2001 From: Mryange <59914473+Mryange@users.noreply.github.com> Date: Mon, 29 Jul 2024 10:35:55 +0800 Subject: [PATCH 1/2] [fix](type)support runtime predicate for time type (#38258) --- be/src/exec/olap_common.h | 3 ++ be/src/runtime/runtime_predicate.cpp | 10 +++++ be/src/vec/runtime/time_value.h | 38 +++++++++++++++++++ .../test_time_in_runtimepredicate.out | 12 ++++++ .../test_time_in_runtimepredicate.groovy | 30 +++++++++++++++ 5 files changed, 93 insertions(+) create mode 100644 be/src/vec/runtime/time_value.h create mode 100644 regression-test/data/datatype_p0/time_type/test_time_in_runtimepredicate.out create mode 100644 regression-test/suites/datatype_p0/time_type/test_time_in_runtimepredicate.groovy diff --git a/be/src/exec/olap_common.h b/be/src/exec/olap_common.h index 4035aa893b9bbf..d66cde2fad3689 100644 --- a/be/src/exec/olap_common.h +++ b/be/src/exec/olap_common.h @@ -43,6 +43,7 @@ #include "runtime/type_limit.h" #include "vec/core/types.h" #include "vec/io/io_helper.h" +#include "vec/runtime/time_value.h" #include "vec/runtime/vdatetime_value.h" namespace doris { @@ -68,6 +69,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 { return boost::lexical_cast(value); } diff --git a/be/src/runtime/runtime_predicate.cpp b/be/src/runtime/runtime_predicate.cpp index 075ae1d11579e9..2bd0aac9c178d6 100644 --- a/be/src/runtime/runtime_predicate.cpp +++ b/be/src/runtime/runtime_predicate.cpp @@ -31,6 +31,12 @@ namespace doris { namespace vectorized { +std::string get_time_value(const Field& field) { + using ValueType = typename PrimitiveTypeTraits::CppType; + ValueType value = field.get(); + return cast_to_string(value, 0); +} + Status RuntimePredicate::init(const PrimitiveType type, const bool nulls_first) { std::unique_lock wlock(_rwlock); @@ -98,6 +104,10 @@ Status RuntimePredicate::init(const PrimitiveType type, const bool nulls_first) _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_decimal32_value; break; diff --git a/be/src/vec/runtime/time_value.h b/be/src/vec/runtime/time_value.h new file mode 100644 index 00000000000000..8283e12f8afff0 --- /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 + +#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::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 00000000000000..6f3daa0f45ccc1 --- /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 00000000000000..3c051593c02444 --- /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 limit 3" +} From 9722d1bb01efcc36aa216cbecf8d1ee750a8c134 Mon Sep 17 00:00:00 2001 From: Mryange <59914473+Mryange@users.noreply.github.com> Date: Tue, 30 Jul 2024 10:24:33 +0800 Subject: [PATCH 2/2] [env](case) fix error case without order by (#38483) ## Proposed changes Issue Number: close #xxx --- .../datatype_p0/time_type/test_time_in_runtimepredicate.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 3c051593c02444..0496192963c2e7 100644 --- 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 @@ -26,5 +26,5 @@ suite("test_time_in_runtimepredicate") { 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 limit 3" + qt_sql2 "select timediff(a, b) as t, count(c) from test_time_in_runtimepredicate group by t order by t limit 3;" }