public class DruidExpression extends Object
VirtualColumnRegistry whenever used by projections, filters,
aggregators, or other query components, these will be converted into native virtual columns using
toVirtualColumn(String, ColumnType, ExprMacroTable)
Approximate expression structure is retained in the arguments, which when fed into the
DruidExpression.ExpressionGenerator that all DruidExpression must be created with will produce the final String
expression (which will be later parsed into Expr during native processing).
This allows using the DruidExpression.DruidExpressionShuttle to examine this expression "tree" and potentially rewrite some
or all of the tree as it visits nodes, and the nodeType property provides high level classification of
the types of expression which a node produces.| Modifier and Type | Class and Description |
|---|---|
static interface |
DruidExpression.DruidExpressionCreator
Create a
DruidExpression given some set of input argument sub-expressions |
static interface |
DruidExpression.DruidExpressionShuttle |
static interface |
DruidExpression.ExpressionGenerator
Used by
DruidExpression to compile a string which can be parsed into an Expr from given the
sub-expression arguments |
static class |
DruidExpression.ExpressionVirtualColumnCreator |
static class |
DruidExpression.IdentifierExpressionGenerator
Direct reference to a physical or virtual column
|
static class |
DruidExpression.LiteralExpressionGenerator
Builds expressions for a static constant value
|
static class |
DruidExpression.NodeType |
static interface |
DruidExpression.VirtualColumnCreator
Used by a
DruidExpression to translate itself into a VirtualColumn to add to a native query when
referenced by a projection, filter, aggregator, etc. |
public static String nullLiteral()
public static DruidExpression.ExpressionGenerator functionCall(String functionName)
@Deprecated public static String functionCall(String functionName, List<DruidExpression> args)
functionCall(String) instead@Deprecated public static String functionCall(String functionName, DruidExpression... args)
functionCall(String) insteadpublic static DruidExpression ofLiteral(@Nullable ColumnType columnType, String literal)
public static DruidExpression ofStringLiteral(String s)
public static DruidExpression ofColumn(@Nullable ColumnType columnType, String column, SimpleExtraction simpleExtraction)
public static DruidExpression ofColumn(ColumnType columnType, String column)
public static DruidExpression ofFunctionCall(ColumnType columnType, String functionName, List<DruidExpression> args)
public static DruidExpression ofVirtualColumn(ColumnType type, DruidExpression.ExpressionGenerator expressionGenerator, List<DruidExpression> arguments, DruidExpression.VirtualColumnCreator virtualColumnCreator)
public static DruidExpression ofExpression(@Nullable ColumnType columnType, DruidExpression.ExpressionGenerator expressionGenerator, List<DruidExpression> arguments)
public static DruidExpression ofExpression(@Nullable ColumnType columnType, SimpleExtraction simpleExtraction, DruidExpression.ExpressionGenerator expressionGenerator, List<DruidExpression> arguments)
@Deprecated public static DruidExpression of(SimpleExtraction simpleExtraction, String expression)
ofExpression(ColumnType, SimpleExtraction, ExpressionGenerator, List) instead to participate
in virtual column and expression optimization@Deprecated public static DruidExpression fromColumn(String column)
ofColumn(ColumnType, String) or ofColumn(ColumnType, String, SimpleExtraction)
instead@Deprecated public static DruidExpression fromExpression(String expression)
ofExpression(ColumnType, ExpressionGenerator, List) instead to participate in virtual
column and expression optimization@Deprecated public static DruidExpression fromFunctionCall(String functionName, List<DruidExpression> args)
ofFunctionCall(ColumnType, String, List) instead to participate in virtual column and
expression optimizationpublic String getExpression()
public boolean isDirectColumnAccess()
public String getDirectColumn()
public boolean isSimpleExtraction()
public SimpleExtraction getSimpleExtraction()
public List<DruidExpression> getArguments()
DruidExpression arguments of this expressionpublic Expr parse(ExprMacroTable macroTable)
DruidExpression into a string and parse it into a native Druid Exprpublic VirtualColumn toVirtualColumn(String name, ColumnType outputType, ExprMacroTable macroTable)
public VirtualColumn toExpressionVirtualColumn(String name, ColumnType outputType, ExprMacroTable macroTable)
public DruidExpression.NodeType getType()
@Nullable public ColumnType getDruidType()
ColumnType of this expression as inferred when this expression was created. This is likely the result
of converting the output of RexNode.getType() using
Calcites.getColumnTypeForRelDataType(RelDataType), but may also be
supplied by other means.
This value is not currently used other than for tracking the types of the DruidExpression tree. The
value passed to toVirtualColumn(String, ColumnType, ExprMacroTable) will instead be whatever type "hint"
was specified when the expression was added to the VirtualColumnRegistry.public DruidExpression map(Function<SimpleExtraction,SimpleExtraction> extractionMap, Function<String,String> expressionMap)
public DruidExpression withArguments(List<DruidExpression> newArgs)
public DruidExpression visit(DruidExpression.DruidExpressionShuttle shuttle)
DruidExpression (the arguments of this expression), allowing the
DruidExpression.DruidExpressionShuttle to potentially rewrite these arguments with new DruidExpression, finally
building a new version of this DruidExpression with updated arguments.Copyright © 2011–2022 The Apache Software Foundation. All rights reserved.