tkalkirill commented on code in PR #13569:
URL: https://github.com/apache/ignite/pull/13569#discussion_r4015446226
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/util/TypeUtils.java:
##########
@@ -409,23 +415,39 @@ else if (val instanceof Number && storageType !=
val.getClass()) {
* @return Millis value.
*/
private static long toLong(DataContext ctx, Object val) {
+ // Java time values have no time zone and use the proleptic Gregorian
calendar, as does Calcite.
if (val instanceof LocalDateTime)
- return
toLong(DateValueUtils.convertToTimestamp((LocalDateTime)val),
DataContext.Variable.TIME_ZONE.get(ctx));
+ return
((LocalDateTime)val).toInstant(ZoneOffset.UTC).toEpochMilli();
if (val instanceof LocalDate)
- return toLong(DateValueUtils.convertToSqlDate((LocalDate)val),
DataContext.Variable.TIME_ZONE.get(ctx));
+ return ((LocalDate)val).toEpochDay() *
DateTimeUtils.MILLIS_PER_DAY;
if (val instanceof LocalTime)
- return toLong(DateValueUtils.convertToSqlTime((LocalTime)val),
DataContext.Variable.TIME_ZONE.get(ctx));
+ return
TimeUnit.NANOSECONDS.toMillis(((LocalTime)val).toNanoOfDay());
- return toLong((java.util.Date)val,
DataContext.Variable.TIME_ZONE.get(ctx));
+ return toLong((java.util.Date)val, timeZone(ctx));
}
/** */
private static long toLong(java.util.Date val, TimeZone tz) {
long time = val.getTime();
+ long locTs = time + tz.getOffset(time);
+
+ if (locTs >= GREGORIAN_CUTOVER)
Review Comment:
Added a comment explaining why the conversion is needed, with the 1500-01-02
→ 1500-01-11 example. Without it, three tests in TypeUtilsTest fail; these
tests are not part of JdbcTestSuite.
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/util/TypeUtils.java:
##########
@@ -409,23 +415,39 @@ else if (val instanceof Number && storageType !=
val.getClass()) {
* @return Millis value.
*/
private static long toLong(DataContext ctx, Object val) {
+ // Java time values have no time zone and use the proleptic Gregorian
calendar, as does Calcite.
if (val instanceof LocalDateTime)
- return
toLong(DateValueUtils.convertToTimestamp((LocalDateTime)val),
DataContext.Variable.TIME_ZONE.get(ctx));
+ return
((LocalDateTime)val).toInstant(ZoneOffset.UTC).toEpochMilli();
if (val instanceof LocalDate)
- return toLong(DateValueUtils.convertToSqlDate((LocalDate)val),
DataContext.Variable.TIME_ZONE.get(ctx));
+ return ((LocalDate)val).toEpochDay() *
DateTimeUtils.MILLIS_PER_DAY;
if (val instanceof LocalTime)
- return toLong(DateValueUtils.convertToSqlTime((LocalTime)val),
DataContext.Variable.TIME_ZONE.get(ctx));
+ return
TimeUnit.NANOSECONDS.toMillis(((LocalTime)val).toNanoOfDay());
- return toLong((java.util.Date)val,
DataContext.Variable.TIME_ZONE.get(ctx));
+ return toLong((java.util.Date)val, timeZone(ctx));
}
/** */
private static long toLong(java.util.Date val, TimeZone tz) {
long time = val.getTime();
+ long locTs = time + tz.getOffset(time);
+
+ if (locTs >= GREGORIAN_CUTOVER)
Review Comment:
Added a comment explaining why the conversion is needed, with the 1500-01-02
→ 1500-01-11 example. Without it, three tests in `TypeUtilsTest` fail; these
tests are not part of `JdbcTestSuite`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]