use of org.apache.flink.table.types.logical.RowType in project flink by apache.
the class CommonExecPythonCorrelate method getPythonTableFunctionOperator.
@SuppressWarnings("unchecked")
private OneInputStreamOperator<RowData, RowData> getPythonTableFunctionOperator(ExecNodeConfig config, Configuration pythonConfig, InternalTypeInfo<RowData> inputRowType, InternalTypeInfo<RowData> outputRowType, PythonFunctionInfo pythonFunctionInfo, int[] udtfInputOffsets) {
Class clazz = CommonPythonUtil.loadClass(PYTHON_TABLE_FUNCTION_OPERATOR_NAME);
final RowType inputType = inputRowType.toRowType();
final RowType outputType = outputRowType.toRowType();
final RowType udfInputType = (RowType) Projection.of(udtfInputOffsets).project(inputType);
final RowType udfOutputType = (RowType) Projection.range(inputType.getFieldCount(), outputType.getFieldCount()).project(outputType);
try {
Constructor ctor = clazz.getConstructor(Configuration.class, PythonFunctionInfo.class, RowType.class, RowType.class, RowType.class, FlinkJoinType.class, GeneratedProjection.class);
return (OneInputStreamOperator<RowData, RowData>) ctor.newInstance(pythonConfig, pythonFunctionInfo, inputType, udfInputType, udfOutputType, joinType, ProjectionCodeGenerator.generateProjection(CodeGeneratorContext.apply(config.getTableConfig()), "UdtfInputProjection", inputType, udfInputType, udtfInputOffsets));
} catch (Exception e) {
throw new TableException("Python Table Function Operator constructed failed.", e);
}
}
use of org.apache.flink.table.types.logical.RowType in project flink by apache.
the class BatchExecPythonGroupWindowAggregate method createPythonOneInputTransformation.
private OneInputTransformation<RowData, RowData> createPythonOneInputTransformation(Transformation<RowData> inputTransform, RowType inputRowType, RowType outputRowType, int maxLimitSize, long windowSize, long slideSize, Configuration pythonConfig, ExecNodeConfig config) {
int[] namePropertyTypeArray = Arrays.stream(namedWindowProperties).mapToInt(p -> {
WindowProperty property = p.getProperty();
if (property instanceof WindowStart) {
return 0;
}
if (property instanceof WindowEnd) {
return 1;
}
if (property instanceof RowtimeAttribute) {
return 2;
}
throw new TableException("Unexpected property " + property);
}).toArray();
Tuple2<int[], PythonFunctionInfo[]> aggInfos = CommonPythonUtil.extractPythonAggregateFunctionInfosFromAggregateCall(aggCalls);
int[] pythonUdafInputOffsets = aggInfos.f0;
PythonFunctionInfo[] pythonFunctionInfos = aggInfos.f1;
OneInputStreamOperator<RowData, RowData> pythonOperator = getPythonGroupWindowAggregateFunctionOperator(config, pythonConfig, inputRowType, outputRowType, maxLimitSize, windowSize, slideSize, namePropertyTypeArray, pythonUdafInputOffsets, pythonFunctionInfos);
return ExecNodeUtil.createOneInputTransformation(inputTransform, createTransformationName(config), createTransformationDescription(config), pythonOperator, InternalTypeInfo.of(outputRowType), inputTransform.getParallelism());
}
use of org.apache.flink.table.types.logical.RowType in project flink by apache.
the class BatchExecPythonGroupWindowAggregate 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 RowType inputRowType = (RowType) inputEdge.getOutputType();
final RowType outputRowType = InternalTypeInfo.of(getOutputType()).toRowType();
final Tuple2<Long, Long> windowSizeAndSlideSize = WindowCodeGenerator.getWindowDef(window);
final Configuration pythonConfig = CommonPythonUtil.getMergedConfig(planner.getExecEnv(), config.getTableConfig());
int groupBufferLimitSize = pythonConfig.getInteger(ExecutionConfigOptions.TABLE_EXEC_WINDOW_AGG_BUFFER_SIZE_LIMIT);
OneInputTransformation<RowData, RowData> transform = createPythonOneInputTransformation(inputTransform, inputRowType, outputRowType, groupBufferLimitSize, windowSizeAndSlideSize.f0, windowSizeAndSlideSize.f1, pythonConfig, config);
if (CommonPythonUtil.isPythonWorkerUsingManagedMemory(pythonConfig)) {
transform.declareManagedMemoryUseCaseAtSlotScope(ManagedMemoryUseCase.PYTHON);
}
return transform;
}
use of org.apache.flink.table.types.logical.RowType in project flink by apache.
the class BatchExecRank method translateToPlanInternal.
@SuppressWarnings("unchecked")
@Override
protected Transformation<RowData> translateToPlanInternal(PlannerBase planner, ExecNodeConfig config) {
ExecEdge inputEdge = getInputEdges().get(0);
Transformation<RowData> inputTransform = (Transformation<RowData>) inputEdge.translateToPlan(planner);
RowType inputType = (RowType) inputEdge.getOutputType();
// operator needn't cache data
// The collation for the partition-by and order-by fields is inessential here,
// we only use the comparator to distinguish fields change.
RankOperator operator = new RankOperator(ComparatorCodeGenerator.gen(config.getTableConfig(), "PartitionByComparator", inputType, SortUtil.getAscendingSortSpec(partitionFields)), ComparatorCodeGenerator.gen(config.getTableConfig(), "OrderByComparator", inputType, SortUtil.getAscendingSortSpec(sortFields)), rankStart, rankEnd, outputRankNumber);
return ExecNodeUtil.createOneInputTransformation(inputTransform, createTransformationName(config), createTransformationDescription(config), SimpleOperatorFactory.of(operator), InternalTypeInfo.of((RowType) getOutputType()), inputTransform.getParallelism());
}
use of org.apache.flink.table.types.logical.RowType in project flink by apache.
the class BatchExecExchange method getHashDistributionDescription.
private String getHashDistributionDescription(HashDistribution hashDistribution) {
RowType inputRowType = (RowType) getInputEdges().get(0).getOutputType();
String[] fieldNames = Arrays.stream(hashDistribution.getKeys()).mapToObj(i -> inputRowType.getFieldNames().get(i)).toArray(String[]::new);
return Arrays.stream(fieldNames).collect(Collectors.joining(", ", "[", "]"));
}
Aggregations