scruz-denodo commented on code in PR #43149:
URL: https://github.com/apache/arrow/pull/43149#discussion_r1668227367
##########
java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcDateVectorAccessor.java:
##########
@@ -108,11 +104,36 @@ private void fillHolder() {
@Override
public Timestamp getTimestamp(Calendar calendar) {
- Date date = getDate(calendar);
- if (date == null) {
+ final LocalDateTime localDateTime = getLocalDateTime(calendar);
+ if (localDateTime == null) {
+ return null;
+ }
+
+ return Timestamp.valueOf(localDateTime);
+ }
+
+ private LocalDateTime getLocalDateTime(Calendar calendar) {
+ getter.get(getCurrentRow(), holder);
+ this.wasNull = holder.isSet == 0;
+ this.wasNullConsumer.setWasNull(this.wasNull);
+ if (this.wasNull) {
return null;
}
- return new Timestamp(date.getTime());
+
+ final LocalDateTime localDateTime =
+
DateUtility.getLocalDateTimeFromEpochMilli(this.timeUnit.toMillis(holder.value));
+ final ZoneId defaultTimeZone =
Calendar.getInstance().getTimeZone().toZoneId();
Review Comment:
Hi, problem here is that `java.sql.Timestamp` and `java.sql.Date` only
contains a long value with milliseconds. You have to tell java how to print
this long, in what timezone.
So, the method has to follow the same approach done at
`org.apache.arrow.driver.jdbc.accessor.impl.calendar.ArrowFlightJdbcTimeStampVectorAccessor#getLocalDateTime`
- first putting the received value (which is in UTC) at the expected time
zone. The expected time zone is the default one for the JVM or the time zone
specified when calling to `java.sql.ResultSet#getDate(java.lang.String,
java.util.Calendar)`. This is done on this line.
`.atZone(sourceTimeZone)`
- then, the value is adjusted to the JVM timezone.
`.withZoneSameInstant(defaultTimeZone)`
When this method is used `java.sql.ResultSet#getDate(java.lang.String,
java.util.Calendar)`, it is expected that the caller prints the date returned
on the specified time zone. Something like:
```
final Date dateValue = rs.getDate("date_field",
Calendar.getInstance(TimeZone.getTimeZone("Asia/Tokyo")));
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("Asia/Tokyo"));
System.out.println("Received date: " +sdf.format(dateValue));
```
--
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]