Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ public Expression visitCast(Cast cast, ExpressionRewriteContext context) {
return ((DateLikeType) dataType).fromString(((StringLikeLiteral) child).getStringValue());
} catch (AnalysisException t) {
if (cast.isExplicitType()) {
return new NullLiteral(dataType);
return cast;
} else {
// If cast is from type coercion, we don't use NULL literal and will throw exception.
throw t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,23 @@ static Result<String, AnalysisException> normalize(String s) {
if (len == 4 || len == 2) {
sb.append(s, i, j);
} else if (len == 3) {
if (partNumber == 0) {
String yy = s.substring(i, i + 2);
int year = Integer.parseInt(yy);
if (year >= 0 && year <= 69) {
sb.append("20");
} else if (year >= 70 && year <= 99) {
sb.append("19");
if (s.charAt(j) == '.') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why "201.01.01" is year 2020, but "201-01-01" is year 201

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this behavior is align to mysql

if (partNumber == 0) {
String yy = s.substring(i, i + 2);
int year = Integer.parseInt(yy);
if (year >= 0 && year <= 69) {
sb.append("20");
} else if (year >= 70 && year <= 99) {
sb.append("19");
}
sb.append(yy).append('-');
} else {
sb.append(s, i, i + 2).append(' ');
}
sb.append(yy).append('-');
j = j - 1;
} else {
sb.append(s, i, i + 2).append(' ');
sb.append("0").append(s, i, j);
}
j = j - 1;
} else if (len == 1) {
if (partNumber == 0) {
sb.append("000").append(c);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ true
-- !sql7 --
\N \N \N \N

-- !sql8 --
2012-03-12T03:00 0123-01-01T00:00 2012-03-12T12:23:59

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
11

-- !sql --
\N
2000-01-01T03:14:17

-- !sql --
\N
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
11

-- !sql --
\N
2000-01-01T03:14:17

-- !sql --
\N
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ suite("test_cast_date_decimal") {
qt_sql7 """
select /*+SET_VAR(debug_skip_fold_constant=true)*/ cast('0000-02-29' as date), cast('0000-02-29' as datetime), cast('00000229' as date), cast('0000-02-29 12:12:12.123' as datetime);
"""

qt_sql8 """
select cast('123.123' as datetimev2), cast('123-01-01' as datetimev2), cast('123.1212.235959' as datetimev2);
"""
}
Loading