Search in sources :

Example 11 with PythonFunctionInfo

use of org.apache.flink.table.functions.python.PythonFunctionInfo in project flink by apache.

the class AbstractArrowPythonAggregateFunctionOperator method getUserDefinedFunctionsProto.

@Override
public FlinkFnApi.UserDefinedFunctions getUserDefinedFunctionsProto() {
    FlinkFnApi.UserDefinedFunctions.Builder builder = FlinkFnApi.UserDefinedFunctions.newBuilder();
    // add udaf proto
    for (PythonFunctionInfo pythonFunctionInfo : pandasAggFunctions) {
        builder.addUdfs(getUserDefinedFunctionProto(pythonFunctionInfo));
    }
    builder.setMetricEnabled(pythonConfig.isMetricEnabled());
    builder.setProfileEnabled(pythonConfig.isProfileEnabled());
    return builder.build();
}
Also used : PythonFunctionInfo(org.apache.flink.table.functions.python.PythonFunctionInfo)

Example 12 with PythonFunctionInfo

use of org.apache.flink.table.functions.python.PythonFunctionInfo in project flink by apache.

the class PythonTableFunctionOperatorTestBase method getTestHarness.

private OneInputStreamOperatorTestHarness<IN, OUT> getTestHarness(Configuration config, JoinRelType joinRelType) throws Exception {
    RowType inputType = new RowType(Arrays.asList(new RowType.RowField("f1", new VarCharType()), new RowType.RowField("f2", new VarCharType()), new RowType.RowField("f3", new BigIntType())));
    RowType outputType = new RowType(Arrays.asList(new RowType.RowField("f1", new VarCharType()), new RowType.RowField("f2", new VarCharType()), new RowType.RowField("f3", new BigIntType()), new RowType.RowField("f4", new BigIntType())));
    PythonTableFunctionOperator operator = getTestOperator(config, new PythonFunctionInfo(PythonScalarFunctionOperatorTestBase.DummyPythonFunction.INSTANCE, new Integer[] { 0 }), inputType, outputType, new int[] { 2 }, joinRelType);
    OneInputStreamOperatorTestHarness<IN, OUT> testHarness = new OneInputStreamOperatorTestHarness(operator);
    testHarness.getStreamConfig().setManagedMemoryFractionOperatorOfUseCase(ManagedMemoryUseCase.PYTHON, 0.5);
    return testHarness;
}
Also used : PythonFunctionInfo(org.apache.flink.table.functions.python.PythonFunctionInfo) RowType(org.apache.flink.table.types.logical.RowType) BigIntType(org.apache.flink.table.types.logical.BigIntType) VarCharType(org.apache.flink.table.types.logical.VarCharType) OneInputStreamOperatorTestHarness(org.apache.flink.streaming.util.OneInputStreamOperatorTestHarness)

Example 13 with PythonFunctionInfo

use of org.apache.flink.table.functions.python.PythonFunctionInfo in project flink by apache.

the class PythonScalarFunctionOperatorTestBase method getTestHarness.

private OneInputStreamOperatorTestHarness<IN, OUT> getTestHarness(Configuration config) throws Exception {
    RowType dataType = new RowType(Arrays.asList(new RowType.RowField("f1", new VarCharType()), new RowType.RowField("f2", new VarCharType()), new RowType.RowField("f3", new BigIntType())));
    AbstractPythonScalarFunctionOperator operator = getTestOperator(config, new PythonFunctionInfo[] { new PythonFunctionInfo(DummyPythonFunction.INSTANCE, new Integer[] { 0 }) }, dataType, dataType, new int[] { 2 }, new int[] { 0, 1 });
    OneInputStreamOperatorTestHarness<IN, OUT> testHarness = new OneInputStreamOperatorTestHarness(operator);
    testHarness.getStreamConfig().setManagedMemoryFractionOperatorOfUseCase(ManagedMemoryUseCase.PYTHON, 0.5);
    testHarness.setup(getOutputTypeSerializer(dataType));
    return testHarness;
}
Also used : PythonFunctionInfo(org.apache.flink.table.functions.python.PythonFunctionInfo) RowType(org.apache.flink.table.types.logical.RowType) BigIntType(org.apache.flink.table.types.logical.BigIntType) VarCharType(org.apache.flink.table.types.logical.VarCharType) OneInputStreamOperatorTestHarness(org.apache.flink.streaming.util.OneInputStreamOperatorTestHarness)

Example 14 with PythonFunctionInfo

use of org.apache.flink.table.functions.python.PythonFunctionInfo in project flink by apache.

the class CommonExecPythonCorrelate method createPythonOneInputTransformation.

