Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions be/src/exec/olap_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions be/src/runtime/runtime_predicate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ std::string get_datetime_value(const Field& field) {
return cast_to_string<TYPE_DATETIME, ValueType>(value, 0);
}

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);
}

std::string get_decimalv2_value(const Field& field) {
// can NOT use PrimitiveTypeTraits<TYPE_DECIMALV2>::CppType since
// it is DecimalV2Value and Decimal128V2 can not convert to it implicitly
Expand Down Expand Up @@ -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<TYPE_DECIMAL32>;
break;
Expand Down
38 changes: 38 additions & 0 deletions be/src/vec/runtime/time_value.h
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -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"
}