-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Support Alternate Datetime Formats (#268) * Add OpenSearchDateType as a datatype for matching with Date/Time OpenSearch types Signed-off-by: Andrew Carbonetto <[email protected]> --------- Signed-off-by: Andrew Carbonetto <[email protected]> Signed-off-by: GabeFernandez310 <[email protected]> Signed-off-by: Guian Gumpac <[email protected]> Signed-off-by: MaxKsyunz <[email protected]> Co-authored-by: Andrew Carbonetto <[email protected]> Co-authored-by: GabeFernandez310 <[email protected]> Co-authored-by: MaxKsyunz <[email protected]> (cherry picked from commit 986db39) Co-authored-by: Guian Gumpac <[email protected]>
- Loading branch information
1 parent
c22cf60
commit 44b536a
Showing
20 changed files
with
1,536 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
integ-test/src/test/java/org/opensearch/sql/sql/DateTimeFormatsIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
|
||
package org.opensearch.sql.sql; | ||
|
||
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_DATE_FORMATS; | ||
import static org.opensearch.sql.legacy.plugin.RestSqlAction.QUERY_API_ENDPOINT; | ||
import static org.opensearch.sql.util.MatcherUtils.rows; | ||
import static org.opensearch.sql.util.MatcherUtils.schema; | ||
import static org.opensearch.sql.util.MatcherUtils.verifyDataRows; | ||
import static org.opensearch.sql.util.MatcherUtils.verifySchema; | ||
import static org.opensearch.sql.util.TestUtils.getResponseBody; | ||
|
||
import java.io.IOException; | ||
import java.util.Locale; | ||
import org.json.JSONObject; | ||
import org.junit.jupiter.api.Test; | ||
import org.opensearch.client.Request; | ||
import org.opensearch.client.RequestOptions; | ||
import org.opensearch.client.Response; | ||
import org.opensearch.sql.legacy.SQLIntegTestCase; | ||
|
||
public class DateTimeFormatsIT extends SQLIntegTestCase { | ||
|
||
@Override | ||
public void init() throws Exception { | ||
super.init(); | ||
loadIndex(Index.DATE_FORMATS); | ||
} | ||
|
||
@Test | ||
public void testReadingDateFormats() throws IOException { | ||
String query = String.format("SELECT weekyear_week_day, hour_minute_second_millis," + | ||
" strict_ordinal_date_time FROM %s LIMIT 1", TEST_INDEX_DATE_FORMATS); | ||
JSONObject result = executeQuery(query); | ||
verifySchema(result, | ||
schema("weekyear_week_day", null, "date"), | ||
schema("hour_minute_second_millis", null, "time"), | ||
schema("strict_ordinal_date_time", null, "timestamp")); | ||
verifyDataRows(result, | ||
rows("1984-04-12", | ||
"09:07:42", | ||
"1984-04-12 09:07:42.000123456" | ||
)); | ||
} | ||
|
||
@Test | ||
public void testDateFormatsWithOr() throws IOException { | ||
String query = String.format("SELECT yyyy-MM-dd_OR_epoch_millis FROM %s", TEST_INDEX_DATE_FORMATS); | ||
JSONObject result = executeQuery(query); | ||
verifyDataRows(result, | ||
rows("1984-04-12 00:00:00"), | ||
rows("1984-04-12 09:07:42.000123456")); | ||
} | ||
|
||
protected JSONObject executeQuery(String query) throws IOException { | ||
Request request = new Request("POST", QUERY_API_ENDPOINT); | ||
request.setJsonEntity(String.format(Locale.ROOT, "{\n" + " \"query\": \"%s\"\n" + "}", query)); | ||
|
||
RequestOptions.Builder restOptionsBuilder = RequestOptions.DEFAULT.toBuilder(); | ||
restOptionsBuilder.addHeader("Content-Type", "application/json"); | ||
request.setOptions(restOptionsBuilder); | ||
|
||
Response response = client().performRequest(request); | ||
return new JSONObject(getResponseBody(response)); | ||
} | ||
} |
Oops, something went wrong.