Search in sources :

Example 21 with TypeInference

use of org.apache.flink.table.types.inference.TypeInference in project flink-mirror by flink-ci.

the class CommonPythonUtil method extractPythonAggregateFunctionInfos.

public static Tuple2<PythonAggregateFunctionInfo[], DataViewSpec[][]> extractPythonAggregateFunctionInfos(AggregateInfoList pythonAggregateInfoList, AggregateCall[] aggCalls) {
    List<PythonAggregateFunctionInfo> pythonAggregateFunctionInfoList = new ArrayList<>();
    List<DataViewSpec[]> dataViewSpecList = new ArrayList<>();
    AggregateInfo[] aggInfos = pythonAggregateInfoList.aggInfos();
    for (int i = 0; i < aggInfos.length; i++) {
        AggregateInfo aggInfo = aggInfos[i];
        UserDefinedFunction function = aggInfo.function();
        if (function instanceof PythonFunction) {
            pythonAggregateFunctionInfoList.add(new PythonAggregateFunctionInfo((PythonFunction) function, Arrays.stream(aggInfo.argIndexes()).boxed().toArray(), aggCalls[i].filterArg, aggCalls[i].isDistinct()));
            TypeInference typeInference = function.getTypeInference(null);
            dataViewSpecList.add(extractDataViewSpecs(i, typeInference.getAccumulatorTypeStrategy().get().inferType(null).get()));
        } else {
            int filterArg = -1;
            boolean distinct = false;
            if (i < aggCalls.length) {
                filterArg = aggCalls[i].filterArg;
                distinct = aggCalls[i].isDistinct();
            }
            pythonAggregateFunctionInfoList.add(new PythonAggregateFunctionInfo(getBuiltInPythonAggregateFunction(function), Arrays.stream(aggInfo.argIndexes()).boxed().toArray(), filterArg, distinct));
            // The data views of the built in Python Aggregate Function are different from Java
            // side, we will create the spec at Python side.
            dataViewSpecList.add(new DataViewSpec[0]);
        }
    }
    return Tuple2.of(pythonAggregateFunctionInfoList.toArray(new PythonAggregateFunctionInfo[0]), dataViewSpecList.toArray(new DataViewSpec[0][0]));
}
Also used : TypeInference(org.apache.flink.table.types.inference.TypeInference) PythonAggregateFunctionInfo(org.apache.flink.table.functions.python.PythonAggregateFunctionInfo) UserDefinedFunction(org.apache.flink.table.functions.UserDefinedFunction) DataViewSpec(org.apache.flink.table.runtime.dataview.DataViewSpec) ArrayList(java.util.ArrayList) PythonFunction(org.apache.flink.table.functions.python.PythonFunction) AggregateInfo(org.apache.flink.table.planner.plan.utils.AggregateInfo)

Aggregations

TypeInference (org.apache.flink.table.types.inference.TypeInference)21 DataTypeFactory (org.apache.flink.table.catalog.DataTypeFactory)12 FunctionDefinition (org.apache.flink.table.functions.FunctionDefinition)9 AggregateFunctionDefinition (org.apache.flink.table.functions.AggregateFunctionDefinition)6 BuiltInFunctionDefinition (org.apache.flink.table.functions.BuiltInFunctionDefinition)6 BridgingSqlFunction (org.apache.flink.table.planner.functions.bridging.BridgingSqlFunction)6 BridgingUtils.createSqlOperandTypeInference (org.apache.flink.table.planner.functions.bridging.BridgingUtils.createSqlOperandTypeInference)6 BridgingUtils.createSqlReturnTypeInference (org.apache.flink.table.planner.functions.bridging.BridgingUtils.createSqlReturnTypeInference)6 LocalDate (java.time.LocalDate)3 ArrayList (java.util.ArrayList)3 Optional (java.util.Optional)3 RexNode (org.apache.calcite.rex.RexNode)3 SqlFunction (org.apache.calcite.sql.SqlFunction)3 DataTypes (org.apache.flink.table.api.DataTypes)3 ValidationException (org.apache.flink.table.api.ValidationException)3 AggregateFunction (org.apache.flink.table.functions.AggregateFunction)3 ScalarFunctionDefinition (org.apache.flink.table.functions.ScalarFunctionDefinition)3 TableAggregateFunctionDefinition (org.apache.flink.table.functions.TableAggregateFunctionDefinition)3 TableFunctionDefinition (org.apache.flink.table.functions.TableFunctionDefinition)3 UserDefinedFunction (org.apache.flink.table.functions.UserDefinedFunction)3