use of org.apache.flink.table.functions.python.PythonFunctionInfo in project flink by apache.
the class BatchExecPythonGroupAggregate method getPythonAggregateFunctionOperator.
@SuppressWarnings("unchecked")
private OneInputStreamOperator<RowData, RowData> getPythonAggregateFunctionOperator(ExecNodeConfig config, Configuration pythonConfig, RowType inputRowType, RowType outputRowType, int[] udafInputOffsets, PythonFunctionInfo[] pythonFunctionInfos) {
final Class<?> clazz = CommonPythonUtil.loadClass(ARROW_PYTHON_AGGREGATE_FUNCTION_OPERATOR_NAME);
RowType udfInputType = (RowType) Projection.of(udafInputOffsets).project(inputRowType);
RowType udfOutputType = (RowType) Projection.range(auxGrouping.length, outputRowType.getFieldCount()).project(outputRowType);
try {
Constructor<?> ctor = clazz.getConstructor(Configuration.class, PythonFunctionInfo[].class, RowType.class, RowType.class, RowType.class, GeneratedProjection.class, GeneratedProjection.class, GeneratedProjection.class);
return (OneInputStreamOperator<RowData, RowData>) ctor.newInstance(pythonConfig, pythonFunctionInfos, inputRowType, udfInputType, udfOutputType, ProjectionCodeGenerator.generateProjection(CodeGeneratorContext.apply(config.getTableConfig()), "UdafInputProjection", inputRowType, udfInputType, udafInputOffsets), ProjectionCodeGenerator.generateProjection(CodeGeneratorContext.apply(config.getTableConfig()), "GroupKey", inputRowType, (RowType) Projection.of(grouping).project(inputRowType), grouping), ProjectionCodeGenerator.generateProjection(CodeGeneratorContext.apply(config.getTableConfig()), "GroupSet", inputRowType, (RowType) Projection.of(auxGrouping).project(inputRowType), auxGrouping));
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
throw new TableException("Python BatchArrowPythonGroupAggregateFunctionOperator constructed failed.", e);
}
}
use of org.apache.flink.table.functions.python.PythonFunctionInfo in project flink by apache.
the class StreamExecPythonGroupWindowAggregate method getPandasPythonStreamGroupWindowAggregateFunctionOperator.
@SuppressWarnings({ "unchecked", "rawtypes" })
private OneInputStreamOperator<RowData, RowData> getPandasPythonStreamGroupWindowAggregateFunctionOperator(ExecNodeConfig config, Configuration pythonConfig, RowType inputRowType, RowType outputRowType, WindowAssigner<?> windowAssigner, Trigger<?> trigger, long allowance, int inputTimeFieldIndex, int[] udafInputOffsets, PythonFunctionInfo[] pythonFunctionInfos, ZoneId shiftTimeZone) {
Class clazz = CommonPythonUtil.loadClass(ARROW_STREAM_PYTHON_GROUP_WINDOW_AGGREGATE_FUNCTION_OPERATOR_NAME);
RowType userDefinedFunctionInputType = (RowType) Projection.of(udafInputOffsets).project(inputRowType);
RowType userDefinedFunctionOutputType = (RowType) Projection.range(grouping.length, outputRowType.getFieldCount() - namedWindowProperties.length).project(outputRowType);
try {
Constructor<OneInputStreamOperator<RowData, RowData>> ctor = clazz.getConstructor(Configuration.class, PythonFunctionInfo[].class, RowType.class, RowType.class, RowType.class, int.class, WindowAssigner.class, Trigger.class, long.class, NamedWindowProperty[].class, ZoneId.class, GeneratedProjection.class);
return ctor.newInstance(pythonConfig, pythonFunctionInfos, inputRowType, userDefinedFunctionInputType, userDefinedFunctionOutputType, inputTimeFieldIndex, windowAssigner, trigger, allowance, namedWindowProperties, shiftTimeZone, ProjectionCodeGenerator.generateProjection(CodeGeneratorContext.apply(config.getTableConfig()), "UdafInputProjection", inputRowType, userDefinedFunctionInputType, udafInputOffsets));
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
throw new TableException("Python StreamArrowPythonGroupWindowAggregateFunctionOperator constructed failed.", e);
}
}
use of org.apache.flink.table.functions.python.PythonFunctionInfo in project flink by apache.
the class CommonPythonUtil method createPythonFunctionInfo.
private static PythonFunctionInfo createPythonFunctionInfo(RexCall pythonRexCall, Map<RexNode, Integer> inputNodes, FunctionDefinition functionDefinition) throws InvocationTargetException, IllegalAccessException {
ArrayList<Object> inputs = new ArrayList<>();
for (RexNode operand : pythonRexCall.getOperands()) {
if (operand instanceof RexCall) {
RexCall childPythonRexCall = (RexCall) operand;
PythonFunctionInfo argPythonInfo = createPythonFunctionInfo(childPythonRexCall, inputNodes);
inputs.add(argPythonInfo);
} else if (operand instanceof RexLiteral) {
RexLiteral literal = (RexLiteral) operand;
inputs.add(convertLiteralToPython(literal, literal.getType().getSqlTypeName()));
} else {
if (inputNodes.containsKey(operand)) {
inputs.add(inputNodes.get(operand));
} else {
Integer inputOffset = inputNodes.size();
inputs.add(inputOffset);
inputNodes.put(operand, inputOffset);
}
}
}
return new PythonFunctionInfo((PythonFunction) functionDefinition, inputs.toArray());
}
Aggregations