- java.lang.Object
-
- com.pervasive.datarush.functions.FieldReference
-
- All Implemented Interfaces:
ScalarValuedFunction
public final class FieldReference extends Object implements ScalarValuedFunction
A reference to a field in a record schema. The defined reference returns the value of the the referenced field. These can be used to combine field 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 Summary
Constructors Constructor Description FieldReference(String name)Defines a reference to the specified field.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)FunctionEvaluatorgetEvaluator(RecordValued input, ScalarSettable output)Constructs an instance of an evaluator for the function.StringgetName()Gets the name of the referenced fieldCollection<String>getRequiredFields()Get the input fields required in the function input.ScalarValuedgetSubexpressionEvaluation(EvaluationContext ctx)Constructs an instance of an evaluation of the function in the context of a larger expression.ScalarTokenTypegetUpperBound()Gets the upper bound on the output type of the function.inthashCode()ScalarValuedFunctionmapFieldsToFunctions(Map<String,ScalarValuedFunction> mapping)Creates a new function, equivalent to the given function, but with specified field references mapped to functions.ScalarValuedFunctionremapFieldReferences(Map<String,String> oldToNewMapping)Creates a new function, equivalent to the given function, but with all field references renamed according to the given mapping.StringtoString()ScalarTokenTypevalidateInputType(RecordTokenType inputType)Calculates the actual output type of the function given the specified input type.static ScalarValuedFunctionvalue(String fieldName)Defines an expression returning the value of the given field.static List<ScalarValuedFunction>values(String... fieldNames)Defines a number of expressions returning the value of a field, one for each given field.
-
-
-
Constructor Detail
-
FieldReference
public FieldReference(String name)
Defines a reference to the specified field.- Parameters:
name- the name of the field referenced
-
-
Method Detail
-
getName
public String getName()
Gets the name of the referenced field- Returns:
- the field name
-
getUpperBound
public ScalarTokenType getUpperBound()
Description copied from interface:ScalarValuedFunctionGets 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 toTokenType#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:
getUpperBoundin interfaceScalarValuedFunction- Returns:
- the most specific type to which any possible return type is assignable.
-
validateInputType
public ScalarTokenType validateInputType(RecordTokenType inputType)
Description copied from interface:ScalarValuedFunctionCalculates the actual output type of the function given the specified input type.The type returned must be assignable to the type returned by
ScalarValuedFunction.getUpperBound(). If this is not the case, runtime type errors may arise.- Specified by:
validateInputTypein interfaceScalarValuedFunction- Parameters:
inputType- the type of the record used as input to the function- Returns:
- the return type of the function for the given input record schema
-
getEvaluator
public FunctionEvaluator getEvaluator(RecordValued input, ScalarSettable output)
Description copied from interface:ScalarValuedFunctionConstructs 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()
- Specified by:
getEvaluatorin interfaceScalarValuedFunction- Parameters:
input- the record source to use as context for evaluating the functionoutput- the buffer into which evaluation results are to be stored- Returns:
- an evaluator bound to the provided input and output
- verify that
-
getSubexpressionEvaluation
public ScalarValued getSubexpressionEvaluation(EvaluationContext ctx)
Description copied from interface:ScalarValuedFunctionConstructs an instance of an evaluation of the function in the context of a larger expression.- Specified by:
getSubexpressionEvaluationin interfaceScalarValuedFunction- Parameters:
ctx- the expression context in which the function is being evaluated as a subexpression- Returns:
- an object representing the subexpression's current value
-
hashCode
public int hashCode()
Description copied from interface:ScalarValuedFunctionScalarValuedFunctions should override this method in a manner consistent with
ScalarValuedFunction.equals(Object).- Specified by:
hashCodein interfaceScalarValuedFunction- Overrides:
hashCodein classObject
-
equals
public boolean equals(Object obj)
Description copied from interface:ScalarValuedFunctionScalarValuedFunctions should override this method to indicate whether they are equal to another ScalarValuedFunction.
- Specified by:
equalsin interfaceScalarValuedFunction- Overrides:
equalsin classObject
-
value
public static ScalarValuedFunction value(String fieldName)
Defines an expression returning the value of the given field.- Parameters:
fieldName- the field whose value is to be returned- Returns:
- a function evaluating to the specified field's value
-
values
public static List<ScalarValuedFunction> values(String... fieldNames)
Defines a number of expressions returning the value of a field, one for each given field.- Parameters:
fieldNames- the fields whose values are to be returned- Returns:
- functions evaluating to the specified fields' values
-
getRequiredFields
public Collection<String> getRequiredFields()
Description copied from interface:ScalarValuedFunctionGet the input fields required in the function input. An empty collection implies no specific fields are required.- Specified by:
getRequiredFieldsin interfaceScalarValuedFunction- 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:ScalarValuedFunctionCreates a new function, equivalent to the given function, but with all field references renamed according to the given mapping.- Specified by:
remapFieldReferencesin interfaceScalarValuedFunction- 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:ScalarValuedFunctionCreates a new function, equivalent to the given function, but with specified field references mapped to functions.- Specified by:
mapFieldsToFunctionsin interfaceScalarValuedFunction- 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
-
-