public class CodeGenerator extends Object implements org.apache.calcite.rex.RexVisitor<GeneratedExpression>
Function
s.
param: config configuration that determines runtime behavior param: nullableInput input(s) can be null. param: input1 type information about the first input of the Function param: input2 type information about the second input if the Function is binary param: input1FieldMapping additional mapping information for input1 (e.g. POJO types have no deterministic field order and some input fields might not be read) param: input2FieldMapping additional mapping information for input2 (e.g. POJO types have no deterministic field order and some input fields might not be read)
Constructor and Description |
---|
CodeGenerator(TableConfig config)
A code generator for generating Flink input formats.
|
CodeGenerator(TableConfig config,
boolean nullableInput,
TypeInformation<?> input1,
scala.Option<TypeInformation<?>> input2,
scala.Option<int[]> input1FieldMapping,
scala.Option<int[]> input2FieldMapping) |
CodeGenerator(TableConfig config,
boolean nullableInput,
TypeInformation<Object> input,
int[] inputFieldMapping)
A code generator for generating unary Flink
Function s with one input. |
Modifier and Type | Method and Description |
---|---|
String |
addReusableArray(Class<?> clazz,
int size)
Adds a reusable array to the member area of the generated
Function . |
String[] |
addReusableConstructor(scala.collection.Seq<Class<?>> parameterTypes)
Adds a reusable constructor statement with the given parameter types.
|
String |
addReusableDate()
Adds a reusable date to the beginning of the SAM of the generated
Function . |
String |
addReusableDecimal(BigDecimal decimal)
Adds a reusable
BigDecimal to the member area of the generated Function . |
String |
addReusableFunction(UserDefinedFunction function)
Adds a reusable
UserDefinedFunction to the member area of the generated Function . |
String |
addReusableLocalTime()
Adds a reusable local time to the beginning of the SAM of the generated
Function . |
String |
addReusableLocalTimestamp()
Adds a reusable local timestamp to the beginning of the SAM of the generated
Function . |
void |
addReusableOutRecord(TypeInformation<?> ti)
Adds a reusable output record to the member area of the generated
Function . |
String |
addReusablePrivateFieldAccess(Class<?> clazz,
String fieldName)
Adds a reusable
Field to the member area of the generated Function . |
String |
addReusableTime()
Adds a reusable time to the beginning of the SAM of the generated
Function . |
String |
addReusableTimestamp()
Adds a reusable timestamp to the beginning of the SAM of the generated
Function . |
String |
collectorTerm() |
String |
contextTerm() |
GeneratedAggregationsFunction |
generateAggregations(String name,
CodeGenerator generator,
scala.collection.Seq<TypeInformation<?>> physicalInputTypes,
AggregateFunction<?,?>[] aggregates,
int[][] aggFields,
int[] aggMapping,
boolean partialResults,
int[] fwdMapping,
scala.Option<int[]> mergeMapping,
scala.Option<scala.Tuple2<Object,Object>[]> constantFlags,
int outputArity,
boolean needRetract,
boolean needMerge,
boolean needReset)
Generates a
GeneratedAggregations that can be
passed to a Java compiler. |
GeneratedExpression |
generateConverterResultExpression(TypeInformation<?> returnType,
scala.collection.Seq<String> resultFieldNames)
Generates an expression that converts the first input (and second input) into the given type.
|
scala.Tuple2<scala.collection.Seq<GeneratedExpression>,scala.collection.Seq<GeneratedExpression>> |
generateCorrelateAccessExprs()
Generates an expression from the left input and the right table function.
|
GeneratedExpression |
generateExpression(org.apache.calcite.rex.RexNode rex)
Generates an expression from a RexNode.
|
<F extends Function,T> |
generateFunction(String name,
Class<F> clazz,
String bodyCode,
TypeInformation<T> returnType)
Generates a
Function that can be passed to Java
compiler. |
GeneratedExpression |
generateInputFieldUnboxing(TypeInformation<?> fieldType,
String fieldTerm)
Converts the external boxed format to an internal mostly primitive field representation.
|
GeneratedExpression |
generateNonNullLiteral(TypeInformation<?> literalType,
String literalCode) |
GeneratedExpression |
generateOutputFieldBoxing(GeneratedExpression expr)
Converts the internal mostly primitive field representation to an external boxed format.
|
GeneratedExpression |
generateRecordTimestamp(boolean isEventTime) |
GeneratedExpression |
generateResultExpression(scala.collection.Seq<GeneratedExpression> fieldExprs,
TypeInformation<?> returnType,
scala.collection.Seq<String> resultFieldNames)
Generates an expression from a sequence of other expressions.
|
GeneratedExpression |
generateResultExpression(TypeInformation<?> returnType,
scala.collection.Seq<String> resultFieldNames,
scala.collection.Seq<org.apache.calcite.rex.RexNode> rexNodes)
Generates an expression from a sequence of RexNode.
|
GeneratedExpression |
generateSymbol(Enum<?> enum_) |
GeneratedCollector |
generateTableFunctionCollector(String name,
String bodyCode,
TypeInformation<Object> collectedType)
Generates a
TableFunctionCollector that can be passed to Java compiler. |
<T extends Row> |
generateValuesInputFormat(String name,
scala.collection.Seq<String> records,
TypeInformation<T> returnType)
Generates a values input format that can be passed to Java compiler.
|
String |
input1Term() |
String |
input2Term() |
boolean |
nullCheck() |
String |
outRecordTerm() |
String |
reuseCloseCode() |
String |
reuseConstructorCode(String className) |
String |
reuseInitCode() |
String |
reuseInputUnboxingCode() |
String |
reuseMemberCode() |
String |
reuseOpenCode() |
String |
reusePerRecordCode() |
GeneratedExpression |
visitCall(org.apache.calcite.rex.RexCall call) |
GeneratedExpression |
visitCorrelVariable(org.apache.calcite.rex.RexCorrelVariable correlVariable) |
GeneratedExpression |
visitDynamicParam(org.apache.calcite.rex.RexDynamicParam dynamicParam) |
GeneratedExpression |
visitFieldAccess(org.apache.calcite.rex.RexFieldAccess rexFieldAccess) |
GeneratedExpression |
visitInputRef(org.apache.calcite.rex.RexInputRef inputRef) |
GeneratedExpression |
visitLiteral(org.apache.calcite.rex.RexLiteral literal) |
GeneratedExpression |
visitLocalRef(org.apache.calcite.rex.RexLocalRef localRef) |
GeneratedExpression |
visitOver(org.apache.calcite.rex.RexOver over) |
GeneratedExpression |
visitPatternFieldRef(org.apache.calcite.rex.RexPatternFieldRef fieldRef) |
GeneratedExpression |
visitRangeRef(org.apache.calcite.rex.RexRangeRef rangeRef) |
GeneratedExpression |
visitSubQuery(org.apache.calcite.rex.RexSubQuery subQuery) |
public CodeGenerator(TableConfig config, boolean nullableInput, TypeInformation<?> input1, scala.Option<TypeInformation<?>> input2, scala.Option<int[]> input1FieldMapping, scala.Option<int[]> input2FieldMapping)
public CodeGenerator(TableConfig config, boolean nullableInput, TypeInformation<Object> input, int[] inputFieldMapping)
Function
s with one input.
config
- configuration that determines runtime behaviornullableInput
- input(s) can be null.input
- type information about the input of the FunctioninputFieldMapping
- additional mapping information necessary for input
(e.g. POJO types have no deterministic field order and some input fields might not be read)public CodeGenerator(TableConfig config)
config
- configuration that determines runtime behaviorpublic String reuseMemberCode()
public String reuseInitCode()
public String reuseOpenCode()
public String reuseCloseCode()
public String reusePerRecordCode()
public String reuseInputUnboxingCode()
public String reuseConstructorCode(String className)
className
- (undocumented)public String input1Term()
public String input2Term()
public String collectorTerm()
public String outRecordTerm()
public String contextTerm()
ProcessFunction
's contextpublic boolean nullCheck()
public GeneratedExpression generateExpression(org.apache.calcite.rex.RexNode rex)
rex
- Calcite row expressionpublic GeneratedAggregationsFunction generateAggregations(String name, CodeGenerator generator, scala.collection.Seq<TypeInformation<?>> physicalInputTypes, AggregateFunction<?,?>[] aggregates, int[][] aggFields, int[] aggMapping, boolean partialResults, int[] fwdMapping, scala.Option<int[]> mergeMapping, scala.Option<scala.Tuple2<Object,Object>[]> constantFlags, int outputArity, boolean needRetract, boolean needMerge, boolean needReset)
GeneratedAggregations
that can be
passed to a Java compiler.
name
- Class name of the function.
Does not need to be unique but has to be a valid Java class identifier.generator
- The code generator instancephysicalInputTypes
- Physical input row typesaggregates
- All aggregate functionsaggFields
- Indexes of the input fields for all aggregate functionsaggMapping
- The mapping of aggregates to output fieldspartialResults
- A flag defining whether final or partial results (accumulators) are set
to the output row.fwdMapping
- The mapping of input fields to output fieldsmergeMapping
- An optional mapping to specify the accumulators to merge. If not set, we
assume that both rows have the accumulators at the same position.constantFlags
- An optional parameter to define where to set constant boolean flags in
the output row.outputArity
- The number of fields in the output row.needRetract
- a flag to indicate if the aggregate needs the retract methodneedMerge
- a flag to indicate if the aggregate needs the merge methodneedReset
- a flag to indicate if the aggregate needs the resetAccumulator method
public <F extends Function,T> GeneratedFunction<F,T> generateFunction(String name, Class<F> clazz, String bodyCode, TypeInformation<T> returnType)
Function
that can be passed to Java
compiler.
name
- Class name of the Function. Must not be unique but has to be a valid Java class
identifier.clazz
- Flink Function to be generated.bodyCode
- code contents of the SAM (Single Abstract Method). Inputs, collector, or
output record can be accessed via the given term methods.returnType
- expected return typepublic <T extends Row> GeneratedInput<GenericInputFormat<T>,T> generateValuesInputFormat(String name, scala.collection.Seq<String> records, TypeInformation<T> returnType)
name
- Class name of the input format. Must not be unique but has to be a
valid Java class identifier.records
- code for creating recordsreturnType
- expected return typepublic GeneratedCollector generateTableFunctionCollector(String name, String bodyCode, TypeInformation<Object> collectedType)
TableFunctionCollector
that can be passed to Java compiler.
name
- Class name of the table function collector. Must not be unique but has to be a
valid Java class identifier.bodyCode
- body code for the collector methodcollectedType
- The type information of the element collected by the collectorpublic GeneratedExpression generateConverterResultExpression(TypeInformation<?> returnType, scala.collection.Seq<String> resultFieldNames)
outRecordTerm
).
returnType
- conversion target type. Inputs and output must have the same arity.resultFieldNames
- result field names necessary for a mapping to POJO fields.public scala.Tuple2<scala.collection.Seq<GeneratedExpression>,scala.collection.Seq<GeneratedExpression>> generateCorrelateAccessExprs()
public GeneratedExpression generateResultExpression(TypeInformation<?> returnType, scala.collection.Seq<String> resultFieldNames, scala.collection.Seq<org.apache.calcite.rex.RexNode> rexNodes)
outRecordTerm
).
returnType
- conversion target type. Type must have the same arity than rexNodes.resultFieldNames
- result field names necessary for a mapping to POJO fields.rexNodes
- sequence of RexNode to be convertedpublic GeneratedExpression generateResultExpression(scala.collection.Seq<GeneratedExpression> fieldExprs, TypeInformation<?> returnType, scala.collection.Seq<String> resultFieldNames)
outRecordTerm
).
fieldExprs
- field expressions to be convertedreturnType
- conversion target type. Type must have the same arity than fieldExprs.resultFieldNames
- result field names necessary for a mapping to POJO fields.public GeneratedExpression visitInputRef(org.apache.calcite.rex.RexInputRef inputRef)
visitInputRef
in interface org.apache.calcite.rex.RexVisitor<GeneratedExpression>
public GeneratedExpression visitFieldAccess(org.apache.calcite.rex.RexFieldAccess rexFieldAccess)
visitFieldAccess
in interface org.apache.calcite.rex.RexVisitor<GeneratedExpression>
public GeneratedExpression visitLiteral(org.apache.calcite.rex.RexLiteral literal)
visitLiteral
in interface org.apache.calcite.rex.RexVisitor<GeneratedExpression>
public GeneratedExpression visitCorrelVariable(org.apache.calcite.rex.RexCorrelVariable correlVariable)
visitCorrelVariable
in interface org.apache.calcite.rex.RexVisitor<GeneratedExpression>
public GeneratedExpression visitLocalRef(org.apache.calcite.rex.RexLocalRef localRef)
visitLocalRef
in interface org.apache.calcite.rex.RexVisitor<GeneratedExpression>
public GeneratedExpression visitRangeRef(org.apache.calcite.rex.RexRangeRef rangeRef)
visitRangeRef
in interface org.apache.calcite.rex.RexVisitor<GeneratedExpression>
public GeneratedExpression visitDynamicParam(org.apache.calcite.rex.RexDynamicParam dynamicParam)
visitDynamicParam
in interface org.apache.calcite.rex.RexVisitor<GeneratedExpression>
public GeneratedExpression visitCall(org.apache.calcite.rex.RexCall call)
visitCall
in interface org.apache.calcite.rex.RexVisitor<GeneratedExpression>
public GeneratedExpression visitOver(org.apache.calcite.rex.RexOver over)
visitOver
in interface org.apache.calcite.rex.RexVisitor<GeneratedExpression>
public GeneratedExpression visitSubQuery(org.apache.calcite.rex.RexSubQuery subQuery)
visitSubQuery
in interface org.apache.calcite.rex.RexVisitor<GeneratedExpression>
public GeneratedExpression visitPatternFieldRef(org.apache.calcite.rex.RexPatternFieldRef fieldRef)
visitPatternFieldRef
in interface org.apache.calcite.rex.RexVisitor<GeneratedExpression>
public GeneratedExpression generateNonNullLiteral(TypeInformation<?> literalType, String literalCode)
public GeneratedExpression generateSymbol(Enum<?> enum_)
public GeneratedExpression generateInputFieldUnboxing(TypeInformation<?> fieldType, String fieldTerm)
fieldType
- type of fieldfieldTerm
- expression term of field to be unboxedpublic GeneratedExpression generateOutputFieldBoxing(GeneratedExpression expr)
expr
- expression to be boxedpublic GeneratedExpression generateRecordTimestamp(boolean isEventTime)
public void addReusableOutRecord(TypeInformation<?> ti)
Function
.
The passed TypeInformation
defines the type class to be instantiated.
ti
- type information of type class to be instantiated during runtimepublic String addReusablePrivateFieldAccess(Class<?> clazz, String fieldName)
Field
to the member area of the generated Function
.
The field can be used for accessing POJO fields more efficiently during runtime, however,
the field does not have to be public.
clazz
- class of containing fieldfieldName
- name of field to be extracted and instantiated during runtimepublic String addReusableDecimal(BigDecimal decimal)
BigDecimal
to the member area of the generated Function
.
decimal
- decimal object to be instantiated during runtimepublic String addReusableFunction(UserDefinedFunction function)
UserDefinedFunction
to the member area of the generated Function
.
function
- UserDefinedFunction
object to be instantiated during runtimepublic String[] addReusableConstructor(scala.collection.Seq<Class<?>> parameterTypes)
parameterTypes
- The parameter types to construct the functionpublic String addReusableArray(Class<?> clazz, int size)
Function
.clazz
- (undocumented)size
- (undocumented)public String addReusableTimestamp()
Function
.public String addReusableLocalTimestamp()
Function
.public String addReusableTime()
Function
.public String addReusableLocalTime()
Function
.public String addReusableDate()
Function
.Copyright © 2014–2018 The Apache Software Foundation. All rights reserved.