Class DruidQuery
- All Implemented Interfaces:
Cloneable,BindableRel,InterpretableRel,RelOptNode,RelNode,ArrayBindable,Bindable<@Nullable Object[]>,Typed
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classPost-aggregator abstract writer.static classDruid query specification.Nested classes/interfaces inherited from interface org.apache.calcite.interpreter.InterpretableRel
InterpretableRel.InterpreterImplementorNested classes/interfaces inherited from interface org.apache.calcite.rel.RelNode
RelNode.Context -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final List<DruidSqlOperatorConverter>Provides a standard list of supported Calcite operators that can be converted to Druid Expressions.protected static final Stringprotected @Nullable DruidQuery.QuerySpecFields inherited from class org.apache.calcite.rel.AbstractRelNode
digest, id, rowType, traitSet -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDruidQuery(RelOptCluster cluster, RelTraitSet traitSet, RelOptTable table, DruidTable druidTable, List<org.joda.time.Interval> intervals, List<RelNode> rels, Map<SqlOperator, DruidSqlOperatorConverter> converterOperatorMap) Creates a DruidQuery. -
Method Summary
Modifier and TypeMethodDescriptionEnumerable<@Nullable Object[]>bind(DataContext dataContext) Executes this statement and returns an enumerable which will yield rows.protected static @Nullable List<org.apache.calcite.adapter.druid.DruidQuery.JsonAggregation>computeDruidJsonAgg(List<AggregateCall> aggCalls, List<String> aggNames, @Nullable Project project, DruidQuery druidQuery) Translates aggregate calls to DruidDruidQuery.JsonAggregations when possible.protected static @Nullable Pair<List<String>,List<VirtualColumn>> computeProjectAsScan(@Nullable Project projectRel, RelDataType inputRowType, DruidQuery druidQuery) Translates a list of projects to Druid Column names and Virtual Columns if any.protected static @Nullable Pair<List<DimensionSpec>,List<VirtualColumn>> computeProjectGroupSet(@Nullable Project projectNode, ImmutableBitSet groupSet, RelDataType inputRowType, DruidQuery druidQuery) Computes the project group set.@Nullable RelOptCostcomputeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) Returns the cost of this plan (not including children).copy(RelTraitSet traitSet, List<RelNode> inputs) Creates a copy of this relational expression, perhaps changing traits and inputs.static DruidQuerycreate(RelOptCluster cluster, RelTraitSet traitSet, RelOptTable table, DruidTable druidTable, List<RelNode> rels) Creates a DruidQuery.static DruidQuerycreate(RelOptCluster cluster, RelTraitSet traitSet, RelOptTable table, DruidTable druidTable, List<RelNode> rels, Map<SqlOperator, DruidSqlOperatorConverter> converterOperatorMap) Creates a DruidQuery.protected DruidQuery.QuerySpecDescribes the inputs and attributes of this relational expression.static DruidQueryextendQuery(DruidQuery query, List<org.joda.time.Interval> intervals) Extends a DruidQuery.static DruidQueryextendQuery(DruidQuery query, RelNode r) Extends a DruidQuery.protected static @Nullable StringextractColumnName(RexNode rexNode, RelDataType rowType, DruidQuery query) Returns Druid column name or null when it is not possible to translate.static StringEquivalent of String.format(Locale.ENGLISH, message, formatArgs).protected CalciteConnectionConfigGets the type of the element(s) that are returned in this collection.protected Map<SqlOperator,DruidSqlOperatorConverter> protected DruidQuery.QuerySpecgetQuery(RelDataType rowType, Filter filter, @Nullable Project project, @Nullable ImmutableBitSet groupSet, @Nullable List<AggregateCall> aggCalls, @Nullable List<String> aggNames, @Nullable List<Integer> collationIndexes, @Nullable List<RelFieldCollation.Direction> collationDirections, ImmutableBitSet numericCollationIndexes, @Nullable Integer fetch, @Nullable Project postProject, @Nullable Filter havingFilter) getTable()If this relational expression represents an access to a table, returns that table, otherwise returns null.protected intReturns the index of the timestamp ref, or -1 if not present.implement(InterpretableRel.InterpreterImplementor implementor) Creates an interpreter node to implement this relational expression.booleanisValid(Litmus litmus, RelNode.Context context) Returns whether this relational expression is valid.voidregister(RelOptPlanner planner) Registers any special rules specific to this kind of relational expression.protected static Pair<String,ExtractionFunction> toDruidColumn(RexNode rexNode, RelDataType rowType, DruidQuery druidQuery) Converts aRexNodeto a Druid column.protected static voidwriteArray(com.fasterxml.jackson.core.JsonGenerator generator, List<?> elements) protected static voidwriteField(com.fasterxml.jackson.core.JsonGenerator generator, String fieldName, Object o) protected static voidwriteFieldIf(com.fasterxml.jackson.core.JsonGenerator generator, String fieldName, @Nullable Object o) protected static voidwriteObject(com.fasterxml.jackson.core.JsonGenerator generator, Object o) Methods inherited from class org.apache.calcite.rel.AbstractRelNode
accept, accept, childrenAccept, collectVariablesSet, collectVariablesUsed, deepEquals, deepHashCode, equals, estimateRowCount, explain, getCluster, getConvention, getCorrelVariable, getDescription, getDigest, getExpectedInputRowType, getId, getInput, getInputs, getRelDigest, getRelTypeName, getRowType, getTraitSet, getVariablesSet, hashCode, isEnforcer, metadata, onRegister, recomputeDigest, replaceInput, sole, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.calcite.rel.RelNode
accept, accept, childrenAccept, collectVariablesSet, collectVariablesUsed, deepEquals, deepHashCode, estimateRowCount, explain, explain, fieldIsNullable, getConvention, getCorrelVariable, getDigest, getExpectedInputRowType, getInput, getInputs, getRelDigest, getRelTypeName, getRowType, getVariablesSet, isEnforcer, metadata, onRegister, recomputeDigest, replaceInput, strippedMethods inherited from interface org.apache.calcite.plan.RelOptNode
getCluster, getDescription, getId, getTraitSet
-
Field Details
-
DEFAULT_OPERATORS_LIST
Provides a standard list of supported Calcite operators that can be converted to Druid Expressions. This can be used as is or re-adapted based on underline engine operator syntax. Methods can refer to https://druid.apache.org/docs/latest/querying/ -
querySpec
-
DRUID_QUERY_FETCH
- See Also:
-
-
Constructor Details
-
DruidQuery
protected DruidQuery(RelOptCluster cluster, RelTraitSet traitSet, RelOptTable table, DruidTable druidTable, List<org.joda.time.Interval> intervals, List<RelNode> rels, Map<SqlOperator, DruidSqlOperatorConverter> converterOperatorMap) Creates a DruidQuery.- Parameters:
cluster- ClustertraitSet- Traitstable- TabledruidTable- Druid tableintervals- Intervals for the queryrels- Internal relational expressionsconverterOperatorMap- mapping of Calcite Sql Operator to Druid Expression API.
-
-
Method Details
-
create
public static DruidQuery create(RelOptCluster cluster, RelTraitSet traitSet, RelOptTable table, DruidTable druidTable, List<RelNode> rels) Creates a DruidQuery. -
create
public static DruidQuery create(RelOptCluster cluster, RelTraitSet traitSet, RelOptTable table, DruidTable druidTable, List<RelNode> rels, Map<SqlOperator, DruidSqlOperatorConverter> converterOperatorMap) Creates a DruidQuery. -
extendQuery
Extends a DruidQuery. -
extendQuery
Extends a DruidQuery. -
toDruidColumn
protected static Pair<String,ExtractionFunction> toDruidColumn(RexNode rexNode, RelDataType rowType, DruidQuery druidQuery) Converts aRexNodeto a Druid column.- Parameters:
rexNode- leaf Input Ref to Druid ColumnrowType- row typedruidQuery- Druid query- Returns:
Pairof Column name and Extraction Function on the top of the input ref, orPair.of(null, null)when cannot translate to a valid Druid column
-
extractColumnName
protected static @Nullable String extractColumnName(RexNode rexNode, RelDataType rowType, DruidQuery query) Returns Druid column name or null when it is not possible to translate.- Parameters:
rexNode- Druid input ref noderowType- Row typequery- Druid query
-
format
Equivalent of String.format(Locale.ENGLISH, message, formatArgs). -
isValid
Description copied from interface:RelNodeReturns whether this relational expression is valid.If assertions are enabled, this method is typically called with
litmus=THROW, as follows:assert rel.isValid(Litmus.THROW)
This signals that the method can throw an
AssertionErrorif it is not valid.- Specified by:
isValidin interfaceRelNode- Overrides:
isValidin classAbstractRelNode- Parameters:
litmus- What to do if invalidcontext- Context for validity checking- Returns:
- Whether relational expression is valid
-
getOperatorConversionMap
-
copy
Description copied from interface:RelNodeCreates a copy of this relational expression, perhaps changing traits and inputs.Sub-classes with other important attributes are encouraged to create variants of this method with more parameters.
- Specified by:
copyin interfaceRelNode- Overrides:
copyin classAbstractRelNode- Parameters:
traitSet- Trait setinputs- Inputs- Returns:
- Copy of this relational expression, substituting traits and inputs
-
deriveRowType
- Overrides:
deriveRowTypein classAbstractRelNode
-
getTableScan
-
getTopNode
-
getTable
Description copied from interface:RelNodeIf this relational expression represents an access to a table, returns that table, otherwise returns null.- Specified by:
getTablein interfaceRelNode- Overrides:
getTablein classAbstractRelNode- Returns:
- If this relational expression represents an access to a table, returns that table, otherwise returns null
-
getDruidTable
-
explainTerms
Description copied from class:AbstractRelNodeDescribes the inputs and attributes of this relational expression. Each node should callsuper.explainTerms, then call theRelWriter.input(String, RelNode)andRelWriter.item(String, Object)methods for each input and attribute.- Overrides:
explainTermsin classAbstractRelNode- Parameters:
pw- Plan writer- Returns:
- Plan writer for fluent-explain pattern
-
computeSelfCost
Description copied from interface:RelNodeReturns the cost of this plan (not including children). The base implementation throws an error; derived classes should override.NOTE jvs 29-Mar-2006: Don't call this method directly. Instead, use
RelMetadataQuery.getNonCumulativeCost(org.apache.calcite.rel.RelNode), which gives plugins a chance to override the rel's default ideas about cost.- Specified by:
computeSelfCostin interfaceRelNode- Overrides:
computeSelfCostin classAbstractRelNode- Parameters:
planner- Planner for cost calculationmq- Metadata query- Returns:
- Cost of this plan (not including children)
-
register
Description copied from interface:RelNodeRegisters any special rules specific to this kind of relational expression.The planner calls this method this first time that it sees a relational expression of this class. The derived class should call
RelOptPlanner.addRule(org.apache.calcite.plan.RelOptRule)for each rule, and then callsuper.register.- Specified by:
registerin interfaceRelNode- Overrides:
registerin classAbstractRelNode- Parameters:
planner- Planner to be used to register additional relational expressions
-
getElementType
Description copied from interface:TypedGets the type of the element(s) that are returned in this collection.- Specified by:
getElementTypein interfaceArrayBindable- Specified by:
getElementTypein interfaceTyped
-
bind
Description copied from interface:BindableExecutes this statement and returns an enumerable which will yield rows. Theenvironmentparameter provides the values in the root of the environment (usually schemas). -
implement
Description copied from interface:InterpretableRelCreates an interpreter node to implement this relational expression.- Specified by:
implementin interfaceInterpretableRel
-
getQuerySpec
-
deriveQuerySpec
-
getQueryType
-
getQueryString
-
getConnectionConfig
-
computeProjectAsScan
protected static @Nullable Pair<List<String>,List<VirtualColumn>> computeProjectAsScan(@Nullable Project projectRel, RelDataType inputRowType, DruidQuery druidQuery) Translates a list of projects to Druid Column names and Virtual Columns if any.We cannot use
Pair.zip(Object[], Object[]), since size may be different.- Parameters:
projectRel- ProjectdruidQuery- Druid query- Returns:
- Pair of list of Druid Columns and Expression Virtual Columns, or null when cannot translate one of the projects
-
computeProjectGroupSet
protected static @Nullable Pair<List<DimensionSpec>,List<VirtualColumn>> computeProjectGroupSet(@Nullable Project projectNode, ImmutableBitSet groupSet, RelDataType inputRowType, DruidQuery druidQuery) Computes the project group set.- Parameters:
projectNode- Project under the Aggregates if anygroupSet- Ids of grouping keys as they are listed inprojectslistinputRowType- Input row type under the projectdruidQuery- Druid query- Returns:
- A list of
DimensionSpeccontaining the group by dimensions, and a list ofVirtualColumncontaining Druid virtual column projections; or null, if translation is not possible. Note that the size of lists can be different.
-
computeDruidJsonAgg
protected static @Nullable List<org.apache.calcite.adapter.druid.DruidQuery.JsonAggregation> computeDruidJsonAgg(List<AggregateCall> aggCalls, List<String> aggNames, @Nullable Project project, DruidQuery druidQuery) Translates aggregate calls to DruidDruidQuery.JsonAggregations when possible.- Parameters:
aggCalls- List of AggregateCalls to translateaggNames- List of aggregate namesproject- Input project under the aggregate calls, or null if we haveTableScanimmediately under theAggregatedruidQuery- Druid query- Returns:
- List of valid Druid
DruidQuery.JsonAggregations, or null if any of the aggregates is not supported
-
getQuery
protected DruidQuery.QuerySpec getQuery(RelDataType rowType, Filter filter, @Nullable Project project, @Nullable ImmutableBitSet groupSet, @Nullable List<AggregateCall> aggCalls, @Nullable List<String> aggNames, @Nullable List<Integer> collationIndexes, @Nullable List<RelFieldCollation.Direction> collationDirections, ImmutableBitSet numericCollationIndexes, @Nullable Integer fetch, @Nullable Project postProject, @Nullable Filter havingFilter) -
writeField
protected static void writeField(com.fasterxml.jackson.core.JsonGenerator generator, String fieldName, Object o) throws IOException - Throws:
IOException
-
writeFieldIf
protected static void writeFieldIf(com.fasterxml.jackson.core.JsonGenerator generator, String fieldName, @Nullable Object o) throws IOException - Throws:
IOException
-
writeArray
protected static void writeArray(com.fasterxml.jackson.core.JsonGenerator generator, List<?> elements) throws IOException - Throws:
IOException
-
writeObject
protected static void writeObject(com.fasterxml.jackson.core.JsonGenerator generator, Object o) throws IOException - Throws:
IOException
-
getTimestampFieldIndex
protected int getTimestampFieldIndex()Returns the index of the timestamp ref, or -1 if not present.
-