AnishMahto commented on code in PR #58645:
URL: https://github.com/apache/spark/pull/58645#discussion_r4020000818
##########
sql/pipelines/src/main/scala/org/apache/spark/sql/pipelines/autocdc/Scd2VersionMap.scala:
##########
@@ -77,15 +83,69 @@ private[pipelines] object Scd2VersionMap {
/**
* Schema of the version map: `Map(String, Boolean)`.
*
- * Keys are dot-delimited paths to *leaf* columns that received a null value
in their
- * corresponding upsert event (e.g. `"address.city"`, `` "`has space`.city"
``). Paths
- * must be formatted by
[[org.apache.spark.sql.catalyst.util.QuotingUtils.quoted]] to
- * ensure segments that need quoting are back-tick escaped.
+ * Keys are compact JSON arrays of the name parts of *leaf* columns that
received a null
+ * value in their upsert event (e.g. `["address","city"]`). Keeping
+ * name parts separate distinguishes a nested path from a column whose name
contains dots
+ * and keeps persisted keys independent of SQL identifier quoting rules.
Name parts use the
+ * persisted target schema's canonical spelling.
*
- * Values indicate authorship. I.e, `true` => authored-null, `false` =>
unauthored-null.
+ * Values indicate authorship: `true` means authored-null, `false` means
unauthored-null.
+ * Null values never appear in the map.
*
* Lack of entry in the map for a null-valued leaf column implies the column
was
* schema-evolved with an unauthored-null.
*/
def mapType: MapType = MapType(StringType, BooleanType, valueContainsNull =
false)
+
+ /** Encodes a leaf path as the compact JSON string persisted as its version
map key. */
+ private[autocdc] def encodePath(path: Seq[String]): String =
+ compact(JArray(path.map(JString(_)).toList))
+
+ /**
+ * Builds the ingest-time version map column for a microbatch. Each row's
map records which
+ * null leaves are authored vs declined, based on the active ignore-null
selection.
+ *
+ * @param schema The schema whose leaves the version map covers.
Null-authorship is tracked
+ * for every leaf column in this schema, as per the version map contract.
+ * @param ignoreNullSelection The ignore-null column selection this schema
is being ingested
+ * under.
+ * @param resolver Case-sensitivity resolver for column name matching.
+ * @return A [[Column]] of [[mapType]] schema.
+ */
+ def buildVersionMap(
+ schema: StructType,
+ ignoreNullSelection: ColumnSelection,
+ resolver: Resolver): Column = {
+ val ignoreNullColumns = ColumnSelection.applyToSchema(
+ schemaName = "ignoreNullSelection",
+ schema = schema,
+ columnSelection = Some(ignoreNullSelection),
+ resolver = resolver
+ )
+ val ignoreNullLeafPaths =
AutoCdcSchemaUtils.extractLeafPaths(ignoreNullColumns).toSet
+
+ // For each leaf, build a nullable struct (key, value). The struct is
non-null only when
+ // the leaf column's runtime value is null (meaning the leaf needs a
version map entry).
+ // The value is a non-nullable BooleanType literal indicating authorship:
true if the null
+ // is authored, false if declined.
Review Comment:
Rephrased as "unauthored" here and in other places, let me know if it still
doesn't read intuitively.
--
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]