public class QueryBuilder extends Object
Modifier and Type | Class and Description |
---|---|
static class |
QueryBuilder.PlanMatcher
Collects expected and non-expected query patterns.
|
static class |
QueryBuilder.QuerySummary
Summary results of a query: records, batches, run time.
|
static class |
QueryBuilder.QuerySummaryFuture
The future used to wait for the completion of an async query.
|
static class |
QueryBuilder.SummaryOnlyQueryEventListener
Listener used to retrieve the query summary (only) asynchronously
using a
QueryBuilder.QuerySummaryFuture . |
static interface |
QueryBuilder.VectorQueryReader<T,V>
VectorQueryReader function interface
|
Modifier and Type | Method and Description |
---|---|
QueryBuilder.PlanMatcher |
detailedPlanMatcher()
Submits explain plan statement
and creates plan matcher instance based on return query plan with all attributes.
|
String |
explain(String format) |
String |
explainDetailed(String format) |
String |
explainJson()
Submit an "EXPLAIN" statement, and return the JSON form of the
plan.
|
String |
explainText()
Submit an "EXPLAIN" statement, and return text form of the
plan.
|
String |
explainTextWithAllAttributes()
Submit an "EXPLAIN" statement, and return text form of the
plan with all attributes.
|
QueryBuilder.QuerySummaryFuture |
futureSummary()
Run the query asynchronously, returning a future to be used
to check for query completion, wait for completion, and obtain
the result summary.
|
QueryBuilder.PlanMatcher |
jsonPlanMatcher()
Submits explain plan statement
and creates plan matcher instance based on return query plan.
|
long |
log()
Run a query and logs the output in TSV format.
|
long |
log(QuerySubmitter.Format format) |
long |
log(QuerySubmitter.Format format,
int colWidth) |
long |
logCsv() |
QueryBuilder |
physical(String plan) |
QueryBuilder |
physicalResource(String resource) |
QueryBuilder |
plan(List<BitControl.PlanFragment> planFragments)
Run a physical plan presented as a list of fragments.
|
QueryBuilder.PlanMatcher |
planMatcher()
Submits explain plan statement
and creates plan matcher instance based on return query plan.
|
long |
print()
Runs a query and prints the output to stdout in TSV format.
|
long |
print(QuerySubmitter.Format format) |
long |
print(QuerySubmitter.Format format,
int colWidth) |
long |
printCsv() |
QueryBuilder |
query(UserBitShared.QueryType type,
String text) |
List<QueryDataBatch> |
results()
Run the query and return a list of the result batches.
|
QueryResultSet |
resultSet() |
DirectRowSet |
rowSet()
Run the query and return the first non-empty batch as a
DirectRowSet object that can be inspected directly
by the code using a RowSetReader . |
QueryRowSetIterator |
rowSetIterator() |
QueryRowSetReader |
rowSetReader() |
QueryBuilder.QuerySummary |
run()
Run the query returning just a summary of the results: record count,
batch count and run time.
|
long |
runAndWait(UserResultsListener listener) |
double |
singletonDouble()
Run the query that is expected to return (at least) one row
with the only (or first) column returning a double value.
|
int |
singletonInt()
Run the query that is expected to return (at least) one row
with the only (or first) column returning a int value.
|
long |
singletonLong()
Run the query that is expected to return (at least) one row
with the only (or first) column returning a long value.
|
org.joda.time.Period |
singletonPeriod()
Run the query that is expected to return (at least) one row
with the only (or first) column returning a
Period value. |
String |
singletonString()
Run the query that is expected to return (at least) one row
with the only (or first) column returning a string value.
|
QueryBuilder |
sql(File file)
Parse a single SQL statement (with optional ending semi-colon) from
the file provided.
|
QueryBuilder |
sql(String sql) |
QueryBuilder |
sql(String query,
Object... args) |
QueryBuilder |
sqlResource(String resource)
Run a query contained in a resource file.
|
QueryBuilder |
sqlResource(String resource,
Object... args) |
<T,V> T |
vectorValue(String columnName,
Class<V> vectorClass,
QueryBuilder.VectorQueryReader<T,V> reader)
Run the query which expect to return vector
V representation
of type T for the column columnName . |
BufferingQueryEventListener |
withEventListener()
Run the query, return an easy-to-use event listener to process
the query results.
|
void |
withListener(UserResultsListener listener)
Run the query with the listener provided.
|
public QueryBuilder query(UserBitShared.QueryType type, String text)
public QueryBuilder sql(String sql)
public QueryBuilder sql(String query, Object... args)
public QueryBuilder plan(List<BitControl.PlanFragment> planFragments)
planFragments
- fragments that make up the planpublic QueryBuilder sql(File file) throws IOException
file
- the file containing exactly one SQL statement, with
optional ending semi-colonIOException
public QueryBuilder physical(String plan)
public QueryBuilder sqlResource(String resource)
resource
- Name of the resourcepublic QueryBuilder sqlResource(String resource, Object... args)
public QueryBuilder physicalResource(String resource)
public QueryBuilder.QuerySummary run() throws Exception
Exception
- if anything goes wrong anywhere in the executionpublic List<QueryDataBatch> results() throws RpcException
RpcException
- if anything goes wrongpublic DirectRowSet rowSet() throws RpcException
DirectRowSet
object that can be inspected directly
by the code using a RowSetReader
.null
if the query returns no data (no batches)RpcException
- if anything goes wrongfor a version that reads a series of
batches as row sets.
public QueryRowSetIterator rowSetIterator()
public QueryRowSetReader rowSetReader()
public <T,V> T vectorValue(String columnName, Class<V> vectorClass, QueryBuilder.VectorQueryReader<T,V> reader) throws RpcException, SchemaChangeException
V
representation
of type T
for the column columnName
.
Example: Setresults = queryBuilder() .sql(query) .vectorValue( "columnName", SomeVector.class, (resultRecordCount, vector) -> { Set r = new HashSet<>(); for (int i = 0; i < resultRecordCount; i++) { r.add(vector.getAccessor().getAsStringBuilder(i).toString()); } return r; } );
V
- vector classT
- return typecolumnName
- name of the column to readvectorClass
- returned by the query vector classreader
- lambda to read the vector value representationreader
lambda or null
if no records returned from the queryRpcException
SchemaChangeException
public long singletonLong() throws RpcException
RpcException
- if anything goes wrongpublic double singletonDouble() throws RpcException
RpcException
- if anything goes wrongpublic int singletonInt() throws RpcException
RpcException
- if anything goes wrongpublic org.joda.time.Period singletonPeriod() throws RpcException
Period
value.
The Period
value cannot be null.RpcException
- if anything goes wrongpublic String singletonString() throws RpcException
RpcException
- if anything goes wrongpublic void withListener(UserResultsListener listener)
listener
- the Drill listenerpublic BufferingQueryEventListener withEventListener()
public long logCsv()
public long log(QuerySubmitter.Format format)
public long log(QuerySubmitter.Format format, int colWidth)
public long log()
QueryTestUtil.testRunAndLog(org.apache.drill.exec.client.DrillClient, org.apache.drill.exec.proto.UserBitShared.QueryType, java.lang.String)
with one query.public long printCsv()
public long print(QuerySubmitter.Format format)
public long print(QuerySubmitter.Format format, int colWidth)
public long print()
QueryTestUtil.testRunAndLog(org.apache.drill.exec.client.DrillClient, org.apache.drill.exec.proto.UserBitShared.QueryType, java.lang.String)
with one query.public QueryBuilder.QuerySummaryFuture futureSummary()
public long runAndWait(UserResultsListener listener)
public String explainText() throws Exception
Exception
- if the query failspublic String explainTextWithAllAttributes() throws Exception
Exception
- if the query failspublic String explainJson() throws Exception
Exception
- if the query failspublic QueryBuilder.PlanMatcher planMatcher() throws Exception
Exception
- if the query failspublic QueryBuilder.PlanMatcher detailedPlanMatcher() throws Exception
Exception
- if the query failspublic QueryBuilder.PlanMatcher jsonPlanMatcher() throws Exception
Exception
- if the query failspublic QueryResultSet resultSet()
Copyright © 2022 The Apache Software Foundation. All rights reserved.