Search in sources :

Example 1 with PartitionSpec

use of org.apache.flink.table.planner.plan.nodes.exec.spec.PartitionSpec in project flink by apache.

the class BatchExecPythonOverAggregate method getPythonOverWindowAggregateFunctionOperator.

@SuppressWarnings("unchecked")
private OneInputStreamOperator<RowData, RowData> getPythonOverWindowAggregateFunctionOperator(ExecNodeConfig config, Configuration pythonConfig, RowType inputRowType, RowType outputRowType, boolean[] isRangeWindows, int[] udafInputOffsets, PythonFunctionInfo[] pythonFunctionInfos) {
    Class<?> clazz = CommonPythonUtil.loadClass(ARROW_PYTHON_OVER_WINDOW_AGGREGATE_FUNCTION_OPERATOR_NAME);
    RowType udfInputType = (RowType) Projection.of(udafInputOffsets).project(inputRowType);
    RowType udfOutputType = (RowType) Projection.range(inputRowType.getFieldCount(), outputRowType.getFieldCount()).project(outputRowType);
    PartitionSpec partitionSpec = overSpec.getPartition();
    List<OverSpec.GroupSpec> groups = overSpec.getGroups();
    SortSpec sortSpec = groups.get(groups.size() - 1).getSort();
    try {
        Constructor<?> ctor = clazz.getConstructor(Configuration.class, PythonFunctionInfo[].class, RowType.class, RowType.class, RowType.class, long[].class, long[].class, boolean[].class, int[].class, int.class, boolean.class, GeneratedProjection.class, GeneratedProjection.class, GeneratedProjection.class);
        return (OneInputStreamOperator<RowData, RowData>) ctor.newInstance(pythonConfig, pythonFunctionInfos, inputRowType, udfInputType, udfOutputType, lowerBoundary.stream().mapToLong(i -> i).toArray(), upperBoundary.stream().mapToLong(i -> i).toArray(), isRangeWindows, aggWindowIndex.stream().mapToInt(i -> i).toArray(), sortSpec.getFieldIndices()[0], sortSpec.getAscendingOrders()[0], ProjectionCodeGenerator.generateProjection(CodeGeneratorContext.apply(config.getTableConfig()), "UdafInputProjection", inputRowType, udfInputType, udafInputOffsets), ProjectionCodeGenerator.generateProjection(CodeGeneratorContext.apply(config.getTableConfig()), "GroupKey", inputRowType, (RowType) Projection.of(partitionSpec.getFieldIndices()).project(inputRowType), partitionSpec.getFieldIndices()), ProjectionCodeGenerator.generateProjection(CodeGeneratorContext.apply(config.getTableConfig()), "GroupSet", inputRowType, (RowType) Projection.of(partitionSpec.getFieldIndices()).project(inputRowType), partitionSpec.getFieldIndices()));
    } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
        throw new TableException("Python BatchArrowPythonOverWindowAggregateFunctionOperator constructed failed.", e);
    }
}
Also used : OverAggregateUtil(org.apache.flink.table.planner.plan.utils.OverAggregateUtil) InputProperty(org.apache.flink.table.planner.plan.nodes.exec.InputProperty) Tuple2(org.apache.flink.api.java.tuple.Tuple2) RowType(org.apache.flink.table.types.logical.RowType) Constructor(java.lang.reflect.Constructor) ExecNode(org.apache.flink.table.planner.plan.nodes.exec.ExecNode) ArrayList(java.util.ArrayList) ExecNodeUtil(org.apache.flink.table.planner.plan.nodes.exec.utils.ExecNodeUtil) ManagedMemoryUseCase(org.apache.flink.core.memory.ManagedMemoryUseCase) PartitionSpec(org.apache.flink.table.planner.plan.nodes.exec.spec.PartitionSpec) CodeGeneratorContext(org.apache.flink.table.planner.codegen.CodeGeneratorContext) Projection(org.apache.flink.table.connector.Projection) ProjectionCodeGenerator(org.apache.flink.table.planner.codegen.ProjectionCodeGenerator) ExecNodeContext(org.apache.flink.table.planner.plan.nodes.exec.ExecNodeContext) RowData(org.apache.flink.table.data.RowData) PlannerBase(org.apache.flink.table.planner.delegation.PlannerBase) CommonPythonUtil(org.apache.flink.table.planner.plan.nodes.exec.utils.CommonPythonUtil) ExecNodeConfig(org.apache.flink.table.planner.plan.nodes.exec.ExecNodeConfig) Configuration(org.apache.flink.configuration.Configuration) TableException(org.apache.flink.table.api.TableException) PythonFunctionInfo(org.apache.flink.table.functions.python.PythonFunctionInfo) OverSpec(org.apache.flink.table.planner.plan.nodes.exec.spec.OverSpec) OneInputTransformation(org.apache.flink.streaming.api.transformations.OneInputTransformation) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) InternalTypeInfo(org.apache.flink.table.runtime.typeutils.InternalTypeInfo) ExecEdge(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge) AggregateCall(org.apache.calcite.rel.core.AggregateCall) GeneratedProjection(org.apache.flink.table.runtime.generated.GeneratedProjection) Transformation(org.apache.flink.api.dag.Transformation) OneInputStreamOperator(org.apache.flink.streaming.api.operators.OneInputStreamOperator) SortSpec(org.apache.flink.table.planner.plan.nodes.exec.spec.SortSpec) PythonFunctionInfo(org.apache.flink.table.functions.python.PythonFunctionInfo) TableException(org.apache.flink.table.api.TableException) RowType(org.apache.flink.table.types.logical.RowType) PartitionSpec(org.apache.flink.table.planner.plan.nodes.exec.spec.PartitionSpec) InvocationTargetException(java.lang.reflect.InvocationTargetException) OneInputStreamOperator(org.apache.flink.streaming.api.operators.OneInputStreamOperator) SortSpec(org.apache.flink.table.planner.plan.nodes.exec.spec.SortSpec)