private OneInputTransformation<RowData, RowData> createPythonOneInputTransformation(Transformation<RowData> inputTransform, ExecNodeConfig config, Configuration pythonConfig) {
    Tuple2<int[], PythonFunctionInfo> extractResult = extractPythonTableFunctionInfo();
    int[] pythonUdtfInputOffsets = extractResult.f0;
    PythonFunctionInfo pythonFunctionInfo = extractResult.f1;
    InternalTypeInfo<RowData> pythonOperatorInputRowType = (InternalTypeInfo<RowData>) inputTransform.getOutputType();
    InternalTypeInfo<RowData> pythonOperatorOutputRowType = InternalTypeInfo.of((RowType) getOutputType());
    OneInputStreamOperator<RowData, RowData> pythonOperator = getPythonTableFunctionOperator(config, pythonConfig, pythonOperatorInputRowType, pythonOperatorOutputRowType, pythonFunctionInfo, pythonUdtfInputOffsets);
    return ExecNodeUtil.createOneInputTransformation(inputTransform, createTransformationName(config), createTransformationDescription(config), pythonOperator, pythonOperatorOutputRowType, inputTransform.getParallelism());
}
Also used : PythonFunctionInfo(org.apache.flink.table.functions.python.PythonFunctionInfo) RowData(org.apache.flink.table.data.RowData) InternalTypeInfo(org.apache.flink.table.runtime.typeutils.InternalTypeInfo)

Example 15 with PythonFunctionInfo

use of org.apache.flink.table.functions.python.PythonFunctionInfo in project flink by apache.

the class BatchExecPythonGroupWindowAggregate method getPythonGroupWindowAggregateFunctionOperator.

@SuppressWarnings("unchecked")
private OneInputStreamOperator<RowData, RowData> getPythonGroupWindowAggregateFunctionOperator(ExecNodeConfig config, Configuration pythonConfig, RowType inputRowType, RowType outputRowType, int maxLimitSize, long windowSize, long slideSize, int[] namePropertyTypeArray, int[] udafInputOffsets, PythonFunctionInfo[] pythonFunctionInfos) {
    Class<?> clazz = CommonPythonUtil.loadClass(ARROW_PYTHON_GROUP_WINDOW_AGGREGATE_FUNCTION_OPERATOR_NAME);
    RowType udfInputType = (RowType) Projection.of(udafInputOffsets).project(inputRowType);
    RowType udfOutputType = (RowType) Projection.range(auxGrouping.length, outputRowType.getFieldCount() - namePropertyTypeArray.length).project(outputRowType);
    try {
        Constructor<?> ctor = clazz.getConstructor(Configuration.class, PythonFunctionInfo[].class, RowType.class, RowType.class, RowType.class, int.class, int.class, long.class, long.class, int[].class, GeneratedProjection.class, GeneratedProjection.class, GeneratedProjection.class);
        return (OneInputStreamOperator<RowData, RowData>) ctor.newInstance(pythonConfig, pythonFunctionInfos, inputRowType, udfInputType, udfOutputType, inputTimeFieldIndex, maxLimitSize, windowSize, slideSize, namePropertyTypeArray, 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 | InstantiationException | IllegalAccessException | InvocationTargetException e) {
        throw new TableException("Python BatchArrowPythonGroupWindowAggregateFunctionOperator constructed failed.", e);
    }
}
Also used : PythonFunctionInfo(org.apache.flink.table.functions.python.PythonFunctionInfo) TableException(org.apache.flink.table.api.TableException) OneInputStreamOperator(org.apache.flink.streaming.api.operators.OneInputStreamOperator) RowType(org.apache.flink.table.types.logical.RowType) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

PythonFunctionInfo (org.apache.flink.table.functions.python.PythonFunctionInfo)18 RowType (org.apache.flink.table.types.logical.RowType)13 TableException (org.apache.flink.table.api.TableException)9 OneInputStreamOperator (org.apache.flink.streaming.api.operators.OneInputStreamOperator)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)7 RowData (org.apache.flink.table.data.RowData)6 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)4 Configuration (org.apache.flink.configuration.Configuration)4 GeneratedProjection (org.apache.flink.table.runtime.generated.GeneratedProjection)4 InternalTypeInfo (org.apache.flink.table.runtime.typeutils.InternalTypeInfo)4 Constructor (java.lang.reflect.Constructor)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 AggregateCall (org.apache.calcite.rel.core.AggregateCall)3 RexCall (org.apache.calcite.rex.RexCall)3 RexNode (org.apache.calcite.rex.RexNode)3 Transformation (org.apache.flink.api.dag.Transformation)3 ManagedMemoryUseCase (org.apache.flink.core.memory.ManagedMemoryUseCase)3 OneInputTransformation (org.apache.flink.streaming.api.transformations.OneInputTransformation)3 Projection (org.apache.flink.table.connector.Projection)3