-
Notifications
You must be signed in to change notification settings - Fork 216
Bugfix: SQL type mapping for legacy JDBC output #3613
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
Merged
Swiddis
merged 14 commits into
opensearch-project:main
from
Swiddis:bugfix/join-timestamps
Sep 30, 2025
Merged
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b43233c
Add reproducers for 1545, 3159, 3204
Swiddis 4bec578
Undo collapse to star import
Swiddis aa66519
Fix timestamp comparison query
Swiddis 4a83cd7
Ignore 3204 test
Swiddis e1e4f13
Hack Protocol to fix the timestamp type issue
Swiddis f0653bb
Apply spotless
Swiddis abdb248
Make protocol mapping more robust
Swiddis 57c4168
Merge remote-tracking branch 'upstream/main' into bugfix/join-timestamps
Swiddis b9bd84d
Add nested -> array type mapping, too
Swiddis bff0a9d
Empty commit (test retry)
Swiddis f52c763
Merge remote-tracking branch 'upstream/main' into bugfix/join-timestamps
Swiddis f9c2df3
Merge remote-tracking branch 'upstream/main' into bugfix/join-timestamps
Swiddis 33d0ff4
Update because new tests depend on broken timestamp
Swiddis 4ba80b9
Merge branch 'main' into bugfix/join-timestamps
Swiddis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
150 changes: 150 additions & 0 deletions
150
integ-test/src/test/java/org/opensearch/sql/sql/ComplexTimestampQueryIT.java
This file contains hidden or 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,150 @@ | ||
| package org.opensearch.sql.sql; | ||
|
|
||
| import org.junit.Ignore; | ||
| import org.opensearch.sql.legacy.SQLIntegTestCase; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Locale; | ||
| import org.json.JSONArray; | ||
| import org.json.JSONObject; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
|
|
||
| import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_DATE_TIME; | ||
| import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_DATE_TIME_NESTED; | ||
|
|
||
| public class ComplexTimestampQueryIT extends SQLIntegTestCase { | ||
| @Override | ||
| protected void init() throws Exception { | ||
| loadIndex(SQLIntegTestCase.Index.DATETIME); | ||
| loadIndex(SQLIntegTestCase.Index.DATETIME_NESTED); | ||
| } | ||
|
|
||
| /** | ||
| * See: <a href="https://github.com/opensearch-project/sql/issues/3159">3159</a> | ||
| */ | ||
| @Test | ||
| public void joinWithTimestampFieldsSchema() throws IOException { | ||
| String query = String.format( | ||
| Locale.ROOT, | ||
| "SELECT one.login_time, two.login_time " + | ||
| "FROM %s AS one JOIN %s AS two " + | ||
| "ON one._id = two._id", | ||
| TEST_INDEX_DATE_TIME, | ||
| TEST_INDEX_DATE_TIME | ||
| ); | ||
|
|
||
| JSONObject result = executeQuery(query); | ||
| JSONArray schema = result.getJSONArray("schema"); | ||
|
|
||
| Assert.assertFalse(schema.isEmpty()); | ||
| for (int i = 0; i < schema.length(); i++) { | ||
| JSONObject column = schema.getJSONObject(i); | ||
| Assert.assertEquals("timestamp", column.getString("type")); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Control for joinWithTimestampFieldsSchema | ||
| */ | ||
| @Test | ||
| public void nonJoinTimestampFieldsSchema() throws IOException { | ||
| String query = String.format( | ||
| Locale.ROOT, | ||
| "SELECT one.login_time " + | ||
| "FROM %s AS one", | ||
| TEST_INDEX_DATE_TIME | ||
| ); | ||
|
|
||
| JSONObject result = executeQuery(query); | ||
| JSONArray schema = result.getJSONArray("schema"); | ||
|
|
||
| Assert.assertFalse(schema.isEmpty()); | ||
| for (int i = 0; i < schema.length(); i++) { | ||
| JSONObject column = schema.getJSONObject(i); | ||
| Assert.assertEquals("timestamp", column.getString("type")); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * See: <a href="https://github.com/opensearch-project/sql/issues/3204">3204</a> | ||
| */ | ||
| // TODO currently out of scope due to V1/V2 engine feature mismatch. Should be fixed with Calcite. | ||
| @Test | ||
| @Ignore | ||
| public void joinTimestampComparison() throws IOException { | ||
| String query = String.format( | ||
| Locale.ROOT, | ||
| "SELECT one.login_time, two.login_time " + | ||
| "FROM %s AS one JOIN %s AS two " + | ||
| "ON one._id = two._id " + | ||
| "WHERE one.login_time > timestamp('2018-05-07 00:00:00')", | ||
| TEST_INDEX_DATE_TIME, TEST_INDEX_DATE_TIME | ||
| ); | ||
|
|
||
| JSONObject result = executeQuery(query); | ||
| Assert.assertEquals(2, result.getJSONArray("datarows").length()); | ||
| } | ||
|
|
||
| /** | ||
| * Control for joinTimestampComparison | ||
| */ | ||
| @Test | ||
| public void nonJoinTimestampComparison() throws IOException { | ||
| String query = String.format( | ||
| Locale.ROOT, | ||
| "SELECT login_time " + | ||
| "FROM %s " + | ||
| "WHERE login_time > timestamp('2018-05-07 00:00:00')", | ||
| TEST_INDEX_DATE_TIME | ||
| ); | ||
|
|
||
| JSONObject result = executeQuery(query); | ||
| System.err.println(result.getJSONArray("datarows").toString()); | ||
| Assert.assertEquals(2, result.getJSONArray("datarows").length()); | ||
| } | ||
|
|
||
| /** | ||
| * See: <a href="https://github.com/opensearch-project/sql/issues/1545">1545</a> | ||
| */ | ||
| @Test | ||
| public void selectDatetimeWithNested() throws IOException { | ||
| String query = String.format( | ||
| Locale.ROOT, | ||
| "SELECT tab.login_time " + | ||
| "FROM %s AS tab, tab.projects AS pro", | ||
| TEST_INDEX_DATE_TIME_NESTED | ||
| ); | ||
|
|
||
| JSONObject result = executeQuery(query); | ||
| JSONArray schema = result.getJSONArray("schema"); | ||
|
|
||
| Assert.assertFalse(schema.isEmpty()); | ||
| for (int i = 0; i < schema.length(); i++) { | ||
| JSONObject column = schema.getJSONObject(i); | ||
| Assert.assertEquals("timestamp", column.getString("type")); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Control for selectDatetimeWithNested | ||
| */ | ||
| @Test | ||
| public void selectDatetimeWithoutNested() throws IOException { | ||
| String query = String.format( | ||
| Locale.ROOT, | ||
| "SELECT tab.login_time " + | ||
| "FROM %s AS tab", | ||
| TEST_INDEX_DATE_TIME_NESTED | ||
| ); | ||
|
|
||
| JSONObject result = executeQuery(query); | ||
| JSONArray schema = result.getJSONArray("schema"); | ||
|
|
||
| Assert.assertFalse(schema.isEmpty()); | ||
| for (int i = 0; i < schema.length(); i++) { | ||
| JSONObject column = schema.getJSONObject(i); | ||
| Assert.assertEquals("timestamp", column.getString("type")); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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,8 @@ | ||
| {"index":{"_id":"1"}} | ||
|
Swiddis marked this conversation as resolved.
|
||
| {"login_time":"2015-01-01", "projects": [{"name": "abc"}]} | ||
| {"index":{"_id":"2"}} | ||
| {"login_time":"2015-01-01T12:10:30Z", "projects": [{"name": "def"}, {"name": "ghi"}]} | ||
| {"index":{"_id":"3"}} | ||
| {"login_time":"1585882955000", "projects": []} | ||
| {"index":{"_id":"4"}} | ||
| {"login_time":"2020-04-08T11:10:30+05:00", "projects": [{"name": "jkl"}]} | ||
12 changes: 12 additions & 0 deletions
12
integ-test/src/test/resources/indexDefinitions/date_time_nested_index_mapping.json
This file contains hidden or 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,12 @@ | ||
| { | ||
| "mappings": { | ||
| "properties": { | ||
| "login_time": { | ||
| "type": "date" | ||
| }, | ||
| "projects": { | ||
| "type": "nested" | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found while writing the reproducers that this was getting parsed as milliseconds instead of seconds, despite the magnitude. That gets sent to January 19, 1970 instead of (probably intended) April 3, 2020. I decided to update the row.