use of org.apache.flink.table.runtime.generated.GeneratedProjection in project flink by apache.
the class PassThroughPythonStreamGroupWindowAggregateOperator method createProjection.
private Projection<RowData, BinaryRowData> createProjection(String name, int[] fields) {
final RowType forwardedFieldType = new RowType(Arrays.stream(fields).mapToObj(i -> inputType.getFields().get(i)).collect(Collectors.toList()));
final GeneratedProjection generatedProjection = ProjectionCodeGenerator.generateProjection(CodeGeneratorContext.apply(new TableConfig()), name, inputType, forwardedFieldType, fields);
// noinspection unchecked
return generatedProjection.newInstance(Thread.currentThread().getContextClassLoader());
}
use of org.apache.flink.table.runtime.generated.GeneratedProjection in project flink by apache.
the class StreamExecPythonOverAggregate method getPythonOverWindowAggregateFunctionOperator.
@SuppressWarnings("unchecked")
private OneInputStreamOperator<RowData, RowData> getPythonOverWindowAggregateFunctionOperator(ExecNodeConfig config, Configuration pythonConfig, RowType inputRowType, RowType outputRowType, int rowTiemIdx, long lowerBoundary, boolean isRowsClause, int[] udafInputOffsets, PythonFunctionInfo[] pythonFunctionInfos, long minIdleStateRetentionTime, long maxIdleStateRetentionTime) {
RowType userDefinedFunctionInputType = (RowType) Projection.of(udafInputOffsets).project(inputRowType);
RowType userDefinedFunctionOutputType = (RowType) Projection.range(inputRowType.getFieldCount(), outputRowType.getFieldCount()).project(outputRowType);
GeneratedProjection generatedProjection = ProjectionCodeGenerator.generateProjection(CodeGeneratorContext.apply(config.getTableConfig()), "UdafInputProjection", inputRowType, userDefinedFunctionInputType, udafInputOffsets);
if (isRowsClause) {
String className;
if (rowTiemIdx != -1) {
className = ARROW_PYTHON_OVER_WINDOW_ROWS_ROW_TIME_AGGREGATE_FUNCTION_OPERATOR_NAME;
} else {
className = ARROW_PYTHON_OVER_WINDOW_ROWS_PROC_TIME_AGGREGATE_FUNCTION_OPERATOR_NAME;
}
Class<?> clazz = CommonPythonUtil.loadClass(className);
try {
Constructor<?> ctor = clazz.getConstructor(Configuration.class, long.class, long.class, PythonFunctionInfo[].class, RowType.class, RowType.class, RowType.class, int.class, long.class, GeneratedProjection.class);
return (OneInputStreamOperator<RowData, RowData>) ctor.newInstance(pythonConfig, minIdleStateRetentionTime, maxIdleStateRetentionTime, pythonFunctionInfos, inputRowType, userDefinedFunctionInputType, userDefinedFunctionOutputType, rowTiemIdx, lowerBoundary, generatedProjection);
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
throw new TableException("Python Arrow Over Rows Window Function Operator constructed failed.", e);
}
} else {
String className;
if (rowTiemIdx != -1) {
className = ARROW_PYTHON_OVER_WINDOW_RANGE_ROW_TIME_AGGREGATE_FUNCTION_OPERATOR_NAME;
} else {
className = ARROW_PYTHON_OVER_WINDOW_RANGE_PROC_TIME_AGGREGATE_FUNCTION_OPERATOR_NAME;
}
Class<?> clazz = CommonPythonUtil.loadClass(className);
try {
Constructor<?> ctor = clazz.getConstructor(Configuration.class, PythonFunctionInfo[].class, RowType.class, RowType.class, RowType.class, int.class, long.class, GeneratedProjection.class);
return (OneInputStreamOperator<RowData, RowData>) ctor.newInstance(pythonConfig, pythonFunctionInfos, inputRowType, userDefinedFunctionInputType, userDefinedFunctionOutputType, rowTiemIdx, lowerBoundary, generatedProjection);
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
throw new TableException("Python Arrow Over Range Window Function Operator constructed failed.", e);
}
}
}
use of org.apache.flink.table.runtime.generated.GeneratedProjection 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.runtime.generated.GeneratedProjection in project flink by apache.
the class KeySelectorUtil method getRowDataSelector.
/**
* Create a RowDataKeySelector to extract keys from DataStream which type is {@link
* InternalTypeInfo} of {@link RowData}.
*
* @param keyFields key fields
* @param rowType type of DataStream to extract keys
* @return the RowDataKeySelector to extract keys from DataStream which type is {@link
* InternalTypeInfo} of {@link RowData}.
*/
public static RowDataKeySelector getRowDataSelector(int[] keyFields, InternalTypeInfo<RowData> rowType) {
if (keyFields.length > 0) {
LogicalType[] inputFieldTypes = rowType.toRowFieldTypes();
LogicalType[] keyFieldTypes = new LogicalType[keyFields.length];
for (int i = 0; i < keyFields.length; ++i) {
keyFieldTypes[i] = inputFieldTypes[keyFields[i]];
}
// do not provide field names for the result key type,
// because we may have duplicate key fields and the field names may conflict
RowType returnType = RowType.of(keyFieldTypes);
RowType inputType = rowType.toRowType();
GeneratedProjection generatedProjection = ProjectionCodeGenerator.generateProjection(CodeGeneratorContext.apply(new TableConfig()), "KeyProjection", inputType, returnType, keyFields);
InternalTypeInfo<RowData> keyRowType = InternalTypeInfo.of(returnType);
return new BinaryRowDataKeySelector(keyRowType, generatedProjection);
} else {
return EmptyRowDataKeySelector.INSTANCE;
}
}
Aggregations