tmnd1991 commented on code in PR #9233:
URL: https://github.com/apache/iceberg/pull/9233#discussion_r1434085055


##########
spark/v3.5/spark-extensions/src/test/java/org/apache/iceberg/spark/extensions/TestSPJWithBucketing.java:
##########
@@ -0,0 +1,219 @@
+/*
+ * 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.extensions;
+
+import java.util.Map;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Consumer;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.spark.SparkCatalogConfig;
+import org.apache.iceberg.spark.SparkSQLProperties;
+import org.apache.spark.scheduler.SparkListener;
+import org.apache.spark.scheduler.SparkListenerTaskEnd;
+import org.apache.spark.sql.Dataset;
+import org.apache.spark.sql.Row;
+import org.apache.spark.sql.SparkSession;
+import org.apache.spark.sql.internal.SQLConf;
+import org.assertj.core.api.Assertions;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runners.Parameterized;
+
+public class TestSPJWithBucketing extends SparkExtensionsTestBase {
+
+  @Test
+  public void testMergeSPJwithCondition() {
+    testWithCondition(
+        "  AND ("
+            + "(t.year_month='202306' AND t.day='01' AND 
testhive.system.bucket(4, t.id) = 0) OR\n"
+            + "(t.year_month='202306' AND t.day='01' AND 
testhive.system.bucket(4, t.id) = 1) OR\n"
+            + "(t.year_month='202306' AND t.day='02' AND 
testhive.system.bucket(4, t.id) = 0) OR\n"
+            + "(t.year_month='202307' AND t.day='01' AND 
testhive.system.bucket(4, t.id) = 3)\n"
+            + ")");
+  }
+
+  @Test
+  public void testMergeSPJwithoutCondition() {
+    testWithCondition("");
+  }
+
+  private void testWithCondition(String condition) {
+    createPartitionedTable(spark, targetTableName);
+    insertRecords(spark, targetTableName);
+    createPartitionedTable(spark, sourceTableName);
+    insertRecordsToUpdate(spark, sourceTableName);
+    int tasks =
+        executeAndCountTasks(
+            spark,
+            (s) ->
+                withSQLConf(
+                    ENABLED_SPJ_SQL_CONF,
+                    () ->
+                        // id STRING, year_month STRING, day STRING, data 
STRING
+                        sql(
+                            s,
+                            "MERGE INTO %s t USING (SELECT * FROM %s) s \n"
+                                + "ON t.id = s.id AND t.year_month = 
s.year_month AND t.day = s.day\n"
+                                + "%s\n"
+                                + "WHEN MATCHED THEN UPDATE SET\n"
+                                + "  t.data = s.data\n"
+                                + "WHEN NOT MATCHED THEN INSERT *",
+                            targetTableName,
+                            sourceTableName,
+                            condition)));
+    long affectedPartitions =
+        sql(spark, "SELECT DISTINCT(partition) FROM %s.files", 
sourceTableName).count();
+    int shufflePartitions = 
Integer.parseInt(spark.conf().get("spark.sql.shuffle.partitions"));
+    Assertions.assertThat(tasks).isEqualTo(affectedPartitions * 2 + 
shufflePartitions);

Review Comment:
   forgot to add: if I add the condition (after the patch to 
ReplaceStaticInvoke) it actually prunes the partitions (and tasks) in 3.4 (but 
not in 3.5).
   
   Another thing: I know that the tasks that get created are actually very fast 
(I would say almost skipped) but the thing is that if the target table has 
400.000 partitions, even the scheduling of those no-op tasks kills the 
performance of my job



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to