rdblue commented on a change in pull request #2165:
URL: https://github.com/apache/iceberg/pull/2165#discussion_r566252086



##########
File path: 
spark3-extensions/src/main/scala/org/apache/spark/sql/execution/datasources/v2/SetWriteDistributionAndOrderingExec.scala
##########
@@ -19,35 +19,48 @@
 
 package org.apache.spark.sql.execution.datasources.v2
 
+import java.util.Locale
+import org.apache.iceberg.DistributionMode
 import org.apache.iceberg.NullOrder
 import org.apache.iceberg.SortDirection
+import org.apache.iceberg.TableProperties.WRITE_DISTRIBUTION_MODE
 import org.apache.iceberg.expressions.Term
 import org.apache.iceberg.spark.source.SparkTable
 import org.apache.spark.sql.catalyst.InternalRow
 import org.apache.spark.sql.catalyst.expressions.Attribute
-import org.apache.spark.sql.connector.catalog.Identifier
-import org.apache.spark.sql.connector.catalog.TableCatalog
+import org.apache.spark.sql.connector.catalog.{Identifier, TableCatalog}
+import org.apache.spark.sql.connector.catalog.CatalogV2Implicits
 
-case class SetWriteOrderExec(
+case class SetWriteDistributionAndOrderingExec(
     catalog: TableCatalog,
     ident: Identifier,
-    sortOrder: Array[(Term, SortDirection, NullOrder)]) extends V2CommandExec {
-  import org.apache.spark.sql.connector.catalog.CatalogV2Implicits._
+    distributionMode: DistributionMode,
+    ordering: Seq[(Term, SortDirection, NullOrder)]) extends V2CommandExec {
+
+  import CatalogV2Implicits._
 
   override lazy val output: Seq[Attribute] = Nil
 
   override protected def run(): Seq[InternalRow] = {
     catalog.loadTable(ident) match {
       case iceberg: SparkTable =>
-        val orderBuilder = iceberg.table.replaceSortOrder()
-        sortOrder.foreach {
+        val txn = iceberg.table.newTransaction()
+
+        val orderBuilder = txn.replaceSortOrder()
+        ordering.foreach {
           case (term, SortDirection.ASC, nullOrder) =>
             orderBuilder.asc(term, nullOrder)
           case (term, SortDirection.DESC, nullOrder) =>
             orderBuilder.desc(term, nullOrder)
         }
         orderBuilder.commit()
 
+        txn.updateProperties()
+          .set(WRITE_DISTRIBUTION_MODE, 
distributionMode.toString.toLowerCase(Locale.ROOT))

Review comment:
       Doesn't distribution mode have a `name` method?




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to