Class Expressions
java.lang.Object
org.apache.druid.sql.calcite.expression.Expressions
A collection of functions for translating from Calcite expressions into Druid objects.
-
Method Summary
Modifier and TypeMethodDescriptionasTimestampFloorExpr(DruidExpression expression, ExpressionParser parser) static DruidLiteralcalciteLiteralToDruidLiteral(PlannerContext plannerContext, org.apache.calcite.rex.RexNode rexNode) Create aDruidLiteralfrom a literalRexNode.static org.apache.calcite.rex.RexNodefromFieldAccess(org.apache.calcite.rel.type.RelDataTypeFactory typeFactory, RowSignature rowSignature, org.apache.calcite.rel.core.Project project, int fieldNumber) Translate a field access, possibly through a projection, to an underlying Druid dataSource.static org.apache.calcite.rex.RexNodefromFieldAccess(RowSignature rowSignature, org.apache.calcite.rel.core.Project project, int fieldNumber) Deprecated.static DruidExpressiontoDruidExpression(PlannerContext plannerContext, RowSignature rowSignature, org.apache.calcite.rex.RexNode rexNode) Translate a CalciteRexNodeto a Druid expression for projections or the aggregators that don't require numeric inputs.static List<DruidExpression>toDruidExpressions(PlannerContext plannerContext, RowSignature rowSignature, List<org.apache.calcite.rex.RexNode> rexNodes) Translate a list of CalciteRexNodeto Druid expressions.static List<DruidExpression>toDruidExpressionsWithPostAggOperands(PlannerContext plannerContext, RowSignature rowSignature, List<org.apache.calcite.rex.RexNode> rexNodes, PostAggregatorVisitor postAggregatorVisitor) Translate a list of CalciteRexNodeto Druid expressions, with the possibility of having postagg operands.static DruidExpressiontoDruidExpressionWithPostAggOperands(PlannerContext plannerContext, RowSignature rowSignature, org.apache.calcite.rex.RexNode rexNode, PostAggregatorVisitor postAggregatorVisitor) static DimFiltertoFilter(PlannerContext plannerContext, RowSignature rowSignature, VirtualColumnRegistry virtualColumnRegistry, org.apache.calcite.rex.RexNode expression) Translates "condition" to a Druid filter, or returns null if we cannot translate the condition.static GranularitytoQueryGranularity(DruidExpression expression, ExpressionParser parser) Converts an expression to a Granularity, if possible.
-
Method Details
-
fromFieldAccess
@Deprecated public static org.apache.calcite.rex.RexNode fromFieldAccess(RowSignature rowSignature, @Nullable org.apache.calcite.rel.core.Project project, int fieldNumber) Deprecated.Old method used to translate a field access, possibly through a projection, to an underlying Druid dataSource. This exists to provide API compatibility to extensions, but is deprecated because there is a 4 argument version that should be used instead. Call sites should have access to a RexBuilder instance that they can get the typeFactory from.- Parameters:
rowSignature- row signature of underlying Druid dataSourceproject- projection, or nullfieldNumber- number of the field to access- Returns:
- row expression
-
fromFieldAccess
public static org.apache.calcite.rex.RexNode fromFieldAccess(org.apache.calcite.rel.type.RelDataTypeFactory typeFactory, RowSignature rowSignature, @Nullable org.apache.calcite.rel.core.Project project, int fieldNumber) Translate a field access, possibly through a projection, to an underlying Druid dataSource.- Parameters:
typeFactory- factory for creating SQL typesrowSignature- row signature of underlying Druid dataSourceproject- projection, or nullfieldNumber- number of the field to access- Returns:
- row expression
-
toDruidExpressions
@Nullable public static List<DruidExpression> toDruidExpressions(PlannerContext plannerContext, RowSignature rowSignature, List<org.apache.calcite.rex.RexNode> rexNodes) Translate a list of CalciteRexNodeto Druid expressions.- Parameters:
plannerContext- SQL planner contextrowSignature- signature of the rows to be extracted fromrexNodes- list of Calcite expressions meant to be applied on top of the rows- Returns:
- list of Druid expressions in the same order as rexNodes, or null if not possible. If a non-null list is returned, all elements will be non-null.
-
toDruidExpressionsWithPostAggOperands
@Nullable public static List<DruidExpression> toDruidExpressionsWithPostAggOperands(PlannerContext plannerContext, RowSignature rowSignature, List<org.apache.calcite.rex.RexNode> rexNodes, PostAggregatorVisitor postAggregatorVisitor) Translate a list of CalciteRexNodeto Druid expressions, with the possibility of having postagg operands.- Parameters:
plannerContext- SQL planner contextrowSignature- signature of the rows to be extracted fromrexNodes- list of Calcite expressions meant to be applied on top of the rowspostAggregatorVisitor- visitor that manages postagg names and tracks postaggs that were created as by the translation- Returns:
- list of Druid expressions in the same order as rexNodes, or null if not possible. If a non-null list is returned, all elements will be non-null.
-
toDruidExpression
@Nullable public static DruidExpression toDruidExpression(PlannerContext plannerContext, RowSignature rowSignature, org.apache.calcite.rex.RexNode rexNode) Translate a CalciteRexNodeto a Druid expression for projections or the aggregators that don't require numeric inputs. Consider usingAggregations.toDruidExpressionForNumericAggregator(org.apache.druid.sql.calcite.planner.PlannerContext, org.apache.druid.segment.column.RowSignature, org.apache.calcite.rex.RexNode)for the aggregators that require numeric inputs.- Parameters:
plannerContext- SQL planner contextrowSignature- signature of the rows to be extracted fromrexNode- expression meant to be applied on top of the rows- Returns:
- DruidExpression referring to fields in rowOrder, or null if not possible to translate
-
toDruidExpressionWithPostAggOperands
@Nullable public static DruidExpression toDruidExpressionWithPostAggOperands(PlannerContext plannerContext, RowSignature rowSignature, org.apache.calcite.rex.RexNode rexNode, @Nullable PostAggregatorVisitor postAggregatorVisitor) -
calciteLiteralToDruidLiteral
@Nullable public static DruidLiteral calciteLiteralToDruidLiteral(PlannerContext plannerContext, org.apache.calcite.rex.RexNode rexNode) Create aDruidLiteralfrom a literalRexNode. Necessary because Calcite represents literals using different Java classes than Druid does.- Parameters:
plannerContext- planner contextrexNode- Calcite literal- Returns:
- converted literal, or null if the literal cannot be converted
-
toFilter
@Nullable public static DimFilter toFilter(PlannerContext plannerContext, RowSignature rowSignature, @Nullable VirtualColumnRegistry virtualColumnRegistry, org.apache.calcite.rex.RexNode expression) Translates "condition" to a Druid filter, or returns null if we cannot translate the condition.- Parameters:
plannerContext- planner contextrowSignature- input row signaturevirtualColumnRegistry- re-usable virtual column references, may be null if virtual columns aren't allowedexpression- Calcite row expression
-
toQueryGranularity
@Nullable public static Granularity toQueryGranularity(DruidExpression expression, ExpressionParser parser) Converts an expression to a Granularity, if possible. This is possible if, and only if, the expression is a timestamp_floor function on the __time column with literal parameters for period, origin, and timeZone.- Returns:
- granularity or null if not possible
-
asTimestampFloorExpr
@Nullable public static TimestampFloorExprMacro.TimestampFloorExpr asTimestampFloorExpr(DruidExpression expression, ExpressionParser parser)
-