hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jd...@apache.org
Subject hive git commit: HIVE-12772: Beeline/JDBC output of decimal values is not 0-padded, does not match with CLI output (Jason Dere, reviewed by Xuefu Zhang)
Date Wed, 13 Jan 2016 01:39:56 GMT
Repository: hive
Updated Branches:
  refs/heads/master fed1214b7 -> 9f1ff4f17


HIVE-12772: Beeline/JDBC output of decimal values is not 0-padded, does not match with CLI
output (Jason Dere, reviewed by Xuefu Zhang)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/9f1ff4f1
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/9f1ff4f1
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/9f1ff4f1

Branch: refs/heads/master
Commit: 9f1ff4f17525b8db5c63c7bcfb43ee73f42836eb
Parents: fed1214
Author: Jason Dere <jdere@hortonworks.com>
Authored: Tue Jan 12 17:39:05 2016 -0800
Committer: Jason Dere <jdere@hortonworks.com>
Committed: Tue Jan 12 17:39:05 2016 -0800

----------------------------------------------------------------------
 data/files/datatypes.txt                              |  2 +-
 .../java/org/apache/hive/jdbc/TestJdbcDriver2.java    |  2 +-
 .../src/java/org/apache/hive/service/cli/Column.java  | 10 ++++++++++
 .../org/apache/hive/service/cli/ColumnBasedSet.java   | 14 +++++++-------
 .../java/org/apache/hive/service/cli/ColumnValue.java | 11 +++++++----
 .../java/org/apache/hive/service/cli/RowBasedSet.java | 14 +++++++-------
 .../java/org/apache/hive/service/cli/TableSchema.java |  6 +++---
 7 files changed, 36 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/9f1ff4f1/data/files/datatypes.txt
----------------------------------------------------------------------
diff --git a/data/files/datatypes.txt b/data/files/datatypes.txt
index 458c5bd..0872a1f 100644
--- a/data/files/datatypes.txt
+++ b/data/files/datatypes.txt
@@ -1,3 +1,3 @@
 \N\N\N\N\N\N\N\N\N\N\N\N\N\N\N\N\N\N\N\N\N\N\N
 -1false-1.1\N\N\N-1-1-1.0-1\N\N\N\N\N\N\N\N\N
-1true1.11121x2ykva92.2111.01abcd1111213142212212x1abcd22012-04-22
09:00:00.123456789123456789.0123456YWJjZA==2013-01-01abc123abc123X'01FF'
+1true1.11121x2ykva92.2111.01abcd1111213142212212x1abcd22012-04-22
09:00:00.123456789123456789.123456YWJjZA==2013-01-01abc123abc123X'01FF'

