venkata91 commented on code in PR #18775:
URL: https://github.com/apache/iceberg/pull/18775#discussion_r4780661151
##########
spark/v4.0/spark/src/test/java/org/apache/iceberg/spark/source/TestSparkReadMetrics.java:
##########
@@ -411,6 +429,59 @@ 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();
+
+ Dataset<Row> df = spark.sql(String.format("SELECT * FROM %s", tableName));
+ assertThat(df.collectAsList()).hasSize(19999);
+
+ List<SparkPlan> sparkPlans =
+
seqAsJavaListConverter(df.queryExecution().executedPlan().collectLeaves()).asJava();
+ 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();
Review Comment:
Good catch, they weren't. Iceberg combined the two small files into one
split, so the scan ran a single task that read both files. The test now reads
with `split-size` set to 1 so each file gets its own task. In 30dab2ad7 it also
checks that two tasks each reported a `scanDuration` and that the scan's value
is their sum. Without the split-size option it fails with `Expected size: 2 but
was: 1`.
##########
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:
Fair, the partition count only showed there were two tasks, not that both
fed the metric. 30dab2ad7 drops it. The test now listens for task-end events,
picks out each task's `scanDuration` update, asserts there are two and both are
positive, and checks the scan's `scanDuration` equals their sum.
##########
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:
It wasn't doing much. Any single task would also make the total positive. I
replaced it in 30dab2ad7 with the per-task check above, so the total is now
compared to the sum of the two task values.
--
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]