Class FragmentContextImpl
- All Implemented Interfaces:
AutoCloseable
,ExchangeFragmentContext
,ExecutorFragmentContext
,FragmentContext
,RootFragmentContext
,UdfUtilities
FragmentContext
: A context provided to non-exchange operators.ExchangeFragmentContext
: A context provided to exchange operators.RootFragmentContext
: A context provided to fragment roots.ExecutorFragmentContext
: A context used by the Drillbit.
FragmentContext
) to least restrictive
(ExecutorFragmentContext
).
Since FragmentContextImpl
implements all of the interfaces listed
above, the facade pattern is used in order to cast a
FragmentContextImpl
object to the desired interface where-ever it is
needed. The facade pattern is powerful since it allows us to easily create
minimal context objects to be used in unit tests. Without the use of
interfaces and the facade pattern we would have to create a complete
FragmentContextImpl
object to unit test any part of the code that
depends on a context.
General guideline: Use the most narrow interface for the task. For example, "internal" operators don't need visibility to the networking functionality. Using the narrow interface allows unit testing without using mocking libraries. Often, the surrounding structure already has exposed the most narrow interface. If there are opportunities to clean up older code, we can do so as needed to make testing easier.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.drill.exec.ops.FragmentContext
FragmentContext.ExecutorState
-
Field Summary
Fields inherited from interface org.apache.drill.exec.ops.UdfUtilities
INJECTABLE_GETTER_METHODS
-
Constructor Summary
ConstructorDescriptionFragmentContextImpl
(DrillbitContext dbContext, BitControl.PlanFragment fragment, FunctionImplementationRegistry funcRegistry) Create a FragmentContext instance for non-root fragment.FragmentContextImpl
(DrillbitContext dbContext, BitControl.PlanFragment fragment, QueryContext queryContext, UserClientConnection connection, FunctionImplementationRegistry funcRegistry) Create a FragmentContext instance for root fragment.FragmentContextImpl
(DrillbitContext dbContext, BitControl.PlanFragment fragment, UserClientConnection connection, FunctionImplementationRegistry funcRegistry) TODO: Remove this constructor when removing the SimpleRootExec (DRILL-2097). -
Method Summary
Modifier and TypeMethodDescriptionvoid
addRuntimeFilter
(RuntimeFilterWritable runtimeFilter) Add a RuntimeFilter when the RuntimeFilter receiver belongs to the same MinorFragment.void
close()
void
Get an instance of alias registry provider for obtaining aliases.Deprecated.getBits()
protected BufferManager
Returns the Drill configuration for this run.getConstantValueHolder
(String value, TypeProtos.MinorType type, org.apache.drill.shaded.guava.com.google.common.base.Function<DrillBuf, ValueHolder> holderInitializer) Works with value holders cache which holds constant value and its wrapper by type.Get the context information such as: - query start time - root fragment timezone - query userName - system userName - default schema name in current session at the time of query.The Drillbit context allows UDFs to view storage information and other pieces of information about the running system.Return the set of execution controls used to inject faults into running code for testing.org.apache.calcite.schema.SchemaPlus
The FragmentHandle for this FragmentGet instance of Metastore registry to obtain Metastore instance if needed.getNewChildAllocator
(String operatorName, int operatorId, long initialReservation, long maximumReservation) Returns a read-only version of the session options.A partition explorer allows UDFs to view the sub-partitions below a particular partition.Returns the root allocator for the Drillbit.getRuntimeFilter
(long rfIdentifier) getRuntimeFilter
(long rfIdentifier, long maxWaitTime, TimeUnit timeUnit) Get the RuntimeFilter with a blocking wait, if the waiting option is enabled.Returns the statement type (e.g.getStats()
boolean
boolean
boolean
boolean
newOperatorContext
(PhysicalOperator popConfig) newOperatorContext
(PhysicalOperator popConfig, OperatorStats stats) void
requestMemory
(RecordBatch requestor) An operator is experiencing memory pressure.void
setBuffers
(IncomingBuffers buffers) void
setExecutorState
(FragmentContext.ExecutorState executorState) void
Methods inherited from class org.apache.drill.exec.ops.BaseFragmentContext
getFunctionRegistry, getImplementationClass, getImplementationClass, getImplementationClass, getImplementationClass, getManagedBuffer, getManagedBuffer, getManagedBufferManager, replace
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.drill.exec.ops.FragmentContext
getFunctionRegistry, getImplementationClass, getImplementationClass, getImplementationClass, getImplementationClass, getManagedBuffer, getManagedBuffer, getManagedBufferManager, replace
-
Constructor Details
-
FragmentContextImpl
public FragmentContextImpl(DrillbitContext dbContext, BitControl.PlanFragment fragment, FunctionImplementationRegistry funcRegistry) throws ExecutionSetupException Create a FragmentContext instance for non-root fragment.- Parameters:
dbContext
- DrillbitContextfragment
- Fragment implementationfuncRegistry
- FunctionImplementationRegistry- Throws:
ExecutionSetupException
- when unable to init fragment context
-
FragmentContextImpl
public FragmentContextImpl(DrillbitContext dbContext, BitControl.PlanFragment fragment, QueryContext queryContext, UserClientConnection connection, FunctionImplementationRegistry funcRegistry) throws ExecutionSetupException Create a FragmentContext instance for root fragment.- Parameters:
dbContext
- DrillbitContextfragment
- Fragment implementationqueryContext
- QueryContextconnection
- UserClientConnectionfuncRegistry
- FunctionImplementationRegistry- Throws:
ExecutionSetupException
- when unable to init fragment context
-
FragmentContextImpl
public FragmentContextImpl(DrillbitContext dbContext, BitControl.PlanFragment fragment, UserClientConnection connection, FunctionImplementationRegistry funcRegistry) throws ExecutionSetupException TODO: Remove this constructor when removing the SimpleRootExec (DRILL-2097). This is kept only to avoid modifying the long list of test files.- Throws:
ExecutionSetupException
-
-
Method Details
-
getOptions
Description copied from interface:FragmentContext
Returns a read-only version of the session options.- Specified by:
getOptions
in interfaceFragmentContext
- Returns:
- the session options
-
getPlanReader
- Specified by:
getPlanReader
in interfaceExecutorFragmentContext
-
getClusterCoordinator
- Specified by:
getClusterCoordinator
in interfaceExecutorFragmentContext
-
setBuffers
- Specified by:
setBuffers
in interfaceExecutorFragmentContext
-
getProfileStoreContext
- Specified by:
getProfileStoreContext
in interfaceExecutorFragmentContext
-
getUserConnections
public Set<Map.Entry<UserServer.BitToUserConnection,UserServer.BitToUserConnectionConfig>> getUserConnections()- Specified by:
getUserConnections
in interfaceExecutorFragmentContext
-
setExecutorState
- Specified by:
setExecutorState
in interfaceRootFragmentContext
-
fail
-
getFullRootSchema
public org.apache.calcite.schema.SchemaPlus getFullRootSchema()- Specified by:
getFullRootSchema
in interfaceFragmentContext
-
getStats
- Specified by:
getStats
in interfaceRootFragmentContext
-
getBits
- Specified by:
getBits
in interfaceExecutorFragmentContext
-
getContextInformation
Description copied from interface:UdfUtilities
Get the context information such as: - query start time - root fragment timezone - query userName - system userName - default schema name in current session at the time of query.- Specified by:
getContextInformation
in interfaceUdfUtilities
- Returns:
- - ContextInformation
-
getDrillbitContext
Description copied from interface:UdfUtilities
The Drillbit context allows UDFs to view storage information and other pieces of information about the running system. See the http_get implementation for details.- Specified by:
getDrillbitContext
in interfaceUdfUtilities
- Returns:
- - an object for accessing drillbit information such as storage configs.
-
getResultSetLoader
- Specified by:
getResultSetLoader
in interfaceUdfUtilities
-
getForemanEndpoint
- Specified by:
getForemanEndpoint
in interfaceExecutorFragmentContext
-
getEndpoint
- Specified by:
getEndpoint
in interfaceExecutorFragmentContext
-
getController
- Specified by:
getController
in interfaceExchangeFragmentContext
-
getOperatorCreatorRegistry
- Specified by:
getOperatorCreatorRegistry
in interfaceExecutorFragmentContext
-
getScanDecodeExecutor
- Specified by:
getScanDecodeExecutor
in interfaceFragmentContext
-
getScanExecutor
- Specified by:
getScanExecutor
in interfaceFragmentContext
-
getHandle
The FragmentHandle for this Fragment- Specified by:
getHandle
in interfaceFragmentContext
- Returns:
- FragmentHandle
-
getFragIdString
- Specified by:
getFragIdString
in interfaceFragmentContext
-
isUserAuthenticationEnabled
public boolean isUserAuthenticationEnabled()- Specified by:
isUserAuthenticationEnabled
in interfaceExecutorFragmentContext
-
addRuntimeFilter
Description copied from interface:FragmentContext
Add a RuntimeFilter when the RuntimeFilter receiver belongs to the same MinorFragment.- Specified by:
addRuntimeFilter
in interfaceFragmentContext
- Parameters:
runtimeFilter
- runtime filter
-
getRuntimeFilter
- Specified by:
getRuntimeFilter
in interfaceFragmentContext
-
getRuntimeFilter
public RuntimeFilterWritable getRuntimeFilter(long rfIdentifier, long maxWaitTime, TimeUnit timeUnit) Description copied from interface:FragmentContext
Get the RuntimeFilter with a blocking wait, if the waiting option is enabled.- Specified by:
getRuntimeFilter
in interfaceFragmentContext
- Parameters:
rfIdentifier
- runtime filter identifiermaxWaitTime
- max wait timetimeUnit
- time unit- Returns:
- the RFW or null
-
getAllocator
Deprecated.Get this fragment's allocator.- Specified by:
getAllocator
in interfaceFragmentContext
- Returns:
- the allocator
-
getRootAllocator
Description copied from interface:ExecutorFragmentContext
Returns the root allocator for the Drillbit.- Specified by:
getRootAllocator
in interfaceExecutorFragmentContext
-
getNewChildAllocator
public BufferAllocator getNewChildAllocator(String operatorName, int operatorId, long initialReservation, long maximumReservation) throws OutOfMemoryException - Specified by:
getNewChildAllocator
in interfaceFragmentContext
- Throws:
OutOfMemoryException
-
isOverMemoryLimit
public boolean isOverMemoryLimit() -
getCompiler
- Specified by:
getCompiler
in interfaceFragmentContext
-
getUserDataTunnel
- Specified by:
getUserDataTunnel
in interfaceExchangeFragmentContext
-
getDataTunnel
- Specified by:
getDataTunnel
in interfaceExchangeFragmentContext
-
getBuffers
- Specified by:
getBuffers
in interfaceExchangeFragmentContext
-
newOperatorContext
public OperatorContext newOperatorContext(PhysicalOperator popConfig, OperatorStats stats) throws OutOfMemoryException - Specified by:
newOperatorContext
in interfaceFragmentContext
- Throws:
OutOfMemoryException
-
newOperatorContext
- Specified by:
newOperatorContext
in interfaceFragmentContext
- Throws:
OutOfMemoryException
-
getConfig
Description copied from interface:FragmentContext
Returns the Drill configuration for this run. Note that the config is global and immutable.- Specified by:
getConfig
in interfaceFragmentContext
- Returns:
- the Drill configuration
-
getExecutorState
- Specified by:
getExecutorState
in interfaceFragmentContext
-
getExecutionControls
Description copied from interface:FragmentContext
Return the set of execution controls used to inject faults into running code for testing.- Specified by:
getExecutionControls
in interfaceFragmentContext
- Returns:
- the execution controls
-
getQueryUserName
- Specified by:
getQueryUserName
in interfaceFragmentContext
- Overrides:
getQueryUserName
in classBaseFragmentContext
-
getQueryId
- Specified by:
getQueryId
in interfaceFragmentContext
- Overrides:
getQueryId
in classBaseFragmentContext
- Returns:
- ID
UUID
of the current query
-
getQueryIdString
- Specified by:
getQueryIdString
in interfaceFragmentContext
- Overrides:
getQueryIdString
in classBaseFragmentContext
- Returns:
- The string representation of the ID
UUID
of the current query
-
isImpersonationEnabled
public boolean isImpersonationEnabled()- Specified by:
isImpersonationEnabled
in interfaceFragmentContext
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceFragmentContext
-
getPartitionExplorer
Description copied from interface:UdfUtilities
A partition explorer allows UDFs to view the sub-partitions below a particular partition. This allows for the implementation of UDFs to query against the partition information, without having to read the actual data contained in the partition. This interface is designed for UDFs that take only constant inputs, as this interface will only be useful if we can evaluate the constant UDF at planning time. Any function defined to use this interface that is not evaluated at planning time by the constant folding rule will be querying the storage plugin for meta-data for each record processed. Be sure to check the query plans to see that this expression has already been evaluated during planning if you write UDFs against this interface. SeeDirectoryExplorers
for example usages of this interface.- Specified by:
getPartitionExplorer
in interfaceUdfUtilities
- Returns:
- - an object for exploring partitions of all available schemas
-
getConstantValueHolder
public ValueHolder getConstantValueHolder(String value, TypeProtos.MinorType type, org.apache.drill.shaded.guava.com.google.common.base.Function<DrillBuf, ValueHolder> holderInitializer) Description copied from interface:UdfUtilities
Works with value holders cache which holds constant value and its wrapper by type. If value is absent uses holderInitializer to create holder and adds it to cache.- Specified by:
getConstantValueHolder
in interfaceUdfUtilities
- Returns:
- - a wrapper object for an constant value.
-
getExecutor
- Specified by:
getExecutor
in interfaceFragmentContext
-
waitForSendComplete
public void waitForSendComplete()- Specified by:
waitForSendComplete
in interfaceExchangeFragmentContext
-
getWorkEventBus
- Specified by:
getWorkEventBus
in interfaceExecutorFragmentContext
-
isBuffersDone
public boolean isBuffersDone() -
getBufferManager
- Specified by:
getBufferManager
in classBaseFragmentContext
-
getSQLStatementType
Description copied from interface:FragmentContext
Returns the statement type (e.g. SELECT, CTAS, ANALYZE) from the query context.- Specified by:
getSQLStatementType
in interfaceFragmentContext
- Overrides:
getSQLStatementType
in classBaseFragmentContext
- Returns:
- query statement type
QueryContext.SqlStatementType
, if known.
-
getMetastoreRegistry
Description copied from interface:FragmentContext
Get instance of Metastore registry to obtain Metastore instance if needed.- Specified by:
getMetastoreRegistry
in interfaceFragmentContext
- Returns:
- Metastore registry
-
getAliasRegistryProvider
Description copied from interface:FragmentContext
Get an instance of alias registry provider for obtaining aliases.- Specified by:
getAliasRegistryProvider
in interfaceFragmentContext
- Returns:
- alias registry provider
-
requestMemory
Description copied from interface:FragmentContext
An operator is experiencing memory pressure. Asks the fragment executor to poll all operators to release an optional memory (such as by spilling.) The request is advisory. The caller should again try to allocate memory, and if the second request fails, throw anOutOfMemoryException
.- Specified by:
requestMemory
in interfaceFragmentContext
-