Skip to content

Commit

Permalink
HBASE-23930 Shell should attempt to format timestamp attributes as …
Browse files Browse the repository at this point in the history
…ISO-8601

Make display of Cell timestamp be ISO8601 format instead of pure milliseconds.
  • Loading branch information
saintstack committed Mar 12, 2020
1 parent 6f1e8ab commit cf12122
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions hbase-shell/src/main/ruby/hbase/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -734,15 +734,20 @@ def parse_column_name(column)
[split[0], split.length > 1 ? split[1] : nil]
end

def toISO8601(millis)
return java.time.Instant.ofEpochMilli(millis).toString
end

# Make a String of the passed kv
# Intercept cells whose format we know such as the info:regioninfo in hbase:meta
def to_string(column, kv, maxlength = -1, converter_class = nil, converter = nil)
if is_meta_table?
if column == 'info:regioninfo' || column == 'info:splitA' || column == 'info:splitB' || \
column.start_with?('info:merge')
hri = org.apache.hadoop.hbase.HRegionInfo.parseFromOrNull(kv.getValueArray,
kv.getValueOffset, kv.getValueLength)
return format('timestamp=%d, value=%s', kv.getTimestamp, hri.nil? ? '' : hri.toString)
kv.getValueOffset, kv.getValueLength)
return format('timestamp=%s, value=%s', toISO8601(kv.getTimestamp),
hri.nil? ? '' : hri.toString)
end
if column == 'info:serverstartcode'
if kv.getValueLength > 0
Expand All @@ -752,14 +757,14 @@ def to_string(column, kv, maxlength = -1, converter_class = nil, converter = nil
str_val = org.apache.hadoop.hbase.util.Bytes.toStringBinary(kv.getValueArray,
kv.getValueOffset, kv.getValueLength)
end
return format('timestamp=%d, value=%s', kv.getTimestamp, str_val)
return format('timestamp=%s, value=%s', toISO8601(kv.getTimestamp), str_val)
end
end

if org.apache.hadoop.hbase.CellUtil.isDelete(kv)
val = "timestamp=#{kv.getTimestamp}, type=#{org.apache.hadoop.hbase.KeyValue::Type.codeToType(kv.getTypeByte)}"
val = "timestamp=#{toISO8601(kv.getTimestamp)}, type=#{org.apache.hadoop.hbase.KeyValue::Type.codeToType(kv.getTypeByte)}"
else
val = "timestamp=#{kv.getTimestamp}, value=#{convert(column, kv, converter_class, converter)}"
val = "timestamp=#{toISO8601(kv.getTimestamp)}, value=#{convert(column, kv, converter_class, converter)}"
end
maxlength != -1 ? val[0, maxlength] : val
end
Expand Down

0 comments on commit cf12122

Please sign in to comment.