Package org.apache.druid.sql
Class DirectStatement
java.lang.Object
org.apache.druid.sql.AbstractStatement
org.apache.druid.sql.DirectStatement
- All Implemented Interfaces:
Closeable,AutoCloseable,SqlLifecycleManager.Cancelable
- Direct Known Subclasses:
HttpStatement
Lifecycle for direct SQL statement execution, which means that the query
is planned and executed in a single step, with no "prepare" step.
Callers need call only:
execute()to execute the query. The caller must close the returnedSequence.close()to report metrics, orcloseQuietly()otherwise.
The cancel() method may be called from any thread and cancels
the query.
All other methods are optional and are generally for introspection.
The class supports two threading models. In the simple case, the same thread creates this object and executes the query. In the split model, a request thread creates this object and plans the query. A separate response thread consumes results and performs any desired logging, etc. The object is transferred between threads, with no overlapping access.
As statement holds no resources and need not be called. Only the
Sequence returned from execute() need be closed.
Use this class for tests and JDBC execution. Use the HTTP variant,
HttpStatement for HTTP requests.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassRepresents the execution plan for a query with the ability to run that plan (once). -
Field Summary
FieldsFields inherited from class org.apache.druid.sql.AbstractStatement
authContextKeys, authResult, hook, plannerContext, queryContext, queryPlus, reporter, sqlToolbox -
Constructor Summary
ConstructorsConstructorDescriptionDirectStatement(SqlToolbox lifecycleToolbox, SqlQueryPlus sqlRequest) DirectStatement(SqlToolbox lifecycleToolbox, SqlQueryPlus queryPlus, String remoteAddress) -
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()voidclose()Releases resources and emits logs and metrics as defined the associated reporter.voidCloses the statement without reporting metrics.voidConvenience method to close the statement and report an error associated with the statement.protected PlannerResultcreatePlan(DruidPlanner planner) Plan the query, which also produces the sequence that runs the query.protected DruidPlannerprotected DirectStatement.ResultSetcreateResultSet(PlannerResult plannerResult) Wrapper around result set creation for the sole purpose of tests which inject failures.execute()Convenience method to perform Direct execution of a query.plan()Prepares and plans a query for execution, returning a result set to execute the query.Methods inherited from class org.apache.druid.sql.AbstractStatement
allResources, authorize, authorizer, context, query, reporter, resources, setHook, sqlQueryId, validateMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.druid.sql.SqlLifecycleManager.Cancelable
resources
-
Field Details
-
prepareResult
-
resultSet
-
-
Constructor Details
-
DirectStatement
-
DirectStatement
-
-
Method Details
-
execute
Convenience method to perform Direct execution of a query. Does both theplan()step and theDirectStatement.ResultSet.run()step.- Returns:
- sequence which delivers query results
-
plan
Prepares and plans a query for execution, returning a result set to execute the query. In Druid, prepare and plan are different: prepare provides information about the query, but plan does the "real" preparation to create an actual executable plan.- Create the planner.
- Parse the statement.
- Provide parameters using a "query optimized" structure.
- Validate the query against the Druid catalog.
- Authorize access to the resources which the query needs.
- Plan the query.
DirectStatement.ResultSet.run()to run the resulting plan. -
createPlanner
-
createPlan
Plan the query, which also produces the sequence that runs the query. -
createResultSet
Wrapper around result set creation for the sole purpose of tests which inject failures. -
prepareResult
-
cancel
public void cancel()- Specified by:
cancelin interfaceSqlLifecycleManager.Cancelable
-
close
public void close()Description copied from class:AbstractStatementReleases resources and emits logs and metrics as defined the associated reporter.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classAbstractStatement
-
closeWithError
Description copied from class:AbstractStatementConvenience method to close the statement and report an error associated with the statement. Same as calling:stmt.reporter().failed(e); stmt.close();- Overrides:
closeWithErrorin classAbstractStatement
-
closeQuietly
public void closeQuietly()Description copied from class:AbstractStatementCloses the statement without reporting metrics.- Overrides:
closeQuietlyin classAbstractStatement
-