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:
- DeltaTableV2
- Configuration (
Map[String, String])
AlterTableSetPropertiesDeltaCommand is created when:
DeltaCatalogis requested to alterTable (withSetPropertytable 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:delta.constraints.-prefixed properties (handled by ALTER TABLE ADD CONSTRAINT)locationprovider
- Filters out
commentproperty changes (as it is used later for the description)
run creates a new Metadata with the following:
- Overwrites description with
commentproperty if defined in the given configuration - Overwrites the current configuration of the delta table with the property changes
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 -> {}}|
+-------+-----------------+-----------------------------------------------------------------------------+