From 675e004cf1f6630547d60b64b43fdf3acf4b50e0 Mon Sep 17 00:00:00 2001 From: Jonathan Hsieh Date: Sat, 17 May 2014 00:32:26 +0000 Subject: [PATCH] HBASE-6990 pretty print TTL (Esteban Gutierrez) git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1595396 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop/hbase/HColumnDescriptor.java | 20 ++++++++++++++++--- .../org/apache/hadoop/hbase/HConstants.java | 7 +++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java index e888e6aa445..94cd263839a 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java @@ -39,6 +39,8 @@ import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.ColumnFamilySchema import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.NameStringPair; import org.apache.hadoop.hbase.regionserver.BloomType; import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.hbase.util.PrettyPrinter; +import org.apache.hadoop.hbase.util.PrettyPrinter.Unit; import org.apache.hadoop.io.Text; import org.apache.hadoop.io.WritableComparable; @@ -929,6 +931,7 @@ public class HColumnDescriptor implements WritableComparable @Override public String toString() { StringBuilder s = new StringBuilder(); + s.append('{'); s.append(HConstants.NAME); s.append(" => '"); @@ -973,7 +976,7 @@ public class HColumnDescriptor implements WritableComparable s.append(", "); s.append(key); s.append(" => "); - s.append('\'').append(value).append('\''); + s.append('\'').append(PrettyPrinter.format(value, getUnit(key))).append('\''); } } @@ -995,7 +998,7 @@ public class HColumnDescriptor implements WritableComparable printComma = true; s.append('\'').append(key).append('\''); s.append(" => "); - s.append('\'').append(value).append('\''); + s.append('\'').append(PrettyPrinter.format(value, getUnit(key))).append('\''); } s.append('}'); } @@ -1010,13 +1013,24 @@ public class HColumnDescriptor implements WritableComparable printCommaForConfiguration = true; s.append('\'').append(e.getKey()).append('\''); s.append(" => "); - s.append('\'').append(e.getValue()).append('\''); + s.append('\'').append(PrettyPrinter.format(e.getValue(), getUnit(e.getKey()))).append('\''); } s.append("}"); } return s; } + public static Unit getUnit(String key) { + Unit unit; + /* TTL for now, we can add more as we neeed */ + if (key.equals(HColumnDescriptor.TTL)) { + unit = Unit.TIME_INTERVAL; + } else { + unit = Unit.NONE; + } + return unit; + } + public static Map getDefaultValues() { return Collections.unmodifiableMap(DEFAULT_VALUES); } diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java index 1b15770ffe6..31aebcbdefd 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java @@ -507,6 +507,13 @@ public final class HConstants { */ public static final int WEEK_IN_SECONDS = 7 * 24 * 3600; + /** + * Seconds in a day, hour and minute + */ + public static final int DAY_IN_SECONDS = 24 * 60 * 60; + public static final int HOUR_IN_SECONDS = 60 * 60; + public static final int MINUTE_IN_SECONDS = 60; + //TODO: although the following are referenced widely to format strings for // the shell. They really aren't a part of the public API. It would be // nice if we could put them somewhere where they did not need to be