This is an automated email from the ASF dual-hosted git repository.
jose-torres pushed a commit to branch branch-4.x
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-4.x by this push:
new 6b7401474025 [SPARK-59786][SDP] SCD1 Ignore-null support; Populate
version map per event row at ingest
6b7401474025 is described below
commit 6b74014740250d996efc4fab89bfe8b3b3b98bbc
Author: AnishMahto <[email protected]>
AuthorDate: Tue Nov 10 08:23:59 2026 -0800
[SPARK-59786][SDP] SCD1 Ignore-null support; Populate version map per event
row at ingest
### What changes were proposed in this pull request?
When processing an incoming microbatch, if ignore-null is enabled for the
AutoCDC flow, a non-null version map is populated for every upsert row. Delete
rows retain a null version map and are handled as row-wide authorship during
later reconciliation.
Per the version-map contract documented in `Scd1VersionMap`, the map
contains authorship information for every non-key user-data leaf in the
target-aligned row. This PR introduces the `extendMicrobatchRowsWithVersionMap`
to produce and project the version map of each upsert representing row
independently, using only that row’s values and sequencing value.
`buildVersionMap` gains `omittedLeafPaths` so that target leaves the
microbatch omits, found by `alignMicrobatchToTargetSchema` and
`fieldPathsMissingFrom`, stay unauthored.
**This PR does not yet implement microbatch reconciliation**, and therefore
does not actually use `extendMicrobatchRowsWithVersionMap` yet. A future PR
will use `extendMicrobatchRowsWithVersionMap` by calling it on the target-table
aligned microbatch.
Instead, in this PR unit tests demonstrate how
`extendMicrobatchRowsWithVersionMap` will eventually be called, and assert on
the properties reconciliation will later rely on.
### Why are the changes needed?
SCD1 ignore-null support.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Unit tests.
### Was this patch authored or co-authored using generative AI tooling?
Co-authored with GPT 5.6 Sol
Closes #59044 from AnishMahto/scd1-populate-version-map-at-ingest.
Authored-by: AnishMahto <[email protected]>
Signed-off-by: Jose Torres <[email protected]>
(cherry picked from commit 34c34d20958358e6a011ff4526042942cb976a3d)
Signed-off-by: Jose Torres <[email protected]>
skip-checks: true
---
.../sql/pipelines/autocdc/AutoCdcSchemaUtils.scala | 17 ++
.../autocdc/Scd1ReconciliationStrategy.scala | 83 +++++++-
.../sql/pipelines/autocdc/Scd1VersionMap.scala | 13 +-
.../autocdc/AutoCdcSchemaUtilsSuite.scala | 24 +++
.../autocdc/Scd1LeafLevelReconciliationSuite.scala | 213 +++++++++++++++++++++
.../pipelines/autocdc/Scd1VersionMapSuite.scala | 42 ++++
6 files changed, 387 insertions(+), 5 deletions(-)
diff --git
a/sql/pipelines/src/main/scala/org/apache/spark/sql/pipelines/autocdc/AutoCdcSchemaUtils.scala
b/sql/pipelines/src/main/scala/org/apache/spark/sql/pipelines/autocdc/AutoCdcSchemaUtils.scala
index 3a59acbf465c..94aec3848299 100644
---
a/sql/pipelines/src/main/scala/org/apache/spark/sql/pipelines/autocdc/AutoCdcSchemaUtils.scala
+++
b/sql/pipelines/src/main/scala/org/apache/spark/sql/pipelines/autocdc/AutoCdcSchemaUtils.scala
@@ -69,4 +69,21 @@ private[autocdc] object AutoCdcSchemaUtils {
)
flattenStructFieldPaths(ignoreNullColumns)
}
+
+ /**
+ * Returns the [[flattenStructFieldPaths]] of `schema` that are absent from
`otherSchema`,
+ * preserving `schema` order. A path is present in `otherSchema` if one of
its flattened paths
+ * has the same length and matches each name part under `resolver`.
+ */
+ def fieldPathsMissingFrom(
+ schema: StructType,
+ otherSchema: StructType,
+ resolver: Resolver): Seq[Seq[String]] = {
+ val otherPaths = flattenStructFieldPaths(otherSchema)
+ flattenStructFieldPaths(schema).filterNot { path =>
+ otherPaths.exists { otherPath =>
+ otherPath.length == path.length &&
path.zip(otherPath).forall(resolver.tupled)
+ }
+ }
+ }
}
diff --git
a/sql/pipelines/src/main/scala/org/apache/spark/sql/pipelines/autocdc/Scd1ReconciliationStrategy.scala
b/sql/pipelines/src/main/scala/org/apache/spark/sql/pipelines/autocdc/Scd1ReconciliationStrategy.scala
index 7444bccd72c8..4313bc518fa9 100644
---
a/sql/pipelines/src/main/scala/org/apache/spark/sql/pipelines/autocdc/Scd1ReconciliationStrategy.scala
+++
b/sql/pipelines/src/main/scala/org/apache/spark/sql/pipelines/autocdc/Scd1ReconciliationStrategy.scala
@@ -21,7 +21,7 @@ import org.apache.spark.sql.{functions => F}
import org.apache.spark.sql.Column
import org.apache.spark.sql.catalyst.util.QuotingUtils
import org.apache.spark.sql.classic.DataFrame
-import org.apache.spark.sql.types.DataType
+import org.apache.spark.sql.types.{DataType, StructType}
import org.apache.spark.util.ArrayImplicits._
/** Strategy for reconciling an SCD1 microbatch. */
@@ -208,3 +208,84 @@ private[pipelines] object Scd1RowLevelReconciliation
extends Scd1ReconciliationS
)
}
}
+
+/** Leaf-level SCD1 reconciliation. */
+private[pipelines] object Scd1LeafLevelReconciliation {
+
+ /**
+ * Aligns microbatch rows with the persisted target schema without adding
target rows.
+ *
+ * Matching fields use the target's order and spelling. Target fields
missing from the microbatch,
+ * including nested fields, are filled with nulls. Microbatch-only fields
are retained after the
+ * target fields.
+ *
+ * Version maps are built from aligned rows, so each key is spelled as in
the target schema and
+ * every target leaf receives an entry, even when the microbatch omits it.
+ *
+ * @param microbatchDf The microbatch rows to align.
+ * @param targetTableDf A target-table snapshot whose schema provides the
canonical field order
+ * and spelling. Its rows are ignored.
+ * @return The microbatch rows aligned with the target schema, with
microbatch-only fields
+ * retained and no rows added from the target.
+ */
+ private[autocdc] def alignMicrobatchToTargetSchema(
+ microbatchDf: DataFrame,
+ targetTableDf: DataFrame): DataFrame =
+ targetTableDf.limit(0).unionByName(microbatchDf, allowMissingColumns =
true)
+
+ /**
+ * Populates the version map for upsert rows, if ignore-null is being used.
+ *
+ * The caller must supply rows whose schema already reflects target column
selection and
+ * target-schema alignment. An upsert does not author the leaves that
alignment added, since its
+ * event did not carry them.
+ *
+ * @param changeArgs The CDC configuration providing keys and the
ignore-null selection.
+ * @param resolvedSequencingType The resolved type of the sequencing
expression and version-map
+ * values.
+ * @param alignedDf Microbatch rows already target-selected and
target-schema-aligned, with the
+ * canonical CDC metadata column populated.
+ * @param unalignedSchema The schema of the microbatch rows before
target-schema alignment. The
+ * leaves of `alignedDf` that it lacks were added by
alignment.
+ * @return `alignedDf` unchanged when ignore-null is disabled; otherwise,
the same rows but with
+ * version maps populated for upsert rows.
+ */
+ private[autocdc] def extendMicrobatchRowsWithVersionMap(
+ changeArgs: ChangeArgs,
+ resolvedSequencingType: DataType,
+ alignedDf: DataFrame,
+ unalignedSchema: StructType): DataFrame =
+ changeArgs.ignoreNullSelection match {
+ case None => alignedDf
+ case Some(ignoreNullSelection) =>
+ val resolver = alignedDf.sparkSession.sessionState.conf.resolver
+ val cdcMetadataCol = F.col(AutoCdcReservedNames.cdcMetadataColName)
+ val upsertSequence =
Scd1BatchProcessor.upsertSequenceOf(cdcMetadataCol)
+ // Keys and CDC metadata columns are not eligible for optional
authorship. Drop them
+ // from the user schema that the version map will be constructed from.
+ val userDataSchema = AutoCdcSchemaUtils.excludeColumns(
+ schema = alignedDf.schema,
+ columnNamesToExclude =
+ changeArgs.keys.map(_.name) :+
AutoCdcReservedNames.cdcMetadataColName,
+ resolver = resolver
+ )
+ val versionMap = F.when(
+ upsertSequence.isNotNull,
+ Scd1VersionMap.buildVersionMap(
+ schema = userDataSchema,
+ ignoreNullSelection = ignoreNullSelection,
+ omittedLeafPaths = AutoCdcSchemaUtils
+ .fieldPathsMissingFrom(userDataSchema, unalignedSchema, resolver)
+ .toSet,
+ authorshipSequence = upsertSequence,
+ sequencingType = resolvedSequencingType,
+ resolver = resolver
+ )
+ )
+
+ alignedDf.withColumn(
+ AutoCdcReservedNames.cdcMetadataColName,
+ cdcMetadataCol.withField(Scd1BatchProcessor.versionMapFieldName,
versionMap)
+ )
+ }
+}
diff --git
a/sql/pipelines/src/main/scala/org/apache/spark/sql/pipelines/autocdc/Scd1VersionMap.scala
b/sql/pipelines/src/main/scala/org/apache/spark/sql/pipelines/autocdc/Scd1VersionMap.scala
index 0a191cbfa5f5..0034d8961c86 100644
---
a/sql/pipelines/src/main/scala/org/apache/spark/sql/pipelines/autocdc/Scd1VersionMap.scala
+++
b/sql/pipelines/src/main/scala/org/apache/spark/sql/pipelines/autocdc/Scd1VersionMap.scala
@@ -89,9 +89,9 @@ private[pipelines] object Scd1VersionMap {
/**
* Builds a column that computes a row's version map from that row's column
values.
*
- * Every leaf in `schema` receives an entry of `authorshipSequence`, except
that a leaf selected
- * by `ignoreNullSelection` is read by path from the row and receives a null
entry when its value
- * is null.
+ * Every leaf in `schema` receives an entry of `authorshipSequence`, except
that a leaf in
+ * `omittedLeafPaths` receives a null entry, and any other leaf selected by
`ignoreNullSelection`
+ * is read by path from the row and receives a null entry when its value is
null.
*
* @param schema The user-data schema, without keys or framework columns,
whose leaves receive
* version-map entries. Keys take each name part's spelling
verbatim from this
@@ -99,6 +99,8 @@ private[pipelines] object Scd1VersionMap {
* same across runs. Its leaves selected by
`ignoreNullSelection` must resolve by
* path in the DataFrame on which the returned column is
evaluated.
* @param ignoreNullSelection The selection identifying leaves whose null
values are unauthored.
+ * @param omittedLeafPaths The leaf paths of `schema`, spelled as in it,
that are not authored at
+ * `authorshipSequence`, such as leaves the row's
source did not carry.
* @param authorshipSequence The sequence at which the leaves of `schema`
are considered authored.
* @param sequencingType The data type of `authorshipSequence`.
* @param resolver The resolver used for column-name matching.
@@ -107,6 +109,7 @@ private[pipelines] object Scd1VersionMap {
def buildVersionMap(
schema: StructType,
ignoreNullSelection: ColumnSelection,
+ omittedLeafPaths: Set[Seq[String]],
authorshipSequence: Column,
sequencingType: DataType,
resolver: Resolver): Column = {
@@ -116,7 +119,9 @@ private[pipelines] object Scd1VersionMap {
val entries = AutoCdcSchemaUtils.flattenStructFieldPaths(schema).map {
path =>
val leafSequence =
- if (ignoreNullLeafPaths.contains(path)) {
+ if (omittedLeafPaths.contains(path)) {
+ F.lit(null)
+ } else if (ignoreNullLeafPaths.contains(path)) {
F.when(F.col(QuotingUtils.quoteNameParts(path)).isNotNull,
authorshipSequence)
} else {
authorshipSequence
diff --git
a/sql/pipelines/src/test/scala/org/apache/spark/sql/pipelines/autocdc/AutoCdcSchemaUtilsSuite.scala
b/sql/pipelines/src/test/scala/org/apache/spark/sql/pipelines/autocdc/AutoCdcSchemaUtilsSuite.scala
index 1faee50af41d..d7fda926ffcb 100644
---
a/sql/pipelines/src/test/scala/org/apache/spark/sql/pipelines/autocdc/AutoCdcSchemaUtilsSuite.scala
+++
b/sql/pipelines/src/test/scala/org/apache/spark/sql/pipelines/autocdc/AutoCdcSchemaUtilsSuite.scala
@@ -169,4 +169,28 @@ class AutoCdcSchemaUtilsSuite extends SparkFunSuite {
Seq("wrapper.with.dot", "back`tick"),
Seq("wrapper.with.dot", "space name")))
}
+
+ test("fieldPathsMissingFrom returns flattened paths absent from the other
schema") {
+ val schema = new StructType()
+ .add("kept", StringType)
+ .add("dropped", StringType)
+ .add("profile", new StructType()
+ .add("City", StringType)
+ .add("zip", StringType))
+ val otherSchema = new StructType()
+ .add("profile", new StructType()
+ .add("city", StringType))
+ .add("KEPT", StringType)
+ .add("extra", StringType)
+
+ assert(AutoCdcSchemaUtils.fieldPathsMissingFrom(
+ schema,
+ otherSchema,
+ caseInsensitiveResolution) === Seq(Seq("dropped"), Seq("profile",
"zip")))
+ assert(AutoCdcSchemaUtils.fieldPathsMissingFrom(
+ schema,
+ otherSchema,
+ caseSensitiveResolution) ===
+ Seq(Seq("kept"), Seq("dropped"), Seq("profile", "City"), Seq("profile",
"zip")))
+ }
}
diff --git
a/sql/pipelines/src/test/scala/org/apache/spark/sql/pipelines/autocdc/Scd1LeafLevelReconciliationSuite.scala
b/sql/pipelines/src/test/scala/org/apache/spark/sql/pipelines/autocdc/Scd1LeafLevelReconciliationSuite.scala
new file mode 100644
index 000000000000..1535678a6b5a
--- /dev/null
+++
b/sql/pipelines/src/test/scala/org/apache/spark/sql/pipelines/autocdc/Scd1LeafLevelReconciliationSuite.scala
@@ -0,0 +1,213 @@
+/*
+ * 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.autocdc
+
+import org.apache.spark.sql.{functions => F, QueryTest, Row}
+import org.apache.spark.sql.catalyst.util.QuotingUtils
+import org.apache.spark.sql.classic.DataFrame
+import org.apache.spark.sql.internal.SQLConf
+import org.apache.spark.sql.test.SharedSparkSession
+import org.apache.spark.sql.types._
+
+class Scd1LeafLevelReconciliationSuite extends QueryTest with
SharedSparkSession {
+
+ private val metadataColName = AutoCdcReservedNames.cdcMetadataColName
+
+ private def dataFrameOf(schema: StructType)(rows: Row*): DataFrame =
+ spark.createDataFrame(spark.sparkContext.parallelize(rows), schema)
+
+ private def changeArgs(ignoreNullSelection: Option[ColumnSelection]):
ChangeArgs =
+ ChangeArgs(
+ keys = Seq(UnqualifiedColumnName("id")),
+ sequencing = F.col("seq"),
+ storedAsScdType = ScdType.Type1,
+ ignoreNullSelection = ignoreNullSelection
+ )
+
+ private def extendMicrobatchRowsWithVersionMap(
+ input: DataFrame,
+ ignoreNullSelection: Option[ColumnSelection],
+ unalignedSchema: Option[StructType] = None): DataFrame =
+ Scd1LeafLevelReconciliation.extendMicrobatchRowsWithVersionMap(
+ changeArgs = changeArgs(ignoreNullSelection),
+ resolvedSequencingType = LongType,
+ alignedDf = input,
+ unalignedSchema = unalignedSchema.getOrElse(input.schema)
+ )
+
+ private def metadataSchema: StructType =
+ Scd1BatchProcessor.cdcMetadataColSchema(LongType)
+
+ private def encodedPath(parts: String*): String =
QuotingUtils.quoteNameParts(parts)
+
+ test("extendMicrobatchRowsWithVersionMap is a no-op when ignore-null is
disabled") {
+ val schema = new StructType()
+ .add("id", IntegerType)
+ .add("value", StringType)
+ .add(metadataColName, metadataSchema)
+ val existingMap = Map(encodedPath("value") -> 5L)
+ val input = dataFrameOf(schema)(
+ Row(1, "value", Row(null, 5L, existingMap))
+ )
+
+ val result = extendMicrobatchRowsWithVersionMap(
+ input = input,
+ ignoreNullSelection = None
+ )
+
+ assert(result eq input)
+ checkAnswer(result, input.collect().toSeq)
+ }
+
+ test("extendMicrobatchRowsWithVersionMap populates upserts without changing
other CDC " +
+ "metadata fields") {
+ val profileType = new StructType()
+ .add("city", StringType)
+ .add("age", IntegerType)
+ val schema = new StructType()
+ .add("id", IntegerType)
+ .add("selectedNull", StringType)
+ .add("selectedValue", StringType)
+ .add("unselectedNull", StringType)
+ .add("profile", profileType)
+ .add(metadataColName, metadataSchema)
+ val input = dataFrameOf(schema)(
+ Row(1, null, "selected", null, Row(null, 42), Row(null, 10L, null)),
+ Row(2, null, null, null, Row(null, null), Row(20L, null, null)),
+ Row(3, "authored", null, null, Row("New York", null), Row(null, 30L,
null))
+ )
+ val ignoreNullSelection = ColumnSelection.IncludeColumns(Seq(
+ UnqualifiedColumnName("selectedNull"),
+ UnqualifiedColumnName("selectedValue"),
+ UnqualifiedColumnName("profile")
+ ))
+
+ val result = extendMicrobatchRowsWithVersionMap(
+ input = input,
+ ignoreNullSelection = Some(ignoreNullSelection)
+ )
+
+ val expectedUpsertMap = Map[String, Any](
+ encodedPath("selectedNull") -> null,
+ encodedPath("selectedValue") -> 10L,
+ encodedPath("unselectedNull") -> 10L,
+ encodedPath("profile", "city") -> null,
+ encodedPath("profile", "age") -> 10L
+ )
+ val expectedSecondUpsertMap = Map[String, Any](
+ encodedPath("selectedNull") -> 30L,
+ encodedPath("selectedValue") -> null,
+ encodedPath("unselectedNull") -> 30L,
+ encodedPath("profile", "city") -> 30L,
+ encodedPath("profile", "age") -> null
+ )
+ checkAnswer(
+ result.select(F.col(metadataColName)),
+ Seq(
+ Row(Row(null, 10L, expectedUpsertMap)),
+ Row(Row(20L, null, null)),
+ Row(Row(null, 30L, expectedSecondUpsertMap))
+ )
+ )
+ }
+
+ test("extendMicrobatchRowsWithVersionMap leaves only the leaves that
alignment added " +
+ "unauthored") {
+ withSQLConf(SQLConf.CASE_SENSITIVE.key -> "false") {
+ val schema = new StructType()
+ .add("id", IntegerType)
+ .add("selected", StringType)
+ .add("carried", StringType)
+ .add("omitted", StringType)
+ .add("profile", new StructType()
+ .add("city", StringType)
+ .add("zip", StringType))
+ .add("address", new StructType()
+ .add("city", StringType))
+ .add(metadataColName, metadataSchema)
+ val unalignedSchema = new StructType()
+ .add("ID", IntegerType)
+ .add("Selected", StringType)
+ .add("Carried", StringType)
+ .add("Address", new StructType()
+ .add("City", StringType))
+ .add(metadataColName, metadataSchema)
+ val input = dataFrameOf(schema)(
+ Row(1, "value", null, null, null, null, Row(null, 10L, null))
+ )
+
+ val result = extendMicrobatchRowsWithVersionMap(
+ input = input,
+ ignoreNullSelection =
+
Some(ColumnSelection.IncludeColumns(Seq(UnqualifiedColumnName("selected")))),
+ unalignedSchema = Some(unalignedSchema)
+ )
+
+ val expectedVersionMap = Map[String, Any](
+ encodedPath("selected") -> 10L,
+ encodedPath("carried") -> 10L,
+ encodedPath("omitted") -> null,
+ encodedPath("profile", "city") -> null,
+ encodedPath("profile", "zip") -> null,
+ encodedPath("address", "city") -> 10L
+ )
+ checkAnswer(
+ result.select(F.col(metadataColName)),
+ Row(Row(null, 10L, expectedVersionMap)))
+ }
+ }
+
+ test("alignMicrobatchToTargetSchema preserves target shape and source-only
columns") {
+ withSQLConf(SQLConf.CASE_SENSITIVE.key -> "false") {
+ val targetProfileType = new StructType()
+ .add("city", StringType)
+ .add("zip", StringType)
+ val targetSchema = new StructType()
+ .add("id", IntegerType)
+ .add("name", StringType)
+ .add("profile", targetProfileType)
+ .add("targetOnly", StringType)
+ val target = dataFrameOf(targetSchema)(
+ Row(999, "target", Row("target city", "target zip"), "target only")
+ )
+
+ val sourceProfileType = new StructType().add("City", StringType)
+ val projectedSchema = new StructType()
+ .add("newColumn", StringType)
+ .add("id", IntegerType)
+ .add("Name", StringType)
+ .add("profile", sourceProfileType)
+ val projected = dataFrameOf(projectedSchema)(
+ Row("new", 1, "Alice", Row("San Francisco"))
+ )
+
+ val result = Scd1LeafLevelReconciliation.alignMicrobatchToTargetSchema(
+ microbatchDf = projected,
+ targetTableDf = target
+ )
+
+ assert(result.schema.fieldNames.toSeq ==
+ Seq("id", "name", "profile", "targetOnly", "newColumn"))
+ assert(result.schema("profile").dataType == targetProfileType)
+ checkAnswer(
+ result,
+ Row(1, "Alice", Row("San Francisco", null), null, "new")
+ )
+ }
+ }
+}
diff --git
a/sql/pipelines/src/test/scala/org/apache/spark/sql/pipelines/autocdc/Scd1VersionMapSuite.scala
b/sql/pipelines/src/test/scala/org/apache/spark/sql/pipelines/autocdc/Scd1VersionMapSuite.scala
index eb2c774bf40a..50974963fad3 100644
---
a/sql/pipelines/src/test/scala/org/apache/spark/sql/pipelines/autocdc/Scd1VersionMapSuite.scala
+++
b/sql/pipelines/src/test/scala/org/apache/spark/sql/pipelines/autocdc/Scd1VersionMapSuite.scala
@@ -60,6 +60,7 @@ class Scd1VersionMapSuite extends QueryTest with
SharedSparkSession {
Scd1VersionMap.buildVersionMap(
schema = userDataSchema,
ignoreNullSelection = ignoreNullSelection,
+ omittedLeafPaths = Set.empty,
authorshipSequence = F.col("seq"),
sequencingType = IntegerType,
resolver = caseSensitiveResolution
@@ -89,6 +90,7 @@ class Scd1VersionMapSuite extends QueryTest with
SharedSparkSession {
Scd1VersionMap.buildVersionMap(
schema = userDataSchema,
ignoreNullSelection = ignoreNullSelection,
+ omittedLeafPaths = Set.empty,
authorshipSequence = F.col("seq"),
sequencingType = LongType,
resolver = caseSensitiveResolution
@@ -122,6 +124,7 @@ class Scd1VersionMapSuite extends QueryTest with
SharedSparkSession {
Scd1VersionMap.buildVersionMap(
schema = userDataSchema,
ignoreNullSelection = ignoreNullSelection,
+ omittedLeafPaths = Set.empty,
authorshipSequence = F.col("seq"),
sequencingType = LongType,
resolver = caseSensitiveResolution
@@ -156,6 +159,7 @@ class Scd1VersionMapSuite extends QueryTest with
SharedSparkSession {
Scd1VersionMap.buildVersionMap(
schema = userDataSchema,
ignoreNullSelection = ignoreNullSelection,
+ omittedLeafPaths = Set.empty,
authorshipSequence = F.col("seq"),
sequencingType = LongType,
resolver = caseSensitiveResolution
@@ -190,6 +194,7 @@ class Scd1VersionMapSuite extends QueryTest with
SharedSparkSession {
Scd1VersionMap.buildVersionMap(
schema = userDataSchema,
ignoreNullSelection = ignoreNullSelection,
+ omittedLeafPaths = Set.empty,
authorshipSequence = F.col("seq"),
sequencingType = LongType,
resolver = caseInsensitiveResolution
@@ -199,6 +204,37 @@ class Scd1VersionMapSuite extends QueryTest with
SharedSparkSession {
checkAnswer(result, Row(Map[String, Any](encodedPath("Value") -> null)))
}
+ test("buildVersionMap gives omitted leaves null entries inside and outside
the selection") {
+ val userDataSchema = new StructType()
+ .add("carried", StringType)
+ .add("omitted", StringType)
+ .add("profile", new StructType()
+ .add("carried", StringType)
+ .add("omitted", StringType))
+ val inputSchema = StructType(userDataSchema.fields :+ StructField("seq",
LongType))
+ val input = dataFrameOf(inputSchema)(Row(null, "ignored", Row("value",
"ignored"), 10L))
+ val ignoreNullSelection =
+ ColumnSelection.IncludeColumns(Seq(UnqualifiedColumnName("profile")))
+
+ val result = input.select(
+ Scd1VersionMap.buildVersionMap(
+ schema = userDataSchema,
+ ignoreNullSelection = ignoreNullSelection,
+ omittedLeafPaths = Set(Seq("omitted"), Seq("profile", "omitted")),
+ authorshipSequence = F.col("seq"),
+ sequencingType = LongType,
+ resolver = caseSensitiveResolution
+ )
+ )
+
+ checkAnswer(result, Row(Map[String, Any](
+ encodedPath("carried") -> 10L,
+ encodedPath("omitted") -> null,
+ encodedPath("profile", "carried") -> 10L,
+ encodedPath("profile", "omitted") -> null
+ )))
+ }
+
test("buildVersionMap produces a typed empty map for an empty schema") {
val input = dataFrameOf(new StructType().add("seq", LongType))(Row(10L))
@@ -206,6 +242,7 @@ class Scd1VersionMapSuite extends QueryTest with
SharedSparkSession {
Scd1VersionMap.buildVersionMap(
schema = new StructType(),
ignoreNullSelection = ColumnSelection.ExcludeColumns(Seq.empty),
+ omittedLeafPaths = Set.empty,
authorshipSequence = F.col("seq"),
sequencingType = LongType,
resolver = caseSensitiveResolution
@@ -229,6 +266,7 @@ class Scd1VersionMapSuite extends QueryTest with
SharedSparkSession {
Scd1VersionMap.buildVersionMap(
schema = userDataSchema,
ignoreNullSelection = ColumnSelection.ExcludeColumns(Seq.empty),
+ omittedLeafPaths = Set.empty,
authorshipSequence = F.col("seq"),
sequencingType = sequencingType,
resolver = caseSensitiveResolution
@@ -279,6 +317,7 @@ class Scd1VersionMapSuite extends QueryTest with
SharedSparkSession {
Scd1VersionMap.buildVersionMap(
schema = userDataSchema,
ignoreNullSelection = ColumnSelection.ExcludeColumns(Seq.empty),
+ omittedLeafPaths = Set.empty,
authorshipSequence = F.col("seq"),
sequencingType = LongType,
resolver = caseSensitiveResolution
@@ -302,6 +341,7 @@ class Scd1VersionMapSuite extends QueryTest with
SharedSparkSession {
Scd1VersionMap.buildVersionMap(
schema = userDataSchema,
ignoreNullSelection = ColumnSelection.ExcludeColumns(Seq.empty),
+ omittedLeafPaths = Set.empty,
authorshipSequence = F.col("seq"),
sequencingType = LongType,
resolver = caseSensitiveResolution
@@ -328,6 +368,7 @@ class Scd1VersionMapSuite extends QueryTest with
SharedSparkSession {
Scd1VersionMap.buildVersionMap(
schema = userDataSchema,
ignoreNullSelection = ignoreNullSelection,
+ omittedLeafPaths = Set.empty,
authorshipSequence = F.col("seq"),
sequencingType = LongType,
resolver = caseSensitiveResolution
@@ -358,6 +399,7 @@ class Scd1VersionMapSuite extends QueryTest with
SharedSparkSession {
Scd1VersionMap.buildVersionMap(
schema = userDataSchema,
ignoreNullSelection = ignoreNullSelection,
+ omittedLeafPaths = Set.empty,
authorshipSequence = F.col("seq"),
sequencingType = sequencingType,
resolver = caseSensitiveResolution
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]