Class FieldDerivation


  • public abstract class FieldDerivation
    extends Object
    Defines how a field's value in the output is derived from fields in the input. These are used to describe the transformations performed by the DeriveFields operator.
    • Method Detail

      • getName

        public String getName()
        Gets the name of the target field to derive.
        Returns:
        the name of the result field, if known. If this is not known, null.
      • getFunction

        public ScalarValuedFunction getFunction()
        Gets the function for deriving the field value.
        Returns:
        the derivation function
      • collectMapping

        public abstract void collectMapping​(RecordTokenType inputType,
                                            Map<String,​ScalarValuedFunction> mappings)
        Verifies derivation can be applied in the given input context and records the field mapping.
        Parameters:
        inputType - the datatype of the input
        mappings - the field to function map
      • mapFieldsToFunctions

        public abstract FieldDerivation mapFieldsToFunctions​(Map<String,​ScalarValuedFunction> mapping)
        Creates a new field derivation, equivalent to the given derivation, but with specified field references mapped to functions.
        Parameters:
        mapping - a mapping from field names to functions. If a name is not present in the given mapping, it will remain as-is.
        Returns:
        a new field derivation with all field reference mapped appropriately
      • derive

        public static FieldDerivation derive​(String name,
                                             ScalarValuedFunction f)
        Defines a derivation of the named field using the specified function.
        Parameters:
        name - the name of the field to use in the output record
        f - the function producing the field's value from the input record
        Returns:
        the specified derivation
      • derive

        public static FieldDerivation derive​(String name,
                                             String expression)
        Defines a derivation of the named field using the specified expression.
        Parameters:
        name - the name of the field to use in the output record
        expression - the expression producing the field's value from the input record
        Returns:
        the specified derivation
      • id

        public static FieldDerivation id​(String name)
        Defines an identity mapping for the specified field.
        Parameters:
        name - the field being mapped to itself
        Returns:
        the specified derivation
      • apply

        public static FieldDerivation apply​(ScalarTokenType fieldType,
                                            ScalarValuedFunction f,
                                            String variableName)
        Applies a function to each input field matching the specified type criteria. The result replaces the value of the input field in the output record.

        The function supplied is a "template" used to produce the function to apply to each matching field. This template is expected to have a field which acts as a place holder to be replaced with the name of matching field. As an example, to define a derivation which will add 3 to every number field in the input:

         ScalarValuedFunction f= Arithmetic.add("X",ConstantReference.constant(3));
         FieldDerivation d= apply(TokenTypeConstant.DOUBLE, f, "X");
         
        Note that the same name, "X" is used in both the function declaration and the derivation. This is the variable name.
        Parameters:
        fieldType - the type of input fields to which to apply the function
        f - the function to apply to matching fields
        variableName - the name of the field used as a place holder in the function. References to this field will be replaced with references to the matching fields to produce specific instances of the function for each field.
        Returns:
        the specified derivation
      • apply

        public static FieldDerivation apply​(ScalarTokenType fieldType,
                                            String expression,
                                            String variableName)
        Applies an expression to each input field matching the specified type criteria. The result replaces the value of the input field in the output record.

        The function supplied is a "template" used to produce the function to apply to each matching field. This template is expected to have a field which acts as a place holder to be replaced with the name of matching field. As an example, to define a derivation which will add 3 to every number field in the input:

         String expression= "X+3";
         FieldDerivation d= apply(TokenTypeConstant.DOUBLE, expression, "X");
         
        Note that the same name, "X" is used in both the function declaration and the derivation. This is the variable name.
        Parameters:
        fieldType - the type of input fields to which to apply the function
        expression - the expression to apply to matching fields
        variableName - the name of the field used as a place holder in the function. References to this field will be replaced with references to the matching fields to produce specific instances of the function for each field.
        Returns:
        the specified derivation