public class MultiRowOutputStepExample extends java.lang.Object implements IStep
This is an example implementation of IStep
that
generates multiple output rows for each input row.
Note: The plugin examples are included in the Data Management Platform Java™ Plugin jar and as such have a package name that represents that location. Therefore, modifying the examples requires placing the modified source, including the package statement, in a new Java™ compilation unit.
PREP_FLAG_FULL, PREP_FLAG_QUICK
Constructor and Description |
---|
MultiRowOutputStepExample() |
Modifier and Type | Method and Description |
---|---|
long |
getNumRows()
Get total number of rows that will be output by the plugin.
|
int |
getParameterCount()
Return the number of parameters this step requires.
|
java.lang.String |
getParameterName(int index)
Get the name of a parameter required by this step.
|
StepStatus |
getStatus()
Return the status of a running step.
|
void |
initialize(PlugStep step)
Notify the plugin of its associated
PlugStep instance. |
StepReadState |
next()
Retrieve the next row.
|
void |
postExec()
Execution of the job is complete.
|
boolean |
preExec()
Prepare for execution.
|
PrepState |
prep(int flags)
Prepare input and output fields.
|
void |
release()
Release resources.
|
void |
setParameterValue(int index,
java.lang.String value)
Set the value of a parameter required by this step.
|
public long getNumRows()
IStep
If a plugin knows how many rows it will return, it should return this number.
Otherwise, the plugin should -1
.
getNumRows
in interface IStep
-1
.public java.lang.String getParameterName(int index)
StepParameters
getParameterName
in interface StepParameters
index
- The 0-based index of the parameter name to retrievepublic int getParameterCount()
StepParameters
getParameterCount
in interface StepParameters
public StepStatus getStatus()
IStep
If the status is unknown, or if the step does not care to report the status, return null
.
getStatus
in interface IStep
StepStatus
that details the status of the plugin. This can
be null
if the status is unknown or unprovided.public void initialize(PlugStep step) throws StepException
IStep
PlugStep
instance.
Called immediately after the plugin is instantiated. The main purpose of this method is
to provide the plugin with the handle to the DataFlow step object (an instance of PlugStep
).
The plugin should cache this handle object locally and use it to interact with the DataFlow
engine.
IMPORTANT: The PlugStep
handle should never be used outside the context
and lifecycle of the instance of this plugin. Doing so could crash the DataFlow process.
This means that the handle should not be passed as an argument to any method nor stored in a
static location external to the plugin instance.
initialize
in interface IStep
step
- The handle to the DataFlow step object.StepException
- If initialization fails.public PrepState prep(int flags)
IStep
This will be called before preExec()
(unless no paramSet values have changed since the
last call). It will also be called when the user is requesting input names that a plugin requires or output
information that a plugin provides. The plugin is expected to build the output items with
PlugStep.buildOutputItems()
and build input names with
PlugStep.addInputName()
. Once this has been called
a single time, it will not be called again unless paramSet values have changed. This is called caching the preparedness.
If the plugin returns anything other than PrepState.ALL_SUCCESS
from this method, it
will not be cached, and will be called again the next time it is required. In addition, it will only be cached if it has
been called with PREP_FLAG_FULL
.
prep
in interface IStep
flags
- This will be PREP_FLAG_FULL
if the parent and all its
parents were successfully prepped. This is to allow prep to be called when one of the parents
failed to prep in the event the plugin is still able to get input names without the parent
being fully prepared.PrepState.ALL_SUCCESS
.
If everything failed, return PrepState.FAILED
. If partially
successful, return one of the other PrepState
values. This allows the DataFlow engine
to still process certain requests. If PrepState.FAILED
is returned, the
plugin should also indicate the error with PlugStep.setError
.public boolean preExec()
IStep
Called when execution of the job is desired. The plugin is expected to prepare itself for execution.
Call PlugStep.getExecutionType
to determine the type of execution
desired. When this method is called, it is guaranteed that prep
has been called
with PREP_FLAG_FULL
on this and all parent steps.
The plugin should calculate the number of rows it expects to produce at this point, if possible.
preExec
in interface IStep
true
on success, or false
on failure. If false
is returned,
the plugin should also indicate the error with PlugStep.setError
.public StepReadState next()
IStep
Called when the next row is desired. The plugin should fetch the row and make it available via
PlugStep.getExistingOutputItems()
.
If the plugin has a parent, parent rows may be retrieved by
PlugStep.parentOutputItems()
.
next
in interface IStep
StepReadState
that indicates the status of the row processing.
This must always be non-null.public void postExec()
IStep
Called after job execution is complete. This is used to notify the plugin that it should do any cleanup after execution. This may be called after the step generated an error.
public void release()
IStep
Called immediately before the plugin is released for garbage collection. This usually happens when the process running a job shuts down, although it can also happen in DataFlow when a node is deleted from a job. The plugin should release any resources, such as file handles, here.
public void setParameterValue(int index, java.lang.String value)
StepParameters
setParameterValue
in interface StepParameters
index
- The 0-based index of the parametervalue
- The value of the parameterCopyright © 2012 SAS Institute Inc. All Rights Reserved.