public class RunScript extends ExecutableOperator implements RecordPipelineOperator
javax.scripting
APIs of JSR 223. The script engine must
support the Compilable
interface.
Operation 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 enviroments are not shared across instances.
Constructor and Description |
---|
RunScript()
Default constructor for the run script operator.
|
RunScript(String engineName,
String onEveryRecordScript,
RecordTokenType outputType)
Construct a run script operator with the minimum parameters required for execution.
|
Modifier and Type | Method and Description |
---|---|
protected void |
computeMetadata(StreamingMetadataContext ctx)
Implementations must adhere to the following contracts
|
static String |
convertFieldName(String fieldName)
Convert an input field name into a valid variable for the scripting
environment being used.
|
protected void |
execute(ExecutionContext context)
Executes the operator.
|
String |
getAfterLastRecordScript()
Get the source of the script run after all input records
have been processed.
|
String |
getBeforeFirstRecordScript()
Get the source of the script run before any input records
are processed.
|
String |
getEngineName()
Get the name of the scripting engine to use.
|
String |
getEngineVersion()
Get the version of the scripting engine to use.
|
RecordPort |
getInput()
Get the input port to the run script operator.
|
String |
getLanguageName()
Get the name of the script language to use.
|
String |
getLanguageVersion()
Get the version of the script language to use.
|
String |
getOnEveryRecordScript()
Get the source of the script to execute for every
input record.
|
RecordPort |
getOutput()
Get the output port of the run script operator.
|
RecordTokenType |
getOutputType()
Get the defined output type.
|
String |
getStderrFileName()
Get the name of the file to use for standard error output.
|
String |
getStdoutFileName()
Get the name of the file to use for standard output.
|
Map<String,Object> |
getVariables()
Get the mapping of variables.
|
void |
setAfterLastRecordScript(String script)
Set the script to use for clean up processing.
|
void |
setBeforeFirstRecordScript(String script)
Set the script to use for initialization processing.
|
void |
setEngineName(String engineName)
Set the name of the script engine to use.
|
void |
setEngineVersion(String engineVersion)
Set the version of the script engine to use.
|
void |
setLanguageName(String languageName)
Set the name of the scripting language to use.
|
void |
setLanguageVersion(String languageVersion)
Set the version of the script language to use.
|
void |
setOnEveryRecordScript(String script)
Set the script to use for processing every input record.
|
void |
setOutputType(RecordTokenType outputType)
Set the output type.
|
void |
setStderrFileName(String stderrFileName)
Set the pathname of the file that will capture the standard error
output of the script execution environment.
|
void |
setStdoutFileName(String stdoutFileName)
Set the pathname of the file that will capture the standard output
of the script execution environment.
|
void |
setVariables(Map<String,Object> variables)
Set the collection of variables to be incorporated into the script
environment before executing any of the given script source.
|
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 RunScript()
public RunScript(String engineName, String onEveryRecordScript, RecordTokenType outputType)
engineName
- name of the scripting engine to useonEveryRecordScript
- script run for every record of inputoutputType
- schema of the output of the executed scriptpublic RecordPort getInput()
getInput
in interface PipelineOperator<RecordPort>
public RecordPort getOutput()
getOutput
in interface PipelineOperator<RecordPort>
public Map<String,Object> getVariables()
public void setVariables(Map<String,Object> variables)
variables
- map of name=value pairspublic String getAfterLastRecordScript()
public String getBeforeFirstRecordScript()
public String getEngineName()
public String getEngineVersion()
public String getLanguageName()
public String getLanguageVersion()
public String getOnEveryRecordScript()
public RecordTokenType getOutputType()
public String getStderrFileName()
public String getStdoutFileName()
public void setAfterLastRecordScript(String script)
script
- source of after last record scriptpublic void setBeforeFirstRecordScript(String script)
script
- source of before first record scriptpublic void setEngineName(String engineName)
engineName
- engine namepublic void setEngineVersion(String engineVersion)
engineVersion
- script engine versionpublic void setLanguageName(String languageName)
languageName
- script language namepublic void setLanguageVersion(String languageVersion)
languageVersion
- script language versionpublic void setOnEveryRecordScript(String script)
script
- source of script for record processingpublic void setOutputType(RecordTokenType outputType)
outputType
- the output type of this operatorpublic void setStderrFileName(String stderrFileName)
stderrFileName
- path of standard error outputpublic void setStdoutFileName(String stdoutFileName)
stdoutFileName
- path of standard outputpublic static String convertFieldName(String fieldName)
Every situation for every scripting environment cannot be handled here. A work around is to rename fields in question before using them in this operator.
fieldName
- name of the input fieldprotected 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 context)
ExecutableOperator
execute
in class ExecutableOperator
context
- context in which to lookup physical ports bound to logical portsCopyright © 2019 Actian Corporation. All rights reserved.