HuangXingBo commented on a change in pull request #13421: URL: https://github.com/apache/flink/pull/13421#discussion_r491994679
########## File path: flink-python/pyflink/fn_execution/beam/beam_operations_fast.pyx ########## @@ -173,6 +173,28 @@ cdef class DataStreamStatelessFunctionOperation(BeamStatelessFunctionOperation): func = operation_utils.extract_data_stream_stateless_funcs(udfs) return func, [] + +cdef class PandasAggregateFunctionOperation(BeamStatelessFunctionOperation): + def __init__(self, name, spec, counter_factory, sampler, consumers): + super(PandasAggregateFunctionOperation, self).__init__(name, spec, counter_factory, + sampler, consumers) + + def generate_func(self, udfs): + pandas_functions, variable_dict, user_defined_funcs = reduce( + lambda x, y: ( + ','.join([x[0], y[0]]), + dict(chain(x[1].items(), y[1].items())), + x[2] + y[2]), + [operation_utils.extract_user_defined_function(udf) for udf in udfs]) + variable_dict['wrap_pandas_result'] = operation_utils.wrap_pandas_result + mapper = eval('lambda value: wrap_pandas_result([%s])' % pandas_functions, variable_dict) + if self._is_python_coder: Review comment: We currently only provide the implementation of arrow coder with python version, so it is always true ########## File path: flink-python/pyflink/table/tests/test_pandas_udaf.py ########## @@ -0,0 +1,48 @@ +################################################################################ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ +from pyflink.table.types import DataTypes + +from pyflink.table.udf import udaf +from pyflink.testing import source_sink_utils +from pyflink.testing.test_case_utils import PyFlinkBlinkBatchTableTestCase + + +class BatchPandasUDAFITTests(PyFlinkBlinkBatchTableTestCase): + def test_group_aggregate_function(self): + t = self.t_env.from_elements( + [(1, 2, 3), (3, 2, 3), (2, 1, 3), (1, 5, 4), (1, 8, 6), (2, 3, 4)], + DataTypes.ROW( + [DataTypes.FIELD("a", DataTypes.TINYINT()), + DataTypes.FIELD("b", DataTypes.SMALLINT()), + DataTypes.FIELD("c", DataTypes.INT())])) + + table_sink = source_sink_utils.TestAppendSink( + ['a', 'b'], + [DataTypes.TINYINT(), DataTypes.FLOAT()]) + self.t_env.register_table_sink("Results", table_sink) + t.group_by("a") \ + .select(t.a, mean_udaf(t.b)) \ + .execute_insert("Results") \ + .wait() + actual = source_sink_utils.results() + self.assert_equals(actual, ["1,5.0", "2,2.0", "3,2.0"]) + + +@udaf(result_type=DataTypes.FLOAT(), udaf_type="pandas") Review comment: Yes.Make sense. ########## File path: flink-python/pyflink/table/udf.py ########## @@ -313,6 +435,70 @@ def _create_judtf(self): return j_table_function +class UserDefinedAggregateFunctionWrapper(UserDefinedFunctionWrapper): Review comment: Yes. Make sense ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org