diff --git a/be/src/runtime/fold_constant_executor.cpp b/be/src/runtime/fold_constant_executor.cpp index e5fd16418d..c3dd21406e 100644 --- a/be/src/runtime/fold_constant_executor.cpp +++ b/be/src/runtime/fold_constant_executor.cpp @@ -195,6 +195,11 @@ string FoldConstantExecutor::_get_result(void* src, size_t size, const TypeDescr double val = *reinterpret_cast(src); return fmt::format("{}", val); } + case TYPE_TIMEV2: { + constexpr static auto ratio_to_time = (1000 * 1000); + double val = *reinterpret_cast(src); + return fmt::format("{}", val / ratio_to_time); + } case TYPE_CHAR: case TYPE_VARCHAR: case TYPE_STRING: diff --git a/regression-test/data/correctness/test_timev2_fold.out b/regression-test/data/correctness/test_timev2_fold.out new file mode 100644 index 0000000000..b070f10507 --- /dev/null +++ b/regression-test/data/correctness/test_timev2_fold.out @@ -0,0 +1,13 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select1 -- +-07:00:00 + +-- !select2 -- +-07:00:00 + +-- !select3 -- +-07:00:00 + +-- !select4 -- +-07:00:00 + diff --git a/regression-test/suites/correctness/test_timev2_fold.groovy b/regression-test/suites/correctness/test_timev2_fold.groovy new file mode 100644 index 0000000000..8ce0576516 --- /dev/null +++ b/regression-test/suites/correctness/test_timev2_fold.groovy @@ -0,0 +1,35 @@ +// 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_timev2_fold") { + sql """ set enable_nereids_planner=false,enable_fold_constant_by_be=false """ + qt_select1 """ + select timediff( convert_tz("2020-05-05 00:00:00", 'UTC', 'America/Los_Angeles'), "2020-05-05 00:00:00"); + """ + sql """ set enable_nereids_planner=true,enable_fold_constant_by_be=false """ + qt_select2 """ + select timediff( convert_tz("2020-05-05 00:00:00", 'UTC', 'America/Los_Angeles'), "2020-05-05 00:00:00"); + """ + sql """ set enable_nereids_planner=false,enable_fold_constant_by_be=true """ + qt_select3 """ + select timediff( convert_tz("2020-05-05 00:00:00", 'UTC', 'America/Los_Angeles'), "2020-05-05 00:00:00"); + """ + sql """ set enable_nereids_planner=true,enable_fold_constant_by_be=true """ + qt_select4 """ + select timediff( convert_tz("2020-05-05 00:00:00", 'UTC', 'America/Los_Angeles'), "2020-05-05 00:00:00"); + """ +} \ No newline at end of file