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

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

commit 9cbfaad0a92b4ffb6302ea1cfbcdfaa24cd8786b
Author: Vitalii Diravka <vita...@apache.org>
AuthorDate: Mon Apr 8 02:19:59 2019 +0300

    DRILL-7049: REST API returns the toString of byte arrays (VARBINARY types)
    
    closes #1739
---
 .../exec/util/ValueVectorElementFormatter.java     | 26 +++++-----------------
 .../exec/util/TestValueVectorElementFormatter.java | 11 +++++++++
 2 files changed, 17 insertions(+), 20 deletions(-)

diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/util/ValueVectorElementFormatter.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/util/ValueVectorElementFormatter.java
index 01921df..63c9440 100644
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/util/ValueVectorElementFormatter.java
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/util/ValueVectorElementFormatter.java
@@ -52,47 +52,33 @@ public class ValueVectorElementFormatter {
    * @return the formatted value, null if failed
    */
   public String format(Object value, TypeProtos.MinorType minorType) {
-    boolean handled = false;
-       String str = null;
     switch (minorType) {
       case TIMESTAMP:
         if (value instanceof LocalDateTime) {
-          handled = true;
-          str = format((LocalDateTime) value,
+          return format((LocalDateTime) value,
                         
options.getString(ExecConstants.WEB_DISPLAY_FORMAT_TIMESTAMP),
                         (v, p) -> v.format(getTimestampFormatter(p)));
         }
-        break;
       case DATE:
         if (value instanceof LocalDate) {
-          handled = true;
-          str = format((LocalDate) value,
+          return format((LocalDate) value,
                         
options.getString(ExecConstants.WEB_DISPLAY_FORMAT_DATE),
                         (v, p) -> v.format(getDateFormatter(p)));
         }
-        break;
       case TIME:
         if (value instanceof LocalTime) {
-          handled = true;
-          str = format((LocalTime) value,
+          return format((LocalTime) value,
                         
options.getString(ExecConstants.WEB_DISPLAY_FORMAT_TIME),
                         (v, p) -> v.format(getTimeFormatter(p)));
         }
-        break;
       case VARBINARY:
         if (value instanceof byte[]) {
-          handled = true;
           byte[] bytes = (byte[]) value;
-          str = 
org.apache.drill.common.util.DrillStringUtils.toBinaryString(bytes);
+          return 
org.apache.drill.common.util.DrillStringUtils.toBinaryString(bytes);
         }
-        break;
+      default:
+        return value.toString();
     }
-
-    if (!handled) {
-      str = value.toString();
-    }
-
-    return str;
   }
 
   /**
diff --git 
a/exec/java-exec/src/test/java/org/apache/drill/exec/util/TestValueVectorElementFormatter.java
 
b/exec/java-exec/src/test/java/org/apache/drill/exec/util/TestValueVectorElementFormatter.java
index 5c6666d..8e7df54 100644
--- 
a/exec/java-exec/src/test/java/org/apache/drill/exec/util/TestValueVectorElementFormatter.java
+++ 
b/exec/java-exec/src/test/java/org/apache/drill/exec/util/TestValueVectorElementFormatter.java
@@ -25,6 +25,7 @@ import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 
+import java.nio.charset.StandardCharsets;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
@@ -142,4 +143,14 @@ public class TestValueVectorElementFormatter {
     assertEquals("Mon, Nov 5, 2012", formattedDate);
     assertEquals("1:00:30 PM", formattedTime);
   }
+
+  @Test // DRILL-7049
+  public void testFormatValueVectorElementBinary() {
+    ValueVectorElementFormatter formatter = new 
ValueVectorElementFormatter(options);
+    String testString = "Fred";
+    String formattedValue = formatter.format(
+            testString.getBytes(StandardCharsets.UTF_8),
+            TypeProtos.MinorType.VARBINARY);
+    assertEquals("Wrong Varbinary value formatting", testString, 
formattedValue);
+  }
 }

Reply via email to