Skip to content

Commit

Permalink
[fix](function) Fix wrong nullable processing for convert_tz (#38764)
Browse files Browse the repository at this point in the history
## Proposed changes

Issue Number: close #xxx

This pr make `convert_tz` use default nullity processing logic rather
than `update_null_map` manually to get correct result. The bug of
`update_null_map` will be fixed by
#38787

before:
```sql
mysql> select convert_tz(dt, '+00:00', IF(property_value IS NULL, '+00:00', property_value)) from cvt_tz;
+--------------------------------------------------------------------------------+
| convert_tz(dt, '+00:00', if(property_value IS NULL, '+00:00', property_value)) |
+--------------------------------------------------------------------------------+
| 2024-04-18 23:20:00                                                            |
|                                                                                |
|                                                                                |
| 2024-04-18 23:20:00                                                            |
|                                                                                |
|                                                                                |
| 2024-04-18 23:20:00                                                            |
|                                                                                |
| 2024-04-18 23:20:00                                                            |
|                                                                                |
| 2024-04-18 23:20:00                                                            |
| 2024-04-18 23:20:00                                                            |
|                                                                                |
|                                                                                |
| 2024-04-18 23:20:00                                                            |
|                                                                                |
| 2024-04-18 23:20:00                                                            |
| 2024-04-18 23:20:00                                                            |
|                                                                                |
| 2024-04-18 23:20:00                                                            |
+--------------------------------------------------------------------------------+
```

after:
```sql
mysql> select convert_tz(dt, '+00:00', IF(property_value IS NULL, '+00:00', property_value)) from cvt_tz;
+--------------------------------------------------------------------------------+
| convert_tz(dt, '+00:00', if(property_value IS NULL, '+00:00', property_value)) |
+--------------------------------------------------------------------------------+
| 2024-04-18 23:20:00                                                            |
| 2024-04-18 23:20:00                                                            |
| 2024-04-18 23:20:00                                                            |
| 2024-04-18 23:20:00                                                            |
| 2024-04-18 23:20:00                                                            |
| 2024-04-18 23:20:00                                                            |
| 2024-04-18 23:20:00                                                            |
| 2024-04-18 23:20:00                                                            |
| 2024-04-18 23:20:00                                                            |
| 2024-04-18 23:20:00                                                            |
| 2024-04-18 23:20:00                                                            |
| 2024-04-18 23:20:00                                                            |
| 2024-04-18 23:20:00                                                            |
| 2024-04-18 23:20:00                                                            |
| 2024-04-18 23:20:00                                                            |
| 2024-04-18 23:20:00                                                            |
| 2024-04-18 23:20:00                                                            |
| 2024-04-18 23:20:00                                                            |
| 2024-04-18 23:20:00                                                            |
| 2024-04-18 23:20:00                                                            |
+--------------------------------------------------------------------------------+
```
  • Loading branch information
zclllyybb authored Aug 5, 2024
1 parent d848afb commit c60c8f5
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 10 deletions.
10 changes: 0 additions & 10 deletions be/src/vec/functions/function_convert_tz.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,6 @@ class FunctionConvertTZ : public IFunction {
std::make_shared<DataTypeString>()};
}

bool use_default_implementation_for_nulls() const override { return false; }

Status close(FunctionContext* context, FunctionContext::FunctionStateScope scope) override {
return Status::OK();
}

Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
size_t result, size_t input_rows_count) const override {
auto result_null_map_column = ColumnUInt8::create(input_rows_count, 0);
Expand All @@ -110,10 +104,6 @@ class FunctionConvertTZ : public IFunction {

default_preprocess_parameter_columns(argument_columns, col_const, {1, 2}, block, arguments);

for (int i = 0; i < 3; i++) {
check_set_nullable(argument_columns[i], result_null_map_column, col_const[i]);
}

if (col_const[1] && col_const[2]) {
auto result_column = ColumnType::create();
execute_tz_const(context, assert_cast<const ColumnType*>(argument_columns[0].get()),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql1 --
2024-04-18T23:20
2024-04-18T23:20
2024-04-18T23:20
2024-04-18T23:20
2024-04-18T23:20
2024-04-18T23:20
2024-04-18T23:20
2024-04-18T23:20
2024-04-18T23:20
2024-04-18T23:20
2024-04-18T23:20
2024-04-18T23:20
2024-04-18T23:20
2024-04-18T23:20
2024-04-18T23:20
2024-04-18T23:20
2024-04-18T23:20
2024-04-18T23:20
2024-04-18T23:20
2024-04-18T23:20

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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_convert_tz") {
sql """
CREATE TABLE `cvt_tz` (
`rowid` int NULL,
`dt` datetime NULL,
`property_value` varchar(65533) NULL
) ENGINE=OLAP
DUPLICATE KEY(`rowid`, `dt`, `property_value`)
DISTRIBUTED BY HASH(`rowid`) BUCKETS 10
PROPERTIES (
"replication_allocation" = "tag.location.default: 1"
);
"""

sql """insert into cvt_tz select number, "2024-04-18 23:20:00", NULL from numbers("number" = "20"); """

order_qt_sql1 """
select convert_tz(dt, '+00:00', IF(property_value IS NULL, '+00:00', property_value)) from cvt_tz
"""
}

0 comments on commit c60c8f5

Please sign in to comment.