public class DruidQuery extends AbstractRelNode implements BindableRel
| Modifier and Type | Class and Description |
|---|---|
private static class |
DruidQuery.DruidQueryNode
Interpreter node that executes a Druid query and sends the results to a
Sink. |
private static class |
DruidQuery.JsonAggregation
Aggregation element of a Druid "groupBy" or "topN" query.
|
private static class |
DruidQuery.JsonCardinalityAggregation
Aggregation element that calls the "cardinality" function.
|
private static class |
DruidQuery.JsonCollation
Collation element of a Druid "groupBy" query.
|
private static class |
DruidQuery.JsonExpressionPostAgg
Druid Json Expression post aggregate.
|
private static class |
DruidQuery.JsonFilteredAggregation
Aggregation element that contains a filter
|
private static class |
DruidQuery.JsonLimit
Collation element of a Druid "groupBy" query.
|
protected static class |
DruidQuery.JsonPostAggregation
Post-Aggregator Post aggregator abstract writer
|
static class |
DruidQuery.QuerySpec
Druid query specification.
|
private static class |
DruidQuery.ScanQuery
Druid Scan Query Body
|
InterpretableRel.InterpreterImplementorRelNode.Context| Modifier and Type | Field and Description |
|---|---|
(package private) Map<SqlOperator,DruidSqlOperatorConverter> |
converterOperatorMap
This operator map provides DruidSqlOperatorConverter instance to convert a Calcite RexNode to
Druid Expression when possible.
|
private static int |
DAYS_IN_TEN_YEARS |
static List<DruidSqlOperatorConverter> |
DEFAULT_OPERATORS_LIST
Provides a standard list of supported Calcite operators that can be converted to
Druid Expressions.
|
protected static String |
DRUID_QUERY_FETCH |
(package private) DruidTable |
druidTable |
private static String |
EXTRACT_COLUMN_NAME_PREFIX |
private static String |
FLOOR_COLUMN_NAME_PREFIX |
(package private) com.google.common.collect.ImmutableList<org.joda.time.Interval> |
intervals |
protected DruidQuery.QuerySpec |
querySpec |
(package private) com.google.common.collect.ImmutableList<RelNode> |
rels |
(package private) RelOptTable |
table |
private static Pattern |
VALID_SIG |
digest, id, rowType, traitSet| Modifier | Constructor and Description |
|---|---|
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.
|
| Modifier and Type | Method and Description |
|---|---|
Enumerable<Object[]> |
bind(DataContext dataContext) |
protected static List<DruidQuery.JsonAggregation> |
computeDruidJsonAgg(List<AggregateCall> aggCalls,
List<String> aggNames,
Project project,
DruidQuery druidQuery)
Translates aggregate calls to Druid
DruidQuery.JsonAggregations when
possible. |
private static DruidJsonFilter |
computeFilter(Filter filterRel,
DruidQuery druidQuery)
Translates Filter rel to Druid Filter Json object if possible.
|
protected static Pair<List<String>,List<VirtualColumn>> |
computeProjectAsScan(Project projectRel,
RelDataType inputRowType,
DruidQuery druidQuery)
Translates list of projects to Druid Column names and Virtual Columns if any
We can not use
Pair.zip(Object[], Object[]), since size can be different |
protected static Pair<List<DimensionSpec>,List<VirtualColumn>> |
computeProjectGroupSet(Project projectNode,
ImmutableBitSet groupSet,
RelDataType inputRowType,
DruidQuery druidQuery)
Computes the project group set.
|
RelOptCost |
computeSelfCost(RelOptPlanner planner,
RelMetadataQuery mq) |
private DruidQuery.JsonLimit |
computeSort(Integer fetch,
List<Integer> collationIndexes,
List<RelFieldCollation.Direction> collationDirections,
ImmutableBitSet numericCollationIndexes,
List<String> queryOutputFieldNames) |
RelNode |
copy(RelTraitSet traitSet,
List<RelNode> inputs) |
private static DruidQuery |
create(RelOptCluster cluster,
RelTraitSet traitSet,
RelOptTable table,
DruidTable druidTable,
List<org.joda.time.Interval> intervals,
List<RelNode> rels,
Map<SqlOperator,DruidSqlOperatorConverter> converterOperatorMap)
Creates a DruidQuery.
|
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 |
deriveQuerySpec() |
RelDataType |
deriveRowType() |
RelWriter |
explainTerms(RelWriter pw) |
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 String |
extractColumnName(RexNode rexNode,
RelDataType rowType,
DruidQuery query) |
static String |
format(String message,
Object... formatArgs)
Equivalent of String.format(Locale.ENGLISH, message, formatArgs).
|
protected CalciteConnectionConfig |
getConnectionConfig() |
DruidTable |
getDruidTable() |
Class<Object[]> |
getElementType() |
private double |
getIntervalCostMultiplier() |
private static DruidQuery.JsonAggregation |
getJsonAggregation(String name,
AggregateCall aggCall,
RexNode filterNode,
String fieldName,
String aggExpression,
DruidQuery druidQuery) |
protected Map<SqlOperator,DruidSqlOperatorConverter> |
getOperatorConversionMap() |
protected DruidQuery.QuerySpec |
getQuery(RelDataType rowType,
Filter filter,
Project project,
ImmutableBitSet groupSet,
List<AggregateCall> aggCalls,
List<String> aggNames,
List<Integer> collationIndexes,
List<RelFieldCollation.Direction> collationDirections,
ImmutableBitSet numericCollationIndexes,
Integer fetch,
Project postProject,
Filter havingFilter) |
DruidQuery.QuerySpec |
getQuerySpec() |
String |
getQueryString() |
QueryType |
getQueryType() |
private double |
getQueryTypeCostMultiplier() |
RelOptTable |
getTable() |
TableScan |
getTableScan() |
protected int |
getTimestampFieldIndex() |
RelNode |
getTopNode() |
Node |
implement(InterpretableRel.InterpreterImplementor implementor) |
boolean |
isValid(Litmus litmus,
RelNode.Context context) |
private static boolean |
isValidLeafCast(RexNode rexNode) |
(package private) static boolean |
isValidSignature(String signature)
Returns whether a signature represents an sequence of relational operators
that can be translated into a valid Druid query.
|
(package private) static String |
metadataQuery(String dataSourceName,
List<org.joda.time.Interval> intervals)
Generates a JSON string to query metadata about a data source.
|
private String |
planAsGroupBy(List<DimensionSpec> groupByKeyDims,
DruidJsonFilter jsonFilter,
List<VirtualColumn> virtualColumnList,
List<DruidQuery.JsonAggregation> aggregations,
List<DruidQuery.JsonExpressionPostAgg> postAggregations,
DruidQuery.JsonLimit limit,
DruidJsonFilter havingFilter) |
private String |
planAsTimeSeries(List<DimensionSpec> groupByKeyDims,
DruidJsonFilter jsonFilter,
List<VirtualColumn> virtualColumnList,
List<DruidQuery.JsonAggregation> aggregations,
List<DruidQuery.JsonExpressionPostAgg> postAggregations,
DruidQuery.JsonLimit limit,
DruidJsonFilter havingFilter) |
private String |
planAsTopN(List<DimensionSpec> groupByKeyDims,
DruidJsonFilter jsonFilter,
List<VirtualColumn> virtualColumnList,
List<DruidQuery.JsonAggregation> aggregations,
List<DruidQuery.JsonExpressionPostAgg> postAggregations,
DruidQuery.JsonLimit limit,
DruidJsonFilter havingFilter) |
void |
register(RelOptPlanner planner) |
(package private) String |
signature()
Returns a string describing the operations inside this query.
|
protected static Pair<String,ExtractionFunction> |
toDruidColumn(RexNode rexNode,
RelDataType rowType,
DruidQuery druidQuery) |
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,
Object o) |
protected static void |
writeObject(com.fasterxml.jackson.core.JsonGenerator generator,
Object o) |
accept, accept, childrenAccept, collectVariablesSet, collectVariablesUsed, computeDigest, computeSelfCost, estimateRowCount, explain, getChildExps, getCluster, getCollationList, getConvention, getCorrelVariable, getDescription, getDigest, getExpectedInputRowType, getId, getInput, getInputs, getQuery, getRelTypeName, getRows, getRowType, getTraitSet, getVariablesSet, getVariablesStopped, isDistinct, isKey, isValid, metadata, onRegister, recomputeDigest, replaceInput, sole, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitaccept, accept, childrenAccept, collectVariablesSet, collectVariablesUsed, computeSelfCost, estimateRowCount, explain, getChildExps, getCollationList, getConvention, getCorrelVariable, getExpectedInputRowType, getInput, getInputs, getQuery, getRelTypeName, getRows, getRowType, getVariablesSet, getVariablesStopped, isDistinct, isKey, isValid, metadata, onRegister, recomputeDigest, replaceInputgetCluster, getDescription, getDigest, getId, getTraitSetpublic static final List<DruidSqlOperatorConverter> DEFAULT_OPERATORS_LIST
protected DruidQuery.QuerySpec querySpec
final RelOptTable table
final DruidTable druidTable
final com.google.common.collect.ImmutableList<org.joda.time.Interval> intervals
final com.google.common.collect.ImmutableList<RelNode> rels
final Map<SqlOperator,DruidSqlOperatorConverter> converterOperatorMap
private static final Pattern VALID_SIG
private static final String EXTRACT_COLUMN_NAME_PREFIX
private static final String FLOOR_COLUMN_NAME_PREFIX
protected static final String DRUID_QUERY_FETCH
private static final int DAYS_IN_TEN_YEARS
protected DruidQuery(RelOptCluster cluster, RelTraitSet traitSet, RelOptTable table, DruidTable druidTable, List<org.joda.time.Interval> intervals, List<RelNode> rels, Map<SqlOperator,DruidSqlOperatorConverter> converterOperatorMap)
cluster - ClustertraitSet - Traitstable - TabledruidTable - Druid tableintervals - Intervals for the queryrels - Internal relational expressionsconverterOperatorMap - mapping of Calcite Sql Operator to Druid Expression API.static boolean isValidSignature(String signature)
public static DruidQuery create(RelOptCluster cluster, RelTraitSet traitSet, RelOptTable table, DruidTable druidTable, List<RelNode> rels)
public static DruidQuery create(RelOptCluster cluster, RelTraitSet traitSet, RelOptTable table, DruidTable druidTable, List<RelNode> rels, Map<SqlOperator,DruidSqlOperatorConverter> converterOperatorMap)
private static DruidQuery create(RelOptCluster cluster, RelTraitSet traitSet, RelOptTable table, DruidTable druidTable, List<org.joda.time.Interval> intervals, List<RelNode> rels, Map<SqlOperator,DruidSqlOperatorConverter> converterOperatorMap)
public static DruidQuery extendQuery(DruidQuery query, RelNode r)
public static DruidQuery extendQuery(DruidQuery query, List<org.joda.time.Interval> intervals)
protected static Pair<String,ExtractionFunction> toDruidColumn(RexNode rexNode, RelDataType rowType, DruidQuery druidQuery)
rexNode - leaf Input Ref to Druid ColumnrowType - row typedruidQuery - druid queryPair of Column name and Extraction Function on the top of the input ref or
of(null, null) when can not translate to valid Druid columnprivate static boolean isValidLeafCast(RexNode rexNode)
rexNode - rexNode@Nullable protected static String extractColumnName(RexNode rexNode, RelDataType rowType, DruidQuery query)
rexNode - Druid input ref noderowType - rowTypequery - Druid Querypublic static String format(String message, Object... formatArgs)
String signature()
For example, "sfpahol" means TableScan (s)
followed by Filter (f)
followed by Project (p)
followed by Aggregate (a)
followed by Filter (h)
followed by Project (o)
followed by Sort (l).
isValidSignature(String)public boolean isValid(Litmus litmus, RelNode.Context context)
isValid in interface RelNodeisValid in class AbstractRelNodeprotected Map<SqlOperator,DruidSqlOperatorConverter> getOperatorConversionMap()
public RelNode copy(RelTraitSet traitSet, List<RelNode> inputs)
copy in interface RelNodecopy in class AbstractRelNodepublic RelDataType deriveRowType()
deriveRowType in class AbstractRelNodepublic TableScan getTableScan()
public RelNode getTopNode()
public RelOptTable getTable()
getTable in interface RelNodegetTable in class AbstractRelNodepublic DruidTable getDruidTable()
public RelWriter explainTerms(RelWriter pw)
explainTerms in class AbstractRelNodepublic RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq)
computeSelfCost in interface RelNodecomputeSelfCost in class AbstractRelNodeprivate double getIntervalCostMultiplier()
private double getQueryTypeCostMultiplier()
public void register(RelOptPlanner planner)
register in interface RelNoderegister in class AbstractRelNodepublic Class<Object[]> getElementType()
getElementType in interface ArrayBindablegetElementType in interface Typedpublic Enumerable<Object[]> bind(DataContext dataContext)
public Node implement(InterpretableRel.InterpreterImplementor implementor)
implement in interface InterpretableRelpublic DruidQuery.QuerySpec getQuerySpec()
protected DruidQuery.QuerySpec deriveQuerySpec()
public QueryType getQueryType()
public String getQueryString()
protected CalciteConnectionConfig getConnectionConfig()
@Nullable private static DruidJsonFilter computeFilter(@Nullable Filter filterRel, DruidQuery druidQuery)
filterRel - input filter reldruidQuery - Druid query@Nullable protected static Pair<List<String>,List<VirtualColumn>> computeProjectAsScan(@Nullable Project projectRel, RelDataType inputRowType, DruidQuery druidQuery)
Pair.zip(Object[], Object[]), since size can be differentprojectRel - Project ReldruidQuery - Druid query@Nullable protected static Pair<List<DimensionSpec>,List<VirtualColumn>> computeProjectGroupSet(@Nullable Project projectNode, ImmutableBitSet groupSet, RelDataType inputRowType, DruidQuery druidQuery)
projectNode - Project under the Aggregates if anygroupSet - Ids of grouping keys as they are listed in projects listinputRowType - Input row type under the projectdruidQuery - Druid QueryDimensionSpec containing the group by dimensions,
and a list of VirtualColumn containing Druid virtual column
projections; or null, if translation is not possible.
Note that the size of lists can be different.@Nullable protected static List<DruidQuery.JsonAggregation> computeDruidJsonAgg(List<AggregateCall> aggCalls, List<String> aggNames, @Nullable Project project, DruidQuery druidQuery)
DruidQuery.JsonAggregations when
possible.aggCalls - List of AggregateCalls to translateaggNames - List of aggregate namesproject - Input project under the aggregate calls,
or null if we have TableScan immediately under the
AggregatedruidQuery - Druid Query RelDruidQuery.JsonAggregations, or null if any of the
aggregates is not supportedprotected DruidQuery.QuerySpec getQuery(RelDataType rowType, Filter filter, Project project, ImmutableBitSet groupSet, List<AggregateCall> aggCalls, List<String> aggNames, List<Integer> collationIndexes, List<RelFieldCollation.Direction> collationDirections, ImmutableBitSet numericCollationIndexes, Integer fetch, Project postProject, Filter havingFilter)
private DruidQuery.JsonLimit computeSort(@Nullable Integer fetch, List<Integer> collationIndexes, List<RelFieldCollation.Direction> collationDirections, ImmutableBitSet numericCollationIndexes, List<String> queryOutputFieldNames)
fetch - limit to fetchcollationIndexes - index of fields as listed in query row outputcollationDirections - direction of sortnumericCollationIndexes - flag of to determine sort comparatorqueryOutputFieldNames - query output fields@Nullable private String planAsTimeSeries(List<DimensionSpec> groupByKeyDims, DruidJsonFilter jsonFilter, List<VirtualColumn> virtualColumnList, List<DruidQuery.JsonAggregation> aggregations, List<DruidQuery.JsonExpressionPostAgg> postAggregations, DruidQuery.JsonLimit limit, DruidJsonFilter havingFilter)
@Nullable private String planAsTopN(List<DimensionSpec> groupByKeyDims, DruidJsonFilter jsonFilter, List<VirtualColumn> virtualColumnList, List<DruidQuery.JsonAggregation> aggregations, List<DruidQuery.JsonExpressionPostAgg> postAggregations, DruidQuery.JsonLimit limit, DruidJsonFilter havingFilter)
@Nullable private String planAsGroupBy(List<DimensionSpec> groupByKeyDims, DruidJsonFilter jsonFilter, List<VirtualColumn> virtualColumnList, List<DruidQuery.JsonAggregation> aggregations, List<DruidQuery.JsonExpressionPostAgg> postAggregations, DruidQuery.JsonLimit limit, DruidJsonFilter havingFilter)
@Nullable private static DruidQuery.JsonAggregation getJsonAggregation(String name, AggregateCall aggCall, RexNode filterNode, String fieldName, String aggExpression, DruidQuery druidQuery)
protected static void writeField(com.fasterxml.jackson.core.JsonGenerator generator,
String fieldName,
Object o)
throws IOException
IOExceptionprotected static void writeFieldIf(com.fasterxml.jackson.core.JsonGenerator generator,
String fieldName,
Object o)
throws IOException
IOExceptionprotected static void writeArray(com.fasterxml.jackson.core.JsonGenerator generator,
List<?> elements)
throws IOException
IOExceptionprotected static void writeObject(com.fasterxml.jackson.core.JsonGenerator generator,
Object o)
throws IOException
IOExceptionstatic String metadataQuery(String dataSourceName, List<org.joda.time.Interval> intervals)
protected int getTimestampFieldIndex()
Copyright © 2012–2018 The Apache Software Foundation. All rights reserved.