Skip to content

Commit

Permalink
DRILL-6847: Add Query Metadata to RESTful Interface
Browse files Browse the repository at this point in the history
closes #1539
  • Loading branch information
cgivre authored and vvysotskyi committed Nov 26, 2018
1 parent 597827e commit 6a990c7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
Expand Up @@ -115,7 +115,7 @@ public QueryResult run(final WorkManager workManager, final WebUserConnection we
} }


// Return the QueryResult. // Return the QueryResult.
return new QueryResult(queryId, webUserConnection.columns, webUserConnection.results); return new QueryResult(queryId, webUserConnection, webUserConnection.results);
} }


//Detect possible excess heap //Detect possible excess heap
Expand All @@ -127,12 +127,15 @@ public static class QueryResult {
private final String queryId; private final String queryId;
public final Collection<String> columns; public final Collection<String> columns;
public final List<Map<String, String>> rows; public final List<Map<String, String>> rows;

public final List<String> metadata;
public QueryResult(QueryId queryId, Collection<String> columns, List<Map<String, String>> rows) {
this.queryId = QueryIdHelper.getQueryId(queryId); //DRILL-6847: Modified the constructor so that the method has access to all the properties in webUserConnection
this.columns = columns; public QueryResult(QueryId queryId, WebUserConnection webUserConnection, List<Map<String, String>> rows) {
this.rows = rows; this.queryId = QueryIdHelper.getQueryId(queryId);
} this.columns = webUserConnection.columns;
this.metadata = webUserConnection.metadata;
this.rows = rows;
}


public String getQueryId() { public String getQueryId() {
return queryId; return queryId;
Expand Down
Expand Up @@ -37,10 +37,12 @@
import org.apache.drill.exec.rpc.RpcOutcomeListener; import org.apache.drill.exec.rpc.RpcOutcomeListener;
import org.apache.drill.exec.rpc.user.UserSession; import org.apache.drill.exec.rpc.user.UserSession;
import org.apache.drill.exec.vector.ValueVector.Accessor; import org.apache.drill.exec.vector.ValueVector.Accessor;
import org.apache.drill.exec.record.MaterializedField;


import java.net.SocketAddress; import java.net.SocketAddress;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.ArrayList;
import java.util.Set; import java.util.Set;


/** /**
Expand All @@ -64,6 +66,8 @@ public class WebUserConnection extends AbstractDisposableUserClientConnection im


public final Set<String> columns = Sets.newLinkedHashSet(); public final Set<String> columns = Sets.newLinkedHashSet();


public final List<String> metadata = new ArrayList<>();

WebUserConnection(WebSessionResources webSessionResources) { WebUserConnection(WebSessionResources webSessionResources) {
this.webSessionResources = webSessionResources; this.webSessionResources = webSessionResources;
} }
Expand Down Expand Up @@ -106,7 +110,29 @@ public void sendData(RpcOutcomeListener<Ack> listener, QueryWritableBatch result
// TODO: Clean: DRILL-2933: That load(...) no longer throws // TODO: Clean: DRILL-2933: That load(...) no longer throws
// SchemaChangeException, so check/clean catch clause below. // SchemaChangeException, so check/clean catch clause below.
for (int i = 0; i < loader.getSchema().getFieldCount(); ++i) { 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()); ValueVectorElementFormatter formatter = new ValueVectorElementFormatter(webSessionResources.getSession().getOptions());
for (int i = 0; i < rows; ++i) { for (int i = 0; i < rows; ++i) {
Expand Down

0 comments on commit 6a990c7

Please sign in to comment.