Example 2 with PartitionSpec

use of org.apache.flink.table.planner.plan.nodes.exec.spec.PartitionSpec in project flink by apache.

the class PartitionSpecSerdeTest method testPartitionSpec.

@Test
public void testPartitionSpec() throws JsonProcessingException {
    PartitionSpec spec = new PartitionSpec(new int[] { 1, 2, 3 });
    ObjectMapper mapper = new ObjectMapper();
    assertEquals(spec, mapper.readValue(mapper.writeValueAsString(spec), PartitionSpec.class));
}
Also used : PartitionSpec(org.apache.flink.table.planner.plan.nodes.exec.spec.PartitionSpec) ObjectMapper(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

PartitionSpec (org.apache.flink.table.planner.plan.nodes.exec.spec.PartitionSpec)2 Constructor (java.lang.reflect.Constructor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AggregateCall (org.apache.calcite.rel.core.AggregateCall)1 Transformation (org.apache.flink.api.dag.Transformation)1 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 Configuration (org.apache.flink.configuration.Configuration)1 ManagedMemoryUseCase (org.apache.flink.core.memory.ManagedMemoryUseCase)1 ObjectMapper (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper)1 OneInputStreamOperator (org.apache.flink.streaming.api.operators.OneInputStreamOperator)1 OneInputTransformation (org.apache.flink.streaming.api.transformations.OneInputTransformation)1 TableException (org.apache.flink.table.api.TableException)1 Projection (org.apache.flink.table.connector.Projection)1 RowData (org.apache.flink.table.data.RowData)1 PythonFunctionInfo (org.apache.flink.table.functions.python.PythonFunctionInfo)1 CodeGeneratorContext (org.apache.flink.table.planner.codegen.CodeGeneratorContext)1 ProjectionCodeGenerator (org.apache.flink.table.planner.codegen.ProjectionCodeGenerator)1 PlannerBase (org.apache.flink.table.planner.delegation.PlannerBase)1