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
Nested ClassesModifier and TypeClassDescriptionstatic interfaceTranslates a field of an input to an expression.static classImplementation ofRexToLixTranslator.InputGetterthat callsPhysType.fieldReference(org.apache.calcite.linq4j.tree.Expression, int).static classResult of translating aRexNode. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionDereferences an expression if it is aRexLocalRef.static RexToLixTranslatorforAggregation(JavaTypeFactory typeFactory, BlockBuilder list, @Nullable RexToLixTranslator.InputGetter inputGetter, SqlConformance conformance) Creates a translator for translating aggregate functions.getRoot()booleanReturns whether an expression is nullable.setBlock(BlockBuilder list) setCorrelates(@Nullable Function1<String, RexToLixTranslator.InputGetter> correlates) static ExpressiontranslateCondition(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 ExpressiontranslateLiteral(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 aRexProgramto a sequence of expressions and declarations.static ExpressiontranslateTableFunction(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, waitMethods 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 aRexProgramto 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 butnullAsisRexImpTable.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,RexToLixTranslatorgenerally 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:
visitInputRefin interfaceRexVisitor<RexToLixTranslator.Result>
-
visitLambdaRef
- Specified by:
visitLambdaRefin interfaceRexVisitor<RexToLixTranslator.Result>
-
visitLocalRef
- Specified by:
visitLocalRefin interfaceRexVisitor<RexToLixTranslator.Result>
-
visitLiteral
VisitRexLiteral. If it has never been visited before,RexToLixTranslatorwill 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:
visitLiteralin interfaceRexVisitor<RexToLixTranslator.Result>
-
visitCall
VisitRexCall. For mostSqlOperators, we can get the implementor fromRexImpTable. Several operators (e.g., CaseWhen) with special semantics need to be implemented separately.- Specified by:
visitCallin interfaceRexVisitor<RexToLixTranslator.Result>
-
visitDynamicParam
- Specified by:
visitDynamicParamin interfaceRexVisitor<RexToLixTranslator.Result>
-
visitFieldAccess
- Specified by:
visitFieldAccessin interfaceRexVisitor<RexToLixTranslator.Result>
-
visitOver
- Specified by:
visitOverin interfaceRexVisitor<RexToLixTranslator.Result>
-
visitCorrelVariable
- Specified by:
visitCorrelVariablein interfaceRexVisitor<RexToLixTranslator.Result>
-
visitRangeRef
- Specified by:
visitRangeRefin interfaceRexVisitor<RexToLixTranslator.Result>
-
visitSubQuery
- Specified by:
visitSubQueryin interfaceRexVisitor<RexToLixTranslator.Result>
-
visitTableInputRef
- Specified by:
visitTableInputRefin interfaceRexVisitor<RexToLixTranslator.Result>
-
visitPatternFieldRef
- Specified by:
visitPatternFieldRefin interfaceRexVisitor<RexToLixTranslator.Result>
-
visitLambda
- Specified by:
visitLambdain interfaceRexVisitor<RexToLixTranslator.Result>
-