use of org.apache.flink.table.planner.codegen.CodeGeneratorContext in project flink by apache.
the class BatchExecHashJoin method translateToPlanInternal.
@Override
@SuppressWarnings("unchecked")
protected Transformation<RowData> translateToPlanInternal(PlannerBase planner, ExecNodeConfig config) {
ExecEdge leftInputEdge = getInputEdges().get(0);
ExecEdge rightInputEdge = getInputEdges().get(1);
Transformation<RowData> leftInputTransform = (Transformation<RowData>) leftInputEdge.translateToPlan(planner);
Transformation<RowData> rightInputTransform = (Transformation<RowData>) rightInputEdge.translateToPlan(planner);
// get input types
RowType leftType = (RowType) leftInputEdge.getOutputType();
RowType rightType = (RowType) rightInputEdge.getOutputType();
JoinUtil.validateJoinSpec(joinSpec, leftType, rightType, false);
int[] leftKeys = joinSpec.getLeftKeys();
int[] rightKeys = joinSpec.getRightKeys();
LogicalType[] keyFieldTypes = IntStream.of(leftKeys).mapToObj(leftType::getTypeAt).toArray(LogicalType[]::new);
RowType keyType = RowType.of(keyFieldTypes);
GeneratedJoinCondition condFunc = JoinUtil.generateConditionFunction(config.getTableConfig(), joinSpec.getNonEquiCondition().orElse(null), leftType, rightType);
// projection for equals
GeneratedProjection leftProj = ProjectionCodeGenerator.generateProjection(new CodeGeneratorContext(config.getTableConfig()), "HashJoinLeftProjection", leftType, keyType, leftKeys);
GeneratedProjection rightProj = ProjectionCodeGenerator.generateProjection(new CodeGeneratorContext(config.getTableConfig()), "HashJoinRightProjection", rightType, keyType, rightKeys);
Transformation<RowData> buildTransform;
Transformation<RowData> probeTransform;
GeneratedProjection buildProj;
GeneratedProjection probeProj;
int[] buildKeys;
int[] probeKeys;
RowType buildType;
RowType probeType;
int buildRowSize;
long buildRowCount;
long probeRowCount;
boolean reverseJoin = !leftIsBuild;
if (leftIsBuild) {
buildTransform = leftInputTransform;
buildProj = leftProj;
buildType = leftType;
buildRowSize = estimatedLeftAvgRowSize;
buildRowCount = estimatedLeftRowCount;
buildKeys = leftKeys;
probeTransform = rightInputTransform;
probeProj = rightProj;
probeType = rightType;
probeRowCount = estimatedLeftRowCount;
probeKeys = rightKeys;
} else {
buildTransform = rightInputTransform;
buildProj = rightProj;
buildType = rightType;
buildRowSize = estimatedRightAvgRowSize;
buildRowCount = estimatedRightRowCount;
buildKeys = rightKeys;
probeTransform = leftInputTransform;
probeProj = leftProj;
probeType = leftType;
probeRowCount = estimatedLeftRowCount;
probeKeys = leftKeys;
}
// operator
StreamOperatorFactory<RowData> operator;
FlinkJoinType joinType = joinSpec.getJoinType();
HashJoinType hashJoinType = HashJoinType.of(leftIsBuild, joinType.isLeftOuter(), joinType.isRightOuter(), joinType == FlinkJoinType.SEMI, joinType == FlinkJoinType.ANTI);
if (LongHashJoinGenerator.support(hashJoinType, keyType, joinSpec.getFilterNulls())) {
operator = LongHashJoinGenerator.gen(config.getTableConfig(), hashJoinType, keyType, buildType, probeType, buildKeys, probeKeys, buildRowSize, buildRowCount, reverseJoin, condFunc);
} else {
operator = SimpleOperatorFactory.of(HashJoinOperator.newHashJoinOperator(hashJoinType, condFunc, reverseJoin, joinSpec.getFilterNulls(), buildProj, probeProj, tryDistinctBuildRow, buildRowSize, buildRowCount, probeRowCount, keyType));
}
long managedMemory = config.get(ExecutionConfigOptions.TABLE_EXEC_RESOURCE_HASH_JOIN_MEMORY).getBytes();
return ExecNodeUtil.createTwoInputTransformation(buildTransform, probeTransform, createTransformationName(config), createTransformationDescription(config), operator, InternalTypeInfo.of(getOutputType()), probeTransform.getParallelism(), managedMemory);
}
use of org.apache.flink.table.planner.codegen.CodeGeneratorContext in project flink by apache.
the class StreamExecDataStreamScan method translateToPlanInternal.
@SuppressWarnings("unchecked")
@Override
protected Transformation<RowData> translateToPlanInternal(PlannerBase planner, ExecNodeConfig config) {
final Transformation<?> sourceTransform = dataStream.getTransformation();
final Optional<RexNode> rowtimeExpr = getRowtimeExpression(planner.getRelBuilder());
final Transformation<RowData> transformation;
// conversion.
if (rowtimeExpr.isPresent() || ScanUtil.needsConversion(sourceType)) {
final String extractElement, resetElement;
if (ScanUtil.hasTimeAttributeField(fieldIndexes)) {
String elementTerm = OperatorCodeGenerator.ELEMENT();
extractElement = String.format("ctx.%s = %s;", elementTerm, elementTerm);
resetElement = String.format("ctx.%s = null;", elementTerm);
} else {
extractElement = "";
resetElement = "";
}
final CodeGeneratorContext ctx = new CodeGeneratorContext(config.getTableConfig()).setOperatorBaseClass(TableStreamOperator.class);
transformation = ScanUtil.convertToInternalRow(ctx, (Transformation<Object>) sourceTransform, fieldIndexes, sourceType, (RowType) getOutputType(), qualifiedName, (detailName, simplifyName) -> createFormattedTransformationName(detailName, simplifyName, config), (description) -> createFormattedTransformationDescription(description, config), JavaScalaConversionUtil.toScala(rowtimeExpr), extractElement, resetElement);
} else {
transformation = (Transformation<RowData>) sourceTransform;
}
return transformation;
}
use of org.apache.flink.table.planner.codegen.CodeGeneratorContext in project flink by apache.
the class CommonExecLookupJoin method createSyncLookupJoin.
private StreamOperatorFactory<RowData> createSyncLookupJoin(RelOptTable temporalTable, ExecNodeConfig config, Map<Integer, LookupJoinUtil.LookupKey> allLookupKeys, TableFunction<?> syncLookupFunction, RelBuilder relBuilder, RowType inputRowType, RowType tableSourceRowType, RowType resultRowType, boolean isLeftOuterJoin, boolean isObjectReuseEnabled) {
DataTypeFactory dataTypeFactory = ShortcutUtils.unwrapContext(relBuilder).getCatalogManager().getDataTypeFactory();
int[] orderedLookupKeys = LookupJoinUtil.getOrderedLookupKeys(allLookupKeys.keySet());
GeneratedFunction<FlatMapFunction<RowData, RowData>> generatedFetcher = LookupJoinCodeGenerator.generateSyncLookupFunction(config.getTableConfig(), dataTypeFactory, inputRowType, tableSourceRowType, resultRowType, allLookupKeys, orderedLookupKeys, syncLookupFunction, StringUtils.join(temporalTable.getQualifiedName(), "."), isObjectReuseEnabled);
RowType rightRowType = Optional.ofNullable(temporalTableOutputType).map(FlinkTypeFactory::toLogicalRowType).orElse(tableSourceRowType);
CodeGeneratorContext ctx = new CodeGeneratorContext(config.getTableConfig());
GeneratedCollector<TableFunctionCollector<RowData>> generatedCollector = LookupJoinCodeGenerator.generateCollector(ctx, inputRowType, rightRowType, resultRowType, JavaScalaConversionUtil.toScala(Optional.ofNullable(joinCondition)), JavaScalaConversionUtil.toScala(Optional.empty()), true);
ProcessFunction<RowData, RowData> processFunc;
if (existCalcOnTemporalTable) {
// a projection or filter after table source scan
GeneratedFunction<FlatMapFunction<RowData, RowData>> generatedCalc = LookupJoinCodeGenerator.generateCalcMapFunction(config.getTableConfig(), JavaScalaConversionUtil.toScala(projectionOnTemporalTable), filterOnTemporalTable, temporalTableOutputType, tableSourceRowType);
processFunc = new LookupJoinWithCalcRunner(generatedFetcher, generatedCalc, generatedCollector, isLeftOuterJoin, rightRowType.getFieldCount());
} else {
// right type is the same as table source row type, because no calc after temporal table
processFunc = new LookupJoinRunner(generatedFetcher, generatedCollector, isLeftOuterJoin, rightRowType.getFieldCount());
}
return SimpleOperatorFactory.of(new ProcessOperator<>(processFunc));
}
use of org.apache.flink.table.planner.codegen.CodeGeneratorContext in project flink by apache.
the class CommonExecCorrelate method translateToPlanInternal.
@SuppressWarnings("unchecked")
@Override
protected Transformation<RowData> translateToPlanInternal(PlannerBase planner, ExecNodeConfig config) {
final ExecEdge inputEdge = getInputEdges().get(0);
final Transformation<RowData> inputTransform = (Transformation<RowData>) inputEdge.translateToPlan(planner);
final CodeGeneratorContext ctx = new CodeGeneratorContext(config.getTableConfig()).setOperatorBaseClass(operatorBaseClass);
return CorrelateCodeGenerator.generateCorrelateTransformation(config.getTableConfig(), ctx, inputTransform, (RowType) inputEdge.getOutputType(), invocation, JavaScalaConversionUtil.toScala(Optional.ofNullable(condition)), (RowType) getOutputType(), joinType, inputTransform.getParallelism(), retainHeader, getClass().getSimpleName(), createTransformationMeta(CORRELATE_TRANSFORMATION, config));
}
use of org.apache.flink.table.planner.codegen.CodeGeneratorContext in project flink by apache.
the class CommonExecExpand method translateToPlanInternal.
@SuppressWarnings("unchecked")
@Override
protected Transformation<RowData> translateToPlanInternal(PlannerBase planner, ExecNodeConfig config) {
final ExecEdge inputEdge = getInputEdges().get(0);
final Transformation<RowData> inputTransform = (Transformation<RowData>) inputEdge.translateToPlan(planner);
final CodeGenOperatorFactory<RowData> operatorFactory = ExpandCodeGenerator.generateExpandOperator(new CodeGeneratorContext(config.getTableConfig()), (RowType) inputEdge.getOutputType(), (RowType) getOutputType(), projects, retainHeader, getClass().getSimpleName());
return ExecNodeUtil.createOneInputTransformation(inputTransform, createTransformationMeta(EXPAND_TRANSFORMATION, config), operatorFactory, InternalTypeInfo.of(getOutputType()), inputTransform.getParallelism());
}
Aggregations