zclllyybb commented on code in PR #47319:
URL: https://github.com/apache/doris/pull/47319#discussion_r1942241526
##########
be/src/vec/data_types/data_type_time.cpp:
##########
@@ -78,4 +80,58 @@ void DataTypeTimeV2::to_string(const IColumn& column, size_t
row_num, BufferWrit
MutableColumnPtr DataTypeTimeV2::create_column() const {
return DataTypeNumberBase<Float64>::create_column();
}
+
+Field DataTypeTimeV2::get_field(const TExprNode& node) const {
Review Comment:
try add beut for this
##########
regression-test/suites/nereids_p0/datatype/test_cast.groovy:
##########
@@ -96,6 +96,197 @@ suite("test_cast") {
sql "select cast(true as date);"
result([[null]])
}
+
+ testFoldConst("select cast('12:00:00' as time);")
+ testFoldConst("select cast('111111' as time);")
+
+ qt_sql "select cast(cast('11:11:11' as time) as char);"
+ qt_sql "select cast(cast('11:11:11' as time) as json);"
+ qt_sql "select cast(cast('11:11:11' as time) as jsonb);"
+ qt_sql "select cast(cast('11:11:11' as time) as string);"
+ qt_sql "select cast(cast('11:11:11' as time) as text);"
+ qt_sql "select cast(cast('11:11:11' as time) as varchar);"
+ qt_sql "select cast(cast('11:11:11' as time) as variant);"
+
+ check_fold_consistency "cast(cast('11:11:11' as time) as char);"
+ check_fold_consistency "cast(cast('11:11:11' as time) as json);"
+ check_fold_consistency "cast(cast('11:11:11' as time) as jsonb);"
+ check_fold_consistency "cast(cast('11:11:11' as time) as string);"
+ check_fold_consistency "cast(cast('11:11:11' as time) as text);"
+ check_fold_consistency "cast(cast('11:11:11' as time) as varchar);"
+ check_fold_consistency "cast(cast('11:11:11' as time) as variant);"
+
+ test {
+ sql "select cast(cast('11:11:11' as time) as bigint);"
+ exception "cannot cast"
+ }
+ test {
+ sql "select cast(cast('11:11:11' as time) as double);"
+ exception "cannot cast"
+ }
+ test {
+ sql "select cast(cast('11:11:11' as time) as float);"
+ exception "cannot cast"
+ }
+ test {
+ sql "select cast(cast('11:11:11' as time) as int);"
+ exception "cannot cast"
+ }
+ test {
+ sql "select cast(cast('11:11:11' as time) as integer);"
+ exception "cannot cast"
+ }
+ test {
+ sql "select cast(cast('11:11:11' as time) as largeint);"
+ exception "cannot cast"
+ }
+ test {
+ sql "select cast(cast('11:11:11' as time) as smallint);"
+ exception "cannot cast"
+ }
+ test {
+ sql "select cast(cast('11:11:11' as time) as tinyint);"
+ exception "cannot cast"
+ }
+ test {
+ sql "select cast(cast('11:11:11' as time) as bitmap);"
+ exception "cannot cast"
+ }
+ test {
+ sql "select cast(cast('11:11:11' as time) as decimal);"
+ exception "cannot cast"
+ }
+ test {
+ sql "select cast(cast('11:11:11' as time) as decimalv2);"
+ exception "cannot cast"
+ }
+ test {
+ sql "select cast(cast('11:11:11' as time) as decimalv3);"
+ exception "cannot cast"
+ }
+ test {
+ sql "select cast(cast('11:11:11' as time) as hll);"
+ exception "cannot cast"
+ }
+ test {
+ sql "select cast(cast('11:11:11' as time) as quantile_state);"
+ exception "cannot cast"
+ }
+ test {
+ sql "select cast(cast('11:11:11' as time) as datetime);"
+ exception "cannot cast"
+ }
+ test {
+ sql "select cast(cast('11:11:11' as time) as date);"
+ exception "cannot cast"
+ }
+ test {
+ sql "select cast(cast('11:11:11' as time) as quantile_state);"
+ exception "cannot cast"
+ }
+
+ qt_sql "select cast('-01:00:00' as time);"
+ qt_sql "select cast('00:-01:00' as time);"
+ qt_sql "select cast('00:00:-01' as time);"
+ qt_sql "select cast('00:00:00' as time);"
+ qt_sql "select cast('838:59:59' as time);"
+ qt_sql "select cast('838:60:59' as time);"
+ qt_sql "select cast('838:59:60' as time);"
+ qt_sql "select cast('839:00:00' as time);"
+
+ qt_sql "select cast('-010000' as time);"
+ qt_sql "select cast('-000100' as time);"
+ qt_sql "select cast('-000001' as time);"
+ qt_sql "select cast('000000' as time);"
+ qt_sql "select cast('8385959' as time);"
+ qt_sql "select cast('8386059' as time);"
+ qt_sql "select cast('8385960' as time);"
+ qt_sql "select cast('8390000' as time);"
+
+ qt_sql "select cast(-010000 as time);"
Review Comment:
compare the behaviours to mysql
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/check/CheckCast.java:
##########
@@ -122,6 +122,10 @@ private static boolean checkPrimitiveType(DataType
originalType, DataType target
if (originalType.isObjectType() || targetType.isObjectType()) {
return false;
}
+ if (originalType.isTimeLikeType() && !(targetType.isStringLikeType()
Review Comment:
add comment for time cast
##########
be/src/vec/exprs/vexpr.h:
##########
@@ -489,6 +489,15 @@ Status create_texpr_literal_node(const void* data,
TExprNode* node, int precisio
literal.__set_value(vectorized::DataTypeIPv6::to_string(*origin_value));
(*node).__set_ipv6_literal(literal);
(*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
+ } else if constexpr (T == TYPE_TIMEV2) {
+ const auto* origin_value = reinterpret_cast<const
VecDateTimeValue*>(data);
Review Comment:
debug this
##########
be/src/vec/exprs/vexpr.h:
##########
@@ -489,6 +489,15 @@ Status create_texpr_literal_node(const void* data,
TExprNode* node, int precisio
literal.__set_value(vectorized::DataTypeIPv6::to_string(*origin_value));
(*node).__set_ipv6_literal(literal);
(*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
+ } else if constexpr (T == TYPE_TIMEV2) {
+ const auto* origin_value = reinterpret_cast<const
VecDateTimeValue*>(data);
Review Comment:
why not float64?
##########
regression-test/suites/nereids_p0/datatype/test_cast.groovy:
##########
@@ -96,6 +96,197 @@ suite("test_cast") {
sql "select cast(true as date);"
result([[null]])
}
+
+ testFoldConst("select cast('12:00:00' as time);")
+ testFoldConst("select cast('111111' as time);")
+
+ qt_sql "select cast(cast('11:11:11' as time) as char);"
Review Comment:
add index for `qt_sql`
##########
be/src/vec/data_types/data_type_time.cpp:
##########
@@ -78,4 +80,58 @@ void DataTypeTimeV2::to_string(const IColumn& column, size_t
row_num, BufferWrit
MutableColumnPtr DataTypeTimeV2::create_column() const {
return DataTypeNumberBase<Float64>::create_column();
}
+
+Field DataTypeTimeV2::get_field(const TExprNode& node) const {
Review Comment:
better keep same with FE's impl. and add comment about keeping.
##########
be/src/vec/data_types/data_type_time.cpp:
##########
@@ -78,4 +80,58 @@ void DataTypeTimeV2::to_string(const IColumn& column, size_t
row_num, BufferWrit
MutableColumnPtr DataTypeTimeV2::create_column() const {
return DataTypeNumberBase<Float64>::create_column();
}
+
+Field DataTypeTimeV2::get_field(const TExprNode& node) const {
Review Comment:
add comment for both FE and BE's impl of consistency.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]