User Defined Function/Operation Assembly


Number of input and output link

Number of input link : One
Number of output link : One

User Defined Function/Operation Assembly () processes data using Java-based functions defined by the user.
This assembly processes one input record at a time and can emit zero, one, or multiple output records.

It is typically used when built-in transformation functions are not sufficient and custom processing logic is required.

Parameters of User Defined Function / Operation

Creating a User Defined Function / Operation

A User Defined Function / Operation is created by:
  1. Creating a Java class that extends com.solusi247.function.Function247
  2. Implementing the following abstract method:
        void operate(List<Comparable> record)
    
    This method is executed once for every input record.

Methods of com.solusi247.function.Function247

The class com.solusi247.function.Function247 provides the following methods:
  1. public abstract void operate(List<Comparable> record)
    Called for every incoming record.
    Contains the core processing logic.
  2. public String getParameter()
    this method returns the received parameter
  3. public void prepare()
    Called after the UDF object is created.
    Used for initialization logic.
  4. public void cleanup()
    Called after all records have been processed.
    Used for cleanup or resource release.
  5. public final void addToOutputCollector(List<Comparable> record)
    Emits a record to the output stream.
  6. public List<String> getIncomingFields()
    Returns the list of field names from the incoming record.

Example: Java-Based User Defined Function / Operation

Reverse a Specific Field in a Record
package plugins.function;

import com.solusi247.function.Function247;
import java.util.ArrayList;
import java.util.List;


public class Reverse extends Function247{

    @Override
    public void operate(List<Comparable> record) {
        
        ArrayList<Comparable> list_out=new ArrayList<>();
        for (int i=0; i<list.size(); i++){
            if (i==5){
                StringBuilder sb=new StringBuilder(record.get(i).toString());
                list_out.add(sb.reverse().toString());
            }else{
                list_out.add(list.get(i));
            }
        }        
        this.addToOutputCollector(list_out);
        
    }
    
}

Explanation of the Example

Deploying the UDF in HGrid247

To make the UDF appear in the HGrid247-3.5 GUI:

Required Dependency

Java-based plug-ins require the following library:
    libCommon/HGrid247CommonLib-3.5.jar

Summary

The User Defined Function / Operation Assembly enables developers to: This assembly provides maximum flexibility and is ideal for complex data processing requirements.

Supported Engines

Map
Reduce
Spark 1.x
RDD
Spark 2.x
RDD
Spark 2.x
Dataset
Apache Beam
2.29.0 Batch
Apache Beam
2.29.0 Streaming
Apache Flink
1.12.0 Batch
Apache Flink
1.12.0 Streaming
Apache Tez
0.9.1
PySpark