venkata91 commented on code in PR #19298:
URL: https://github.com/apache/iceberg/pull/19298#discussion_r4795558487
##########
spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/source/BaseBatchReader.java:
##########
@@ -62,6 +62,11 @@ abstract class BaseBatchReader<T extends ScanTask> extends
BaseReader<ColumnarBa
this.orcConf = orcConf;
}
+ @Override
+ protected boolean timeEachCall() {
Review Comment:
Good catch. `TestBaseReader` now has a reader that extends `BaseBatchReader`
and pauses inside each batch. It checks that the duration covers both batches
and leaves out the pause between calls. Without the override, the batch path
samples, and the test fails.
##########
spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/source/BaseReader.java:
##########
@@ -149,9 +168,11 @@ public boolean next() throws IOException {
} else if (tasks.hasNext()) {
this.currentIterator.close();
this.currentTask = tasks.next();
+ scanTimer.start();
Review Comment:
Thanks for tracing this. With sampled per-call timing, the readers' timed
windows can't overlap on one thread. So the k-way merge sum stays within wall
time, and the default `mergeWith` is right again.
##########
spark/v4.1/spark/src/test/java/org/apache/iceberg/spark/source/TestSparkReadMetrics.java:
##########
@@ -420,23 +425,48 @@ public void testReadMetricsForV2Table() throws
NoSuchTableException {
}
@Test
- public void scanDurationAggregatedAcrossTasks() throws NoSuchTableException {
+ 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();
- Dataset<Row> df = spark.sql(String.format("SELECT * FROM %s", tableName));
- assertThat(df.collectAsList()).hasSize(19999);
+ 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);
Review Comment:
Agreed. `scanDurationAggregatedAcrossTasksForNonVectorizedRead` runs the
same check with `read.parquet.vectorization.enabled=false`. It also asserts
that the scan isn't columnar, so it really goes through `RowDataReader`.
##########
spark/v4.1/spark/src/test/java/org/apache/iceberg/spark/source/TestMergingSortedRowDataReader.java:
##########
@@ -533,6 +533,33 @@ void metricsReportTasksAndDeletes() throws IOException {
}
}
+ @Test
+ void scanDurationDoesNotCountConcurrentlyOpenFilesTwice()
+ throws IOException, InterruptedException {
+ DataFile file1 = writeDataFile(record(1, "a"), record(3, "c"));
+ DataFile file2 = writeDataFile(record(2, "b"), record(4, "d"));
+
+ table.newAppend().appendFile(file1).appendFile(file2).commit();
+
+ BaseScanTaskGroup<FileScanTask> taskGroup = new
BaseScanTaskGroup<>(planFiles(table));
+ long start = System.nanoTime();
+ try (MergingSortedRowDataReader reader =
+ new MergingSortedRowDataReader(table, table.io(), taskGroup,
table.schema(), true, false)) {
+ while (reader.next()) {
+ // keep both files open long enough that summing their read windows
would be visible
+ Thread.sleep(5);
Review Comment:
With sampled timing the 4.1 merging reader goes back to summing each file's
value, which is correct when the timed windows can't overlap. So I removed this
test along with the change it covered.
##########
spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/source/MergingSortedRowDataReader.java:
##########
@@ -132,6 +133,8 @@ class MergingSortedRowDataReader implements
PartitionReader<InternalRow> {
UnsafeProjection deepCopyProjection =
UnsafeProjection.create(SparkSchemaUtil.convert(mergeReadSchema));
+ // timed here rather than summed per file, as all files are open for the
whole merge
Review Comment:
That comment went away with the timer. The 4.1 reader sums per-file values
again, so #19116 can keep per-file summing for 4.2 as it is.
--
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]