You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by sm...@apache.org on 2014/11/25 07:42:21 UTC

[4/4] incubator-drill git commit: DRILL-1404: Queries with empty results are throwing "HTTP ERROR 500" from Web UI

DRILL-1404: Queries with empty results are throwing "HTTP ERROR 500" from Web UI


Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/774a1f04
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/774a1f04
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/774a1f04

Branch: refs/heads/master
Commit: 774a1f04cd234a318cd25bd242ecface75a2df08
Parents: bbf9bc3
Author: Hsuan-Yi Chu <hs...@usc.edu>
Authored: Thu Nov 13 15:52:31 2014 -0800
Committer: Steven Phillips <sp...@maprtech.com>
Committed: Mon Nov 24 19:26:22 2014 -0800

----------------------------------------------------------------------
 .../drill/exec/server/rest/QueryResources.java  | 22 +++++++++++++--
 .../drill/exec/server/rest/QueryWrapper.java    | 28 +++++++++++++++++---
 2 files changed, 45 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/774a1f04/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/QueryResources.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/QueryResources.java b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/QueryResources.java
index bea693c..ba59d8f 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/QueryResources.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/QueryResources.java
@@ -70,14 +70,32 @@ public class QueryResources {
 
     List<String> columnNames = new ArrayList<>(result.get(0).keySet());
     List<List<Object>> records = new ArrayList<>();
-    for(Map m : result) {
-      records.add(new ArrayList<Object>(m.values()));
+
+    if(!isEmptyResult(result)) {
+      for (Map m : result) {
+        records.add(new ArrayList<Object>(m.values()));
+      }
     }
+
     Table table = new Table(columnNames, records);
 
     return new Viewable("/rest/query/result.ftl", table);
   }
 
+  private boolean isEmptyResult(List<Map<String, Object>> result) {
+    if (result.size() > 1) {
+      return false;
+    } else {
+      for(Object col : result.get(0).values()) {
+        if(col != null) {
+          return false;
+        }
+      }
+
+      return true;
+    }
+  }
+
   public class Table {
     private List<String> columnNames;
     private List<List<Object>> records;

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/774a1f04/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/QueryWrapper.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/QueryWrapper.java b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/QueryWrapper.java
index f03bfe6..922533a 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/QueryWrapper.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/QueryWrapper.java
@@ -35,6 +35,7 @@ import org.apache.drill.exec.exception.SchemaChangeException;
 import org.apache.drill.exec.memory.BufferAllocator;
 import org.apache.drill.exec.physical.impl.flatten.FlattenRecordBatch;
 import org.apache.drill.exec.proto.UserBitShared;
+import org.apache.drill.exec.record.MaterializedField;
 import org.apache.drill.exec.record.RecordBatchLoader;
 import org.apache.drill.exec.record.VectorWrapper;
 import org.apache.drill.exec.rpc.RpcException;
@@ -42,6 +43,7 @@ import org.apache.drill.exec.rpc.user.ConnectionThrottle;
 import org.apache.drill.exec.rpc.user.QueryResultBatch;
 import org.apache.drill.exec.rpc.user.UserResultsListener;
 import org.apache.drill.exec.vector.ValueVector;
+import org.apache.drill.exec.proto.UserBitShared.SerializedField;
 
 import com.fasterxml.jackson.annotation.JsonCreator;
 import com.fasterxml.jackson.annotation.JsonProperty;
@@ -87,6 +89,14 @@ public class QueryWrapper {
       client.runQuery(getType(), query, listener);
 
       List<Map<String, Object>> result = listener.waitForCompletion();
+      if (result.isEmpty()) {
+        Map<String, Object> dumbRecord = new HashMap<>();
+        for (String columnName : listener.getColumnNames()) {
+          dumbRecord.put(columnName, null);
+        }
+        result.add(dumbRecord);
+      }
+
       return result;
     }
   }
@@ -120,12 +130,12 @@ public class QueryWrapper {
     @Override
     public void resultArrived(QueryResultBatch result, ConnectionThrottle throttle) {
       int rows = result.getHeader().getRowCount();
-      if (result.getData() != null) {
+      if (result.hasData()) {
         count.addAndGet(rows);
         try {
           loader.load(result.getHeader().getDef(), result.getData());
-          if (!schemaAdded) {
-            columnNames = new ArrayList<>();
+          if (!schemaAdded || output.isEmpty()) {
+                columnNames = new ArrayList<>();
             for (int i = 0; i < loader.getSchema().getFieldCount(); ++i) {
               columnNames.add(loader.getSchema().getColumn(i).getPath().getAsUnescapedPath());
             }
@@ -152,7 +162,15 @@ public class QueryWrapper {
           }
           output.add(record);
         }
+      } else if (!schemaAdded) {
+        columnNames = new ArrayList<>();
+        schemaAdded = true;
+        for (SerializedField fmd : result.getHeader().getDef().getFieldList()) {
+          MaterializedField fieldDef = MaterializedField.create(fmd);
+          columnNames.add(fieldDef.getPath().getAsUnescapedPath());
+        }
       }
+
       result.release();
       if (result.getHeader().getIsLastChunk()) {
         latch.countDown();
@@ -170,5 +188,9 @@ public class QueryWrapper {
       }
       return output;
     }
+
+    public List<String> getColumnNames() {
+      return new ArrayList<String> (columnNames);
+    }
   }
 }