suhuruli commented on code in PR #60462:
URL: https://github.com/apache/spark/pull/60462#discussion_r4646700041
##########
python/pyspark/pipelines/api.py:
##########
@@ -152,7 +152,9 @@ def table(
These confs will be set when the query for the dataset is executed and
they can override \
confs set for the pipeline or on the cluster.
:param table_properties: A dict where the keys are the property names and
the values are the \
- property values. These properties will be set on the table.
+ property values. These properties will be set on the table. A property
removed from \
Review Comment:
On a second look your sentence reads better than mine, so the
`table_properties` docstrings now use it: "If the table already exists and has
a property that an earlier run declared in this dict and that is no longer in
it, that property is removed from the table (see the migration guide for
exceptions)." I added one qualifier, "that an earlier run declared in this
dict", because a property the definition never declared, such as one set by the
catalog or with `ALTER TABLE`, is not removed. All four copies are changed, the
three in `python/pyspark/pipelines/api.py` and the one on `Table` in
`python/pyspark/pipelines/output.py`.
##########
sql/pipelines/src/test/scala/org/apache/spark/sql/pipelines/graph/MaterializeTablesSuite.scala:
##########
@@ -1610,17 +1640,340 @@ abstract class MaterializeTablesSuite extends
BaseCoreExecutionTest {
}
}
- test("re-materializing with a dropped property neither removes it nor issues
an alterTable") {
+ test("SPARK-57670: re-materializing with a dropped property removes it") {
withRecordingCatalog {
val schema = new StructType().add("id", IntegerType)
- // This test locks in the current buggy behavior where dropped
properties do not materialize
- // against the catalog table entity. See SPARK-57670.
materializeStreamingTable("t", schema, Map("p.keep" -> "v", "p.stale" ->
"old"))
assert(recordingCatalog.recordedAlters.isEmpty)
+ // A property the pipeline never declared, e.g. one managed by the
catalog.
+ spark.sql(
+ s"ALTER TABLE $recordingCatalogName.$recordingNamespace.t " +
+ "SET TBLPROPERTIES ('p.external' = 'e')")
+ recordingCatalog.recordedAlters.clear()
+
materializeStreamingTable("t", schema, Map("p.keep" -> "v"))
+ assert(recordingCatalog.recordedAlters.size == 1)
+ val changes = recordingCatalog.recordedAlters.flatten
+ assert(changes.collect { case r: TableChange.RemoveProperty =>
r.property() } ==
+ Seq("p.stale"))
+
+ val props = loadTableFromRecordingCatalog("t").properties()
+ assert(!props.containsKey("p.stale"))
+ assert(props.get("p.keep") == "v")
+ assert(props.get("p.external") == "e")
+ assert(declaredKeysRecord("t").contains("""["p.keep"]"""))
Review Comment:
Added after all, since it states the intent directly even though the line
above already implies it. The test "SPARK-57670: re-materializing with a
dropped property removes it" in `MaterializeTablesSuite` now also asserts
`!declaredKeysRecord("t").exists(_.contains("p.external"))`. I used the
`exists(_.contains(...))` form because `declaredKeysRecord` returns an `Option`
holding the whole JSON array, and `contains` on an `Option` is equality, so the
suggested form would only fail for a record that is exactly `["p.external"]`.
--
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]