UDFPythonAggregation247 Function


This aggregation function is used to invoke a Python-based aggregation.

Parameters Used by UDFPythonAggregation247


Sample of the UDFPythonAggregation247 Parameters Dialog in HGrid247-3.5




The Python code specified in the Python File may be written in either procedural or object-oriented programming style.

1. Procedural Programming Style

In procedural programming style, the Python code must define a function named receive. Optionally, the Python code may also define a function named prepare that takes one parameter.
The prepare function is invoked by HGrid247 during the startup process.

Example of Python Code Used in an Aggregation Function (Procedural Programming Style)

    output=0
    counter=0
    def receive(list,index) :
            global output,counter
            output=output+(list[index]*list[4])
            counter=counter+1

    def complete():
            global output,counter
            result=output/counter
            output=0
            counter=0
            return result
   

2. Object-Oriented Programming Style

In object-oriented programming style, the Python code must define a class that inherits from HGridAggregation.

Example of Python Code Used in an Aggregation Function (Object-Oriented Programming Style)

    class SumAggregation(HGridAggregation):
            def __init__(self,parameter):
                    self.parameter=parameter
                    self.output=0
                    self.counter=0

            def receive(self,list,index) :
                    self.output=self.output+(list[index]*list[4])
                    self.counter=self.counter+1

            def complete(self):
                    result=self.output/self.counter
                    self.output=0
                    self.counter=0
                    return result
   

Note: Do not forget to include the Jython library (jython-standalone-2.7.3.jar) when submitting the job.


On mapreduce job :
hadoop jar <project-name>_mr.jar ClassToRun -libjars <JYTHON-PATH>/jython-standalone-2.7.3.jar input output
For example :
        hadoop jar workshop_mr.jar workshop.python.TestPython -libjars /root/jython-standalone-2.7.3.jar
   
On spark job :
spark-submit --class ClassToRun --master yarn --jars <JYTHON-PATH>/jython-standalone-2.7.3.jar    <project-name>_spark2.jar input output
For example :
        spark-submit  --class workshop.python.TestPython --master yarn  --jars /root/jython-standalone-2.7.3.jar workshop_spark2.jar
   
On Flink job :
flink run -c ClassToRun --classpath file:///<JYTHON-PATH>/jython-standalone-2.7.3.jar    -j <project-name>_flink.jar --input_option input_path --output_option output_path
For example :
        flink run -c  workshop.python.TestPython --classpath file:///root/jython-standalone-2.7.3.jar -j workshop_flink.jar --hfs_source_1 file:///D:/hgrid/input/sample_data  --hfs_sink_1 file:///D:/hgrid/test/python_out 
   
On Beam job Direct-Runner on Windows :
java -cp <project-name>_beam.jar;<HGridApp-Path>\HGrid247-3.5\BeamRunner\direct-runner/*;<JYTHON-PATH>\jython-standalone-2.7.3.jar ClassToRun --input_option=input_path --output_option=output_path
For example :
        java  -cp workshop_beam.jar;D:\BigDataTool\HGrid247-3.5\BeamRunner\direct-runner/*;D:\jython\jython-standalone-2.7.3.jar workshop.python.TestPython --hfs_source_1=D:/hgrid/input/sample_data  --hfs_sink_1=D:/hgrid/test/python_out 
   
On Beam job Direct-Runner on Linux :
java -cp <project-name>_beam.jar:<HGridApp-Path>/HGrid247-3.5/BeamRunner/direct-runner/*:<JYTHON-PATH>/jython-standalone-2.7.3.jar ClassToRun --input_option=input_path --output_option=output_path
For example :
        java  -cp workshop_beam.jar:/root/HGrid247-3.5/BeamRunner/direct-runner/*:/root/jython/jython-standalone-2.7.3.jar workshop.python.TestPython --hfs_source_1=/root/hgrid/input/sample_data  --hfs_sink_1=/root/hgrid/test/python_out