Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function str_to_date should work with two-digits year #2841

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -173,7 +173,7 @@ interface DateTimeFormatHandler {
.put("%T", "HH:mm:ss") // %T => HH:mm:ss
.put("%W", "EEEE") // %W => EEEE - Weekday name (Sunday..Saturday)
.put("%Y", "u") // %Y => yyyy - Year, numeric, 4 digits
.put("%y", "u") // %y => yy - Year, numeric, 2 digits
.put("%y", "uu") // %y => yy - Year, numeric, 2 digits
Copy link
Member Author

Choose a reason for hiding this comment

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

.put("%f", "n") // %f => n - Nanoseconds
// The following have been implemented but cannot be aligned with
// MySQL due to the limitations of the DatetimeFormatter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ private static Stream<Arguments> getTestDataForStrToDate() {
"%Y,%m,%d,%h,%i",
new ExprTimestampValue("2000-01-01 10:11:00"),
TIMESTAMP),
Arguments.of(
"01-May-13", "%d-%b-%y", new ExprTimestampValue("2013-05-01 00:00:00"), TIMESTAMP),
Arguments.of(
"01-Jan-00", "%d-%b-%y", new ExprTimestampValue("2000-01-01 00:00:00"), TIMESTAMP),
// Behavior consistent with OpenSearch Core
Arguments.of(
"31-Jul-99", "%d-%b-%y", new ExprTimestampValue("2099-07-31 00:00:00"), TIMESTAMP),

// Invalid Arguments (should return null)
Arguments.of("a09:30:17", "a%h:%i:%s", ExprNullValue.of(), UNDEFINED),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1486,6 +1486,14 @@ public void testStrToDate() throws IOException {
TEST_INDEX_DATE, "%d,%m,%Y"));
verifySchema(result, schema("f", null, "timestamp"));
verifySome(result.getJSONArray("datarows"), rows("2013-05-01 00:00:00"));
// two digits year case
result =
executeQuery(
String.format(
"source=%s | eval f = str_to_date('1-May-13', '%s') | fields f",
TEST_INDEX_DATE, "%d-%b-%y"));
verifySchema(result, schema("f", null, "timestamp"));
verifySome(result.getJSONArray("datarows"), rows("2013-05-01 00:00:00"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,10 @@ public void testStrToDate() throws IOException {
"SELECT str_to_date(firstname," + " '%%Y-%%m-%%d %%h:%%i:%%s') FROM %s LIMIT 2",
TEST_INDEX_BANK));
verifyDataRows(result, rows((Object) null), rows((Object) null));

// two digits year case
result = executeQuery("SELECT str_to_date('23-Oct-17 00:00:00', '%d-%b-%y %h:%i:%s')");
verifyDataRows(result, rows("2017-10-23 00:00:00"));
}

@Test
Expand Down
Loading