Skip to content

[SPARK-58116][SDP] Validate user-specified schema for tables fed by a named flow#57245

Open
anew wants to merge 1 commit into
apache:masterfrom
anew:fix-autocdc-schema-validation-keying
Open

[SPARK-58116][SDP] Validate user-specified schema for tables fed by a named flow#57245
anew wants to merge 1 commit into
apache:masterfrom
anew:fix-autocdc-schema-validation-keying

Conversation

@anew

@anew anew commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

GraphValidations.validateUserSpecifiedSchemas looked up a table by the incoming flow's own identifier (table.get(f.identifier)). That only matches when the flow is an implicit/default flow whose identifier equals its destination table's. For a named flow (e.g. CREATE FLOW <name> AS AUTO CDC INTO <target>, or any explicitly-named flow) the lookup returned None, so the table's declared schema was never validated against the inferred schema.

This changes the lookup to key on f.destinationIdentifier (with .distinct, since multiple flows can share a destination), matching the sibling validateFlowStreamingness validation.

Why are the changes needed?

An incompatible user-declared schema on a named-flow table went undetected at graph-validation time and surfaced only as a confusing mid-stream runtime failure at materialization.

Does this introduce any user-facing change?

Yes: an incompatible user-specified schema on a table fed by a named flow now fails with USER_SPECIFIED_AND_INFERRED_SCHEMA_NOT_COMPATIBLE at validation time, as it already did for the implicit-flow form.

How was this patch tested?

New UserSpecifiedSchemaValidationSuite covers validateUserSpecifiedSchemas across the flow-identity axis (implicit flow, where the flow identifier equals the destination table's, vs. named flow, where it differs) and the schema-compatibility axis, for both plain and AUTO CDC flows:

  • Plain flow (inferred schema == the source's data columns), implicit and named: a compatible declared schema is accepted; one missing a data column is rejected.
  • AUTO CDC flow (inferred schema == the data columns plus the appended reserved __spark_autocdc_metadata column), implicit and named: a data-only declared schema is rejected (it omits the metadata column); one that also includes the metadata column is accepted.

The named-flow cases fail without the fix (the table lookup returns None, so validation is skipped). The AUTO CDC positive cases derive the expected schema from the resolved graph's inferred schema rather than hardcoding the reserved metadata struct. Also ran ConnectValid/Invalid, SqlPipeline, and AutoCdc pipeline suites green.

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

Generated-by: Claude Opus 4.8

… named flow

### What changes were proposed in this pull request?

`GraphValidations.validateUserSpecifiedSchemas` looked up a table by the incoming flow's own
identifier (`table.get(f.identifier)`). That only matches when the flow is an implicit/default
flow whose identifier equals its destination table's. For a named flow (e.g.
`CREATE FLOW <name> AS AUTO CDC INTO <target>`, or any explicitly-named flow) the lookup returned
`None`, so the table's declared schema was never validated against the inferred schema.

This changes the lookup to key on `f.destinationIdentifier` (with `.distinct`, since multiple
flows can share a destination), matching the sibling `validateFlowStreamingness` validation.

### Why are the changes needed?

An incompatible user-declared schema on a named-flow table went undetected at graph-validation
time and surfaced only as a confusing mid-stream runtime failure at materialization.

### Does this introduce _any_ user-facing change?

Yes: an incompatible user-specified schema on a table fed by a named flow now fails with
`USER_SPECIFIED_AND_INFERRED_SCHEMA_NOT_COMPATIBLE` at validation time, as it already did for the
implicit-flow form.

### How was this patch tested?

New `UserSpecifiedSchemaValidationSuite` asserts the error is raised for both the implicit- and
named-flow forms; confirmed the named-flow case fails without the fix. Ran ConnectValid/Invalid,
SqlPipeline, and AutoCdc pipeline suites (130 tests) green.

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

Generated-by: Claude Opus 4.8

Co-authored-by: Isaac
@anew anew force-pushed the fix-autocdc-schema-validation-keying branch from f686241 to be639bc Compare July 14, 2026 23:57
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.

1 participant