Generate a DataStage Python SDK script from an optimized Substrait plan. This skill is
the DataStage flow-generation handoff after di-agent-query-optimization.
Current support is limited to full pushdown: one database connector executes a SQL statement and writes the returned rows to one Sequential file stage. If a plan is partial pushdown, raw Substrait, lowered Substrait, or otherwise not the compact full-pushdown shape, stop instead of generating a partial DataStage graph.
Reference Files
Load only the files needed for the current step:
references/datastage-generation.md— required for Python generation. Contains the compact full-pushdown shape checks, SQL-mode connector pattern, type mapping, output alias rules,template-skeleton.pycontract, and MCPsdk_codesubset contract.references/flow-execution.md— required only when the user asks to create, run, monitor, or fetch results from the generated flow.references/minimal-full-pushdown-example.md— optional worked example forexamples/minimal_full_pushdown.substrait.json.references/template-skeleton.py— authoritative complete SDK script skeleton. Substitute<FLOW_NAME>and<PROJECT_ID>, then replace only the# <<< BEGIN_FILL >>>/# <<< END_FILL >>>region.references/datastage-connector-sdk-reference.md— connector labels, SDK map names, connection type aliases, enum names, SQL-read support, and common SDK properties.references/connector-type-label-map.json— utility-stage labels and variable prefixes, especiallyPxSequentialFile->type = "Sequential file"andsequentialfile_0.references/connector-property-values.md— connector property value sources and SQL-mode read rules.../di-agent-knowledge-engine-datastage/stages/SequentialFileStage.md— Sequential file stage behavior, when deeper stage semantics are needed.
Input Preconditions
The input must be an optimized plan produced by di-agent-query-optimization.
Specifically, it must use the compact full-pushdown contract:
- Exactly one top-level relation.
- The relation contains
relations[0].root.input.read. read.common.advancedExtension.enhancement.nodeKind == "full_pushdown_read".read.common.advancedExtension.enhancement.sqlStatementis present and non-empty.- The read node carries exactly one source database connection id at
read.advanced_extension.optimization[0].connection_id.
If the user hands you a raw plan or a lowered plan, ask them to run it through
di-agent-query-optimization first.
If the plan is marked partial_pushdown_unsupported, stop and say:
Partial pushdown is not supported yet by this skill. This flow skill only accepts the currently supported full-pushdown optimized Substrait shape where the complete plan is represented by one SQL-bearing read from a single connector.
For any other missing full-pushdown field, do not generate Python. Report the exact missing field and ask for the required metadata only when it cannot be derived.
Required Runtime Metadata
The optimized plan contains SQL, but SDK generation also needs runtime DataStage metadata:
{
"project_id": "<watsonx project ID used as the script fallback>",
"connection_name": "<DataStage connection name matching the plan connection_id>",
"connector_stage": "<DataStage connector stage label, e.g. IBM Db2>",
"output_file": "<flow_name>.csv"
}
Rules:
connection_idmust come from the optimized plan. Never invent it.connection_nameis required because the SDK callsproject.connections.get(name="..."). If it is missing, ask the user for the matching connection name and include theconnection_idin the question.- Resolve
connector_stage, SDK map name, and enum fromreferences/datastage-connector-sdk-reference.md. If the source uses a three-levelcatalog.schema.tablenamespace (e.g. Azure Databricks), fully qualify every table ascatalog.schema.tableinside theselect_statement. output_filedefaults to a flat<flow_name>.csv(no directory prefix) when the user does not specify it. The Sequential file writer does not create parent directories, so a path likedi/<flow_name>.csvfails at runtime withUnable to open <path>: No such file or directoryunless that directory already exists on the engine storage. Use a bare filename, or a directory you have confirmed exists.
Workflow
- Verify the input satisfies the full-pushdown preconditions above.
- Read
references/datastage-generation.md. - Extract
sqlStatement,connection_id, output names, output types, and a flow name. Sanitize output names only when needed by the rules in the generation reference. - Resolve the connector label, map name, enum, and SQL-mode read support from
references/datastage-connector-sdk-reference.md; consultreferences/connector-property-values.mdfor property values. - Generate exactly two stages and one link:
- one SQL-mode database connector source;
- one
Sequential filesink; - one source-to-sink link with the optimized output schema.
- Keep two artifacts:
- a complete SDK script produced from
references/template-skeleton.py; - a no-boilerplate MCP
sdk_codesubset forcreate_datastage_flow.
- a complete SDK script produced from
- Create the flow with
create_datastage_flowwhen it is available. If it fails with a clear SDK-code error, fix and retry with non-emptysdk_code. If it fails because a flow with that name already exists, do NOT retry automatically: ask the user whether to overwrite the existing flow withupdate_datastage_flow(sameflow_name,project_id,sdk_code) or create it under a new name. - If the user asked to run the flow or fetch results, read
references/flow-execution.mdand use MCP job/result tools first; use the saved script only as the local fallback.
Do not insert additional stages, transformers, joins, or alternate sinks. This skill emits exactly the currently supported full-pushdown topology.
Output Format
Return:
### DataStage Flow Generation
- Mode: full_pushdown
- Source stage: <connector_stage>
- Sink stage: Sequential file
- Output file: <output_file>
### Python SDK Script
```python
<complete script or requested fill block>
```
When the flow is created or run through MCP tools, include the resulting flow, job, job-run, and output links or IDs that were returned by the tools.
Current Support
- Generates DataStage Python only for the compact full-pushdown optimized shape.
- Partial-pushdown plans are a planned extension point. Until supported, stop and say partial pushdown is not supported in this case.
- Does not infer or create database connections.
- The generated sink is always a Sequential file stage.