Class ConstantReference

  • All Implemented Interfaces:
    ScalarValuedFunction

    public final class ConstantReference
    extends Object
    implements ScalarValuedFunction
    A reference to a known value. The defined function returns the value. These can be used to combine constant values with other functions. Note however, that many of the built-in functions provide convenience signatures which do not require direct use of this class.
    • Constructor Detail

      • ConstantReference

        public ConstantReference​(ScalarValued v)
        Defines a function evaluating to the specified value
        Parameters:
        v - the value to return from the function
    • Method Detail

      • getUpperBound

        public ScalarTokenType getUpperBound()
        Description copied from interface: ScalarValuedFunction
        Gets the upper bound on the output type of the function. This need not be the exact type of the output, but is expected to be a type to which the actual output type is assignable, as according to TokenType#isAssignableFrom(TokenType).

        This value is used to detect type consistency issues as early as possible. It is always valid to return TokenTypeConstant#SCALAR, in which case no type consistency issues can be caught early.

        Specified by:
        getUpperBound in interface ScalarValuedFunction
        Returns:
        the most specific type to which any possible return type is assignable.
      • getEvaluator

        public FunctionEvaluator getEvaluator​(RecordValued input,
                                              ScalarSettable output)
        Description copied from interface: ScalarValuedFunction
        Constructs an instance of an evaluator for the function. The evaluator returns the result of the the function applied to the specified input into the given output target.

        Implementations may assume that the input and output are known to be compatible with the function. Normally, this method is only invoked by the DataRush framework, which guarantees this is the case. In general, to satisfy this requirement, callers are expected to:

        • verify that validateInputType(input.getType()) does not throw an exception
        • verify the output type returned is assignable to result.getType()
        Failure to meet this contract may result in runtime exceptions.
        Specified by:
        getEvaluator in interface ScalarValuedFunction
        Parameters:
        input - the record source to use as context for evaluating the function
        output - the buffer into which evaluation results are to be stored
        Returns:
        an evaluator bound to the provided input and output
      • getSubexpressionEvaluation

        public ScalarValued getSubexpressionEvaluation​(EvaluationContext ctx)
        Description copied from interface: ScalarValuedFunction
        Constructs an instance of an evaluation of the function in the context of a larger expression.
        Specified by:
        getSubexpressionEvaluation in interface ScalarValuedFunction
        Parameters:
        ctx - the expression context in which the function is being evaluated as a subexpression
        Returns:
        an object representing the subexpression's current value
      • constant

        public static ScalarValuedFunction constant​(byte[] value)
        Creates a function evaluating to the specified binary constant.
        Parameters:
        value - the constant value to return
        Returns:
        the constant function
      • constant

        public static ScalarValuedFunction constant​(boolean value)
        Creates a function evaluating to the specified boolean constant.
        Parameters:
        value - the constant value to return
        Returns:
        the constant function
      • constant

        public static ScalarValuedFunction constant​(char value)
        Creates a function evaluating to the specified char constant.
        Parameters:
        value - the constant value to return
        Returns:
        the constant function
      • constant

        public static ScalarValuedFunction constant​(int value)
        Creates a function evaluating to the specified int constant.
        Parameters:
        value - the constant value to return
        Returns:
        the constant function
      • constant

        public static ScalarValuedFunction constant​(long value)
        Creates a function evaluating to the specified long constant.
        Parameters:
        value - the constant value to return
        Returns:
        the constant function
      • constant

        public static ScalarValuedFunction constant​(float value)
        Creates a function evaluating to the specified float constant.
        Parameters:
        value - the constant value to return
        Returns:
        the constant function
      • constant

        public static ScalarValuedFunction constant​(double value)
        Creates a function evaluating to the specified double constant.
        Parameters:
        value - the constant value to return
        Returns:
        the constant function
      • constant

        public static ScalarValuedFunction constant​(BigDecimal value)
        Creates a function evaluating to the specified numeric constant.
        Parameters:
        value - the constant value to return
        Returns:
        the constant function
      • constant

        public static ScalarValuedFunction constant​(String value)
        Creates a function evaluating to the specified string constant.
        Parameters:
        value - the constant value to return
        Returns:
        the constant function
      • constant

        public static <O> ScalarValuedFunction constant​(O value)
        Creates a function evaluating to the specified object constant.
        Type Parameters:
        O - the type of the object
        Parameters:
        value - the constant value to return
        Returns:
        the constant function
      • constant

        public static ScalarValuedFunction constant​(ScalarToken value)
        Creates a function evaluating to the specified value.
        Parameters:
        value - the constant value to return
        Returns:
        the constant function
      • nullValue

        @Deprecated
        public static ScalarValuedFunction nullValue​(String fieldName)
        Deprecated.
        Untyped null tokens are now supported. Use nullValue() to generate a null token without an input type.
        Creates a function, of the same type as the specified field, evaluating to null.
        Parameters:
        fieldName - an input field, the type of which will be used as the result type
        Returns:
        the null function
      • nullValue

        @Deprecated
        public static ScalarValuedFunction nullValue​(ScalarValuedFunction expr)
        Deprecated.
        Untyped null tokens are now supported. Use nullValue() to generate a null token without an input type.
        Creates a function, of the same type as the specified expression, evaluating to null.
        Parameters:
        fieldName - an expression, the type of which will be used as the result type
        Returns:
        the null function
      • nullValue

        public static ScalarValuedFunction nullValue()
        Creates a function evaluating to null.
        Returns:
        the null function
      • getRequiredFields

        public Collection<String> getRequiredFields()
        Description copied from interface: ScalarValuedFunction
        Get the input fields required in the function input. An empty collection implies no specific fields are required.
        Specified by:
        getRequiredFields in interface ScalarValuedFunction
        Returns:
        the names of fields which must be present in the record input schema
      • remapFieldReferences

        public ScalarValuedFunction remapFieldReferences​(Map<String,​String> oldToNewMapping)
        Description copied from interface: ScalarValuedFunction
        Creates a new function, equivalent to the given function, but with all field references renamed according to the given mapping.
        Specified by:
        remapFieldReferences in interface ScalarValuedFunction
        Parameters:
        oldToNewMapping - a mapping from old names to new names. If a name is not present in the given mapping, it will remain as-is.
        Returns:
        a new function with all field reference renamed appropriately
      • mapFieldsToFunctions

        public ScalarValuedFunction mapFieldsToFunctions​(Map<String,​ScalarValuedFunction> mapping)
        Description copied from interface: ScalarValuedFunction
        Creates a new function, equivalent to the given function, but with specified field references mapped to functions.
        Specified by:
        mapFieldsToFunctions in interface ScalarValuedFunction
        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 function with all field reference mapped appropriately