edgarRd commented on a change in pull request #2254:
URL: https://github.com/apache/iceberg/pull/2254#discussion_r584050196
##########
File path:
mr/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergFilterFactory.java
##########
@@ -172,15 +171,24 @@ private static BigDecimal
hiveDecimalToBigDecimal(HiveDecimalWritable hiveDecima
return
hiveDecimalWritable.getHiveDecimal().bigDecimalValue().setScale(hiveDecimalWritable.scale());
}
+ // Hive uses `java.sql.Date.valueOf(lit.toString());` to convert a literal
to Date
+ // Which uses `java.util.Date()` internally to create the object and that
uses the TimeZone.getDefaultRef()
+ // To get back the expected date we have to use the LocalDate which gets rid
of the TimeZone misery as it uses
+ // the year/month/day to generate the object
private static int daysFromDate(Date date) {
- return DateTimeUtil.daysFromInstant(Instant.ofEpochMilli(date.getTime()));
+ return DateTimeUtil.daysFromDate(date.toLocalDate());
}
+ // Hive uses `java.sql.Timestamp.valueOf(lit.toString());` to convert a
literal to Timestamp
+ // Which again uses `java.util.Date()` internally to create the object which
uses the TimeZone.getDefaultRef()
+ // To get back the expected timestamp we have to use the LocalDateTime which
gets rid of the TimeZone misery
+ // as it uses the year/month/day/hour/min/sec/nanos to generate the object
private static int daysFromTimestamp(Timestamp timestamp) {
- return DateTimeUtil.daysFromInstant(timestamp.toInstant());
+ return
DateTimeUtil.daysFromDate(timestamp.toLocalDateTime().toLocalDate());
}
+ // We have to use the LocalDateTime to get the micros. See the comment above.
private static long microsFromTimestamp(Timestamp timestamp) {
- return DateTimeUtil.microsFromInstant(timestamp.toInstant());
+ return DateTimeUtil.microsFromTimestamp(timestamp.toLocalDateTime());
Review comment:
I'm in PST, if you replace
https://github.com/apache/iceberg/blob/master/mr/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergFilterFactory.java#L240-L242
for:
```
TimeZone defaultTz = TimeZone.getDefault();
try {
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
UnboundPredicate actual = (UnboundPredicate)
HiveIcebergFilterFactory.generateFilterExpression(arg);
assertPredicatesMatch(expected, actual);
} finally {
TimeZone.setDefault(defaultTz);
}
```
to set the TimeZone, you should be able to repro - conversely if I use
`"UTC"` instead of `"America/Los_Angeles"` the test pass.
I'm running the unit test out of the master branch, with:
```
./gradlew clean :iceberg-mr:test --tests
org.apache.iceberg.mr.hive.TestHiveIcebergFilterFactory
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]