manuzhang commented on code in PR #18775:
URL: https://github.com/apache/iceberg/pull/18775#discussion_r4779752893


##########
spark/v4.0/spark/src/test/java/org/apache/iceberg/spark/source/TestSparkReadMetrics.java:
##########
@@ -411,6 +429,62 @@ public void testReadMetricsForV2Table() throws 
NoSuchTableException {
             "skippedDeleteFiles", sqlMetric -> 
assertThat(sqlMetric.value()).isEqualTo(0));
   }
 
+  @Test
+  public void scanDurationAggregatedAcrossTasks() throws NoSuchTableException {
+    sql("CREATE TABLE %s (id BIGINT) USING iceberg", tableName);
+
+    spark.range(10000).coalesce(1).writeTo(tableName).append();
+    spark.range(10001, 20000).coalesce(1).writeTo(tableName).append();
+
+    // a tiny split size keeps the two files from being combined into one task
+    Dataset<Row> df =
+        spark.read().format("iceberg").option(SparkReadOptions.SPLIT_SIZE, 
"1").load(tableName);
+    assertThat(df.collectAsList()).hasSize(19999);
+
+    List<SparkPlan> sparkPlans =
+        
seqAsJavaListConverter(df.queryExecution().executedPlan().collectLeaves()).asJava();
+    assertThat(((BatchScanExec) 
sparkPlans.get(0)).inputRDD().getNumPartitions()).isEqualTo(2);
+    Map<String, SQLMetric> metricsMap =
+        
JavaConverters.mapAsJavaMapConverter(sparkPlans.get(0).metrics()).asJava();
+
+    // the driver-side accumulator sums TaskScanDuration across all tasks of 
the scan
+    long aggregatedNanos = metricsMap.get("scanDuration").value();
+    assertThat(aggregatedNanos).isGreaterThan(0);

Review Comment:
   what's this assert for?



##########
spark/v4.0/spark/src/test/java/org/apache/iceberg/spark/source/TestSparkReadMetrics.java:
##########
@@ -411,6 +429,62 @@ public void testReadMetricsForV2Table() throws 
NoSuchTableException {
             "skippedDeleteFiles", sqlMetric -> 
assertThat(sqlMetric.value()).isEqualTo(0));
   }
 
+  @Test
+  public void scanDurationAggregatedAcrossTasks() throws NoSuchTableException {
+    sql("CREATE TABLE %s (id BIGINT) USING iceberg", tableName);
+
+    spark.range(10000).coalesce(1).writeTo(tableName).append();
+    spark.range(10001, 20000).coalesce(1).writeTo(tableName).append();
+
+    // a tiny split size keeps the two files from being combined into one task
+    Dataset<Row> df =
+        spark.read().format("iceberg").option(SparkReadOptions.SPLIT_SIZE, 
"1").load(tableName);
+    assertThat(df.collectAsList()).hasSize(19999);
+
+    List<SparkPlan> sparkPlans =
+        
seqAsJavaListConverter(df.queryExecution().executedPlan().collectLeaves()).asJava();
+    assertThat(((BatchScanExec) 
sparkPlans.get(0)).inputRDD().getNumPartitions()).isEqualTo(2);
+    Map<String, SQLMetric> metricsMap =
+        
JavaConverters.mapAsJavaMapConverter(sparkPlans.get(0).metrics()).asJava();

Review Comment:
   how do we know the metrics are from multiple tasks?



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