szehon-ho commented on code in PR #57669:
URL: https://github.com/apache/spark/pull/57669#discussion_r3692683607


##########
sql/pipelines/src/test/scala/org/apache/spark/sql/pipelines/graph/AutoCdcScd2ColumnEvolutionSuite.scala:
##########
@@ -0,0 +1,339 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.pipelines.graph
+
+import org.apache.spark.sql.Row
+import org.apache.spark.sql.execution.streaming.runtime.MemoryStream
+import org.apache.spark.sql.functions
+import org.apache.spark.sql.pipelines.autocdc.{ColumnSelection, ScdType, 
UnqualifiedColumnName}
+import org.apache.spark.sql.pipelines.utils.{ExecutionTest, 
TestGraphRegistrationContext}
+import org.apache.spark.sql.test.SharedSparkSession
+
+/**
+ * End-to-end tests for SCD Type 2 AutoCDC column-schema evolution across 
runs: a microbatch that
+ * is narrower than the already-evolved target (a source column dropped, a 
nested struct/array field
+ * dropped, or the `COLUMNS` selection narrowed) must reconcile correctly 
instead of failing the
+ * internal union.
+ *
+ * These exercise the fix for SPARK-58418. Before it, 
`Scd2ForeachBatchHandler.reconcileMicrobatch`
+ * unioned the microbatch with the affected target/aux rows without 
`allowMissingColumns`, so a
+ * narrower microbatch failed with NUM_COLUMNS_MISMATCH (top-level) or 
INCOMPATIBLE_COLUMN_TYPE
+ * (nested). The contract asserted here is additive-tolerant: records already 
written keep their
+ * values for the no-longer-emitted column, and only records opened by the 
narrower microbatch carry
+ * null for it.
+ *
+ * This matches SCD1's behavior for a dropped top-level column
+ * ([[AutoCdcScd1SchemaEvolutionSuite]]). SCD2 applies the same behavior to a 
dropped *nested*
+ * struct/array field, where SCD1 instead fails with 
INCOMPATIBLE_DATA_FOR_TABLE.CANNOT_FIND_DATA:
+ * SCD1's MERGE source is missing the nested field and the v2 writer's 
resolver rejects it, whereas
+ * SCD2's `allowMissingColumns` pads the field before the union/MERGE. So SCD2 
handles nested
+ * subtractive evolution consistently with the top-level case (and with SCD1's 
top-level case),
+ * rather than reproducing SCD1's nested-drop limitation.
+ *
+ * Changing the effective *tracked-history* column set is a distinct, 
separately-scoped concern
+ * (SPARK-58452 / SPARK-58391) and is deliberately not exercised here: every 
scenario keeps the
+ * effective tracked set unchanged across runs, so the only thing evolving is 
the set of user
+ * columns the flow emits. Each scenario tracks history explicitly on `name` 
and drops the

Review Comment:
   Nit: this says each scenario tracks history on `name` and drops non-tracked 
`email`, but the nested-struct and `array<struct>` tests below use default 
tracking on `value` / `vals` (their local comments are correct). Soften to 
something like "the top-level drop scenarios…" so the class-level paragraph 
matches the suite.



-- 
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