You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by dm...@apache.org on 2020/07/16 13:23:25 UTC

[hive] branch master updated: HIVE-23856: Beeline Should Print Binary Data in Base64 (Hunter Logan via David Mollitor)

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

dmollitor pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git


The following commit(s) were added to refs/heads/master by this push:
     new acfc0d5  HIVE-23856: Beeline Should Print Binary Data in Base64 (Hunter Logan via David Mollitor)
acfc0d5 is described below

commit acfc0d5d1f9ec12972d9be4c584e0803ab3053e1
Author: Hunter Logan <hu...@outlook.com>
AuthorDate: Thu Jul 16 09:23:07 2020 -0400

    HIVE-23856: Beeline Should Print Binary Data in Base64 (Hunter Logan via David Mollitor)
---
 beeline/src/java/org/apache/hive/beeline/Rows.java                | 8 +++++---
 beeline/src/test/org/apache/hive/beeline/TestIncrementalRows.java | 2 +-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/beeline/src/java/org/apache/hive/beeline/Rows.java b/beeline/src/java/org/apache/hive/beeline/Rows.java
index 8826bcd..3d5eaec 100644
--- a/beeline/src/java/org/apache/hive/beeline/Rows.java
+++ b/beeline/src/java/org/apache/hive/beeline/Rows.java
@@ -22,12 +22,14 @@
  */
 package org.apache.hive.beeline;
 
+import java.nio.charset.StandardCharsets;
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 import java.text.DecimalFormat;
 import java.text.NumberFormat;
 import java.util.Arrays;
+import java.util.Base64;
 import java.util.Iterator;
 
 import org.apache.hadoop.hive.common.cli.EscapeCRLFHelper;
@@ -41,7 +43,7 @@ abstract class Rows implements Iterator {
   final ResultSetMetaData rsMeta;
   final Boolean[] primaryKeys;
   final NumberFormat numberFormat;
-  private boolean convertBinaryArray;
+  private boolean convertBinaryArrayToString;
   private final String nullStr;
 
   Rows(BeeLine beeLine, ResultSet rs) throws SQLException {
@@ -55,7 +57,7 @@ abstract class Rows implements Iterator {
     } else {
       numberFormat = new DecimalFormat(beeLine.getOpts().getNumberFormat());
     }
-    this.convertBinaryArray = beeLine.getOpts().getConvertBinaryArrayToString();
+    this.convertBinaryArrayToString = beeLine.getOpts().getConvertBinaryArrayToString();
   }
 
   @Override
@@ -162,7 +164,7 @@ abstract class Rows implements Iterator {
         } else if (o instanceof Number) {
           value = numberFormat != null ? numberFormat.format(o) : o.toString();
         } else if (o instanceof byte[]) {
-          value = convertBinaryArray ? new String((byte[])o) : Arrays.toString((byte[])o);
+          value = convertBinaryArrayToString ? new String((byte[])o, StandardCharsets.UTF_8) : Base64.getEncoder().withoutPadding().encodeToString((byte[])o);
         } else {
           value = o.toString();
         }
diff --git a/beeline/src/test/org/apache/hive/beeline/TestIncrementalRows.java b/beeline/src/test/org/apache/hive/beeline/TestIncrementalRows.java
index 61661a1..eb4e27b 100644
--- a/beeline/src/test/org/apache/hive/beeline/TestIncrementalRows.java
+++ b/beeline/src/test/org/apache/hive/beeline/TestIncrementalRows.java
@@ -94,7 +94,7 @@ public class TestIncrementalRows {
 
     convertedIr.next();
     String row = convertedIr.next().toString();
-    Assert.assertEquals("[[77, 77, 77]]", row);
+    Assert.assertEquals("[TU1N]", row);
   }
 
   public void initNrOfResultSetCalls(final int iter) throws SQLException {