Package org.apache.druid.query.groupby
Class GroupByQueryResources
- java.lang.Object
-
- org.apache.druid.query.groupby.GroupByQueryResources
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public class GroupByQueryResources extends Object implements Closeable
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 byGroupByQueryRunnerFactory.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
Constructors Constructor Description GroupByQueryResources(List<ReferenceCountingResourceHolder<ByteBuffer>> toolchestMergeBuffersHolders, List<ReferenceCountingResourceHolder<ByteBuffer>> mergingQueryRunnerMergeBuffersHolders)
-
Method Summary
-
-
-
Constructor Detail
-
GroupByQueryResources
public GroupByQueryResources(@Nullable List<ReferenceCountingResourceHolder<ByteBuffer>> toolchestMergeBuffersHolders, @Nullable List<ReferenceCountingResourceHolder<ByteBuffer>> mergingQueryRunnerMergeBuffersHolders)
-
-
Method Detail
-
countRequiredMergeBufferNumForToolchestMerge
public static int countRequiredMergeBufferNumForToolchestMerge(GroupByQuery query)
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 forGroupByMergingQueryRunner
It can be either 1 or 2, depending on the query's config
-
getToolchestMergeBuffer
public ResourceHolder<ByteBuffer> getToolchestMergeBuffer()
Returns a merge buffer associate with theGroupByQueryQueryToolChest.mergeResults(org.apache.druid.query.QueryRunner<org.apache.druid.query.groupby.ResultRow>)
-
getMergingQueryRunnerMergeBuffer
public ResourceHolder<ByteBuffer> 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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
-