suhuruli commented on code in PR #60462:
URL: https://github.com/apache/spark/pull/60462#discussion_r4620632959
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/V2SessionCatalog.scala:
##########
@@ -294,8 +294,16 @@ class V2SessionCatalog(catalog: SessionCatalog)
val properties =
CatalogV2Util.applyPropertiesChanges(catalogTable.properties, changes)
val schema = CatalogV2Util.applySchemaChanges(
catalogTable.schema, changes, catalogTable.provider, "ALTER TABLE")
- val comment = properties.get(TableCatalog.PROP_COMMENT)
- val collation = properties.get(TableCatalog.PROP_COLLATION)
+ // The comment and collation live in dedicated fields of the catalog table
and are not mirrored
+ // in its properties: the in-memory catalog drops the `comment` key from
the stored properties,
+ // the Hive catalog moves `comment` and `collation` out of the table
parameters when it reads a
+ // table, and a table created by DDL never had them there. Keep the
existing values unless the
+ // changes set or remove the corresponding property, as the v1 SET/UNSET
TBLPROPERTIES commands
+ // do.
+ val comment = properties.get(TableCatalog.PROP_COMMENT).orElse(
+ if (removesProperty(changes, TableCatalog.PROP_COMMENT)) None else
catalogTable.comment)
+ val collation = properties.get(TableCatalog.PROP_COLLATION).orElse(
+ if (removesProperty(changes, TableCatalog.PROP_COLLATION)) None else
catalogTable.collation)
Review Comment:
Done. I moved the session-catalog comment and collation fix out of this PR
into its own PR, "[SPARK-62033][SQL] Keep session-catalog table comment and
default collation across ALTER TABLE (#60680)", together with its SQL-level
tests and your shorter comment wording. This branch now leaves
`V2SessionCatalog.scala`, `V2SessionCatalogSuite.scala` and
`HiveDDLSuite.scala` as they are on master. This PR depends on that one for two
comment tests, "a dropped comment declared as a table property is removed on
the session catalog" and "table comments survive the declared-keys bootstrap
and removal alters", which fail on this branch until it merges. I will update
this PR on top of it once it merges.
##########
sql/pipelines/src/main/scala/org/apache/spark/sql/pipelines/graph/PipelinesTableProperties.scala:
##########
@@ -37,6 +37,33 @@ object PipelinesTableProperties {
val resetAllowed: PipelineTableProperty[Boolean] =
buildProp("pipelines.reset.allowed", default = true)
+ /**
+ * Internal table property recording, as a sorted JSON string array (see
+ * [[JsonStringArrayCodec]]), the keys of the table properties declared in
the dataset definition
+ * (SQL `TBLPROPERTIES`, Python `table_properties`) as of the latest
materialization.
+ *
+ * `DatasetManager` writes it, through `resolveTableProperties`, only when
the definition declares
+ * at least one table property, and never for a table in a JDBC catalog,
which appends every
+ * non-reserved table property to its `CREATE TABLE` statement as a DDL
option. It covers those
+ * declared keys, not the `comment` and `provider` entries derived from the
dataset's comment and
+ * format. On the next materialization, `evolveTable` removes a recorded key
when the resolved
+ * table properties of the definition no longer contain it, it is still on
the table, and it is
+ * not a reserved catalog property other than `comment` (the keys the SQL
parser rejects in
+ * `TBLPROPERTIES`). The resolved properties include the `comment` and
`provider` derived from the
+ * definition, so a comment moved from the table properties to the dataset's
comment field stays.
+ * A dropped reserved key such as `owner`, which Python `table_properties`
passes through, is
+ * recorded but never removed. Ownership follows declaration: a key is
removable once a definition
+ * declared it, even if the catalog had already set it to the same value.
Properties the
+ * definition never declared, e.g. catalog-managed ones, are never removed.
A table without the
+ * record, or with one that is not a JSON string array, has nothing removed.
The record itself is
+ * removed once the definition declares no table property, whether or not
the keys it listed are
+ * removed with it. Auxiliary tables never carry it.
+ *
+ * This key is not registered as a user-settable property, so
[[validateAndCanonicalize]] drops
+ * it if a user declares it.
+ */
+ val declaredPropertyKeys: String = s"${pipelinesPrefix}declaredPropertyKeys"
Review Comment:
The name stays `pipelines.declaredPropertyKeys`. I added a section header in
`PipelinesTableProperties.scala` above its Scaladoc that separates it from the
user-settable properties: internal keys are written by the pipeline, are not
user-settable, and `validateAndCanonicalize` drops a user declaration of them.
That last point was already true for this key, so I removed the same sentence
from the end of the Scaladoc to state it once.
##########
sql/pipelines/src/main/scala/org/apache/spark/sql/pipelines/graph/DatasetManager.scala:
##########
@@ -694,31 +705,73 @@ object DatasetManager extends Logging {
val existingProperties = existingTable.properties()
- // TODO (SPARK-57670): Property removal is intentionally not handled here:
a property dropped
- // from the table definition between runs is left in place rather than
actually removed from the
- // corresponding catalog table entry. Removing it reliably is hard because
we cannot distinguish
- // a user-declared property the user dropped from a catalog/engine-managed
property (e.g. the
- // non-reserved `clusteringColumns`, or arbitrary catalog-internal keys)
that must never be
- // removed, and there is no record of which keys the pipeline previously
set.
+ // Property removal is driven by the declared-keys record a previous
materialization left on
+ // the table (see PipelinesTableProperties.declaredPropertyKeys). A
recorded key is removed when
+ // all of these hold:
+ // - `properties` no longer contains it, i.e. the definition dropped it;
+ // - it is still present on the table;
+ // - it is not a reserved catalog property other than `comment` (see
+ // `nonRemovableReservedProperties`).
+ // Ownership follows declaration, not who first set the property: a key a
definition declared is
+ // removable once dropped, even if the catalog had already set it to the
same value and no
+ // SetProperty was ever issued for it. Every property outside the record
may be catalog-managed
+ // (e.g. the non-reserved `clusteringColumns`, or arbitrary
catalog-internal keys) or set
+ // outside the pipeline, and is left alone. A table without a record (e.g.
one materialized
+ // before the record was introduced), or whose record is not a JSON string
array, has nothing
+ // removed. The record itself is removed once `properties` no longer
carries one, i.e. the
+ // definition no longer declares any table property. Only graph datasets
pass the record in
+ // `properties`; auxiliary tables never carry it (see
`materializeAuxiliaryTable`).
+ val recordKey = PipelinesTableProperties.declaredPropertyKeys
+ val previouslyDeclaredKeys = Option(existingProperties.get(recordKey))
+ .flatMap(JsonStringArrayCodec.parse)
+ .getOrElse(Seq.empty)
+ .filterNot(nonRemovableReservedProperties.contains)
+ val propertiesToRemove = (previouslyDeclaredKeys :+
recordKey).distinct.collect {
Review Comment:
Thanks, fixed as you suggested. `evolveTable` now filters the record key out
of `previouslyDeclaredKeys`, so a record that lists its own key gives a single
removal of the record, and the INFO line names only the user keys. The removals
keep their order, user keys first and the record last. The new test
"SPARK-57670: a declared-keys record that lists its own key removes the record
once" in `MaterializeTablesSuite` asserts the removal list and the INFO line,
and it fails without the filter.
--
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]