JingsongLi commented on a change in pull request #10212:
[FLINK-14806][table-planner-blink] Add setTimestamp/getTimestamp inte…
URL: https://github.com/apache/flink/pull/10212#discussion_r347332620
##########
File path:
flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/dataformat/vector/VectorizedColumnBatch.java
##########
@@ -132,4 +136,48 @@ public Decimal getDecimal(int rowId, int colId, int
precision, int scale) {
return Decimal.fromUnscaledBytes(precision, scale,
bytes);
}
}
+
+ public SqlTimestamp getTimestamp(int rowId, int colId, int precision) {
+ if (isNullAt(rowId, colId)) {
+ return null;
+ }
+
+ // The precision of Timestamp in parquet should be one of
MILLIS, MICROS or NANOS.
+ //
https://github.com/apache/parquet-format/blob/master/LogicalTypes.md#timestamp
+ //
+ // For MILLIS, the underlying INT64 holds milliseconds
+ // For MICROS, the underlying INT64 holds microseconds
+ // For NANOS, the underlying INT96 holds nanoOfDay(8 bytes) and
julianDay(4 bytes)
+ if (columns[colId] instanceof TimestampColumnVector) {
+ return ((TimestampColumnVector)
(columns[colId])).getTimestamp(rowId, precision);
+ } else if (precision <= 3) {
+ return SqlTimestamp.fromEpochMillis(getLong(rowId,
colId));
+ } else if (precision <= 6) {
+ long microseconds = getLong(rowId, colId);
+ return SqlTimestamp.fromEpochMillis(
+ microseconds / 1000, (int) (microseconds %
1000) * 1000);
+ } else {
+ byte[] bytes = getBytes(rowId, colId);
+ assert bytes.length == 12;
+ long l = 0;
+ for (int i = 0; i < 8; i++) {
+ l <<= 8;
+ l |= (bytes[i] & (0xff));
+ }
+ int n = 0;
+ for (int i = 8; i < 12; i++) {
+ n <<= 8;
+ n |= (bytes[i] & (0xff));
+ }
+ LocalTime localTime = LocalTime.ofNanoOfDay(l);
Review comment:
Why use `LocalTime`?
We just need get millseconds from `nanoseconds`.
----------------------------------------------------------------
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]
With regards,
Apache Git Services