UDFTransform247 Function

Number of input and output field

Number of input field : One or more
Number of output field : One or more

UDFTransform247 is a transformation function used to run User Defined Transformation (UDF) on HGrid247 workflow.

This function allows users to create custom data transformation logic using Java.

This transformation is called via the Transformer or Transformer2 assembly in the workflow.

Parameters Used by UDFTransform247

There are two main parameters used.
  1. UDF Class Name
    The name of a Java class that is a subclass of:
        com.solusi247.function.TransformationFunction247
            
    Example:
        plugins.transform.UDFRotateTransform
    
  2. Parameter
    Additional parameters passed to the UDF class.
    This parameter can be accessed via the method:
        getParameter ()
    

UDF Transformation Class Requirements

To be used in HGrid247, a UDF class must:
Extend abstract class
    com.solusi247.function.TransformationFunction247
Implementing the main method
public abstract List<Comparable> call(List<Comparable> record)
This method works for:

Important Inherited Methods

UDF classes also inherit some important methods from their superclasses.
  1. public String getParameter()
    Used to retrieve parameters given to a UDF.
  2. public List<Comparable> call(Comparable data)
    Used to transform a single data object
  3. public List<Comparable> getIncomingRecord()
    Restores the original record from the previous assembly .
  4. public int[] getInputFields()
    Returns the index of the input field.
  5. public int[] getOutputFields()
    Returns the data type of the output field.
  6. public byte[] getInputFieldsType()
    return array type of input
  7. public byte[] getOutputFieldsType()
    return array type of output
  8. public List<String> getIncomingFields()
    return the list of field's names of incoming record

Field Data Types

Fields in UDFTransform247 can have the following data types:
    FieldType.STRING
    FieldType.BYTE
    FieldType.SHORT
    FieldType.INT
    FieldType.LONG
    FieldType.FLOAT
    FieldType.DOUBLE
    FieldType.DATE
    FieldType.TIMESTAMP
    FieldType.OBJECT
This type is used to determine the input and output field types.

Example UDF Transformation Class

Here is an example of a transformation class that reverses the text in each field.
    package plugins.transform;

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

    
    public class UDFRotateTransform extends TransformationFunction247{

        @Override
        public List<Comparable> call(List<Comparable> record) {
            List<Comparable> list=new ArrayList<Comparable>();
            for (int i=0; i<record.size(); i++){
                StringBuilder sb=new StringBuilder(record.get(i).toString());
                list.add(sb.reverse().toString());
            }

            return list;
        }
    }   

Explanation of Example

The program performs the following steps:
  1. Receives input records in the formList<Comparable>
  2. Iterate over each field
  3. Use StringBuilder.reverse() to reverse a string
  4. Save the results in the output list
  5. Returns a list as the result of the transformation.

Compile and Deploy UDF Transformation

To make the transformation appear in the HGrid247 GUI, do the following steps.
  1. Compile Java Class
    Compile using the HGrid247 library:
        javac -cp HGrid247CommonLib-3.5.jar UDFRotateTransform.java 
    
  2. Create JAR File
    Create a JAR file:
    jar cvf udfrotate.jar plugins/transform/UDFRotateTransform.class
    
  3. Copy to Plugins Folder
    Save the jar file in the folder:
        HGrid247-3.5/plugins
    
  4. Restart HGrid247
    After restart, the transformation class will appear in the transformation parameters dialog