diff --git a/be/src/vec/sink/vmysql_result_writer.cpp b/be/src/vec/sink/vmysql_result_writer.cpp index 2757b60358..31871b6c36 100644 --- a/be/src/vec/sink/vmysql_result_writer.cpp +++ b/be/src/vec/sink/vmysql_result_writer.cpp @@ -173,10 +173,10 @@ Status VMysqlResultWriter::_add_one_column( } else { if (WhichDataType(remove_nullable(nested_type_ptr)).is_string()) { buf_ret = rows_buffer[i].push_string("'", 1); - buf_ret = _add_one_cell(data, j, nested_type_ptr, rows_buffer[i]); + buf_ret = _add_one_cell(data, j, nested_type_ptr, rows_buffer[i], scale); buf_ret = rows_buffer[i].push_string("'", 1); } else { - buf_ret = _add_one_cell(data, j, nested_type_ptr, rows_buffer[i]); + buf_ret = _add_one_cell(data, j, nested_type_ptr, rows_buffer[i], scale); } } begin = false; @@ -247,21 +247,22 @@ Status VMysqlResultWriter::_add_one_column( } if constexpr (type == TYPE_DATETIME) { auto time_num = data[i]; - VecDateTimeValue time_val; - memcpy(static_cast(&time_val), &time_num, sizeof(Int64)); + VecDateTimeValue time_val = binary_cast(time_num); buf_ret = rows_buffer[i].push_vec_datetime(time_val); } if constexpr (type == TYPE_DATEV2) { auto time_num = data[i]; - doris::vectorized::DateV2Value date_val; - memcpy(static_cast(&date_val), &time_num, sizeof(UInt32)); + DateV2Value date_val = + binary_cast>(time_num); buf_ret = rows_buffer[i].push_vec_datetime(date_val); } if constexpr (type == TYPE_DATETIMEV2) { auto time_num = data[i]; - doris::vectorized::DateV2Value date_val; - memcpy(static_cast(&date_val), &time_num, sizeof(UInt64)); - buf_ret = rows_buffer[i].push_vec_datetime(date_val); + char buf[64]; + DateV2Value date_val = + binary_cast>(time_num); + char* pos = date_val.to_string(buf, scale); + buf_ret = rows_buffer[i].push_string(buf, pos - buf - 1); } if constexpr (type == TYPE_DECIMALV2) { DecimalV2Value decimal_val(data[i]); @@ -280,7 +281,8 @@ Status VMysqlResultWriter::_add_one_column( template int VMysqlResultWriter::_add_one_cell(const ColumnPtr& column_ptr, size_t row_idx, const DataTypePtr& type, - MysqlRowBuffer& buffer) { + MysqlRowBuffer& buffer, + int scale) { WhichDataType which(type->get_type_id()); if (which.is_nullable() && column_ptr->is_null_at(row_idx)) { return buffer.push_null(); @@ -358,7 +360,7 @@ int VMysqlResultWriter::_add_one_cell(const ColumnPtr& column_ DateV2Value datetimev2 = binary_cast>(value); char buf[64]; - char* pos = datetimev2.to_string(buf); + char* pos = datetimev2.to_string(buf, scale); return buffer.push_string(buf, pos - buf - 1); } else if (which.is_decimal32()) { DataTypePtr nested_type = type; @@ -672,16 +674,19 @@ Status VMysqlResultWriter::append_block(Block& input_block) { break; } case TYPE_ARRAY: { + // Currently all functions only support single-level nested arrays, + // so we use Array's child scale to represent the scale of nested type. + scale = _output_vexpr_ctxs[i]->root()->type().children[0].scale; if (type_ptr->is_nullable()) { auto& nested_type = assert_cast(*type_ptr).get_nested_type(); auto& sub_type = assert_cast(*nested_type).get_nested_type(); - status = _add_one_column(column_ptr, result, - rows_buffer, sub_type); + status = _add_one_column( + column_ptr, result, rows_buffer, sub_type, scale); } else { auto& sub_type = assert_cast(*type_ptr).get_nested_type(); - status = _add_one_column(column_ptr, result, - rows_buffer, sub_type); + status = _add_one_column( + column_ptr, result, rows_buffer, sub_type, scale); } break; } diff --git a/be/src/vec/sink/vmysql_result_writer.h b/be/src/vec/sink/vmysql_result_writer.h index 178fa585d4..58282d413c 100644 --- a/be/src/vec/sink/vmysql_result_writer.h +++ b/be/src/vec/sink/vmysql_result_writer.h @@ -56,7 +56,7 @@ private: std::vector>& rows_buffer, const DataTypePtr& nested_type_ptr = nullptr, int scale = -1); int _add_one_cell(const ColumnPtr& column_ptr, size_t row_idx, const DataTypePtr& type, - MysqlRowBuffer& buffer); + MysqlRowBuffer& buffer, int scale = -1); private: BufferControlBlock* _sinker; diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java index 80439ac65d..203b0d0696 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java @@ -546,6 +546,7 @@ public class DateLiteral extends LiteralExpr { if (type.isDate() || type.isDateV2()) { return String.format("%04d-%02d-%02d", year, month, day); } else if (type.isDatetimeV2()) { + int scale = ((ScalarType) type).getScalarScale(); long ms = Double.valueOf(microsecond / (int) (Math.pow(10, 6 - ((ScalarType) type).getScalarScale())) * (Math.pow(10, 6 - ((ScalarType) type).getScalarScale()))).longValue(); String tmp = String.format("%04d-%02d-%02d %02d:%02d:%02d", @@ -553,7 +554,7 @@ public class DateLiteral extends LiteralExpr { if (ms == 0) { return tmp; } - return tmp + String.format(".%06d", ms); + return tmp + String.format(".%06d", ms).substring(0, scale + 1); } else { return String.format("%04d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, minute, second); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java index 4eb0895990..17eebe567a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java @@ -91,6 +91,9 @@ public class FunctionCallExpr extends Expr { } else if (children != null && children.size() > 0 && children.get(0).getType().isDatetimeV2() && returnType.isDatetimeV2()) { return children.get(0).getType(); + } else if (children != null && children.size() > 0 && children.get(0).getType().isDecimalV2() + && returnType.isDecimalV2()) { + return children.get(0).getType(); } else { return returnType; } @@ -146,6 +149,30 @@ public class FunctionCallExpr extends Expr { } }); + PRECISION_INFER_RULE.put("array_min", (children, returnType) -> { + Preconditions.checkArgument(children != null && children.size() > 0); + if (children.get(0).getType().isArrayType() && ( + ((ArrayType) children.get(0).getType()).getItemType().isDecimalV3() || ((ArrayType) children.get(0) + .getType()).getItemType().isDecimalV2() || ((ArrayType) children.get(0) + .getType()).getItemType().isDatetimeV2())) { + return ((ArrayType) children.get(0).getType()).getItemType(); + } else { + return returnType; + } + }); + + PRECISION_INFER_RULE.put("array_max", (children, returnType) -> { + Preconditions.checkArgument(children != null && children.size() > 0); + if (children.get(0).getType().isArrayType() && ( + ((ArrayType) children.get(0).getType()).getItemType().isDecimalV3() || ((ArrayType) children.get(0) + .getType()).getItemType().isDecimalV2() || ((ArrayType) children.get(0) + .getType()).getItemType().isDatetimeV2())) { + return ((ArrayType) children.get(0).getType()).getItemType(); + } else { + return returnType; + } + }); + PRECISION_INFER_RULE.put("round", roundRule); PRECISION_INFER_RULE.put("round_bankers", roundRule); PRECISION_INFER_RULE.put("ceil", roundRule); @@ -1338,6 +1365,20 @@ public class FunctionCallExpr extends Expr { if (fnName.getFunction().equalsIgnoreCase("money_format") && children.get(0).getType().isDecimalV3() && args[ix].isDecimalV3()) { continue; + } else if (fnName.getFunction().equalsIgnoreCase("array") + && (children.get(0).getType().isDecimalV3() && args[ix].isDecimalV3() + || children.get(0).getType().isDatetimeV2() && args[ix].isDatetimeV2())) { + continue; + } else if ((fnName.getFunction().equalsIgnoreCase("array_min") || fnName.getFunction() + .equalsIgnoreCase("array_max")) + && (( + children.get(0).getType().isDecimalV3() && ((ArrayType) args[ix]).getItemType() + .isDecimalV3()) + || (children.get(0).getType().isDatetimeV2() + && ((ArrayType) args[ix]).getItemType().isDatetimeV2()) + || (children.get(0).getType().isDecimalV2() + && ((ArrayType) args[ix]).getItemType().isDecimalV2()))) { + continue; } else if (!argTypes[i].matchesType(args[ix]) && !( argTypes[i].isDateOrDateTime() && args[ix].isDateOrDateTime()) && (!fn.getReturnType().isDecimalV3() @@ -1413,7 +1454,7 @@ public class FunctionCallExpr extends Expr { // if return type is nested type, need to be determined the sub-element type private void analyzeNestedFunction() { // array - if ("array".equalsIgnoreCase(fnName.getFunction())) { + if (fnName.getFunction().equalsIgnoreCase("array")) { if (children.size() > 0) { this.type = new ArrayType(children.get(0).getType()); } diff --git a/fe/fe-core/src/test/java/org/apache/doris/rewrite/RewriteDateLiteralRuleTest.java b/fe/fe-core/src/test/java/org/apache/doris/rewrite/RewriteDateLiteralRuleTest.java index 40bc9bb2c3..55a875fd2d 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/rewrite/RewriteDateLiteralRuleTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/rewrite/RewriteDateLiteralRuleTest.java @@ -122,7 +122,7 @@ public class RewriteDateLiteralRuleTest { public void testWithStringFormatDateV2() throws Exception { String query = "select * from " + DB_NAME + ".tb2 where k1 > '2021030112334455'"; String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("`k1` > '2021-03-01 12:33:44.550000'")); + Assert.assertTrue(planString.contains("`k1` > '2021-03-01 12:33:44.550'")); query = "select k1 > '20210301' from " + DB_NAME + ".tb2"; planString = dorisAssert.query(query).explainQuery(); @@ -130,7 +130,7 @@ public class RewriteDateLiteralRuleTest { query = "select k1 > '20210301233234.34' from " + DB_NAME + ".tb2"; planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("`k1` > '2021-03-01 23:32:34.340000'")); + Assert.assertTrue(planString.contains("`k1` > '2021-03-01 23:32:34.340'")); query = "select * from " + DB_NAME + ".tb2 where k1 > '2021-03-01'"; planString = dorisAssert.query(query).explainQuery(); diff --git a/regression-test/data/compaction/test_compaction_uniq_keys_row_store.out b/regression-test/data/compaction/test_compaction_uniq_keys_row_store.out index 7c163c62d3..d73e9c1bb4 100644 --- a/regression-test/data/compaction/test_compaction_uniq_keys_row_store.out +++ b/regression-test/data/compaction/test_compaction_uniq_keys_row_store.out @@ -1,49 +1,49 @@ -- This file is automatically generated. You should know what you did if you want to edit this -- !point_select -- -1 2017-10-01 2017-10-01 2017-10-01T11:11:11.021 2017-10-01T11:11:11.011 Beijing 10 1 2020-01-01T00:00 2020-01-01T00:00 2017-10-01T11:11:11.170 2017-10-01T11:11:11.110111 2020-01-01T00:00 1 30 20 +1 2017-10-01 2017-10-01 2017-10-01 11:11:11.021 2017-10-01 11:11:11.011000 Beijing 10 1 2020-01-01T00:00 2020-01-01T00:00 2017-10-01 11:11:11.170 2017-10-01 11:11:11.110111 2020-01-01T00:00 1 30 20 -- !point_select -- -1 2017-10-01 2017-10-01 2017-10-01T11:11:11.022 2017-10-01T11:11:11.012 Beijing 10 1 2020-01-02T00:00 2020-01-02T00:00 2017-10-01T11:11:11.160 2017-10-01T11:11:11.100111 2020-01-02T00:00 1 31 19 +1 2017-10-01 2017-10-01 2017-10-01 11:11:11.022 2017-10-01 11:11:11.012000 Beijing 10 1 2020-01-02T00:00 2020-01-02T00:00 2017-10-01 11:11:11.160 2017-10-01 11:11:11.100111 2020-01-02T00:00 1 31 19 -- !point_select -- -2 2017-10-01 2017-10-01 2017-10-01T11:11:11.023 2017-10-01T11:11:11.013 Beijing 10 1 2020-01-02T00:00 2020-01-02T00:00 2017-10-01T11:11:11.150 2017-10-01T11:11:11.130111 2020-01-02T00:00 1 31 21 +2 2017-10-01 2017-10-01 2017-10-01 11:11:11.023 2017-10-01 11:11:11.013000 Beijing 10 1 2020-01-02T00:00 2020-01-02T00:00 2017-10-01 11:11:11.150 2017-10-01 11:11:11.130111 2020-01-02T00:00 1 31 21 -- !point_select -- -2 2017-10-01 2017-10-01 2017-10-01T11:11:11.024 2017-10-01T11:11:11.014 Beijing 10 1 2020-01-03T00:00 2020-01-03T00:00 2017-10-01T11:11:11.140 2017-10-01T11:11:11.120111 2020-01-03T00:00 1 32 20 +2 2017-10-01 2017-10-01 2017-10-01 11:11:11.024 2017-10-01 11:11:11.014000 Beijing 10 1 2020-01-03T00:00 2020-01-03T00:00 2017-10-01 11:11:11.140 2017-10-01 11:11:11.120111 2020-01-03T00:00 1 32 20 -- !point_select -- -3 2017-10-01 2017-10-01 2017-10-01T11:11:11.025 2017-10-01T11:11:11.015 Beijing 10 1 2020-01-03T00:00 2020-01-03T00:00 2017-10-01T11:11:11.100 2017-10-01T11:11:11.140111 2020-01-03T00:00 1 32 22 +3 2017-10-01 2017-10-01 2017-10-01 11:11:11.025 2017-10-01 11:11:11.015000 Beijing 10 1 2020-01-03T00:00 2020-01-03T00:00 2017-10-01 11:11:11.100 2017-10-01 11:11:11.140111 2020-01-03T00:00 1 32 22 -- !point_select -- -3 2017-10-01 2017-10-01 2017-10-01T11:11:11.026 2017-10-01T11:11:11.016 Beijing 10 1 2020-01-04T00:00 2020-01-04T00:00 2017-10-01T11:11:11.110 2017-10-01T11:11:11.150111 2020-01-04T00:00 1 33 21 +3 2017-10-01 2017-10-01 2017-10-01 11:11:11.026 2017-10-01 11:11:11.016000 Beijing 10 1 2020-01-04T00:00 2020-01-04T00:00 2017-10-01 11:11:11.110 2017-10-01 11:11:11.150111 2020-01-04T00:00 1 33 21 -- !point_select -- -3 2017-10-01 2017-10-01 2017-10-01T11:11:11.027 2017-10-01T11:11:11.017 Beijing 10 1 \N \N \N \N 2020-01-05T00:00 1 34 20 +3 2017-10-01 2017-10-01 2017-10-01 11:11:11.027 2017-10-01 11:11:11.017000 Beijing 10 1 \N \N \N \N 2020-01-05T00:00 1 34 20 -- !point_select -- -4 2017-10-01 2017-10-01 2017-10-01T11:11:11.028 2017-10-01T11:11:11.018 Beijing 10 1 \N \N \N \N 2020-01-05T00:00 1 34 20 +4 2017-10-01 2017-10-01 2017-10-01 11:11:11.028 2017-10-01 11:11:11.018000 Beijing 10 1 \N \N \N \N 2020-01-05T00:00 1 34 20 -- !point_select -- -1 2017-10-01 2017-10-01 2017-10-01T11:11:11.021 2017-10-01T11:11:11.011 Beijing 10 1 2020-01-01T00:00 2020-01-01T00:00 2017-10-01T11:11:11.170 2017-10-01T11:11:11.110111 2020-01-01T00:00 1 30 20 +1 2017-10-01 2017-10-01 2017-10-01 11:11:11.021 2017-10-01 11:11:11.011000 Beijing 10 1 2020-01-01T00:00 2020-01-01T00:00 2017-10-01 11:11:11.170 2017-10-01 11:11:11.110111 2020-01-01T00:00 1 30 20 -- !point_select -- -1 2017-10-01 2017-10-01 2017-10-01T11:11:11.022 2017-10-01T11:11:11.012 Beijing 10 1 2020-01-02T00:00 2020-01-02T00:00 2017-10-01T11:11:11.160 2017-10-01T11:11:11.100111 2020-01-02T00:00 1 31 19 +1 2017-10-01 2017-10-01 2017-10-01 11:11:11.022 2017-10-01 11:11:11.012000 Beijing 10 1 2020-01-02T00:00 2020-01-02T00:00 2017-10-01 11:11:11.160 2017-10-01 11:11:11.100111 2020-01-02T00:00 1 31 19 -- !point_select -- -2 2017-10-01 2017-10-01 2017-10-01T11:11:11.023 2017-10-01T11:11:11.013 Beijing 10 1 2020-01-02T00:00 2020-01-02T00:00 2017-10-01T11:11:11.150 2017-10-01T11:11:11.130111 2020-01-02T00:00 1 31 21 +2 2017-10-01 2017-10-01 2017-10-01 11:11:11.023 2017-10-01 11:11:11.013000 Beijing 10 1 2020-01-02T00:00 2020-01-02T00:00 2017-10-01 11:11:11.150 2017-10-01 11:11:11.130111 2020-01-02T00:00 1 31 21 -- !point_select -- -2 2017-10-01 2017-10-01 2017-10-01T11:11:11.024 2017-10-01T11:11:11.014 Beijing 10 1 2020-01-03T00:00 2020-01-03T00:00 2017-10-01T11:11:11.140 2017-10-01T11:11:11.120111 2020-01-03T00:00 1 32 20 +2 2017-10-01 2017-10-01 2017-10-01 11:11:11.024 2017-10-01 11:11:11.014000 Beijing 10 1 2020-01-03T00:00 2020-01-03T00:00 2017-10-01 11:11:11.140 2017-10-01 11:11:11.120111 2020-01-03T00:00 1 32 20 -- !point_select -- -3 2017-10-01 2017-10-01 2017-10-01T11:11:11.025 2017-10-01T11:11:11.015 Beijing 10 1 2020-01-03T00:00 2020-01-03T00:00 2017-10-01T11:11:11.100 2017-10-01T11:11:11.140111 2020-01-03T00:00 1 32 22 +3 2017-10-01 2017-10-01 2017-10-01 11:11:11.025 2017-10-01 11:11:11.015000 Beijing 10 1 2020-01-03T00:00 2020-01-03T00:00 2017-10-01 11:11:11.100 2017-10-01 11:11:11.140111 2020-01-03T00:00 1 32 22 -- !point_select -- -3 2017-10-01 2017-10-01 2017-10-01T11:11:11.026 2017-10-01T11:11:11.016 Beijing 10 1 2020-01-04T00:00 2020-01-04T00:00 2017-10-01T11:11:11.110 2017-10-01T11:11:11.150111 2020-01-04T00:00 1 33 21 +3 2017-10-01 2017-10-01 2017-10-01 11:11:11.026 2017-10-01 11:11:11.016000 Beijing 10 1 2020-01-04T00:00 2020-01-04T00:00 2017-10-01 11:11:11.110 2017-10-01 11:11:11.150111 2020-01-04T00:00 1 33 21 -- !point_select -- -3 2017-10-01 2017-10-01 2017-10-01T11:11:11.027 2017-10-01T11:11:11.017 Beijing 10 1 \N \N \N \N 2020-01-05T00:00 1 34 20 +3 2017-10-01 2017-10-01 2017-10-01 11:11:11.027 2017-10-01 11:11:11.017000 Beijing 10 1 \N \N \N \N 2020-01-05T00:00 1 34 20 -- !point_select -- -4 2017-10-01 2017-10-01 2017-10-01T11:11:11.028 2017-10-01T11:11:11.018 Beijing 10 1 \N \N \N \N 2020-01-05T00:00 1 34 20 +4 2017-10-01 2017-10-01 2017-10-01 11:11:11.028 2017-10-01 11:11:11.018000 Beijing 10 1 \N \N \N \N 2020-01-05T00:00 1 34 20 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 d8fb5e32af..22a42eb4cf 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 @@ -590,14 +590,14 @@ 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] +1 [2023-01-19 18:11:11.111, 2023-01-19 18:22:22.222, 2023-01-19 18:33:33.333] [2023-01-19 18:22:22.222, 2023-01-19 18:33:33.333, 2023-01-19 18:44:44.444] [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] +[2023-01-19 18:11:11, 2023-01-19 18:22:22, 2023-01-19 18:33:33] -- !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] +[2023-01-19 18:22:22, 2023-01-19 18:33:33, 2023-01-19 18:44:44] -- !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] +[2023-01-19 18:11:11, 2023-01-19 18:22:22, 2023-01-19 18:33:33] diff --git a/regression-test/data/query_p0/sql_functions/array_functions/test_array_with_scale_type.out b/regression-test/data/query_p0/sql_functions/array_functions/test_array_with_scale_type.out new file mode 100644 index 0000000000..2376a7bb1f --- /dev/null +++ b/regression-test/data/query_p0/sql_functions/array_functions/test_array_with_scale_type.out @@ -0,0 +1,80 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select -- +2022-12-02T22:23:24.999999 + +-- !select -- +2022-12-02T22:23:24.999 + +-- !select -- +2022-12-01T22:23:24.999 +2022-12-02T22:23:24.999 + +-- !select -- +2022-12-02T22:23:24.999999 + +-- !select -- +2022-12-02T22:23:24.999 + +-- !select -- +2022-12-01T23:23:24.999 +2022-12-02T23:23:24.999 + +-- !select -- +22.000000000 + +-- !select -- +22.990000000 + +-- !select -- +22.990000000 + +-- !select -- +22.678000000 +23.678000000 + +-- !select -- +22.000000000 + +-- !select -- +22.990000000 + +-- !select -- +22.990000000 + +-- !select -- +33.678900000 +34.678900000 + +-- !select -- +[22.678] +[23.678] + +-- !select -- +[24.99, 25.99] +[24.99, 25.99] + +-- !select -- +[24.990, 25.990] + +-- !select -- +[33.678] +[34.678] + +-- !select -- +[24.990, 25.990] +[24.990, 25.990] + +-- !select -- +[24.990, 25.990] + +-- !select -- +[2022-12-01 22:23:24.999] +[2022-12-02 22:23:24.999] + +-- !select -- +[2022-12-02 22:23:24.999, 2022-12-02 22:23:23.997] +[2022-12-02 22:23:24.999, 2022-12-02 22:23:23.997] + +-- !select -- +[2022-12-02 22:23:24.999, 2022-12-02 22:23:23.997] + diff --git a/regression-test/data/query_p0/sql_functions/cast_function/test_cast_with_scale_type.out b/regression-test/data/query_p0/sql_functions/cast_function/test_cast_with_scale_type.out new file mode 100644 index 0000000000..def023304e --- /dev/null +++ b/regression-test/data/query_p0/sql_functions/cast_function/test_cast_with_scale_type.out @@ -0,0 +1,16 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select1 -- +1 2022-12-01T22:23:24.999 2022-12-01 22:23:24.999999 +2 2022-12-02T22:23:24.999 2022-12-02 22:23:24.999999 + +-- !select2 -- +1 2022-12-01T22:23:24.999 2022-12-01T22:23:24.999 +2 2022-12-02T22:23:24.999 2022-12-02T22:23:24.999 + +-- !select3 -- +2022-12-02T22:23:24.999 2022-12-02T22:23:23.999 +2022-12-02T22:23:24.999 2022-12-02T22:23:23.999 + +-- !select4 -- +2022-12-02T22:23:24.999 2022-12-02T22:23:23.999 + diff --git a/regression-test/suites/compaction/test_compaction_uniq_keys_row_store.groovy b/regression-test/suites/compaction/test_compaction_uniq_keys_row_store.groovy index fb02063459..7ef5f419b6 100644 --- a/regression-test/suites/compaction/test_compaction_uniq_keys_row_store.groovy +++ b/regression-test/suites/compaction/test_compaction_uniq_keys_row_store.groovy @@ -71,7 +71,6 @@ suite("test_compaction_uniq_keys_row_store") { } def checkValue = { -> - println "fuckkkkk" def user = context.config.jdbcUser def password = context.config.jdbcPassword def url = context.config.jdbcUrl + "&useServerPrepStmts=true" 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 9456e01540..096d3245fc 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 @@ -158,8 +158,8 @@ suite("test_array_functions") { sql """ CREATE TABLE IF NOT EXISTS ${tableName4} ( `k1` int COMMENT "", - `k2` ARRAY COMMENT "", - `k3` ARRAY COMMENT "", + `k2` ARRAY COMMENT "", + `k3` ARRAY COMMENT "", `k4` ARRAY COMMENT "" ) ENGINE=OLAP DUPLICATE KEY(`k1`) @@ -175,6 +175,7 @@ suite("test_array_functions") { ["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}" + // Todo(Yukang-Lian): will fix if function bugs in the future 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}" diff --git a/regression-test/suites/query_p0/sql_functions/array_functions/test_array_with_scale_type.groovy b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_with_scale_type.groovy new file mode 100644 index 0000000000..827f03858c --- /dev/null +++ b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_with_scale_type.groovy @@ -0,0 +1,72 @@ +// 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_array_with_scale_type") { + + def tableName = "test_array_with_scale_type_table" + sql "DROP TABLE IF EXISTS ${tableName}" + sql """ + CREATE TABLE IF NOT EXISTS `${tableName}` ( + `uid` int(11) NULL COMMENT "", + `c_datetimev2` datetimev2(3) NULL COMMENT "", + `c_decimal` decimal(8,3) NULL COMMENT "", + `c_decimalv3` decimalv3(8,3) NULL COMMENT "", + `c_array_datetimev2` ARRAY NULL COMMENT "", + `c_array_decimal` ARRAY NULL COMMENT "" + ) ENGINE=OLAP + DUPLICATE KEY(`uid`) + DISTRIBUTED BY HASH(`uid`) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "storage_format" = "V2" + ) + """ + + sql """INSERT INTO ${tableName} values + (1,"2022-12-01 22:23:24.999999",22.678,33.6789,["2022-12-01 22:23:24.999999","2022-12-01 23:23:24.999999"],[22.678,33.6789]), + (2,"2022-12-02 22:23:24.999999",23.678,34.6789,["2022-12-02 22:23:24.999999","2022-12-02 23:23:24.999999"],[23.678,34.6789]) + """ + qt_select "select array_min(array(cast ('2022-12-02 22:23:24.999999' as datetimev2(6))))" + qt_select "select array_min(array(cast ('2022-12-02 22:23:24.999999' as datetimev2(3))))" + qt_select "select array_min(c_array_datetimev2) from ${tableName}" + qt_select "select array_max(array(cast ('2022-12-02 22:23:24.999999' as datetimev2(6))))" + qt_select "select array_max(array(cast ('2022-12-02 22:23:24.999999' as datetimev2(3))))" + qt_select "select array_max(c_array_datetimev2) from ${tableName}" + + qt_select "select array_min(array(cast (22.99 as decimal)))" + qt_select "select array_min(array(cast (22.99 as decimal(10,3))))" + qt_select "select array_min(array(cast (22.99 as decimal(10,6))))" + qt_select "select array_min(c_array_decimal) from ${tableName}" + qt_select "select array_max(array(cast (22.99 as decimal)))" + qt_select "select array_max(array(cast (22.99 as decimal(10,3))))" + qt_select "select array_max(array(cast (22.99 as decimal(10,6))))" + qt_select "select array_max(c_array_decimal) from ${tableName}" + + qt_select "select array(c_decimal) from ${tableName}" + qt_select "select array(cast (24.99 as decimal(10,3)),cast (25.99 as decimal(10,3))) from ${tableName}" + qt_select "select array(cast (24.99 as decimal(10,3)),cast (25.99 as decimal(10,3)))" + + qt_select "select array(c_decimalv3) from ${tableName}" + qt_select "select array(cast (24.99 as decimalv3(10,3)),cast (25.99 as decimalv3(10,3))) from ${tableName}" + qt_select "select array(cast (24.99 as decimalv3(10,3)),cast (25.99 as decimalv3(10,3)))" + + qt_select "select array(c_datetimev2) from ${tableName}" + qt_select "select array(cast ('2022-12-02 22:23:24.999999' as datetimev2(3)),cast ('2022-12-02 22:23:23.997799' as datetimev2(3))) from ${tableName}" + qt_select "select array(cast ('2022-12-02 22:23:24.999999' as datetimev2(3)),cast ('2022-12-02 22:23:23.997799' as datetimev2(3)))" + + sql "DROP TABLE IF EXISTS ${tableName}" +} \ No newline at end of file diff --git a/regression-test/suites/query_p0/sql_functions/cast_function/test_cast_with_scale_type.groovy b/regression-test/suites/query_p0/sql_functions/cast_function/test_cast_with_scale_type.groovy new file mode 100644 index 0000000000..5b22a0a479 --- /dev/null +++ b/regression-test/suites/query_p0/sql_functions/cast_function/test_cast_with_scale_type.groovy @@ -0,0 +1,49 @@ +// 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_cast_with_scale_type") { + + def tableName = "test_cast_with_scale_type_table" + sql "DROP TABLE IF EXISTS ${tableName}" + sql """ + CREATE TABLE IF NOT EXISTS `${tableName}` ( + `uid` int(11) NULL COMMENT "", + `c_datetimev2` datetimev2(3) NULL COMMENT "", + `c_string` varchar(30) NULL COMMENT "" + ) ENGINE=OLAP + DUPLICATE KEY(`uid`) + COMMENT "OLAP" + DISTRIBUTED BY HASH(`uid`) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "in_memory" = "false", + "storage_format" = "V2" + ) + """ + + sql """INSERT INTO ${tableName} values + (1,"2022-12-01 22:23:24.999999",'2022-12-01 22:23:24.999999'), + (2,"2022-12-02 22:23:24.999999",'2022-12-02 22:23:24.999999') + """ + + qt_select1 "select * from ${tableName}" + qt_select2 "select uid, c_datetimev2, cast(c_string as datetimev2(3)) from ${tableName} order by uid asc" + qt_select3 "select cast ('2022-12-02 22:23:24.999999' as datetimev2(3)),cast ('2022-12-02 22:23:23.999999' as datetimev2(3)) from ${tableName}" + qt_select4 "select cast ('2022-12-02 22:23:24.999999' as datetimev2(3)),cast ('2022-12-02 22:23:23.999999' as datetimev2(3))" + + sql "DROP TABLE IF EXISTS ${tableName}" +} \ No newline at end of file