You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2020/03/12 00:14:54 UTC

[hbase] branch branch-2 updated: HBASE-23930 Shell should attempt to format `timestamp` attributes as ISO-8601

This is an automated email from the ASF dual-hosted git repository.

stack pushed a commit to branch branch-2
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-2 by this push:
     new 08603f0  HBASE-23930 Shell should attempt to format `timestamp` attributes as ISO-8601
08603f0 is described below

commit 08603f02eabf1c151a7300930a9b8dba7f938b36
Author: stack <st...@apache.org>
AuthorDate: Wed Mar 11 17:14:11 2020 -0700

    HBASE-23930 Shell should attempt to format `timestamp` attributes as ISO-8601
    
    Make display of Cell timestamp be ISO8601 format instead of pure milliseconds.
---
 hbase-shell/src/main/ruby/hbase/table.rb | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/hbase-shell/src/main/ruby/hbase/table.rb b/hbase-shell/src/main/ruby/hbase/table.rb
index 49f389e..2526ceb 100644
--- a/hbase-shell/src/main/ruby/hbase/table.rb
+++ b/hbase-shell/src/main/ruby/hbase/table.rb
@@ -734,6 +734,10 @@ EOF
       [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)
@@ -741,8 +745,9 @@ EOF
         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
@@ -752,14 +757,14 @@ EOF
             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