Function Operation in SwitchCase

In HGrid247, SwitchCase Transformation is used to create branching logic (conditional processing) on ​​data.

To extend the capabilities of SwitchCase, users can create custom Function Operations using Java-based User Defined Functions (UDFs) .

This function is created by subclassing the abstract class:
    com.labs247.function.SwitchCaseFunction247

UDF Class Requirements

The class created must:
  1. Extend class
        com.labs247.function.SwitchCaseFunction247
            
  2. Implementing the main method
        public abstract Comparable transform(List<Comparable> current_record);
    
    This method is used to:
    • receive input records
    • carry out transformation
    • returns the transformation result as a single value (Comparable)

Inherited Methods

This UDF class also inherits several methods from the superclass SwitchCaseFunction247.
  1. public String getParameter()
    takes the parameters passed to the function.
  2. public void prepare()
    • called after the object is created
    • used for variable initialization or initial configuration
  3. public List<String> getIncomingFields()
    returns a list of field names from the input record.
  4. public List<Comparable> getIncomingRecord()
    eturns the input record currently being processed.

Example UDF Function Operation

The following is an example of the implementation of the UDF Function Operation which reverses the text in the first field.
   
   package hgrid.plugins.fcase;

   import com.labs247.function.SwitchCaseFunction247;
   import java.util.List;

   public class Reverse extends SwitchCaseFunction247{

      @Override
      public Comparable transform(List<Comparable> current_record) {
          StringBuilder sb=new StringBuilder(current_record.get(0).toString());
          return sb.reverse().toString();
      }  
   }

Explanation of Example

The above program performs the following processes:
  1. Receives input records in the formList<Comparable>
  2. Take the first field:
        current_record.get(0)
        
  3. Use StringBuilderto reverse a string:
        sb.reverse() 
        
  4. Returns the result as an output value.

Deploying the UDF Plugin

To make this function usable in the HGrid247 GUI, perform the following steps.
  1. Compile Java Class
    Compile using the HGrid247 library:
        javac -cp HGrid247CommonLib-3.5.jar Reverse.java
    
  2. Create JAR File
    Create a jar file:
        jar cvf switchcase-plugin.jar hgrid/plugins/fcase/Reverse.class
    
  3. Copy JAR to Plugins Folder
    Save the jar file in the folder:
    HGrid247-3.5/plugins
    
  4. Restart HGrid247
    After restart, the class will appear in the SwitchCase Function Transformation parameter dialog .