http://git-wip-us.apache.org/repos/asf/hive/blob/9f1ff4f1/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java
----------------------------------------------------------------------
diff --git a/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java
index 71ea5d2..09905ea 100644
--- a/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java
+++ b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java
@@ -905,7 +905,7 @@ public class TestJdbcDriver2 {
     assertEquals("[{\"m\":{},\"n\":1},{\"m\":{\"a\":\"b\",\"c\":\"d\"},\"n\":2}]", res.getString(16));
     assertEquals("2012-04-22 09:00:00.123456789", res.getString(17));
     assertEquals("2012-04-22 09:00:00.123456789", res.getTimestamp(17).toString());
-    assertEquals("123456789.0123456", res.getBigDecimal(18).toString());
+    assertEquals("123456789.1234560", res.getBigDecimal(18).toString());
     assertEquals("abcd", res.getString(19));
     assertEquals("2013-01-01", res.getString(20));
     assertEquals("2013-01-01", res.getDate(20).toString());

http://git-wip-us.apache.org/repos/asf/hive/blob/9f1ff4f1/service/src/java/org/apache/hive/service/cli/Column.java
----------------------------------------------------------------------
diff --git a/service/src/java/org/apache/hive/service/cli/Column.java b/service/src/java/org/apache/hive/service/cli/Column.java
index a14c14e..102d920 100644
--- a/service/src/java/org/apache/hive/service/cli/Column.java
+++ b/service/src/java/org/apache/hive/service/cli/Column.java
@@ -42,6 +42,8 @@ import com.google.common.primitives.Ints;
 import com.google.common.primitives.Longs;
 import com.google.common.primitives.Shorts;
 
+import org.apache.hadoop.hive.common.type.HiveDecimal;
+
 /**
  * Column.
  */
@@ -326,6 +328,14 @@ public class Column extends AbstractList {
   private static final ByteBuffer EMPTY_BINARY = ByteBuffer.allocate(0);
   private static final String EMPTY_STRING = "";
 
+  public void addValue(TypeDescriptor typeDescriptor, Object field) {
+    if (field != null && typeDescriptor.getType() == Type.DECIMAL_TYPE) {
+      int scale = typeDescriptor.getDecimalDigits();
+      field = ((HiveDecimal) field).toFormatString(scale);
+    }
+    addValue(typeDescriptor.getType(), field);
+  }
+
   public void addValue(Type type, Object field) {
     switch (type) {
       case BOOLEAN_TYPE:

http://git-wip-us.apache.org/repos/asf/hive/blob/9f1ff4f1/service/src/java/org/apache/hive/service/cli/ColumnBasedSet.java
----------------------------------------------------------------------
diff --git a/service/src/java/org/apache/hive/service/cli/ColumnBasedSet.java b/service/src/java/org/apache/hive/service/cli/ColumnBasedSet.java
index e162f25..b7fe663 100644
--- a/service/src/java/org/apache/hive/service/cli/ColumnBasedSet.java
+++ b/service/src/java/org/apache/hive/service/cli/ColumnBasedSet.java
@@ -33,11 +33,11 @@ public class ColumnBasedSet implements RowSet {
 
   private long startOffset;
 
-  private final Type[] types; // non-null only for writing (server-side)
+  private final TypeDescriptor[] descriptors; // non-null only for writing (server-side)
   private final List<Column> columns;
 
   public ColumnBasedSet(TableSchema schema) {
-    types = schema.toTypes();
+    descriptors = schema.toTypeDescriptors();
     columns = new ArrayList<Column>();
     for (ColumnDescriptor colDesc : schema.getColumnDescriptors()) {
       columns.add(new Column(colDesc.getType()));
@@ -45,7 +45,7 @@ public class ColumnBasedSet implements RowSet {
   }
 
   public ColumnBasedSet(TRowSet tRowSet) {
-    types = null;
+    descriptors = null;
     columns = new ArrayList<Column>();
     for (TColumn tvalue : tRowSet.getColumns()) {
       columns.add(new Column(tvalue));
@@ -53,8 +53,8 @@ public class ColumnBasedSet implements RowSet {
     startOffset = tRowSet.getStartRowOffset();
   }
 
-  private ColumnBasedSet(Type[] types, List<Column> columns, long startOffset) {
-    this.types = types;
+  private ColumnBasedSet(TypeDescriptor[] descriptors, List<Column> columns, long startOffset)
{
+    this.descriptors = descriptors;
     this.columns = columns;
     this.startOffset = startOffset;
   }
@@ -62,7 +62,7 @@ public class ColumnBasedSet implements RowSet {
   @Override
   public ColumnBasedSet addRow(Object[] fields) {
     for (int i = 0; i < fields.length; i++) {
-      columns.get(i).addValue(types[i], fields[i]);
+      columns.get(i).addValue(descriptors[i], fields[i]);
     }
     return this;
   }
@@ -89,7 +89,7 @@ public class ColumnBasedSet implements RowSet {
     for (int i = 0; i < columns.size(); i++) {
       subset.add(columns.get(i).extractSubset(0, numRows));
     }
-    ColumnBasedSet result = new ColumnBasedSet(types, subset, startOffset);
+    ColumnBasedSet result = new ColumnBasedSet(descriptors, subset, startOffset);
     startOffset += numRows;
     return result;
   }

http://git-wip-us.apache.org/repos/asf/hive/blob/9f1ff4f1/service/src/java/org/apache/hive/service/cli/ColumnValue.java
----------------------------------------------------------------------
diff --git a/service/src/java/org/apache/hive/service/cli/ColumnValue.java b/service/src/java/org/apache/hive/service/cli/ColumnValue.java
index 12bb653..37460e6 100644
--- a/service/src/java/org/apache/hive/service/cli/ColumnValue.java
+++ b/service/src/java/org/apache/hive/service/cli/ColumnValue.java
@@ -138,10 +138,11 @@ public class ColumnValue {
     return TColumnValue.stringVal(tStringValue);
   }
 
-  private static TColumnValue stringValue(HiveDecimal value) {
+  private static TColumnValue stringValue(HiveDecimal value, TypeDescriptor typeDescriptor)
{
     TStringValue tStrValue = new TStringValue();
     if (value != null) {
-      tStrValue.setValue(value.toString());
+      int scale = typeDescriptor.getDecimalDigits();
+      tStrValue.setValue(value.toFormatString(scale));
     }
     return TColumnValue.stringVal(tStrValue);
   }
@@ -162,7 +163,9 @@ public class ColumnValue {
     return TColumnValue.stringVal(tStrValue);
   }
 
-  public static TColumnValue toTColumnValue(Type type, Object value) {
+  public static TColumnValue toTColumnValue(TypeDescriptor typeDescriptor, Object value)
{
+    Type type = typeDescriptor.getType();
+
     switch (type) {
     case BOOLEAN_TYPE:
       return booleanValue((Boolean)value);
@@ -193,7 +196,7 @@ public class ColumnValue {
     case INTERVAL_DAY_TIME_TYPE:
       return stringValue((HiveIntervalDayTime) value);
     case DECIMAL_TYPE:
-      return stringValue(((HiveDecimal)value));
+      return stringValue((HiveDecimal)value, typeDescriptor);
     case BINARY_TYPE:
       return stringValue((String)value);
     case ARRAY_TYPE:

http://git-wip-us.apache.org/repos/asf/hive/blob/9f1ff4f1/service/src/java/org/apache/hive/service/cli/RowBasedSet.java
----------------------------------------------------------------------
diff --git a/service/src/java/org/apache/hive/service/cli/RowBasedSet.java b/service/src/java/org/apache/hive/service/cli/RowBasedSet.java
index c1c8cfc..a80bac5 100644
--- a/service/src/java/org/apache/hive/service/cli/RowBasedSet.java
+++ b/service/src/java/org/apache/hive/service/cli/RowBasedSet.java
@@ -33,22 +33,22 @@ public class RowBasedSet implements RowSet {
 
   private long startOffset;
 
-  private final Type[] types; // non-null only for writing (server-side)
+  private final TypeDescriptor[] descriptors; // non-null only for writing (server-side)
   private final RemovableList<TRow> rows;
 
   public RowBasedSet(TableSchema schema) {
-    types = schema.toTypes();
+    descriptors = schema.toTypeDescriptors();
     rows = new RemovableList<TRow>();
   }
 
   public RowBasedSet(TRowSet tRowSet) {
-    types = null;
+    descriptors = null;
     rows = new RemovableList<TRow>(tRowSet.getRows());
     startOffset = tRowSet.getStartRowOffset();
   }
 
-  private RowBasedSet(Type[] types, List<TRow> rows, long startOffset) {
-    this.types = types;
+  private RowBasedSet(TypeDescriptor[] descriptors, List<TRow> rows, long startOffset)
{
+    this.descriptors = descriptors;
     this.rows = new RemovableList<TRow>(rows);
     this.startOffset = startOffset;
   }
@@ -57,7 +57,7 @@ public class RowBasedSet implements RowSet {
   public RowBasedSet addRow(Object[] fields) {
     TRow tRow = new TRow();
     for (int i = 0; i < fields.length; i++) {
-      tRow.addToColVals(ColumnValue.toTColumnValue(types[i], fields[i]));
+      tRow.addToColVals(ColumnValue.toTColumnValue(descriptors[i], fields[i]));
     }
     rows.add(tRow);
     return this;
@@ -75,7 +75,7 @@ public class RowBasedSet implements RowSet {
 
   public RowBasedSet extractSubset(int maxRows) {
     int numRows = Math.min(numRows(), maxRows);
-    RowBasedSet result = new RowBasedSet(types, rows.subList(0, numRows), startOffset);
+    RowBasedSet result = new RowBasedSet(descriptors, rows.subList(0, numRows), startOffset);
     rows.removeRange(0, numRows);
     startOffset += numRows;
     return result;

http://git-wip-us.apache.org/repos/asf/hive/blob/9f1ff4f1/service/src/java/org/apache/hive/service/cli/TableSchema.java
----------------------------------------------------------------------
diff --git a/service/src/java/org/apache/hive/service/cli/TableSchema.java b/service/src/java/org/apache/hive/service/cli/TableSchema.java
index 22f15bf..2206e2c 100644
--- a/service/src/java/org/apache/hive/service/cli/TableSchema.java
+++ b/service/src/java/org/apache/hive/service/cli/TableSchema.java
@@ -82,10 +82,10 @@ public class TableSchema {
     return tTableSchema;
   }
 
-  public Type[] toTypes() {
-    Type[] types = new Type[columns.size()];
+  public TypeDescriptor[] toTypeDescriptors() {
+    TypeDescriptor[] types = new TypeDescriptor[columns.size()];
     for (int i = 0; i < types.length; i++) {
-      types[i] = columns.get(i).getType();
+      types[i] = columns.get(i).getTypeDescriptor();
     }
     return types;
   }


Mime
View raw message