drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From volody...@apache.org
Subject [drill] 05/15: DRILL-6847: Add Query Metadata to RESTful Interface
Date Mon, 26 Nov 2018 16:03:59 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit 6a990c7eb928b00311935e107427c8420258fd6c
Author: Charles S. Givre <cgivre@gmail.com>
AuthorDate: Wed Nov 21 08:15:00 2018 -0500

    DRILL-6847: Add Query Metadata to RESTful Interface
    
    closes #1539
---
 .../drill/exec/server/rest/QueryWrapper.java       | 17 +++++++------
 .../drill/exec/server/rest/WebUserConnection.java  | 28 +++++++++++++++++++++-
 2 files changed, 37 insertions(+), 8 deletions(-)

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 4e09858..4eb1656 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
@@ -115,7 +115,7 @@ public class QueryWrapper {
     }
 
     // Return the QueryResult.
-    return new QueryResult(queryId, webUserConnection.columns, webUserConnection.results);
+    return new QueryResult(queryId, webUserConnection, webUserConnection.results);
   }
 
   //Detect possible excess heap
@@ -127,12 +127,15 @@ public class QueryWrapper {
     private final String queryId;
     public final Collection<String> columns;
     public final List<Map<String, String>> rows;
-
-    public QueryResult(QueryId queryId, Collection<String> columns, List<Map<String,
String>> rows) {
-      this.queryId = QueryIdHelper.getQueryId(queryId);
-      this.columns = columns;
-      this.rows = rows;
-    }
+    public final List<String> metadata;
+
+    //DRILL-6847:  Modified the constructor so that the method has access to all the properties
in webUserConnection
+    public QueryResult(QueryId queryId, WebUserConnection webUserConnection, List<Map<String,
String>> rows) {
+        this.queryId = QueryIdHelper.getQueryId(queryId);
+        this.columns = webUserConnection.columns;
+        this.metadata = webUserConnection.metadata;
+        this.rows = rows;
+      }
 
     public String getQueryId() {
       return queryId;
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/WebUserConnection.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/WebUserConnection.java
index 9d6e7e4..b70dc7b 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/WebUserConnection.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/WebUserConnection.java
@@ -37,10 +37,12 @@ import org.apache.drill.exec.rpc.ConnectionThrottle;
 import org.apache.drill.exec.rpc.RpcOutcomeListener;
 import org.apache.drill.exec.rpc.user.UserSession;
 import org.apache.drill.exec.vector.ValueVector.Accessor;
+import org.apache.drill.exec.record.MaterializedField;
 
 import java.net.SocketAddress;
 import java.util.List;
 import java.util.Map;
+import java.util.ArrayList;
 import java.util.Set;
 
 /**
@@ -64,6 +66,8 @@ public class WebUserConnection extends AbstractDisposableUserClientConnection
im
 
   public final Set<String> columns = Sets.newLinkedHashSet();
 
+  public final List<String> metadata = new ArrayList<>();
+
   WebUserConnection(WebSessionResources webSessionResources) {
     this.webSessionResources = webSessionResources;
   }
@@ -106,7 +110,29 @@ public class WebUserConnection extends AbstractDisposableUserClientConnection
im
         // TODO:  Clean:  DRILL-2933:  That load(...) no longer throws
         // SchemaChangeException, so check/clean catch clause below.
         for (int i = 0; i < loader.getSchema().getFieldCount(); ++i) {
-          columns.add(loader.getSchema().getColumn(i).getName());
+          //DRILL-6847:  This section adds query metadata to the REST results
+          MaterializedField col = loader.getSchema().getColumn(i);
+          columns.add(col.getName());
+          StringBuilder dataType = new StringBuilder(col.getType().getMinorType().name());
+
+          //For DECIMAL type
+          if (col.getType().hasPrecision()) {
+            dataType.append("(");
+            dataType.append(col.getType().getPrecision());
+
+            if (col.getType().hasScale()) {
+              dataType.append(", ");
+              dataType.append(col.getType().getScale());
+            }
+
+            dataType.append(")");
+          } else if (col.getType().hasWidth()) {
+            //Case for VARCHAR columns with specified width
+            dataType.append("(");
+            dataType.append(col.getType().getWidth());
+            dataType.append(")");
+          }
+          metadata.add(dataType.toString());
         }
         ValueVectorElementFormatter formatter = new ValueVectorElementFormatter(webSessionResources.getSession().getOptions());
         for (int i = 0; i < rows; ++i) {


Mime
View raw message