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 @@ -183,6 +183,10 @@ static String normalize(String s) {
}

// normalize leading 0 for date and time
// The first part is 1-digit x: 000x-month-day
// The first part is 2-digit xy: 20xy-month-day / 19xy-month-day
// The first part is 3-digit xyz: 20xy-0z-day / 19xy-0z-day
// The first part is 4-digit xyzw: xyzw-month-day
while (i < s.length() && partNumber < 6) {
char c = s.charAt(i);
if (Character.isDigit(c)) {
Expand All @@ -194,6 +198,20 @@ static String normalize(String s) {
int len = j - i;
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");
}
sb.append(yy).append('-');
} else {
sb.append(s, i, i + 2).append(' ');
}
j = j - 1;
} else if (len == 1) {
if (partNumber == 0) {
sb.append("000").append(c);
Expand Down
14 changes: 13 additions & 1 deletion regression-test/data/correctness_p0/test_cast_date_decimal.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql --
-- !sql1 --
true

-- !sql2 --
2024-12-12

-- !sql3 --
2024-12-12

-- !sql4 --
2024-12-12

-- !sql5 --
2012-03-12

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,23 @@
// under the License.

suite("test_cast_date_decimal") {
qt_sql """
qt_sql1 """
select cast('2020-02-02' as date ) between cast('2020-02-02' as date ) and cast('2020-02-02' as date ) + 1.0;
"""

qt_sql2 """
select cast('2024-12-12' as date);
"""

qt_sql3 """
select cast('2024.12.12' as date);
"""

qt_sql4 """
select cast('24.12.12' as date);
"""

qt_sql5 """
select cast('123.123' as date);
"""
}