public class RunJavaScript extends AbstractExecutableRecordPipeline
The execution of the operator is as follows:
beforeFirstRecordScript
onEveryRecordScript
afterLastRecordScript
Note that this operator supports running in a distributed context, whether that be locally partitioned or within a cluster. Each instance of the operator executes the above operation sequence. This implies that the before and after scripts only affect the scripting environment within which they are run. The environments are not shared across operator instances.
By default, the highest level of optimization is used for compiling the scripts.
This will provide the most efficient and highest performing script execution. Setting
the optimization level to -1
turns on interpreted mode, disabling the
performance gains of compiled scripts. There should never be a need to lower the
optimization level. However, compiled scripts can type variables differently at
times. If this causes an issues, use interpreted mode by setting the optimization
level to -1.
By default, the JavaScript language version is set to version 1.8. As of this writing, this was the highest language version supported by the Rhino engine. Set the language version lower to disable newer language features as desired.
input, output
Constructor and Description |
---|
RunJavaScript() |
Modifier and Type | Method and Description |
---|---|
static String[] |
compile(Map<String,Object> variables,
String... scriptSources)
Compile the given snippets of JavaScript code and capture any errors or
warnings that occur.
|
static String |
compile(String scriptSource)
Compile the given snippet of JavaScript and capture any warnings or errors.
|
protected void |
computeMetadata(StreamingMetadataContext ctx)
Implementations must adhere to the following contracts
|
protected void |
execute(ExecutionContext ctx)
Executes the operator.
|
String |
getAfterLastRecordScript() |
String |
getBeforeFirstRecordScript() |
boolean |
getEnforceType() |
static String |
getIdentifierRegex()
Function to return a Regular Expression string that can be used to identify a valid JS identifier.
|
int |
getLanguageVersion() |
String |
getOnEveryRecordScript() |
int |
getOptimizationLevel() |
RecordTokenType |
getOutputType() |
Map<String,Object> |
getVariables() |
void |
setAfterLastRecordScript(String afterLastRecordScript) |
void |
setBeforeFirstRecordScript(String beforeFirstRecordScript) |
void |
setEnforceType(boolean enforceType) |
void |
setLanguageVersion(int languageVersion) |
void |
setOnEveryRecordScript(String scriptText) |
void |
setOptimizationLevel(int optimizationLevel) |
void |
setOutputType(RecordTokenType outputType) |
void |
setVariables(Map<String,Object> variables) |
static String |
validateFieldName(int position,
String fldName)
Function to ensure an input/output field name conforms to JS variable identifier requirements.
|
getInput, getOutput
cloneForExecution, getNumInputCopies, getPortSettings, handleInactiveOutput
disableParallelism, getInputPorts, getOutputPorts, newInput, newInput, newOutput, newRecordInput, newRecordInput, newRecordOutput, notifyError
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
disableParallelism, getInputPorts, getOutputPorts
public String getOnEveryRecordScript()
public void setOnEveryRecordScript(String scriptText)
public int getOptimizationLevel()
public void setOptimizationLevel(int optimizationLevel)
public int getLanguageVersion()
public void setLanguageVersion(int languageVersion)
public RecordTokenType getOutputType()
public void setOutputType(RecordTokenType outputType)
public String getBeforeFirstRecordScript()
public void setBeforeFirstRecordScript(String beforeFirstRecordScript)
public String getAfterLastRecordScript()
public void setAfterLastRecordScript(String afterLastRecordScript)
public boolean getEnforceType()
public void setEnforceType(boolean enforceType)
protected void computeMetadata(StreamingMetadataContext ctx)
StreamingOperator
StreamingMetadataContext.parallelize(ParallelismStrategy)
.
RecordPort#setRequiredDataOrdering
, otherwise data may arrive in any order.
RecordPort#setRequiredDataDistribution
, otherwise data will arrive in an unspecified partial distribution
.
RecordPort#getSourceDataDistribution
and RecordPort#getSourceDataOrdering
. These should be
viewed as a hints to help chose a more efficient algorithm. In such cases, though, operators must
still declare data ordering and data distribution requirements; otherwise there is no guarantee that
data will arrive sorted/distributed as required.
RecordPort#setType
.RecordPort#setOutputDataOrdering
RecordPort#setOutputDataDistribution
AbstractModelPort#setMergeHandler
.MergeModel
is a convenient, re-usable model reducer, parameterized with
a merge-handler.
SimpleModelPort
's have no associated metadata and therefore there is
never any output metadata to declare. PMMLPort
's, on the other hand,
do have associated metadata. For all PMMLPorts, implementations must declare
the following:
PMMLPort.setPMMLModelSpec
.
computeMetadata
in class StreamingOperator
ctx
- the contextprotected void execute(ExecutionContext ctx)
ExecutableOperator
execute
in class ExecutableOperator
ctx
- context in which to lookup physical ports bound to logical portspublic static String validateFieldName(int position, String fldName)
position
- the ordinal position of the field in the source/target schema - may be needed to disambiguate field names after character substitution takes place.fldName
- the name of the field being validatedpublic static String getIdentifierRegex()
public static String compile(String scriptSource)
scriptSource
- String containing the script to compilepublic static String[] compile(Map<String,Object> variables, String... scriptSources)
The input variables are set into a JavaScript scope. The scope is used when evaluating each script. Set up the variables that need to be defined for the given scripts. The values can be default values allowing a simple evaluation of the scripts to catch warning and error messages.
variables
- initial settings of input variables used by the given scriptsscriptSources
- sources of scripts to compile and evaluateCopyright © 2016 Actian Corporation. All rights reserved.