Skip to content

AlterTableSetPropertiesDeltaCommand

AlterTableSetPropertiesDeltaCommand is a transactional AlterDeltaTableCommand for SetProperty table changes (when altering a delta table).

AlterTableSetPropertiesDeltaCommand represents ALTER TABLE SET TBLPROPERTIES SQL command.

Creating Instance

AlterTableSetPropertiesDeltaCommand takes the following to be created:

AlterTableSetPropertiesDeltaCommand is created when:

  • DeltaCatalog is requested to alterTable (with SetProperty table changes)

Executing Command

run(
  sparkSession: SparkSession): Seq[Row]

run is part of the RunnableCommand (Spark SQL) abstraction.

Begin Transaction

run starts a transaction.

Update Metadata

run requests the transaction for the table metadata and does sanity check to prevent illegal changes (on reserved properties):

  • Throws AnalysisExceptions for the following:
  • Filters out comment property changes (as it is used later for the description)

run creates a new Metadata with the following:

run updates the metadata (of the transaction).

Commit Transaction

run commits the transaction with SET TBLPROPERTIES operation (with the given configuration) and no actions.

In the end, run returns an empty collection.

RunnableCommand

AlterTableSetPropertiesDeltaCommand is a LeafRunnableCommand (Spark SQL) logical operator.

IgnoreCachedData

AlterTableSetPropertiesDeltaCommand is a IgnoreCachedData (Spark SQL) logical operator.

Demo

sql("""
DROP TABLE IF EXISTS delta_demo;
""")
sql("""
CREATE TABLE delta_demo (id INT)
USING delta;
""")
sql("""
DESC HISTORY delta_demo;
""")
  .select('version, 'operation, 'operationParameters)
  .show(truncate = false)
+-------+------------+-----------------------------------------------------------------------------+
|version|operation   |operationParameters                                                          |
+-------+------------+-----------------------------------------------------------------------------+
|0      |CREATE TABLE|{isManaged -> true, description -> null, partitionBy -> [], properties -> {}}|
+-------+------------+-----------------------------------------------------------------------------+
sql("""
ALTER TABLE delta_demo
SET TBLPROPERTIES (delta.enableChangeDataFeed = true);
""")
sql("""
DESC HISTORY delta_demo;
""")
  .select('version, 'operation, 'operationParameters)
  .show(truncate = false)
+-------+-----------------+-----------------------------------------------------------------------------+
|version|operation        |operationParameters                                                          |
+-------+-----------------+-----------------------------------------------------------------------------+
|1      |SET TBLPROPERTIES|{properties -> {"delta.enableChangeDataFeed":"true"}}                        |
|0      |CREATE TABLE     |{isManaged -> true, description -> null, partitionBy -> [], properties -> {}}|
+-------+-----------------+-----------------------------------------------------------------------------+