You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "jose-torres (via GitHub)" <gi...@apache.org> on 2026/07/25 00:52:08 UTC
Re: [PR] [SPARK-58313][SDP] Validate SCD2 track-history columns at AutoCDC flow construction [spark]
jose-torres commented on code in PR #57490:
URL: https://github.com/apache/spark/pull/57490#discussion_r3648940929
##########
sql/pipelines/src/main/scala/org/apache/spark/sql/pipelines/autocdc/Scd2BatchProcessor.scala:
##########
@@ -1410,6 +1395,44 @@ object Scd2BatchProcessor {
AutoCdcReservedNames.cdcMetadataColName
)
+ /**
+ * Resolve [[ChangeArgs.trackHistorySelection]] against `schema` and return the field names of
+ * the history-tracking columns: the eligible user-data columns (those that are neither
+ * [[ChangeArgs.keys]] nor framework reserved columns) filtered through the selection.
+ *
+ * This is the single source of truth for which columns define an SCD2 run. It is called both
+ * per-microbatch (against the reconciled dataframe's schema) and at
+ * [[org.apache.spark.sql.pipelines.graph.AutoCdcMergeFlow]] construction time (against the
+ * user-selected source schema), so an unresolvable or ineligible selection fails fast with a
+ * user-actionable [[org.apache.spark.sql.AnalysisException]] instead of surfacing mid-stream
+ * (SPARK-58313).
Review Comment:
nit: spark ticket comment as per other PR
##########
sql/pipelines/src/main/scala/org/apache/spark/sql/pipelines/autocdc/Scd2BatchProcessor.scala:
##########
@@ -922,28 +923,12 @@ case class Scd2BatchProcessor(
* the eligible user-data columns (those not in [[ChangeArgs.keys]] or the framework
* reserved set) filtered through [[ChangeArgs.trackHistorySelection]].
*/
- private def computeTrackedHistoryColumns(df: DataFrame): Seq[String] = {
- val conf = df.sparkSession.sessionState.conf
- val resolver = conf.resolver
-
- val keyColNames = changeArgs.keys.map(_.name)
- val reservedColNames = Scd2BatchProcessor.reservedFrameworkColNames
-
- val eligibleSchema = StructType(df.schema.fields.filterNot { field =>
- reservedColNames.exists(resolver(_, field.name)) ||
- keyColNames.exists(resolver(_, field.name))
- })
-
- ColumnSelection
- .applyToSchema(
- schemaName = "trackHistorySelection",
- schema = eligibleSchema,
- columnSelection = changeArgs.trackHistorySelection,
- caseSensitive = conf.caseSensitiveAnalysis
- )
- .fieldNames
- .toImmutableArraySeq
- }
+ private def computeTrackedHistoryColumns(df: DataFrame): Seq[String] =
+ Scd2BatchProcessor.computeTrackedHistoryColumns(
+ schema = df.schema,
+ changeArgs = changeArgs,
+ caseSensitive = df.sparkSession.sessionState.conf.caseSensitiveAnalysis
Review Comment:
I guess I'm OK with this, it's unlikely we'll introduce some third resolution mode all of the sudden.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org