Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cfmcgrady committed Feb 16, 2023
1 parent f560135 commit 78b7cab
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class SparkArrowbasedOperationSuite extends WithSparkSQLEngine with SparkDataTyp
statement.executeQuery(s"set ${KyuubiConf.ARROW_BASED_ROWSET_TIMESTAMP_AS_STRING.key}=false")
checkArrowBasedRowSetTimestampAsString(statement, "false")
setTimeZone("UTC")
check("2022-12-08 01:15:35.0")
check("2022-12-07 17:15:35.0")
setTimeZone("GMT+8")
check("2022-12-08 01:15:35.0")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,14 @@ private Object getColumnValue(int columnIndex) throws SQLException {
wasNull = row.isNullAt(columnIndex - 1);
if (wasNull) {
return null;
} else if (columnType == TTypeId.TIMESTAMP_TYPE) {
return row.get(
columnIndex - 1,
columnType,
columnAttributes.get(columnIndex - 1).timeZone,
timestampAsString);
} else {
return row.get(columnIndex - 1, columnType, timestampAsString);
return row.get(columnIndex - 1, columnType, null, timestampAsString);
}
} catch (Exception e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
import org.apache.arrow.vector.util.DateUtility;
import org.apache.hive.service.rpc.thrift.TTypeId;
import org.apache.kyuubi.jdbc.hive.common.DateUtils;
import org.apache.kyuubi.jdbc.hive.common.HiveIntervalDayTime;
Expand Down Expand Up @@ -104,7 +109,7 @@ public Object getMap(int ordinal) {
throw new UnsupportedOperationException();
}

public Object get(int ordinal, TTypeId dataType, boolean timestampAsString) {
public Object get(int ordinal, TTypeId dataType, String timeZone, boolean timestampAsString) {
long seconds;
long milliseconds;
long microseconds;
Expand Down Expand Up @@ -134,12 +139,14 @@ public Object get(int ordinal, TTypeId dataType, boolean timestampAsString) {
if (timestampAsString) {
return Timestamp.valueOf(getString(ordinal));
} else {
microseconds = getLong(ordinal);
System.out.println("microseconds: " + microseconds);
nanos = (int) (microseconds % 1_000_000) * 1000;
Timestamp timestamp = new Timestamp(microseconds / 1_000);
timestamp.setNanos(nanos);
return timestamp;
LocalDateTime localDateTime =
DateUtility.getLocalDateTimeFromEpochMicro(getLong(ordinal), timeZone);
long millis = TimeUnit.MICROSECONDS.toMillis(getLong(ordinal));
TimeZone zone = TimeZone.getTimeZone(timeZone);
localDateTime =
localDateTime.minus(
zone.getOffset(millis) - zone.getOffset(millis), ChronoUnit.MILLIS);
return Timestamp.valueOf(localDateTime);
}
case DATE_TYPE:
return DateUtils.internalToDate(getInt(ordinal));
Expand Down

0 comments on commit 78b7cab

Please sign in to comment.