cascading.operation.expression

## Class ScriptFilter

- java.lang.Object
- - cascading.operation.BaseOperation<ScriptOperation.Context>
  - - cascading.operation.expression.ScriptOperation
    - - cascading.operation.expression.ScriptFilter

- All Implemented Interfaces:
    DeclaresResults, Filter<ScriptOperation.Context>, Operation<ScriptOperation.Context>, Traceable, java.io.Serializable

      public class ScriptFilter
      extends ScriptOperation
      implements Filter<ScriptOperation.Context>

  Class ScriptFilter dynamically resolves a given expression using argument `Tuple` values. This `Filter` is based on the Janino compiler.

  Specifically this filter 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 `ExpressionFilter`, 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.
  See Also:
    Serialized Form

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class cascading.operation.expression.ScriptOperation

      `ScriptOperation.Context`

  - ### Field Summary

    - ### Fields inherited from class cascading.operation.expression.ScriptOperation

      `block, parameterNames, parameterTypes, returnType`

    - ### Fields inherited from class cascading.operation.BaseOperation

      `fieldDeclaration, numArgs, trace`

    - ### Fields inherited from interface cascading.operation.Operation

      `ANY`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ScriptFilter(java.lang.String script)` Constructor ScriptFilter creates a new ScriptFilter instance.
    `ScriptFilter(java.lang.String script, java.lang.Class[] expectedTypes)` Constructor ScriptFilter creates a new ScriptFilter instance.
    `ScriptFilter(java.lang.String script, java.lang.String[] parameterNames, java.lang.Class[] parameterTypes)` Constructor ScriptFilter creates a new ScriptFilter instance.
    `ScriptFilter(java.lang.String script, java.lang.String parameterName, java.lang.Class parameterType)` Constructor ScriptFilter creates a new ScriptFilter instance.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.lang.String` | `getScript()`
    `boolean` | `isRemove(FlowProcess flowProcess, FilterCall<ScriptOperation.Context> filterCall)` Method isRemove returns true if input should be removed from the tuple stream.

    - ### Methods inherited from class cascading.operation.expression.ScriptOperation

      `equals, evaluate, getBlock, getEvaluator, getParameterNames, getParameterTypes, getReturnType, guessParameterNames, hashCode, prepare`

    - ### Methods inherited from class cascading.operation.BaseOperation

      `cleanup, flush, getFieldDeclaration, getNumArgs, getTrace, isSafe, printOperationInternal, toString, toStringInternal`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface cascading.operation.Operation

      `cleanup, flush, getFieldDeclaration, getNumArgs, isSafe, prepare`

- - ### Constructor Detail

    - #### ScriptFilter

          @ConstructorProperties(value="script")
          public ScriptFilter(java.lang.String script)

      Constructor ScriptFilter creates a new ScriptFilter instance.
      Parameters:
        `script` - of type String

    - #### ScriptFilter

          @ConstructorProperties(value={"script","parameterName","parameterType"})
          public ScriptFilter(java.lang.String script,
                                            java.lang.String parameterName,
                                            java.lang.Class parameterType)

      Constructor ScriptFilter creates a new ScriptFilter instance.
      Parameters:
        `script` - of type String
        `parameterName` - of type String
        `parameterType` - of type Class

    - #### ScriptFilter

          @ConstructorProperties(value={"script","expectedTypes"})
          public ScriptFilter(java.lang.String script,
                                            java.lang.Class[] expectedTypes)

      Constructor ScriptFilter creates a new ScriptFilter instance.

      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.
      Parameters:
        `script` - of type String
        `expectedTypes` - of type Class[]

    - #### ScriptFilter

          @ConstructorProperties(value={"script","parameterNames","parameterTypes"})
          public ScriptFilter(java.lang.String script,
                                            java.lang.String[] parameterNames,
                                            java.lang.Class[] parameterTypes)

      Constructor ScriptFilter creates a new ScriptFilter instance.
      Parameters:
        `script` - of type String
        `parameterNames` - of type String[]
        `parameterTypes` - of type Class[]

  - ### Method Detail

    - #### getScript

          public java.lang.String getScript()

    - #### isRemove

          public boolean isRemove(FlowProcess flowProcess,
                         FilterCall<ScriptOperation.Context> filterCall)

      Description copied from interface: `Filter`
      Method isRemove returns true if input should be removed from the tuple stream.
      Specified by:
        `isRemove` in interface `Filter<ScriptOperation.Context>`
      Parameters:
        `flowProcess` - of type FlowProcess
        `filterCall` - of type FilterCall
      Returns:
        boolean

Copyright © 2007-2015 Xplenty, Inc. All Rights Reserved.