ericm-db opened a new pull request, #60263:
URL: https://github.com/apache/spark/pull/60263

   ### What changes were proposed in this pull request?
   
   This is one of four PRs that let `DataStreamReader.name()` and SQL 
`IDENTIFIED BY` turn on streaming source evolution for a query without the 
internal config `spark.sql.streaming.queryEvolution.enableSourceEvolution`. 
They are meant to land together, in order:
   
   1. SPARK-61309: check source names against the checkpoint before creating 
sources (this PR)
   2. SPARK-61310: decide source evolution once per query run
   3. SPARK-61311: enable source evolution for queries that name a source
   4. SPARK-61312: docs
   
   `MicroBatchExecution` now checks the source names in the analyzed plan 
against the source tracking recorded in the checkpoint, before it creates any 
source:
   
   - A checkpoint that tracks sources by name, restarted with no named source, 
fails with the new 
`STREAMING_QUERY_EVOLUTION_ERROR.CANNOT_DISABLE_ON_EXISTING_CHECKPOINT`.
   - A positional checkpoint (offset log v1 or v2) restarted with named sources 
fails with `CANNOT_ENABLE_ON_EXISTING_CHECKPOINT`. One exception: if every 
named source already keeps its metadata in `sources/<name>`, the query keeps 
running by position. Spark 4.2 writes such checkpoints. `FindDataSourceTable` 
unwraps the `NamedStreamingRelation` of a catalog table before 
`NameStreamingSources` runs, so `STREAM t IDENTIFIED BY x` and 
`readStream.name("x").table("t")` run without the config, by position, with the 
source metadata in `sources/x`.
   - A query with both named and unnamed sources fails with 
`UNNAMED_STREAMING_SOURCES_WITH_ENFORCEMENT`. This includes a union of 
DataFrames analyzed separately, which reaches the query start with no 
`NamedStreamingRelation` left for the analyzer to check.
   
   The existing rejection of the config on an offset log v1 checkpoint moves 
from `CheckpointVersionManager.resolveOffsetLogVersion` into the same check, 
unchanged. SPARK-61311 removes it.
   
   A new catalyst helper, `StreamingSourceIdentifyingName.collectSources`, 
returns every source in a plan with its name, whether it is still wrapped in 
`NamedStreamingRelation` or already carries the name.
   
   ### Why are the changes needed?
   
   The source evolution checks ran too late or not at all:
   
   - A named checkpoint restarted without names hit `assert("All sources should 
be named at this point ...")` after the sources had been created.
   - A positional v1 checkpoint restarted with names failed only after the 
sources had been created under `sources/<name>`.
   - A positional v2 checkpoint restarted with names ran half-named: offsets 
keyed by position, source metadata read from an empty `sources/<name>`. File 
sources keep their seen-files log there.
   
   Raising these errors before any source exists also means a rejected run 
leaves nothing behind in the checkpoint. SPARK-61311 relies on these checks 
once naming a source enables source evolution.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, compared to Spark 4.2:
   
   - Restarting a named checkpoint without names: `AssertionError` becomes 
`CANNOT_DISABLE_ON_EXISTING_CHECKPOINT`.
   - Restarting a positional offset log v2 checkpoint with newly named sources, 
which requires the config today: the query ran half-named and now fails with 
`CANNOT_ENABLE_ON_EXISTING_CHECKPOINT`.
   - Restarting a positional v1 checkpoint with names: same error as before, 
raised before any source is created.
   - A new query that mixes named and unnamed sources and passes analysis, such 
as a union of separately analyzed DataFrames with the config on, or catalog 
tables without it: an `AssertionError` or a half-named run becomes 
`UNNAMED_STREAMING_SOURCES_WITH_ENFORCEMENT`.
   
   Checkpoints that Spark 4.2 wrote for catalog tables named with `IDENTIFIED 
BY` keep running.
   
   ### How was this patch tested?
   
   New tests:
   - `NameStreamingSourcesSuite`: `collectSources` on wrapped and already named 
sources, and on leaves that cannot carry a name.
   - `StreamingSourceEvolutionSuite`: each rejection, checking that no source 
was created; restarts that keep the checkpoint's tracking; and a positional 
checkpoint written under source names, which keeps running and does not 
reprocess its input.
   
   ```
   build/sbt 'catalyst/testOnly *NameStreamingSourcesSuite 
*NamedStreamingRelationSuite *StreamRelationParserSuite'
   build/sbt 'sql/testOnly *StreamingSourceEvolutionSuite *OffsetSeqLogSuite 
*StreamRelationSuite *StreamingSourceIdentifyingNameSuite 
*ChangelogEndToEndSuite'
   ```
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code (Claude Opus 5.5)
   
   This pull request and its description were written by Isaac.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to