venkata91 commented on code in PR #18775:
URL: https://github.com/apache/iceberg/pull/18775#discussion_r4794167013
##########
spark/v4.0/spark/src/test/java/org/apache/iceberg/spark/source/TestSparkReadMetrics.java:
##########
@@ -411,6 +433,84 @@ public void testReadMetricsForV2Table() throws
NoSuchTableException {
"skippedDeleteFiles", sqlMetric ->
assertThat(sqlMetric.value()).isEqualTo(0));
}
+ @Test
+ public void scanDurationAggregatedAcrossTasks() throws NoSuchTableException,
TimeoutException {
+ 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();
+
+ List<SparkListenerTaskEnd> taskEnds =
Collections.synchronizedList(Lists.newArrayList());
+ SparkListener listener =
+ new SparkListener() {
+ @Override
+ public void onTaskEnd(SparkListenerTaskEnd taskEnd) {
+ taskEnds.add(taskEnd);
+ }
+ };
+
+ // 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);
+ spark.sparkContext().addSparkListener(listener);
+ try {
+ assertThat(df.collectAsList()).hasSize(19999);
+ spark.sparkContext().listenerBus().waitUntilEmpty();
+ } finally {
+ spark.sparkContext().removeSparkListener(listener);
+ }
+
+ List<SparkPlan> sparkPlans =
+
seqAsJavaListConverter(df.queryExecution().executedPlan().collectLeaves()).asJava();
+ Map<String, SQLMetric> metricsMap =
+
JavaConverters.mapAsJavaMapConverter(sparkPlans.get(0).metrics()).asJava();
+ SQLMetric scanDuration = metricsMap.get("scanDuration");
+
+ List<Long> taskNanos =
+ taskEnds.stream()
+ .flatMap(
+ taskEnd ->
+
seqAsJavaListConverter(taskEnd.taskInfo().accumulables()).asJava().stream())
+ .filter(accumulable -> accumulable.id() == scanDuration.id())
+ .map(accumulable -> (Long) accumulable.update().get())
+ .collect(Collectors.toList());
+ assertThat(taskNanos).hasSize(2).allSatisfy(nanos ->
assertThat(nanos).isPositive());
+ assertThat(scanDuration.value()).isEqualTo(taskNanos.get(0) +
taskNanos.get(1));
+
+ // the value the UI renders, read back from the SQL status store
+ assertThat(lastExecutedMetricValue(spark, new
ScanDuration().description()))
Review Comment:
No, `TestScanDuration` already covers the formatting with fixed values, and
here it only repeats that with a regex. I'll remove it.
--
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]