Skip to content

Commit 1e8db48

Browse files
authored
HBASE-24937 table.rb use LocalDateTime to replace Instant (#2351)
Signed-off-by: Pankaj Kumar<[email protected]>
1 parent 19d0140 commit 1e8db48

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

hbase-shell/src/main/ruby/hbase/table.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -750,8 +750,9 @@ def parse_column_name(column)
750750
[spec.family, spec.qualifier]
751751
end
752752

753-
def toISO8601(millis)
754-
return java.time.Instant.ofEpochMilli(millis).toString
753+
def toLocalDateTime(millis)
754+
instant = java.time.Instant.ofEpochMilli(millis)
755+
return java.time.LocalDateTime.ofInstant(instant, java.time.ZoneId.systemDefault()).toString
755756
end
756757

757758
# Make a String of the passed kv
@@ -762,7 +763,7 @@ def to_string(column, kv, maxlength = -1, converter_class = nil, converter = nil
762763
column.start_with?('info:merge')
763764
hri = org.apache.hadoop.hbase.client.RegionInfo.parseFromOrNull(kv.getValueArray,
764765
kv.getValueOffset, kv.getValueLength)
765-
return format('timestamp=%s, value=%s', toISO8601(kv.getTimestamp),
766+
return format('timestamp=%s, value=%s', toLocalDateTime(kv.getTimestamp),
766767
hri.nil? ? '' : hri.toString)
767768
end
768769
if column == 'info:serverstartcode'
@@ -773,14 +774,14 @@ def to_string(column, kv, maxlength = -1, converter_class = nil, converter = nil
773774
str_val = org.apache.hadoop.hbase.util.Bytes.toStringBinary(kv.getValueArray,
774775
kv.getValueOffset, kv.getValueLength)
775776
end
776-
return format('timestamp=%s, value=%s', toISO8601(kv.getTimestamp), str_val)
777+
return format('timestamp=%s, value=%s', toLocalDateTime(kv.getTimestamp), str_val)
777778
end
778779
end
779780

780781
if org.apache.hadoop.hbase.CellUtil.isDelete(kv)
781-
val = "timestamp=#{toISO8601(kv.getTimestamp)}, type=#{org.apache.hadoop.hbase.KeyValue::Type.codeToType(kv.getTypeByte)}"
782+
val = "timestamp=#{toLocalDateTime(kv.getTimestamp)}, type=#{org.apache.hadoop.hbase.KeyValue::Type.codeToType(kv.getTypeByte)}"
782783
else
783-
val = "timestamp=#{toISO8601(kv.getTimestamp)}, value=#{convert(column, kv, converter_class, converter)}"
784+
val = "timestamp=#{toLocalDateTime(kv.getTimestamp)}, value=#{convert(column, kv, converter_class, converter)}"
784785
end
785786
maxlength != -1 ? val[0, maxlength] : val
786787
end

0 commit comments

Comments
 (0)