You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by GitBox <gi...@apache.org> on 2018/11/26 16:04:22 UTC

[GitHub] asfgit closed pull request #1539: DRILL-6847: Add Query Metadata to RESTful Interface

asfgit closed pull request #1539: DRILL-6847: Add Query Metadata to RESTful Interface
URL: https://github.com/apache/drill/pull/1539
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 4e0985852c2..4eb165660e2 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 QueryResult run(final WorkManager workManager, final WebUserConnection we
     }
 
     // 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 @@ private float getHeapUsage() {
     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 9d6e7e41f42..b70dc7b8f82 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.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 final Set<String> columns = Sets.newLinkedHashSet();
 
+  public final List<String> metadata = new ArrayList<>();
+
   WebUserConnection(WebSessionResources webSessionResources) {
     this.webSessionResources = webSessionResources;
   }
@@ -106,7 +110,29 @@ public void sendData(RpcOutcomeListener<Ack> listener, QueryWritableBatch result
         // 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) {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services