[fix](datetimev2) Fix BE datetimev2 type returning wrong result (#15885)

This commit is contained in:
abmdocrt
2023-01-20 22:25:20 +08:00
committed by GitHub
parent 6b110aeba6
commit 9ffd109b35
3 changed files with 50 additions and 4 deletions

View File

@ -337,8 +337,7 @@ int VMysqlResultWriter<is_binary_format>::_add_one_cell(const ColumnPtr& column_
} else if (which.is_date_or_datetime()) {
auto& column_vector = assert_cast<const ColumnVector<Int64>&>(*column);
auto value = column_vector[row_idx].get<Int64>();
VecDateTimeValue datetime;
memcpy(static_cast<void*>(&datetime), static_cast<void*>(&value), sizeof(value));
VecDateTimeValue datetime = binary_cast<Int64, VecDateTimeValue>(value);
if (which.is_date()) {
datetime.cast_to_date();
}
@ -348,11 +347,19 @@ int VMysqlResultWriter<is_binary_format>::_add_one_cell(const ColumnPtr& column_
} else if (which.is_date_v2()) {
auto& column_vector = assert_cast<const ColumnVector<UInt32>&>(*column);
auto value = column_vector[row_idx].get<UInt32>();
DateV2Value<DateV2ValueType> datev2;
memcpy(static_cast<void*>(&datev2), static_cast<void*>(&value), sizeof(value));
DateV2Value<DateV2ValueType> datev2 =
binary_cast<UInt32, DateV2Value<DateV2ValueType>>(value);
char buf[64];
char* pos = datev2.to_string(buf);
return buffer.push_string(buf, pos - buf - 1);
} else if (which.is_date_time_v2()) {
auto& column_vector = assert_cast<const ColumnVector<UInt64>&>(*column);
auto value = column_vector[row_idx].get<UInt64>();
DateV2Value<DateTimeV2ValueType> datetimev2 =
binary_cast<UInt64, DateV2Value<DateTimeV2ValueType>>(value);
char buf[64];
char* pos = datetimev2.to_string(buf);
return buffer.push_string(buf, pos - buf - 1);
} else if (which.is_decimal32()) {
DataTypePtr nested_type = type;
if (type->is_nullable()) {

View File

@ -589,3 +589,15 @@
10005 [10005, NULL, NULL] [NULL]
10006 [60002, 60002, 60003, NULL, 60005] [NULL]
-- !select_array_datetimev2_1 --
1 [2023-01-19 18:11:11.111100, 2023-01-19 18:22:22.222200, 2023-01-19 18:33:33.333300] [2023-01-19 18:22:22.222200, 2023-01-19 18:33:33.333300, 2023-01-19 18:44:44.444400] [2023-01-19 18:11:11.111111, 2023-01-19 18:22:22.222222, 2023-01-19 18:33:33.333333]
-- !select_array_datetimev2_2 --
[2023-01-19 18:11:11.111100, 2023-01-19 18:22:22.222200, 2023-01-19 18:33:33.333300]
-- !select_array_datetimev2_3 --
[2023-01-19 18:22:22.222200, 2023-01-19 18:33:33.333300, 2023-01-19 18:44:44.444400]
-- !select_array_datetimev2_4 --
[2023-01-19 18:11:11.111111, 2023-01-19 18:22:22.222222, 2023-01-19 18:33:33.333333]

View File

@ -151,4 +151,31 @@ suite("test_array_functions") {
qt_select_union "select class_id, student_ids, array_union(student_ids,[1,2,3]) from ${tableName3} order by class_id;"
qt_select_except "select class_id, student_ids, array_except(student_ids,[1,2,3]) from ${tableName3} order by class_id;"
qt_select_intersect "select class_id, student_ids, array_intersect(student_ids,[1,2,3,null]) from ${tableName3} order by class_id;"
def tableName4 = "tbl_test_array_datetimev2_functions"
sql """DROP TABLE IF EXISTS ${tableName4}"""
sql """
CREATE TABLE IF NOT EXISTS ${tableName4} (
`k1` int COMMENT "",
`k2` ARRAY<datetimev2(4)> COMMENT "",
`k3` ARRAY<datetimev2(4)> COMMENT "",
`k4` ARRAY<datetimev2(6)> COMMENT ""
) ENGINE=OLAP
DUPLICATE KEY(`k1`)
DISTRIBUTED BY HASH(`k1`) BUCKETS 1
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"storage_format" = "V2"
)
"""
sql """ INSERT INTO ${tableName4} VALUES(1,
["2023-01-19 18:11:11.1111","2023-01-19 18:22:22.2222","2023-01-19 18:33:33.3333"],
["2023-01-19 18:22:22.2222","2023-01-19 18:33:33.3333","2023-01-19 18:44:44.4444"],
["2023-01-19 18:11:11.111111","2023-01-19 18:22:22.222222","2023-01-19 18:33:33.333333"]) """
qt_select_array_datetimev2_1 "SELECT * FROM ${tableName4}"
qt_select_array_datetimev2_2 "SELECT if(1,k2,k3) FROM ${tableName4}"
qt_select_array_datetimev2_3 "SELECT if(0,k2,k3) FROM ${tableName4}"
qt_select_array_datetimev2_4 "SELECT if(0,k2,k4) FROM ${tableName4}"
}