You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by ga...@apache.org on 2023/01/20 14:25:28 UTC
[doris] branch master updated: [fix](datetimev2) Fix BE datetimev2 type returning wrong result (#15885)
This is an automated email from the ASF dual-hosted git repository.
gabriellee pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 9ffd109b35 [fix](datetimev2) Fix BE datetimev2 type returning wrong result (#15885)
9ffd109b35 is described below
commit 9ffd109b35ffbdf9e91e8918c5fd7629f0dddd4e
Author: abmdocrt <Yu...@gmail.com>
AuthorDate: Fri Jan 20 22:25:20 2023 +0800
[fix](datetimev2) Fix BE datetimev2 type returning wrong result (#15885)
---
be/src/vec/sink/vmysql_result_writer.cpp | 15 ++++++++----
.../array_functions/test_array_functions.out | 12 ++++++++++
.../array_functions/test_array_functions.groovy | 27 ++++++++++++++++++++++
3 files changed, 50 insertions(+), 4 deletions(-)
diff --git a/be/src/vec/sink/vmysql_result_writer.cpp b/be/src/vec/sink/vmysql_result_writer.cpp
index 7aca6801be..2757b60358 100644
--- a/be/src/vec/sink/vmysql_result_writer.cpp
+++ b/be/src/vec/sink/vmysql_result_writer.cpp
@@ -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()) {
diff --git a/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions.out b/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions.out
index e0bb00b0e0..d8fb5e32af 100644
--- a/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions.out
+++ b/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions.out
@@ -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]
+
diff --git a/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions.groovy b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions.groovy
index d9b4c6cb6c..9456e01540 100644
--- a/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions.groovy
+++ b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions.groovy
@@ -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}"
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org