Package org.apache.druid.query.groupby
Class GroupByQueryResources
java.lang.Object
org.apache.druid.query.groupby.GroupByQueryResources
- All Implemented Interfaces:
Closeable,AutoCloseable
This class contains resources required for a groupBy query execution.
Currently, it contains only merge buffers, but any additional resources can be added in the future.
It contains merge buffers for the execution of
a)
GroupByQueryQueryToolChest.mergeResults(QueryRunner) - Required for merging the results of the subqueries
and the subtotals.
b) GroupByMergingQueryRunner - Required for merging the results
of the individual runners created by GroupByQueryRunnerFactory.createRunner(Segment)
The resources should be acquired once throughout the execution of the query (with caveats such as union being treated
as separate queries on the data servers) or it should release all the resources before re-acquiring them (if needed),
to prevent deadlocks.-
Constructor Summary
ConstructorsConstructorDescriptionGroupByQueryResources(List<ReferenceCountingResourceHolder<ByteBuffer>> toolchestMergeBuffersHolders, List<ReferenceCountingResourceHolder<ByteBuffer>> mergingQueryRunnerMergeBuffersHolders) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the query resource.static intCount the number of merge buffers required forGroupByMergingQueryRunnerIt can be either 1 or 2, depending on the query's configstatic intCounts the number of merge buffers required forGroupByQueryQueryToolChest.mergeResults(org.apache.druid.query.QueryRunner<org.apache.druid.query.groupby.ResultRow>).Returns a merge buffer associated with theGroupByMergingQueryRunnerintReturns the number of the currently unused merge buffers reserved forGroupByMergingQueryRunnerReturns a merge buffer associate with theGroupByQueryQueryToolChest.mergeResults(org.apache.druid.query.QueryRunner<org.apache.druid.query.groupby.ResultRow>)
-
Constructor Details
-
GroupByQueryResources
public GroupByQueryResources(@Nullable List<ReferenceCountingResourceHolder<ByteBuffer>> toolchestMergeBuffersHolders, @Nullable List<ReferenceCountingResourceHolder<ByteBuffer>> mergingQueryRunnerMergeBuffersHolders)
-
-
Method Details
-
countRequiredMergeBufferNumForToolchestMerge
Counts the number of merge buffers required forGroupByQueryQueryToolChest.mergeResults(org.apache.druid.query.QueryRunner<org.apache.druid.query.groupby.ResultRow>). For a given query, it is dependent on the structure of the group by query. -
countRequiredMergeBufferNumForMergingQueryRunner
public static int countRequiredMergeBufferNumForMergingQueryRunner(GroupByQueryConfig config, GroupByQuery query) Count the number of merge buffers required forGroupByMergingQueryRunnerIt can be either 1 or 2, depending on the query's config -
getToolchestMergeBuffer
Returns a merge buffer associate with theGroupByQueryQueryToolChest.mergeResults(org.apache.druid.query.QueryRunner<org.apache.druid.query.groupby.ResultRow>) -
getMergingQueryRunnerMergeBuffer
Returns a merge buffer associated with theGroupByMergingQueryRunner -
getNumMergingQueryRunnerMergeBuffers
public int getNumMergingQueryRunnerMergeBuffers()Returns the number of the currently unused merge buffers reserved forGroupByMergingQueryRunner -
close
public void close()Closes the query resource. It must be called to release back the acquired merge buffers back into the global merging pool from where all the merge buffers are acquired. The references to the merge buffers will become invalid once this method is called. The user must ensure that the callers are not using the stale references to the merge buffers after this method is called, as reading them would give incorrect results and writing there would interfere with other users of the merge buffers- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-