aokolnychyi commented on code in PR #7637:
URL: https://github.com/apache/iceberg/pull/7637#discussion_r1199420860


##########
spark/v3.4/spark/src/main/java/org/apache/iceberg/spark/SparkWriteUtil.java:
##########
@@ -0,0 +1,247 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.spark;
+
+import static 
org.apache.spark.sql.connector.write.RowLevelOperation.Command.DELETE;
+import static 
org.apache.spark.sql.connector.write.RowLevelOperation.Command.MERGE;
+import static 
org.apache.spark.sql.connector.write.RowLevelOperation.Command.UPDATE;
+
+import java.util.Arrays;
+import org.apache.iceberg.DistributionMode;
+import org.apache.iceberg.MetadataColumns;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.relocated.com.google.common.collect.ObjectArrays;
+import org.apache.iceberg.types.Types;
+import org.apache.iceberg.util.SortOrderUtil;
+import org.apache.spark.sql.connector.distributions.Distribution;
+import org.apache.spark.sql.connector.distributions.Distributions;
+import org.apache.spark.sql.connector.expressions.Expression;
+import org.apache.spark.sql.connector.expressions.Expressions;
+import org.apache.spark.sql.connector.expressions.NamedReference;
+import org.apache.spark.sql.connector.expressions.SortDirection;
+import org.apache.spark.sql.connector.expressions.SortOrder;
+import org.apache.spark.sql.connector.write.RowLevelOperation.Command;
+
+/**
+ * A utility that contains helper methods for working with Spark writes.
+ *
+ * <p>Note it is an evolving internal API that is subject to change even in 
minor releases.
+ */
+public class SparkWriteUtil {
+
+  private static final NamedReference SPEC_ID = ref(MetadataColumns.SPEC_ID);
+  private static final NamedReference PARTITION = 
ref(MetadataColumns.PARTITION_COLUMN_NAME);
+  private static final NamedReference FILE_PATH = 
ref(MetadataColumns.FILE_PATH);
+  private static final NamedReference ROW_POSITION = 
ref(MetadataColumns.ROW_POSITION);
+
+  private static final Expression[] FILE_CLUSTERING = clusterBy(FILE_PATH);
+  private static final Expression[] SPEC_ID_PARTITION_CLUSTERING = 
clusterBy(SPEC_ID, PARTITION);
+  private static final Expression[] SPEC_ID_PARTITION_FILE_CLUSTERING =
+      clusterBy(SPEC_ID, PARTITION, FILE_PATH);
+
+  private static final SortOrder[] EMPTY_ORDERING = new SortOrder[0];
+  private static final SortOrder[] EXISTING_FILE_ORDERING = orderBy(FILE_PATH, 
ROW_POSITION);
+  private static final SortOrder[] SPEC_ID_PARTITION_ORDERING = 
orderBy(SPEC_ID, PARTITION);
+  private static final SortOrder[] SPEC_ID_PARTITION_FILE_ORDERING =
+      orderBy(SPEC_ID, PARTITION, FILE_PATH);
+  private static final SortOrder[] POSITION_DELETE_ORDERING =
+      orderBy(SPEC_ID, PARTITION, FILE_PATH, ROW_POSITION);
+
+  private SparkWriteUtil() {}

Review Comment:
   This utility would also hold the logic to compute the advisory partition 
size. It is similar to the old distribution and ordering utility but uses a 
shorter name/syntax and builds  `SparkWriteRequirements`.



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

Reply via email to