Skip to content

[SPARK-57402][SQL][SDP] Register AUTO CDC SQL syntax with the dataflow graph#57176

Open
anew wants to merge 1 commit into
apache:masterfrom
anew:hookup-sql-parser-with-dataflow-graph
Open

[SPARK-57402][SQL][SDP] Register AUTO CDC SQL syntax with the dataflow graph#57176
anew wants to merge 1 commit into
apache:masterfrom
anew:hookup-sql-parser-with-dataflow-graph

Conversation

@anew

@anew anew commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request? Hook up the two AUTO CDC SQL constructs introduced in SPARK-56249 to the Spark Declarative Pipelines dataflow graph in SqlGraphRegistrationContext:

  1. CREATE STREAMING TABLE <name> FLOW AUTO CDC FROM <source> ..., parsed into CreateStreamingTableAutoCdc, now registers the streaming table and an AutoCdcFlow that targets it.
  2. CREATE FLOW <name> AS AUTO CDC INTO <target> FROM <source> ..., parsed into a CreateFlowCommand wrapping an AutoCdcIntoCommand, now registers an AutoCdcFlow from the named flow into the target dataset.

A shared buildChangeArgs helper converts the parse-time expressions and unresolved attributes into the ChangeArgs consumed by AutoCdcFlow (keys, sequencing, delete condition, include/exclude column selection). SQL AUTO CDC only supports SCD Type 1, matching the Connect/proto path.

Why are the changes needed?

Before this change the AUTO CDC SQL syntax parsed successfully but was rejected during graph registration, so it could not be used to define pipeline datasets or flows.

Does this PR introduce any user-facing change?

Yes. AUTO CDC SQL statements now register datasets and flows in a pipeline.

How was this patch tested?

Added registration and end-to-end execution tests to SqlPipelineSuite covering both syntaxes, the optional clauses (APPLY AS DELETE WHEN, COLUMNS, COLUMNS * EXCEPT), and the multipart-flow-name error. Full SqlPipelineSuite passes (50 tests).

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Opus 4.8

### What changes were proposed in this pull request?
Hook up the two AUTO CDC SQL constructs introduced in SPARK-56249 to the
Spark Declarative Pipelines dataflow graph in `SqlGraphRegistrationContext`:

1. `CREATE STREAMING TABLE <name> FLOW AUTO CDC FROM <source> ...`, parsed
   into `CreateStreamingTableAutoCdc`, now registers the streaming table and
   an `AutoCdcFlow` that targets it.
2. `CREATE FLOW <name> AS AUTO CDC INTO <target> FROM <source> ...`, parsed
   into a `CreateFlowCommand` wrapping an `AutoCdcIntoCommand`, now registers
   an `AutoCdcFlow` from the named flow into the target dataset.

A shared `buildChangeArgs` helper converts the parse-time expressions and
unresolved attributes into the `ChangeArgs` consumed by `AutoCdcFlow`
(keys, sequencing, delete condition, include/exclude column selection). SQL
AUTO CDC only supports SCD Type 1, matching the Connect/proto path.

### Why are the changes needed?
Before this change the AUTO CDC SQL syntax parsed successfully but was
rejected during graph registration, so it could not be used to define
pipeline datasets or flows.

### Does this PR introduce _any_ user-facing change?
Yes. AUTO CDC SQL statements now register datasets and flows in a pipeline.

### How was this patch tested?
Added registration and end-to-end execution tests to `SqlPipelineSuite`
covering both syntaxes, the optional clauses (APPLY AS DELETE WHEN, COLUMNS,
COLUMNS * EXCEPT), and the multipart-flow-name error. Full `SqlPipelineSuite`
passes (50 tests).

### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Opus 4.8

Co-authored-by: Isaac
@anew anew changed the title [SPARK-57402][SDP] Register AUTO CDC SQL syntax with the dataflow graph [SPARK-57402][SQL][SDP] Register AUTO CDC SQL syntax with the dataflow graph Jul 10, 2026

@szehon-ho szehon-ho left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some review comments

identifier = stIdentifier,
comment = cst.tableSpec.comment,
specifiedSchema =
Option.when(cst.columns.nonEmpty)(StructType(cst.columns.map(_.toV1Column))),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If users write CREATE STREAMING TABLE target (id INT, name STRING) FLOW AUTO CDC ..., this stores the listed columns as the table’s full specified schema. But Auto CDC later appends _cdc_metadata to the flow schema, so validation can reject an otherwise natural data-column-only declaration. Could we either reject column lists for this SQL form, or interpret them as the data schema and add the metadata field internally before validation?

case createStreamingTableCommand: CreateStreamingTable =>
// CREATE STREAMING TABLE [ streaming_table_name ] [ options ]
CreateStreamingTableHandler.handle(createStreamingTableCommand, queryOrigin)
case createStreamingTableAutoCdcCommand: CreateStreamingTableAutoCdc =>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This registers CreateStreamingTableAutoCdc in the pipeline graph path, but the normal Spark execution guard in SparkStrategies.Pipelines only rejects CreateFlowCommand and CreateStreamingTableAsSelect today. If someone runs this statement through regular spark.sql outside pipeline registration, it may miss the curated unsupported STREAMING TABLE error. Can we add a matching CreateStreamingTableAutoCdc case there?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants