From b472d4ea22cd19361bdc3d07cda81fd03e52dc08 Mon Sep 17 00:00:00 2001 From: Jiaheng Tang Date: Fri, 3 May 2024 10:37:46 -0700 Subject: [PATCH] [Example] Update clustering example for 3.2 (#2991) #### Which Delta project/connector is this regarding? - [ ] Spark - [ ] Standalone - [ ] Flink - [ ] Kernel - [x] Other (Example) ## Description Update clustering example for delta 3.2 ## How was this patch tested? Manually ran the example ``` python3 run-integration-tests.py --use-local ``` ## Does this PR introduce _any_ user-facing changes? No --- .../src/main/scala/example/Clustering.scala | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/examples/scala/src/main/scala/example/Clustering.scala b/examples/scala/src/main/scala/example/Clustering.scala index 12ffafee19f..5c59e16e172 100644 --- a/examples/scala/src/main/scala/example/Clustering.scala +++ b/examples/scala/src/main/scala/example/Clustering.scala @@ -15,6 +15,8 @@ */ package example +import io.delta.tables.DeltaTable + import org.apache.spark.sql.SparkSession object Clustering { @@ -51,6 +53,29 @@ object Clustering { // Optimize the table println("Optimize the table") deltaSpark.sql(s"OPTIMIZE $tableName") + + // Change the clustering columns + println("Change the clustering columns") + deltaSpark.sql( + s"""ALTER TABLE $tableName CLUSTER BY (col2, col1)""".stripMargin) + + + // Check the clustering columns + println("Check the clustering columns") + deltaSpark.sql(s"DESCRIBE DETAIL $tableName").show(false) + } finally { + // Cleanup + deltaSpark.sql(s"DROP TABLE IF EXISTS $tableName") + } + + // DeltaTable clusterBy Scala API + try { + val table = io.delta.tables.DeltaTable.create() + .tableName(tableName) + .addColumn("col1", "INT") + .addColumn("col2", "STRING") + .clusterBy("col1", "col2") + .execute() } finally { // Cleanup deltaSpark.sql(s"DROP TABLE IF EXISTS $tableName")