Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
Drill, mail # dev - [5/7] git commit: DRILL-433: Enhance QuerySubmitter to accept custom column width to be used while printing results.


Copy link to this message
-
[5/7] git commit: DRILL-433: Enhance QuerySubmitter to accept custom column width to be used while printing results.
jacques@... 2014-03-29, 18:37
DRILL-433: Enhance QuerySubmitter to accept custom column width to be used while printing results.
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/dafd53aa
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/dafd53aa
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/dafd53aa

Branch: refs/heads/master
Commit: dafd53aac7273a60ae1c25f5ddda4be6c2726bec
Parents: 3419e8c
Author: Mehant Baid <[EMAIL PROTECTED]>
Authored: Fri Mar 21 20:20:41 2014 -0700
Committer: Jacques Nadeau <[EMAIL PROTECTED]>
Committed: Sat Mar 29 11:28:19 2014 -0700

 .../drill/exec/client/QuerySubmitter.java       | 17 ++++++++++----
 .../org/apache/drill/exec/util/VectorUtil.java  | 24 +++++++++++++-------
 2 files changed, 29 insertions(+), 12 deletions(-)
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/dafd53aa/exec/java-exec/src/main/java/org/apache/drill/exec/client/QuerySubmitter.java
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/client/QuerySubmitter.java b/exec/java-exec/src/main/java/org/apache/drill/exec/client/QuerySubmitter.java
index 3fb607c..4551e53 100644
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/client/QuerySubmitter.java
@@ -68,7 +68,7 @@ public class QuerySubmitter {
       System.exit(0);
     }
 
-    System.exit(submitter.submitQuery(o.location, o.queryString, o.planType, o.zk, o.local, o.bits, o.format));
+    System.exit(submitter.submitQuery(o.location, o.queryString, o.planType, o.zk, o.local, o.bits, o.format, o.width));
   }
 
   static class Options {
@@ -95,6 +95,9 @@ public class QuerySubmitter {
 
     @Parameter(names = {"--format"}, description = "output format, csv,tsv,table", required = false)
     public String format = "table";
+
+    @Parameter(names = {"-w", "--width"}, description = "max column width", required = false)
+    public int width = VectorUtil.DEFAULT_COLUMN_WIDTH;
   }
 
   public enum Format {
@@ -102,6 +105,10 @@ public class QuerySubmitter {
   }
 
   public int submitQuery(String planLocation, String queryString, String type, String zkQuorum, boolean local, int bits, String format) throws Exception {
+      return submitQuery(planLocation, queryString, type, zkQuorum, local, bits, format, VectorUtil.DEFAULT_COLUMN_WIDTH);
+  }
+
+  public int submitQuery(String planLocation, String queryString, String type, String zkQuorum, boolean local, int bits, String format, int width) throws Exception {
     DrillConfig config = DrillConfig.create();
     DrillClient client = null;
 
@@ -168,7 +175,7 @@ public class QuerySubmitter {
       }
       Stopwatch watch = new Stopwatch();
       for (String query : queries) {
-        listener = new QueryResultsListener(outputFormat);
+        listener = new QueryResultsListener(outputFormat, width);
         watch.start();
         client.runQuery(queryType, query, listener);
         int rows = listener.await();
@@ -190,10 +197,12 @@ public class QuerySubmitter {
     private CountDownLatch latch = new CountDownLatch(1);
     RecordBatchLoader loader = new RecordBatchLoader(new BootStrapContext(DrillConfig.create()).getAllocator());
     Format format;
+    int    columnWidth;
     volatile Exception exception;
 
-    public QueryResultsListener(Format format) {
+    public QueryResultsListener(Format format, int columnWidth) {
       this.format = format;
+      this.columnWidth = columnWidth;
     }
 
     @Override
@@ -215,7 +224,7 @@ public class QuerySubmitter {
 
         switch(format) {
           case TABLE:
-            VectorUtil.showVectorAccessibleContent(loader);
+            VectorUtil.showVectorAccessibleContent(loader, columnWidth);
             break;
           case TSV:
             VectorUtil.showVectorAccessibleContent(loader, "\t");

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/dafd53aa/exec/java-exec/src/main/java/org/apache/drill/exec/util/VectorUtil.java
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/util/VectorUtil.java b/exec/java-exec/src/main/java/org/apache/drill/exec/util/VectorUtil.java
index a9e6f30..c19faa0 100644
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/util/VectorUtil.java
@@ -29,6 +29,8 @@ import com.beust.jcommander.internal.Lists;
 
 public class VectorUtil {
 
+  public static final int DEFAULT_COLUMN_WIDTH = 15;
+
   public static void showVectorAccessibleContent(VectorAccessible va, final String delimiter) {
 
     int rows = va.getRecordCount();
@@ -68,6 +70,9 @@ public class VectorUtil {
   }
 
   public static void showVectorAccessibleContent(VectorAccessible va) {
+      showVectorAccessibleContent(va, DEFAULT_COLUMN_WIDTH);
+  }
+  public static void showVectorAccessibleContent(VectorAccessible va, int columnWidth) {
 
     int rows = va.getRecordCount();
     List<String> columns = Lists.newArrayList();
@@ -75,28 +80,31 @@ public class VectorUtil {
       columns.add(vw.getValueVector().getField().getName());
     }
 
-    int width = columns.size();
+    int width = columns.size() * (columnWidth + 2);
+
+    String format = ("| %-" + columnWidth + "s");
+
     for (int row = 0; row < rows; row++) {
       if (row%50 == 0) {
-        System.out.println(StringUtils.repeat("-", width*17 + 1));
+        System.out.println(StringUtils.repeat("-", width + 1));
         for (String column : columns) {
-          System.out.printf("| %-15s", column.length() <= 15 ? column : column.substring(0, 14));
+          System.out.printf(format, column.length() <= columnWidth ? column : column.substring(0, columnWidth - 1));
         }
         System.out.printf("|\n");
-        System.out.println(StringUtils.repeat("-", width*17 + 1));
+        System.out.println(StringUtils.repeat("-", width + 1));
       }
       for (VectorWrapper<?> vw : va) {
         Object o = vw.getValueVector().getAccessor().getObject(row);
         if (o == null) {
           //null value
-          System.