-
Notifications
You must be signed in to change notification settings - Fork 25.2k
SQL: Fix getTime() methods in JDBC #40484
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
*/ | ||
package org.elasticsearch.xpack.sql.qa.jdbc; | ||
|
||
import com.carrotsearch.randomizedtesting.annotations.Repeat; | ||
import org.elasticsearch.client.Request; | ||
import org.elasticsearch.common.CheckedBiFunction; | ||
import org.elasticsearch.common.CheckedConsumer; | ||
|
@@ -63,6 +64,7 @@ | |
import static org.elasticsearch.xpack.sql.qa.jdbc.JdbcTestUtils.JDBC_TIMEZONE; | ||
import static org.elasticsearch.xpack.sql.qa.jdbc.JdbcTestUtils.of; | ||
|
||
@Repeat(iterations = 100) | ||
public class ResultSetTestCase extends JdbcIntegrationTestCase { | ||
|
||
static final Set<String> fieldsNames = Stream.of("test_byte", "test_integer", "test_long", "test_short", "test_double", | ||
|
@@ -880,7 +882,7 @@ public void testGettingDateWithoutCalendar() throws Exception { | |
doWithQuery(SELECT_ALL_FIELDS, (results) -> { | ||
results.next(); | ||
|
||
ZoneId zoneId = ZoneId.of(timeZoneId); | ||
ZoneId zoneId = getZoneFromOffset(randomLongDate); | ||
java.sql.Date expectedDate = new java.sql.Date( | ||
ZonedDateTime.ofInstant(Instant.ofEpochMilli(randomLongDate), zoneId) | ||
.toLocalDate().atStartOfDay(zoneId).toInstant().toEpochMilli()); | ||
|
@@ -939,11 +941,14 @@ public void testGettingTimeWithoutCalendar() throws Exception { | |
}); | ||
Long randomLongDate = randomNonNegativeLong(); | ||
indexSimpleDocumentWithTrueValues(randomLongDate); | ||
|
||
doWithQuery(SELECT_ALL_FIELDS, (results) -> { | ||
results.next(); | ||
|
||
java.sql.Time expectedTime = new java.sql.Time(randomLongDate % 86400000L); | ||
ZoneId zoneId = getZoneFromOffset(randomLongDate); | ||
java.sql.Time expectedTime = new java.sql.Time( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be extracted in a utils class? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't do it as it's used only once here, but I can extract it. |
||
ZonedDateTime.ofInstant(Instant.ofEpochMilli(randomLongDate), zoneId) | ||
.toLocalTime().atDate(JdbcTestUtils.EPOCH).atZone(zoneId).toInstant().toEpochMilli()); | ||
|
||
assertEquals(expectedTime, results.getTime("test_date")); | ||
assertEquals(expectedTime, results.getTime(9)); | ||
|
@@ -953,7 +958,7 @@ public void testGettingTimeWithoutCalendar() throws Exception { | |
validateErrorsForTimeTestsWithoutCalendar(results::getTime); | ||
}); | ||
} | ||
|
||
public void testGettingTimeWithCalendar() throws Exception { | ||
createIndex("test"); | ||
updateMappingForNumericValuesTests("test"); | ||
|
@@ -1748,4 +1753,8 @@ private Connection esWithLeniency(boolean multiValueLeniency) throws SQLExceptio | |
private String asDateString(long millis) { | ||
return of(millis, timeZoneId); | ||
} | ||
|
||
private ZoneId getZoneFromOffset(Long randomLongDate) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ZoneId is better I would argue though at the same time, if this is a cause for failure it might mean that the offset rules on the server are different than that on the client which is an issue on itself. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I kind of agree that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The "issue" is that |
||
return ZoneId.of(ZoneId.of(timeZoneId).getRules().getOffset(Instant.ofEpochMilli(randomLongDate)).toString()); | ||
} | ||
} |
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.
The method signature seems incorrect
column
seems to be used only locally andsb
can be returned by the method - passing them as arguments doesn't offer any value.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.
Will fix, just used the automatic refactoring.