From 6686c9bc0523aa44e80a325225afe6e9edf52cd0 Mon Sep 17 00:00:00 2001 From: Mryange <2319153948@qq.com> Date: Tue, 23 Jul 2024 18:00:16 +0800 Subject: [PATCH] upd --- 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 778444346d3d4c..c2199cd6be9360 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 b746ffabb3b23b..23130811a8ccfb 100644 --- a/be/src/runtime/runtime_predicate.cpp +++ b/be/src/runtime/runtime_predicate.cpp @@ -92,6 +92,12 @@ std::string get_datetime_value(const Field& field) { return cast_to_string(value, 0); } +std::string get_time_value(const Field& field) { + using ValueType = typename PrimitiveTypeTraits::CppType; + ValueType value = field.get(); + return cast_to_string(value, 0); +} + std::string get_decimalv2_value(const Field& field) { // can NOT use PrimitiveTypeTraits::CppType since // it is DecimalV2Value and Decimal128V2 can not convert to it implicitly @@ -158,6 +164,10 @@ bool RuntimePredicate::_init(PrimitiveType type) { _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; 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" +}