Class RexToLixTranslator
java.lang.Object
org.apache.calcite.adapter.enumerable.RexToLixTranslator
- All Implemented Interfaces:
RexVisitor<RexToLixTranslator.Result>
Translates
REX expressions
to
linq4j expressions
.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Translates a field of an input to an expression.static class
Implementation ofRexToLixTranslator.InputGetter
that callsPhysType.fieldReference(org.apache.calcite.linq4j.tree.Expression, int)
.static class
Result of translating aRexNode
. -
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionDereferences an expression if it is aRexLocalRef
.static RexToLixTranslator
forAggregation
(JavaTypeFactory typeFactory, BlockBuilder list, @Nullable RexToLixTranslator.InputGetter inputGetter, SqlConformance conformance) Creates a translator for translating aggregate functions.getRoot()
boolean
Returns whether an expression is nullable.setBlock
(BlockBuilder list) setCorrelates
(@Nullable Function1<String, RexToLixTranslator.InputGetter> correlates) static Expression
translateCondition
(RexProgram program, JavaTypeFactory typeFactory, BlockBuilder list, RexToLixTranslator.InputGetter inputGetter, Function1<String, RexToLixTranslator.InputGetter> correlates, SqlConformance conformance) translateList
(List<? extends RexNode> operandList) Translates the list ofRexNode
, using the default output types.translateList
(List<? extends RexNode> operandList, @Nullable List<? extends @Nullable Type> storageTypes) Translates the list ofRexNode
, while optimizing for output storage.translateList
(List<RexNode> operandList, RexImpTable.NullAs nullAs) translateList
(List<RexNode> operandList, RexImpTable.NullAs nullAs, List<? extends @Nullable Type> storageTypes) static Expression
translateLiteral
(RexLiteral literal, RelDataType type, JavaTypeFactory typeFactory, RexImpTable.NullAs nullAs) Translates a literal.static List<Expression>
translateProjects
(RexProgram program, JavaTypeFactory typeFactory, SqlConformance conformance, BlockBuilder list, @Nullable PhysType outputPhysType, Expression root, RexToLixTranslator.InputGetter inputGetter, @Nullable Function1<String, RexToLixTranslator.InputGetter> correlates) Deprecated.static List<Expression>
translateProjects
(RexProgram program, JavaTypeFactory typeFactory, SqlConformance conformance, BlockBuilder list, @Nullable BlockBuilder staticList, @Nullable PhysType outputPhysType, Expression root, RexToLixTranslator.InputGetter inputGetter, @Nullable Function1<String, RexToLixTranslator.InputGetter> correlates) Translates aRexProgram
to a sequence of expressions and declarations.static Expression
translateTableFunction
(JavaTypeFactory typeFactory, SqlConformance conformance, BlockBuilder list, Expression root, RexCall rexCall, Expression inputEnumerable, PhysType inputPhysType, PhysType outputPhysType) VisitRexCall
.visitCorrelVariable
(RexCorrelVariable correlVariable) visitDynamicParam
(RexDynamicParam dynamicParam) visitFieldAccess
(RexFieldAccess fieldAccess) visitInputRef
(RexInputRef inputRef) VisitRexInputRef
.visitLambda
(RexLambda lambda) visitLiteral
(RexLiteral literal) VisitRexLiteral
.visitLocalRef
(RexLocalRef localRef) visitPatternFieldRef
(RexPatternFieldRef fieldRef) visitRangeRef
(RexRangeRef rangeRef) visitSubQuery
(RexSubQuery subQuery) visitTableInputRef
(RexTableInputRef fieldRef) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.calcite.rex.RexVisitor
visitEach, visitList, visitList
-
Field Details
-
JAVA_TO_SQL_METHOD_MAP
-
-
Method Details
-
translateProjects
public static List<Expression> translateProjects(RexProgram program, JavaTypeFactory typeFactory, SqlConformance conformance, BlockBuilder list, @Nullable BlockBuilder staticList, @Nullable PhysType outputPhysType, Expression root, RexToLixTranslator.InputGetter inputGetter, @Nullable Function1<String, RexToLixTranslator.InputGetter> correlates) Translates aRexProgram
to a sequence of expressions and declarations.- Parameters:
program
- Program to be translatedtypeFactory
- Type factoryconformance
- SQL conformancelist
- List of statements, populated with declarationsstaticList
- List of member declarationsoutputPhysType
- Output type, or nullroot
- Root expressioninputGetter
- Generates expressions for inputscorrelates
- Provider of references to the values of correlated variables- Returns:
- Sequence of expressions, optional condition
-
translateProjects
@Deprecated public static List<Expression> translateProjects(RexProgram program, JavaTypeFactory typeFactory, SqlConformance conformance, BlockBuilder list, @Nullable PhysType outputPhysType, Expression root, RexToLixTranslator.InputGetter inputGetter, @Nullable Function1<String, RexToLixTranslator.InputGetter> correlates) Deprecated. -
translateTableFunction
public static Expression translateTableFunction(JavaTypeFactory typeFactory, SqlConformance conformance, BlockBuilder list, Expression root, RexCall rexCall, Expression inputEnumerable, PhysType inputPhysType, PhysType outputPhysType) -
forAggregation
public static RexToLixTranslator forAggregation(JavaTypeFactory typeFactory, BlockBuilder list, @Nullable RexToLixTranslator.InputGetter inputGetter, SqlConformance conformance) Creates a translator for translating aggregate functions. -
deref
Dereferences an expression if it is aRexLocalRef
. -
translateLiteral
public static Expression translateLiteral(RexLiteral literal, RelDataType type, JavaTypeFactory typeFactory, RexImpTable.NullAs nullAs) Translates a literal.- Throws:
ControlFlowException
- if literal is null butnullAs
isRexImpTable.NullAs.NOT_POSSIBLE
.
-
translateList
-
translateList
public List<Expression> translateList(List<RexNode> operandList, RexImpTable.NullAs nullAs, List<? extends @Nullable Type> storageTypes) -
translateList
Translates the list ofRexNode
, using the default output types. This might be suboptimal in terms of additional box-unbox when you use the translation later. If you know the java class that will be used to store the results, usetranslateList(java.util.List, java.util.List)
version.- Parameters:
operandList
- list of RexNodes to translate- Returns:
- translated expressions
-
translateList
public List<Expression> translateList(List<? extends RexNode> operandList, @Nullable List<? extends @Nullable Type> storageTypes) Translates the list ofRexNode
, while optimizing for output storage. For instance, if the result of translation is going to be stored inObject[]
, and the input isObject[]
as well, then translator will avoid casting, boxing, etc.- Parameters:
operandList
- list of RexNodes to translatestorageTypes
- hints of the java classes that will be used to store translation results. Use null to use default storage type- Returns:
- translated expressions
-
translateCondition
public static Expression translateCondition(RexProgram program, JavaTypeFactory typeFactory, BlockBuilder list, RexToLixTranslator.InputGetter inputGetter, Function1<String, RexToLixTranslator.InputGetter> correlates, SqlConformance conformance) -
isNullable
Returns whether an expression is nullable.- Parameters:
e
- Expression- Returns:
- Whether expression is nullable
-
setBlock
-
setCorrelates
public RexToLixTranslator setCorrelates(@Nullable Function1<String, RexToLixTranslator.InputGetter> correlates) -
getRoot
-
visitInputRef
VisitRexInputRef
. If it has never been visited under current storage type before,RexToLixTranslator
generally produces three lines of code.For example, when visiting a column (named commission) in table Employee, the generated code snippet is:
final Employee current = (Employee) inputEnumerator.current(); final Integer input_value = current.commission; final boolean input_isNull = input_value == null;
- Specified by:
visitInputRef
in interfaceRexVisitor<RexToLixTranslator.Result>
-
visitLambdaRef
- Specified by:
visitLambdaRef
in interfaceRexVisitor<RexToLixTranslator.Result>
-
visitLocalRef
- Specified by:
visitLocalRef
in interfaceRexVisitor<RexToLixTranslator.Result>
-
visitLiteral
VisitRexLiteral
. If it has never been visited before,RexToLixTranslator
will generate two lines of code. For example, when visiting a primitive int (10), the generated code snippet is:final int literal_value = 10; final boolean literal_isNull = false;
- Specified by:
visitLiteral
in interfaceRexVisitor<RexToLixTranslator.Result>
-
visitCall
VisitRexCall
. For mostSqlOperator
s, we can get the implementor fromRexImpTable
. Several operators (e.g., CaseWhen) with special semantics need to be implemented separately.- Specified by:
visitCall
in interfaceRexVisitor<RexToLixTranslator.Result>
-
visitDynamicParam
- Specified by:
visitDynamicParam
in interfaceRexVisitor<RexToLixTranslator.Result>
-
visitFieldAccess
- Specified by:
visitFieldAccess
in interfaceRexVisitor<RexToLixTranslator.Result>
-
visitOver
- Specified by:
visitOver
in interfaceRexVisitor<RexToLixTranslator.Result>
-
visitCorrelVariable
- Specified by:
visitCorrelVariable
in interfaceRexVisitor<RexToLixTranslator.Result>
-
visitRangeRef
- Specified by:
visitRangeRef
in interfaceRexVisitor<RexToLixTranslator.Result>
-
visitSubQuery
- Specified by:
visitSubQuery
in interfaceRexVisitor<RexToLixTranslator.Result>
-
visitTableInputRef
- Specified by:
visitTableInputRef
in interfaceRexVisitor<RexToLixTranslator.Result>
-
visitPatternFieldRef
- Specified by:
visitPatternFieldRef
in interfaceRexVisitor<RexToLixTranslator.Result>
-
visitLambda
- Specified by:
visitLambda
in interfaceRexVisitor<RexToLixTranslator.Result>
-