Class DruidQuery
- All Implemented Interfaces:
Cloneable
,BindableRel
,InterpretableRel
,RelOptNode
,RelNode
,ArrayBindable
,Bindable<@Nullable Object[]>
,Typed
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
Post-aggregator abstract writer.static class
Druid query specification.Nested classes/interfaces inherited from interface org.apache.calcite.interpreter.InterpretableRel
InterpretableRel.InterpreterImplementor
Nested classes/interfaces inherited from interface org.apache.calcite.rel.RelNode
RelNode.Context
-
Field Summary
Modifier and TypeFieldDescriptionstatic final List<DruidSqlOperatorConverter>
Provides a standard list of supported Calcite operators that can be converted to Druid Expressions.protected static final String
protected @Nullable DruidQuery.QuerySpec
Fields inherited from class org.apache.calcite.rel.AbstractRelNode
digest, id, rowType, traitSet
-
Constructor Summary
ModifierConstructorDescriptionprotected
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. -
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.JsonAggregation
s 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 RelOptCost
computeSelfCost
(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 DruidQuery
create
(RelOptCluster cluster, RelTraitSet traitSet, RelOptTable table, DruidTable druidTable, List<RelNode> rels) Creates a DruidQuery.static DruidQuery
create
(RelOptCluster cluster, RelTraitSet traitSet, RelOptTable table, DruidTable druidTable, List<RelNode> rels, Map<SqlOperator, DruidSqlOperatorConverter> converterOperatorMap) Creates a DruidQuery.protected DruidQuery.QuerySpec
Describes the inputs and attributes of this relational expression.static DruidQuery
extendQuery
(DruidQuery query, List<org.joda.time.Interval> intervals) Extends a DruidQuery.static DruidQuery
extendQuery
(DruidQuery query, RelNode r) Extends a DruidQuery.protected static @Nullable String
extractColumnName
(RexNode rexNode, RelDataType rowType, DruidQuery query) Returns Druid column name or null when it is not possible to translate.static String
Equivalent of String.format(Locale.ENGLISH, message, formatArgs).protected CalciteConnectionConfig
Gets the type of the element(s) that are returned in this collection.protected Map<SqlOperator,
DruidSqlOperatorConverter> 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) getTable()
If this relational expression represents an access to a table, returns that table, otherwise returns null.protected int
Returns the index of the timestamp ref, or -1 if not present.implement
(InterpretableRel.InterpreterImplementor implementor) Creates an interpreter node to implement this relational expression.boolean
isValid
(Litmus litmus, RelNode.Context context) Returns whether this relational expression is valid.void
register
(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 aRexNode
to a Druid column.protected static void
writeArray
(com.fasterxml.jackson.core.JsonGenerator generator, List<?> elements) protected static void
writeField
(com.fasterxml.jackson.core.JsonGenerator generator, String fieldName, Object o) protected static void
writeFieldIf
(com.fasterxml.jackson.core.JsonGenerator generator, String fieldName, @Nullable Object o) protected static void
writeObject
(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, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods 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, stripped
Methods 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. -
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 aRexNode
to a Druid column.- Parameters:
rexNode
- leaf Input Ref to Druid ColumnrowType
- row typedruidQuery
- Druid query- Returns:
Pair
of 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:RelNode
Returns 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
AssertionError
if it is not valid.- Specified by:
isValid
in interfaceRelNode
- Overrides:
isValid
in classAbstractRelNode
- Parameters:
litmus
- What to do if invalidcontext
- Context for validity checking- Returns:
- Whether relational expression is valid
-
getOperatorConversionMap
-
copy
Description copied from interface:RelNode
Creates 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:
copy
in interfaceRelNode
- Overrides:
copy
in classAbstractRelNode
- Parameters:
traitSet
- Trait setinputs
- Inputs- Returns:
- Copy of this relational expression, substituting traits and inputs
-
deriveRowType
- Overrides:
deriveRowType
in classAbstractRelNode
-
getTableScan
-
getTopNode
-
getTable
Description copied from interface:RelNode
If this relational expression represents an access to a table, returns that table, otherwise returns null.- Specified by:
getTable
in interfaceRelNode
- Overrides:
getTable
in classAbstractRelNode
- Returns:
- If this relational expression represents an access to a table, returns that table, otherwise returns null
-
getDruidTable
-
explainTerms
Description copied from class:AbstractRelNode
Describes 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:
explainTerms
in classAbstractRelNode
- Parameters:
pw
- Plan writer- Returns:
- Plan writer for fluent-explain pattern
-
computeSelfCost
Description copied from interface:RelNode
Returns 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:
computeSelfCost
in interfaceRelNode
- Overrides:
computeSelfCost
in classAbstractRelNode
- Parameters:
planner
- Planner for cost calculationmq
- Metadata query- Returns:
- Cost of this plan (not including children)
-
register
Description copied from interface:RelNode
Registers 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:
register
in interfaceRelNode
- Overrides:
register
in classAbstractRelNode
- Parameters:
planner
- Planner to be used to register additional relational expressions
-
getElementType
Description copied from interface:Typed
Gets the type of the element(s) that are returned in this collection.- Specified by:
getElementType
in interfaceArrayBindable
- Specified by:
getElementType
in interfaceTyped
-
bind
Description copied from interface:Bindable
Executes this statement and returns an enumerable which will yield rows. Theenvironment
parameter provides the values in the root of the environment (usually schemas). -
implement
Description copied from interface:InterpretableRel
Creates an interpreter node to implement this relational expression.- Specified by:
implement
in 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 inprojects
listinputRowType
- Input row type under the projectdruidQuery
- Druid query- Returns:
- A list of
DimensionSpec
containing the group by dimensions, and a list ofVirtualColumn
containing 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.JsonAggregation
s when possible.- Parameters:
aggCalls
- List of AggregateCalls to translateaggNames
- List of aggregate namesproject
- Input project under the aggregate calls, or null if we haveTableScan
immediately under theAggregate
druidQuery
- Druid query- Returns:
- List of valid Druid
DruidQuery.JsonAggregation
s, 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.
-