## Proposed changes https://github.com/apache/doris/pull/38258 Issue Number: close #xxx <!--Describe your changes.-->
This commit is contained in:
@ -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) {
|
||||
|
||||
@ -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;
|
||||
|
||||
38
be/src/vec/runtime/time_value.h
Normal file
38
be/src/vec/runtime/time_value.h
Normal file
@ -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
|
||||
@ -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
|
||||
|
||||
@ -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;"
|
||||
}
|
||||
Reference in New Issue
Block a user