Package org.apache.druid.query.scan
Class ScanQuery
- java.lang.Object
-
- org.apache.druid.query.BaseQuery<ScanResultValue>
-
- org.apache.druid.query.scan.ScanQuery
-
- All Implemented Interfaces:
Query<ScanResultValue>
public class ScanQuery extends BaseQuery<ScanResultValue>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ScanQuery.Order
static class
ScanQuery.OrderBy
static class
ScanQuery.ResultFormat
-
Field Summary
Fields Modifier and Type Field Description static String
CTX_KEY_OUTERMOST
This context flag corresponds to whether the query is running on the "outermost" process (i.e.static int
DEFAULT_BATCH_SIZE
-
Fields inherited from class org.apache.druid.query.BaseQuery
QUERY_ID, SQL_QUERY_ID, SUB_QUERY_ID
-
Fields inherited from interface org.apache.druid.query.Query
DATASOURCE_METADATA, GROUP_BY, SCAN, SEARCH, SEGMENT_METADATA, SELECT, TIME_BOUNDARY, TIMESERIES, TOPN, WINDOW_OPERATOR
-
-
Constructor Summary
Constructors Constructor Description ScanQuery(DataSource dataSource, QuerySegmentSpec querySegmentSpec, VirtualColumns virtualColumns, ScanQuery.ResultFormat resultFormat, int batchSize, long scanRowsOffset, long scanRowsLimit, ScanQuery.Order orderFromUser, List<ScanQuery.OrderBy> orderBysFromUser, DimFilter dimFilter, List<String> columns, Boolean legacy, Map<String,Object> context)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
int
getBatchSize()
List<String>
getColumns()
DimFilter
getFilter()
Integer
getMaxRowsQueuedForOrdering()
Integer
getMaxSegmentPartitionsOrderedInMemory()
OffsetLimit
getOffsetLimit()
List<ScanQuery.OrderBy>
getOrderBys()
Set<String>
getRequiredColumns()
Returns the set of columns that this query will need to access out of its datasource.ScanQuery.ResultFormat
getResultFormat()
com.google.common.collect.Ordering<ScanResultValue>
getResultOrdering()
Default implementation ofQuery.getResultOrdering()
that usesOrdering.natural()
.long
getScanRowsLimit()
Limit for this query; behaves like SQL "LIMIT".long
getScanRowsOffset()
Offset for this query; behaves like SQL "OFFSET".ScanQuery.Order
getTimeOrder()
If this query is purely-time-ordered, returns a value of the enumScanQuery.Order
.String
getType()
VirtualColumns
getVirtualColumns()
boolean
hasFilters()
int
hashCode()
Boolean
isLegacy()
Compatibility mode with the legacy scan-query extension.boolean
isLimited()
Returns whether this query is limited or not.String
toString()
static void
verifyOrderByForNativeExecution(ScanQuery query)
Verifies that the ordering of a query is solely determined bygetTimeOrder()
.ScanQuery
withDataSource(DataSource dataSource)
ScanQuery
withLimit(long newLimit)
ScanQuery
withNonNullLegacy(ScanQueryConfig scanQueryConfig)
ScanQuery
withOffset(long newOffset)
ScanQuery
withOverriddenContext(Map<String,Object> contextOverrides)
ScanQuery
withQuerySegmentSpec(QuerySegmentSpec querySegmentSpec)
Returns a new query, identical to this one, but with a different associatedQuerySegmentSpec
.-
Methods inherited from class org.apache.druid.query.BaseQuery
checkInterrupted, computeOverriddenContext, computeOverridenContext, context, getContext, getDataSource, getDuration, getGranularity, getId, getIntervals, getQuerySegmentSpec, getQuerySegmentSpecForLookUp, getRunner, getSubQueryId, getTimezone, isDescending, withId, withSqlQueryId, withSubQueryId
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.druid.query.Query
getContextBoolean, getContextHumanReadableBytes, getContextValue, getMostSpecificId, getSqlQueryId, optimizeForSegment, withDefaultSubQueryId, withLane, withPriority
-
-
-
-
Field Detail
-
CTX_KEY_OUTERMOST
public static final String CTX_KEY_OUTERMOST
This context flag corresponds to whether the query is running on the "outermost" process (i.e. the process the query is sent to).- See Also:
- Constant Field Values
-
DEFAULT_BATCH_SIZE
public static final int DEFAULT_BATCH_SIZE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ScanQuery
public ScanQuery(DataSource dataSource, QuerySegmentSpec querySegmentSpec, VirtualColumns virtualColumns, ScanQuery.ResultFormat resultFormat, int batchSize, long scanRowsOffset, long scanRowsLimit, ScanQuery.Order orderFromUser, List<ScanQuery.OrderBy> orderBysFromUser, DimFilter dimFilter, List<String> columns, Boolean legacy, Map<String,Object> context)
-
-
Method Detail
-
verifyOrderByForNativeExecution
public static void verifyOrderByForNativeExecution(ScanQuery query)
Verifies that the ordering of a query is solely determined bygetTimeOrder()
. Required to actually execute queries, becausegetOrderBys()
is not yet understood by the query engines.- Throws:
IllegalStateException
- if the ordering is not solely determined bygetTimeOrder()
-
getVirtualColumns
public VirtualColumns getVirtualColumns()
-
getResultFormat
public ScanQuery.ResultFormat getResultFormat()
-
getBatchSize
public int getBatchSize()
-
getScanRowsOffset
public long getScanRowsOffset()
Offset for this query; behaves like SQL "OFFSET". Zero means no offset. Negative values are invalid.
-
getScanRowsLimit
public long getScanRowsLimit()
Limit for this query; behaves like SQL "LIMIT". Will always be positive.Long.MAX_VALUE
is used in situations where the user wants an effectively unlimited result set.
-
getOffsetLimit
public OffsetLimit getOffsetLimit()
-
isLimited
public boolean isLimited()
Returns whether this query is limited or not. BecauseLong.MAX_VALUE
is used to signify unlimitedness, this is equivalent togetScanRowsLimit() != Long.Max_VALUE
.- See Also:
getScanRowsLimit()
-
getTimeOrder
public ScanQuery.Order getTimeOrder()
If this query is purely-time-ordered, returns a value of the enumScanQuery.Order
. Otherwise, returnsScanQuery.Order.NONE
. If the returned value isScanQuery.Order.NONE
it may not agree withgetOrderBys()
.
-
getOrderBys
public List<ScanQuery.OrderBy> getOrderBys()
-
getMaxSegmentPartitionsOrderedInMemory
@Nullable public Integer getMaxSegmentPartitionsOrderedInMemory()
-
hasFilters
public boolean hasFilters()
-
getType
public String getType()
-
isLegacy
@Nullable public Boolean isLegacy()
Compatibility mode with the legacy scan-query extension. True, false, and null have different meanings: true/false mean "legacy" and "not legacy"; null means use the default set byScanQueryConfig.isLegacy()
. The methodwithNonNullLegacy(org.apache.druid.query.scan.ScanQueryConfig)
is provided to help with this.
-
getResultOrdering
public com.google.common.collect.Ordering<ScanResultValue> getResultOrdering()
Description copied from class:BaseQuery
Default implementation ofQuery.getResultOrdering()
that usesOrdering.natural()
. If your query result type T is not Comparable, you must override this method.- Specified by:
getResultOrdering
in interfaceQuery<ScanResultValue>
- Overrides:
getResultOrdering
in classBaseQuery<ScanResultValue>
-
getRequiredColumns
@Nullable public Set<String> getRequiredColumns()
Description copied from interface:Query
Returns the set of columns that this query will need to access out of its datasource. This method does not "look into" what the datasource itself is doing. For example, if a query is built on aQueryDataSource
, this method will not return the columns used by that subquery. As another example, if a query is built on aJoinDataSource
, this method will not return the columns from the underlying datasources that are used by the join condition, unless those columns are also used by this query in other ways. Returns null if the set of required columns cannot be known ahead of time.
-
withOffset
public ScanQuery withOffset(long newOffset)
-
withLimit
public ScanQuery withLimit(long newLimit)
-
withNonNullLegacy
public ScanQuery withNonNullLegacy(ScanQueryConfig scanQueryConfig)
-
withQuerySegmentSpec
public ScanQuery withQuerySegmentSpec(QuerySegmentSpec querySegmentSpec)
Description copied from interface:Query
Returns a new query, identical to this one, but with a different associatedQuerySegmentSpec
. This often changes the behavior ofQuery.getRunner(QuerySegmentWalker)
, since most queries inherit that method fromBaseQuery
, which implements it by callingQuerySegmentSpec.lookup(org.apache.druid.query.Query<T>, org.apache.druid.query.QuerySegmentWalker)
.
-
withDataSource
public ScanQuery withDataSource(DataSource dataSource)
-
equals
public boolean equals(Object o)
- Overrides:
equals
in classBaseQuery<ScanResultValue>
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classBaseQuery<ScanResultValue>
-
-