[fix](datatype) fix some bugs about data type array datetimev2 and decimalv3 (#16132)

This commit is contained in:
abmdocrt
2023-01-29 14:26:08 +08:00
committed by GitHub
parent 3235b636cc
commit eb7da1c0ee
13 changed files with 307 additions and 43 deletions

View File

@ -173,10 +173,10 @@ Status VMysqlResultWriter<is_binary_format>::_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<is_binary_format>::_add_one_column(
}
if constexpr (type == TYPE_DATETIME) {
auto time_num = data[i];
VecDateTimeValue time_val;
memcpy(static_cast<void*>(&time_val), &time_num, sizeof(Int64));
VecDateTimeValue time_val = binary_cast<Int64, VecDateTimeValue>(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<DateV2ValueType> date_val;
memcpy(static_cast<void*>(&date_val), &time_num, sizeof(UInt32));
DateV2Value<DateV2ValueType> date_val =
binary_cast<UInt32, DateV2Value<DateV2ValueType>>(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<DateTimeV2ValueType> date_val;
memcpy(static_cast<void*>(&date_val), &time_num, sizeof(UInt64));
buf_ret = rows_buffer[i].push_vec_datetime(date_val);
char buf[64];
DateV2Value<DateTimeV2ValueType> date_val =
binary_cast<UInt64, DateV2Value<DateTimeV2ValueType>>(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<is_binary_format>::_add_one_column(
template <bool is_binary_format>
int VMysqlResultWriter<is_binary_format>::_add_one_cell(const ColumnPtr& column_ptr, size_t row_idx,
const DataTypePtr& type,
MysqlRowBuffer<is_binary_format>& buffer) {
MysqlRowBuffer<is_binary_format>& 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<is_binary_format>::_add_one_cell(const ColumnPtr& column_
DateV2Value<DateTimeV2ValueType> datetimev2 =
binary_cast<UInt64, DateV2Value<DateTimeV2ValueType>>(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<is_binary_format>::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<const DataTypeNullable&>(*type_ptr).get_nested_type();
auto& sub_type = assert_cast<const DataTypeArray&>(*nested_type).get_nested_type();
status = _add_one_column<PrimitiveType::TYPE_ARRAY, true>(column_ptr, result,
rows_buffer, sub_type);
status = _add_one_column<PrimitiveType::TYPE_ARRAY, true>(
column_ptr, result, rows_buffer, sub_type, scale);
} else {
auto& sub_type = assert_cast<const DataTypeArray&>(*type_ptr).get_nested_type();
status = _add_one_column<PrimitiveType::TYPE_ARRAY, false>(column_ptr, result,
rows_buffer, sub_type);
status = _add_one_column<PrimitiveType::TYPE_ARRAY, false>(
column_ptr, result, rows_buffer, sub_type, scale);
}
break;
}

View File

@ -56,7 +56,7 @@ private:
std::vector<MysqlRowBuffer<is_binary_format>>& 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<is_binary_format>& buffer);
MysqlRowBuffer<is_binary_format>& buffer, int scale = -1);
private:
BufferControlBlock* _sinker;

View File

@ -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);
}

View File

@ -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());
}

View File

@ -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();

View File

@ -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

View File

@ -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]

View File

@ -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]

View File

@ -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

View File

@ -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"

View File

@ -158,8 +158,8 @@ suite("test_array_functions") {
sql """
CREATE TABLE IF NOT EXISTS ${tableName4} (
`k1` int COMMENT "",
`k2` ARRAY<datetimev2(4)> COMMENT "",
`k3` ARRAY<datetimev2(4)> COMMENT "",
`k2` ARRAY<datetimev2(3)> COMMENT "",
`k3` ARRAY<datetimev2(3)> COMMENT "",
`k4` ARRAY<datetimev2(6)> 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}"

View File

@ -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<datetimev2(3)> NULL COMMENT "",
`c_array_decimal` ARRAY<decimal(8,3)> 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}"
}

View File

@ -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}"
}