public class ScriptFunction extends ScriptOperation implements cascading.operation.Function<ScriptOperation.Context>
Tuple
values.
This Function
is based on the Janino compiler.
This class is different from ScriptTupleFunction
in that it allows any return type instance to be returned
by the script. ScriptTupleFunction allows only a single Tuple
instance to be returned.
Specifically this function uses the ScriptEvaluator
,
thus the syntax from that class is inherited here.
A script may use field names directly as parameters in the expression, or field positions with the syntax "$n", where n is an integer.
Given an argument tuple with the fields "a" and "b", the following script returns true:
boolean result = (a + b == $0 + $1);
return boolean;
Unlike an "expression" used by ExpressionFunction
, a "script" requires each line to end in an semi-colon
(@{code ;}) and the final line to be a return
statement.
Further, the types of the tuple elements will be coerced into the given parameterTypes. Regardless of the actual tuple element values, they will be converted to the types expected by the script if possible.
ScriptOperation.Context, ScriptOperation.Evaluator
block, parameterNames, parameterTypes, returnType
Constructor and Description |
---|
ScriptFunction(cascading.tuple.Fields fieldDeclaration,
java.lang.String script)
Constructor ScriptFunction creates a new ScriptFunction instance.
|
ScriptFunction(cascading.tuple.Fields fieldDeclaration,
java.lang.String script,
java.lang.Class returnType)
Constructor ScriptFunction creates a new ScriptFunction instance.
|
ScriptFunction(cascading.tuple.Fields fieldDeclaration,
java.lang.String script,
java.lang.Class returnType,
java.lang.Class[] expectedTypes)
Constructor ScriptFunction creates a new ScriptFunction instance.
|
ScriptFunction(cascading.tuple.Fields fieldDeclaration,
java.lang.String script,
java.lang.Class returnType,
java.lang.String[] parameterNames,
java.lang.Class[] parameterTypes)
Constructor ScriptFunction creates a new ScriptFunction instance.
|
ScriptFunction(cascading.tuple.Fields fieldDeclaration,
java.lang.String script,
java.lang.String[] parameterNames,
java.lang.Class[] parameterTypes)
Constructor ScriptFunction creates a new ScriptFunction instance.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getScript() |
void |
operate(cascading.flow.FlowProcess flowProcess,
cascading.operation.FunctionCall<ScriptOperation.Context> functionCall) |
equals, evaluate, getBlock, getEvaluator, getExtendedClass, getParameterNames, getParameterTypes, getReturnType, guessParameterNames, hashCode, prepare
cleanup, flush, getFieldDeclaration, getNumArgs, getTrace, isSafe, printOperationInternal, toString, toStringInternal
@ConstructorProperties(value={"fieldDeclaration","script"}) public ScriptFunction(cascading.tuple.Fields fieldDeclaration, java.lang.String script)
This constructor will use the runtime OperationCall.getArgumentFields()
to source the parameterNames
and parameterTypes
required by the other constructors.
The returnType
will be retrieved from the given fieldDeclaration.getTypeClass(0)
.
fieldDeclaration
- of type Fieldsscript
- of type String@ConstructorProperties(value={"fieldDeclaration","script","returnType"}) public ScriptFunction(cascading.tuple.Fields fieldDeclaration, java.lang.String script, java.lang.Class returnType)
This constructor will use the runtime OperationCall.getArgumentFields()
to source the parameterNames
and parameterTypes
required by the other constructors.
fieldDeclaration
- of type Fieldsscript
- of type StringreturnType
- of type Class@ConstructorProperties(value={"fieldDeclaration","script","returnType","expectedTypes"}) public ScriptFunction(cascading.tuple.Fields fieldDeclaration, java.lang.String script, java.lang.Class returnType, java.lang.Class[] expectedTypes)
This constructor will use the runtime OperationCall.getArgumentFields()
to source the parameterNames
and parameterTypes
required by the other constructors, but
use expectedTypes
to coerce the incoming types to before passing as parameters to the expression.
fieldDeclaration
- of type Fieldsscript
- of type StringreturnType
- of type ClassexpectedTypes
- of type Class[]@ConstructorProperties(value={"fieldDeclaration","script","returnType","parameterNames","parameterTypes"}) public ScriptFunction(cascading.tuple.Fields fieldDeclaration, java.lang.String script, java.lang.Class returnType, java.lang.String[] parameterNames, java.lang.Class[] parameterTypes)
This constructor expects all parameter type names to be declared with their types. Positional parameters must be named the same as in the given script with the "$" sign prepended.
fieldDeclaration
- of type Fieldsscript
- of type StringreturnType
- of type ClassparameterNames
- of type String[]parameterTypes
- of type Class[]@ConstructorProperties(value={"fieldDeclaration","script","parameterNames","parameterTypes"}) public ScriptFunction(cascading.tuple.Fields fieldDeclaration, java.lang.String script, java.lang.String[] parameterNames, java.lang.Class[] parameterTypes)
This constructor expects all parameter type names to be declared with their types. Positional parameters must be named the same as in the given script with the "$" sign prepended.
fieldDeclaration
- of type Fieldsscript
- of type StringparameterNames
- of type String[]parameterTypes
- of type Class[]public java.lang.String getScript()
public void operate(cascading.flow.FlowProcess flowProcess, cascading.operation.FunctionCall<ScriptOperation.Context> functionCall)
operate
in interface cascading.operation.Function<ScriptOperation.Context>
Copyright © 2007-2017 Cascading Maintainers. All Rights Reserved.