Skip to content

Fix type cast to datetime #1328

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

Closed
Closed
Show file tree
Hide file tree
Changes from 5 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 @@ -314,6 +314,7 @@ public void castIntFieldToDoubleWithAliasJdbcFormatGroupByTest() {
rows("35.0"));
}

@Ignore("V2 engine doesn't support datetime with TZ")
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can add new tests instead of disabled. For example:

SELECT
  CAST(date0 AS date),
  CAST(time0 AS datetime),
  CAST(time1 AS time),  
  CAST(datetime0 AS timestamp),
FROM calcs;

@Test
public void castKeywordFieldToDatetimeWithoutAliasJdbcFormatTest() {
JSONObject response = executeJdbcRequest("SELECT CAST(date_keyword AS DATETIME) FROM "
Expand All @@ -326,6 +327,7 @@ public void castKeywordFieldToDatetimeWithoutAliasJdbcFormatTest() {
rows("2019-09-25 02:04:13.469"));
}

@Ignore("V2 engine doesn't support datetime with TZ")
@Test
public void castKeywordFieldToDatetimeWithAliasJdbcFormatTest() {
JSONObject response =
Expand All @@ -339,6 +341,7 @@ public void castKeywordFieldToDatetimeWithAliasJdbcFormatTest() {
rows("2019-09-25 02:04:13.469"));
}

@Ignore("V2 engine doesn't support datetime with TZ")
@Test
public void castFieldToDatetimeWithWhereClauseJdbcFormatTest() {
JSONObject response = executeJdbcRequest("SELECT CAST(date_keyword AS DATETIME) FROM "
Expand Down Expand Up @@ -476,6 +479,7 @@ public void castStatementInWhereClauseLessThanConstantTest() {
* Testing compilation
* Result comparison is empty then comparing different types (Date and keyword)
*/
@Ignore("V2 engine doesn't support datetime with TZ and implicit cast from string")
@Test
public void castStatementInWhereClauseDatetimeCastTest() {
JSONObject response = executeJdbcRequest("SELECT date_keyword FROM "
Expand Down
3 changes: 3 additions & 0 deletions integ-test/src/test/resources/correctness/bugfixes/853.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT CAST(CAST(timestamp AS DATE) AS DATETIME) AS castDateToDatetime FROM opensearch_dashboards_sample_data_flights
SELECT CAST(CAST(timestamp AS TIME) AS DATETIME) AS castTimeToDatetime FROM opensearch_dashboards_sample_data_flights
SELECT CAST(CAST(timestamp AS TIMESTAMP) AS DATETIME) AS castTsToDatetime FROM opensearch_dashboards_sample_data_flights
1 change: 1 addition & 0 deletions sql/src/main/antlr/OpenSearchSQLParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ altMultiFieldRelevanceFunction
convertedDataType
: typeName=DATE
| typeName=TIME
| typeName=DATETIME
| typeName=TIMESTAMP
| typeName=INT
| typeName=INTEGER
Expand Down