venkata91 opened a new pull request, #19088: URL: https://github.com/apache/iceberg/pull/19088
## Intent Address https://github.com/apache/iceberg/pull/17562#issuecomment-7069609240 by backporting the scanDuration metric to Spark 4.0 and 3.5. This task is the Spark 3.5 backport. Base it on main rather than stacking it on the open read-metrics backport PRs. Context: PR #17562 ("Spark 4.1: Add per-task scanDuration metric", merged as commit cbfabba93) added a `scanDuration` custom read metric to Spark 4.1: the wall time a task spends in `BaseReader.next()`, covering split open and iteration, accumulated in a `finally` so a failing task still reports it. `TaskScanDuration` is reported from `BatchDataReader` and `RowDataReader` and aggregated by `ScanDuration`, mirroring the `TotalPlanningDuration` pair. It is in nanoseconds and the aggregate renders as `total (min, med, max)`. The PR said "Happy to backport to 4.0 and 3.5 in a follow-up." Reviewer gerashegalov replied: "Thank you for the ScanDuration metric. We are interested in seeing backported within 1.13 across all Spark shims". Spark 4.1 (#17562) and 4.2 (#18751) already have it, while spark/v4.0 and spark/v3.5 do not. ## What Changed - Backports the Spark 4.1 `scanDuration` custom read metric (#17562) to `spark/v3.5`. `BaseReader.next()` now adds its wall time in nanoseconds (split open plus iteration) to a running total. The update happens in a `finally` block, so a failing task still reports its time. - `BatchDataReader` and `RowDataReader` report the per-task value as `TaskScanDuration`. `SparkScan` registers the new `ScanDuration` aggregate, which renders as `total (min, med, max)` in readable units (ns, us, ms or s) and sorts a copy of the task values instead of the array Spark passes in. - Adds `TestScanDuration` unit tests (aggregation, no tasks, stragglers, input not mutated, locale independence) and two `TestSparkReadMetrics` cases, one covering vectorized and one covering non-vectorized reads. ## Risk Assessment ✅ Low: The diff is a line-for-line port of the merged Spark 4.1 change (cbfabba93), based on main. It covers both 3.5 readers that report task metrics (BatchDataReader, RowDataReader), and the test helper import already exists in 3.5. ## Testing Ran the targeted Spark 3.5 read-metrics tests against a real local Spark 3.5 session with a Hadoop catalog. All 8 TestSparkReadMetrics tests passed, including the 2 new scanDuration tests: one checks the cross-task total and the UI value, the other the non-vectorized path. All 5 TestScanDuration formatting tests passed. The metric classes are also identical to Spark 4.1. The case where a task fails mid-read and still reports its time was not exercised by any test run. - Live validation: ✅ go - 4 of 4 scenarios driven live against the product | Scenario | Result | Live | Evidence | | --- | --- | --- | --- | | Vectorized SELECT over a 2-file Iceberg table in local Spark 3.5 reports a summed scanDuration > 0, and the UI shows it as 'total (min, med, max)' with time units | ✅ pass | live | TestSparkReadMetrics.scanDurationAggregatedAcrossTasks in TEST-org.apache.iceberg.spark.source.TestSparkReadMetrics.xml | | Non-vectorized (RowDataReader) SELECT reports scanDuration > 0 on a confirmed non-columnar plan | ✅ pass | live | TestSparkReadMetrics.scanDurationForNonVectorizedRead | | Existing data and delete scan queries also report scanDuration > 0 alongside the other read metrics | ✅ pass | live | Existing TestSparkReadMetrics tests (8/8 passed) | | Aggregated nanosecond values format as 'total (min, med, max)' with readable units, the same as Spark 4.1 | ✅ pass | live | TestScanDuration (5/5 passed); class files identical to spark/v4.1 | <details> <summary>Evidence: Gradle test log</summary> ```text % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 100 43764 100 43764 0 0 153k 0 --:--:-- --:--:-- --:--:-- 154k Initialized native services in: ~/.gradle/native Initialized jansi services in: ~/.gradle/native The client will now receive all logging from the daemon (pid: 2764090). The daemon log file: ~/.gradle/daemon/8.14.6/daemon-2764090.out.log Starting 3rd build in daemon [uptime: 6 mins 53.058 secs, performance: 100%, GC rate: 0.00/s, heap usage: 0% of 1.5 GiB] Using 15 worker leases. Configuration on demand is an incubating feature. Not watching {run-worktree} since the file system is not supported Watching the file system is configured to be enabled if available File system watching is active Starting Build Invalidating in-memory cache of ~/.gradle/caches/journal-1/file-access.bin Settings evaluated using settings file '{run-worktree}/settings.gradle'. Using local directory build cache for the root build (location = ~/.gradle/caches/build-cache-1, remove unused entries = after 7 days). Projects loaded. Root project using build file '{run-worktree}/build.gradle'. Included projects: [root project 'iceberg', project ':iceberg-aliyun', project ':iceberg-api', project ':iceberg-arrow', project ':iceberg-aws', project ':iceberg-aws-bundle', project ':iceberg-azure', project ':iceberg-azure-bundle', project ':iceberg-bigquery', project ':iceberg-bom', project ':iceberg-bundled-guava', project ':iceberg-common', project ':iceberg-core', project ':iceberg-data', project ':iceberg-dell', project ':iceberg-delta-lake', project ':iceberg-flink', project ':iceberg-gcp', project ':iceberg-gcp-bundle', project ':iceberg-hive-metastore', project ':iceberg-kafka-connect', project ':iceberg-mr', project ':iceberg-nessie', project ':iceberg-open-api', project ':iceberg-orc', project ':iceberg-parquet', project ':iceberg-snowflake', project ':iceberg-spark', project ':iceberg-flink:iceberg-flink-1.20', project ':iceberg-flink:iceberg-flink-2.2', project ':iceberg-flink:iceberg-flink-2.3', project ':iceberg-flink:iceberg-flink-runtime-1.20', project ':iceberg -flink:iceberg-flink-runtime-2.2', project ':iceberg-flink:iceberg-flink-runtime-2.3', project ':iceberg-kafka-connect:iceberg-kafka-connect', project ':iceberg-kafka-connect:iceberg-kafka-connect-events', project ':iceberg-kafka-connect:iceberg-kafka-connect-runtime', project ':iceberg-kafka-connect:iceberg-kafka-connect-transforms', project ':iceberg-spark:iceberg-spark-3.5_2.12', project ':iceberg-spark:iceberg-spark-extensions-3.5_2.12', project ':iceberg-spark:iceberg-spark-runtime-3.5_2.12'] Task path ':iceberg-spark:iceberg-spark-3.5_2.12:test' matched project ':iceberg-spark:iceberg-spark-3.5_2.12' > Configure project : Evaluating root project 'iceberg' using build file '{run-worktree}/build.gradle'. Starting process 'command 'git''. Working directory: {run-worktree} Command: git describe --tags --always --first-parent --abbrev=7 --match=apache-iceberg-* HEAD Successfully started process 'command 'git'' Starting process 'command 'git''. Working directory: {run-worktree} Command: git status --porcelain Successfully started process 'command 'git'' Generating iceberg-build.properties from git Starting process 'command 'git''. Working directory: {run-worktree} Command: git branch --show-current Successfully started process 'command 'git'' > Configure project :iceberg-spark Evaluating project ':iceberg-spark' using build file '{run-worktree}/spark/build.gradle'. > Configure project :iceberg-spark:iceberg-spark-3.5_2.12 Evaluating project ':iceberg-spark:iceberg-spark-3.5_2.12' using build file '{run-worktree}/spark/v3.5/spark/build.gradle'. Using scalastyle configuration {run-worktree}/project/scalastyle_config.xml for jmh source set Using scalastyle configuration {run-worktree}/project/scalastyle_config.xml for main source set Using scalastyle configuration {run-worktree}/project/scalastyle_config.xml for test source set Task name matched 'test' Selected primary task 'test' from project :iceberg-spark:iceberg-spark-3.5_2.12 > Configure project :iceberg-api Evaluating project ':iceberg-api' using build file '{run-worktree}/api/build.gradle'. > Configure project :iceberg-bundled-guava Evaluating project ':iceberg-bundled-guava' using build file '{run-worktree}/bundled-guava/build.gradle'. > Configure project :iceberg-common Evaluating project ':iceberg-common' using build file '{run-worktree}/common/build.gradle'. > Configure project :iceberg-core Evaluating project ':iceberg-core' using build file '{run-worktree}/core/build.gradle'. > Configure project :iceberg-data Evaluating project ':iceberg-data' using build file '{run-worktree}/data/build.gradle'. > Configure project :iceberg-orc Evaluating project ':iceberg-orc' using build file '{run-worktree}/orc/build.gradle'. > Configure project :iceberg-parquet Evaluating project ':iceberg-parquet' using build file '{run-worktree}/parquet/build.gradle'. > Configure project :iceberg-arrow Evaluating project ':iceberg-arrow' using build file '{run-worktree}/arrow/build.gradle'. > Configure project :iceberg-hive-metastore Evaluating project ':iceberg-hive-metastore' using build file '{run-worktree}/hive-metastore/build.gradle'. > Configure project :iceberg-open-api Evaluating project ':iceberg-open-api' using build file '{run-worktree}/open-api/build.gradle'. > Configure project :iceberg-aws Evaluating project ':iceberg-aws' using build file '{run-worktree}/aws/build.gradle'. > Configure project :iceberg-gcp Evaluating project ':iceberg-gcp' using build file '{run-worktree}/gcp/build.gradle'. > Configure project :iceberg-azure Evaluating project ':iceberg-azure' using build file '{run-worktree}/azure/build.gradle'. > Configure project :iceberg-aws-bundle Evaluating project ':iceberg-aws-bundle' using build file '{run-worktree}/aws-bundle/build.gradle'. > Configure project :iceberg-azure-bundle Evaluating project ':iceberg-azure-bundle' using build file '{run-worktree}/azure-bundle/build.gradle'. > Configure project :iceberg-gcp-bundle Evaluating project ':iceberg-gcp-bundle' using build file '{run-worktree}/gcp-bundle/build.gradle'. Variant Selection Exception: org.gradle.internal.component.resolution.failure.exception.VariantSelectionBy ... [384726 bytes truncated] ... st worker] INFO org.apache.iceberg.BaseMetastoreCatalog - Table loaded by catalog: testhadoop.default.table [pool-10-thread-4] INFO org.apache.hadoop.hive.metastore.HiveMetaStore - 4: source:127.0.0.1 get_database: default [pool-10-thread-4] INFO org.apache.hadoop.hive.metastore.HiveMetaStore.audit - ugi=coder ip=127.0.0.1 cmd=source:127.0.0.1 get_database: default [pool-10-thread-4] INFO org.apache.hadoop.hive.metastore.HiveMetaStore - 4: source:127.0.0.1 get_table : db=default tbl=dim [pool-10-thread-4] INFO org.apache.hadoop.hive.metastore.HiveMetaStore.audit - ugi=coder ip=127.0.0.1 cmd=source:127.0.0.1 get_table : db=default tbl=dim TestSparkReadMetrics STANDARD_ERROR [Test worker] INFO hive.metastore - Trying to connect to metastore with URI thrift://localhost:44581 [Test worker] INFO hive.metastore - Opened a connection to metastore, current connections: 4 [Test worker] INFO hive.metastore - Connected to metastore. [pool-10-thread-5] INFO org.apache.hadoop.hive.metastore.HiveMetaStore - 5: source:127.0.0.1 get_all_databases [pool-10-thread-5] INFO org.apache.hadoop.hive.metastore.HiveMetaStore.audit - ugi=coder ip=127.0.0.1 cmd=source:127.0.0.1 get_all_databases [pool-10-thread-5] INFO org.apache.hadoop.hive.metastore.HiveMetaStore - 5: Opening raw store with implementation class:org.apache.hadoop.hive.metastore.ObjectStore [pool-10-thread-5] INFO org.apache.hadoop.hive.metastore.ObjectStore - ObjectStore, initialize called [pool-10-thread-5] INFO org.apache.hadoop.hive.metastore.ObjectStore - Initialized ObjectStore [pool-10-thread-5] INFO org.apache.hadoop.hive.metastore.HiveMetaStore - 5: source:127.0.0.1 get_all_tables: db=default [pool-10-thread-5] INFO org.apache.hadoop.hive.metastore.HiveMetaStore.audit - ugi=coder ip=127.0.0.1 cmd=source:127.0.0.1 get_all_tables: db=default [Test worker] INFO hive.metastore - Closed a connection to metastore, current connections: 3 [pool-10-thread-5] INFO org.apache.hadoop.hive.metastore.HiveMetaStore - 5: Cleaning up thread local RawStore... [pool-10-thread-5] INFO org.apache.hadoop.hive.metastore.HiveMetaStore.audit - ugi=coder ip=127.0.0.1 cmd=Cleaning up thread local RawStore... [pool-10-thread-5] INFO org.apache.hadoop.hive.metastore.HiveMetaStore - 5: Done cleaning up thread local RawStore [Test worker] INFO org.apache.hadoop.hive.metastore.HiveMetaStore - 0: Cleaning up thread local RawStore... [pool-10-thread-5] INFO org.apache.hadoop.hive.metastore.HiveMetaStore.audit - ugi=coder ip=127.0.0.1 cmd=Done cleaning up thread local RawStore [Test worker] INFO org.apache.hadoop.hive.metastore.HiveMetaStore.audit - ugi=coder ip=unknown-ip-addr cmd=Cleaning up thread local RawStore... [Test worker] INFO org.apache.hadoop.hive.metastore.HiveMetaStore - 0: Done cleaning up thread local RawStore [Test worker] INFO org.apache.hadoop.hive.metastore.HiveMetaStore.audit - ugi=coder ip=unknown-ip-addr cmd=Done cleaning up thread local RawStore [Test worker] INFO org.apache.spark.SparkContext - SparkContext is stopping with exitCode 0. [dispatcher-event-loop-0] INFO org.apache.spark.MapOutputTrackerMasterEndpoint - MapOutputTrackerMasterEndpoint stopped! [Test worker] INFO org.apache.iceberg.spark.SparkExecutorCache - Invalidating 0 keys associated with testhadoop.default.table [Test worker] INFO org.apache.iceberg.spark.SparkExecutorCache - Current cache stats CacheStats{hitCount=0, missCount=1, loadSuccessCount=1, loadFailureCount=0, totalLoadTime=12982811, evictionCount=0, evictionWeight=0} [Test worker] INFO org.apache.iceberg.spark.SparkExecutorCache - Invalidating 0 keys associated with testhadoop.default.table [Test worker] INFO org.apache.iceberg.spark.SparkExecutorCache - Current cache stats CacheStats{hitCount=0, missCount=1, loadSuccessCount=1, loadFailureCount=0, totalLoadTime=12982811, evictionCount=0, evictionWeight=0} [Test worker] INFO org.apache.iceberg.spark.SparkExecutorCache - Invalidating 0 keys associated with testhadoop.default.table [Test worker] INFO org.apache.iceberg.spark.SparkExecutorCache - Current cache stats CacheStats{hitCount=0, missCount=1, loadSuccessCount=1, loadFailureCount=0, totalLoadTime=12982811, evictionCount=0, evictionWeight=0} [Test worker] INFO org.apache.iceberg.spark.SparkExecutorCache - Invalidating 0 keys associated with testhadoop.default.table [Test worker] INFO org.apache.iceberg.spark.SparkExecutorCache - Current cache stats CacheStats{hitCount=0, missCount=1, loadSuccessCount=1, loadFailureCount=0, totalLoadTime=12982811, evictionCount=0, evictionWeight=0} [Test worker] INFO org.apache.iceberg.spark.SparkExecutorCache - Invalidating 0 keys associated with testhadoop.default.table [Test worker] INFO org.apache.iceberg.spark.SparkExecutorCache - Current cache stats CacheStats{hitCount=0, missCount=1, loadSuccessCount=1, loadFailureCount=0, totalLoadTime=12982811, evictionCount=0, evictionWeight=0} [Test worker] INFO org.apache.iceberg.spark.SparkExecutorCache - Invalidating 0 keys associated with testhadoop.default.table [Test worker] INFO org.apache.iceberg.spark.SparkExecutorCache - Current cache stats CacheStats{hitCount=0, missCount=1, loadSuccessCount=1, loadFailureCount=0, totalLoadTime=12982811, evictionCount=0, evictionWeight=0} [Test worker] INFO org.apache.spark.storage.memory.MemoryStore - MemoryStore cleared [Test worker] INFO org.apache.spark.storage.BlockManager - BlockManager stopped [Test worker] INFO org.apache.spark.storage.BlockManagerMaster - BlockManagerMaster stopped [dispatcher-event-loop-0] INFO org.apache.spark.scheduler.OutputCommitCoordinator$OutputCommitCoordinatorEndpoint - OutputCommitCoordinator stopped! [Test worker] INFO org.apache.spark.SparkContext - Successfully stopped SparkContext [Test worker] INFO org.eclipse.jetty.server.Server - Stopped oejs.Server@7abe27bf{STOPPING}[12.1.14,sto=0] [Test worker] INFO org.eclipse.jetty.server.AbstractConnector - Stopped oejs.ServerConnector@3b7b05a8{HTTP/1.1, (http/1.1)}{0.0.0.0:38163} [Test worker] INFO org.eclipse.jetty.ee10.servlet.ServletContextHandler - Stopped oeje10s.ServletContextHandler@7573e12f{ROOT,/,b=null,a=AVAILABLE,h=oejcs.CompressionHandler@51b1a8f6{STOPPED,supported=gzip}} Gradle Test Executor 16 finished executing tests. [shutdown-hook-0] INFO org.apache.spark.util.ShutdownHookManager - Shutdown hook called [shutdown-hook-0] INFO org.apache.spark.util.ShutdownHookManager - Deleting directory /tmp/spark-4f11cee1-2f4a-4c8c-a77c-882ab043cbc2 > Task :iceberg-spark:iceberg-spark-3.5_2.12:test Finished generating test XML results (0.012 secs) into: {run-worktree}/spark/v3.5/spark/build/test-results/test Generating HTML test report... Finished generating test html results (0.013 secs) into: {run-worktree}/spark/v3.5/spark/build/reports/tests/test Invalidating in-memory cache of ~/.gradle/caches/journal-1/file-access.bin Stored cache entry for task ':iceberg-spark:iceberg-spark-3.5_2.12:test' with cache key 4ca4a7b25bbc41ee8f0ee31071de8504 [Incubating] Problems report is available at: file://{run-worktree}/build/reports/problems/problems-report.html Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0. You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins. For more on this, please refer to https://docs.gradle.org/8.14.6/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation. BUILD SUCCESSFUL in 43s 53 actionable tasks: 28 executed, 25 from cache Some of the file system contents retained in the virtual file system are on file systems that Gradle doesn't support watching. The relevant state was discarded to ensure changes to these locations are properly detected. You can override this by explicitly enabling file system watching. ``` </details> - Evidence: TestSparkReadMetrics JUnit report (8 tests, 0 failures) (local file: <code>~/.no-mistakes/evidence/01M80R128RB80NCEDYMXRM1G2E/TEST-org.apache.iceberg.spark.source.TestSparkReadMetrics.xml</code>) <details> <summary>Evidence: TestScanDuration JUnit report (5 tests, 0 failures)</summary> ```text <?xml version="1.0" encoding="UTF-8"?> <testsuite name="org.apache.iceberg.spark.source.metrics.TestScanDuration" tests="5" skipped="0" failures="0" errors="0" timestamp="2026-11-22T04:26:50.159Z" hostname="vsowrirajan-microsoft-devbox-vsowrirajan-dev-6b698f4977-zvfhg" time="0.011"> <properties/> <testcase name="aggregateTaskMetricsDoesNotMutateInput()" classname="org.apache.iceberg.spark.source.metrics.TestScanDuration" time="0.005"/> <testcase name="aggregateTaskMetricsSurfacesStragglers()" classname="org.apache.iceberg.spark.source.metrics.TestScanDuration" time="0.001"/> <testcase name="aggregateTaskMetricsIsLocaleIndependent()" classname="org.apache.iceberg.spark.source.metrics.TestScanDuration" time="0.003"/> <testcase name="aggregateTaskMetrics()" classname="org.apache.iceberg.spark.source.metrics.TestScanDuration" time="0.001"/> <testcase name="aggregateTaskMetricsWithNoTasks()" classname="org.apache.iceberg.spark.source.metrics.TestScanDuration" time="0.0"/> <system-out><![CDATA[]]></system-out> <system-err><![CDATA[]]></system-err> </testsuite> ``` </details> ## Pipeline Updates from [git push no-mistakes](https://github.com/kunchenguid/no-mistakes) <!-- no-mistakes-pipeline-attestation:v1 {"head_sha":"f9b672fbf33295d818eef0441ef89db07dcc1445","steps":[{"step":"intent","status":"completed"},{"step":"rebase","status":"completed"},{"step":"review","status":"completed"},{"step":"test","status":"completed"},{"step":"document","status":"completed"},{"step":"lint","status":"completed"},{"step":"push","status":"completed"},{"step":"pr","status":"running"},{"step":"ci","status":"pending"}],"live_validation":{"verdict":"go","live":4,"total":4}} --> <details> <summary>✅ **Intent** - passed</summary> ✅ No issues found. </details> <details> <summary>✅ **Rebase** - passed</summary> ✅ No issues found. </details> <details> <summary>✅ **Review** - passed</summary> ✅ No issues found. </details> <details> <summary>✅ **Test** - passed</summary> ✅ No issues found. - Live validation: ✅ go - 4 of 4 scenarios driven live against the product | Scenario | Result | Live | Evidence | | --- | --- | --- | --- | | Vectorized SELECT over a 2-file Iceberg table in local Spark 3.5 reports a summed scanDuration > 0, and the UI shows it as 'total (min, med, max)' with time units | ✅ pass | live | TestSparkReadMetrics.scanDurationAggregatedAcrossTasks in TEST-org.apache.iceberg.spark.source.TestSparkReadMetrics.xml | | Non-vectorized (RowDataReader) SELECT reports scanDuration > 0 on a confirmed non-columnar plan | ✅ pass | live | TestSparkReadMetrics.scanDurationForNonVectorizedRead | | Existing data and delete scan queries also report scanDuration > 0 alongside the other read metrics | ✅ pass | live | Existing TestSparkReadMetrics tests (8/8 passed) | | Aggregated nanosecond values format as 'total (min, med, max)' with readable units, the same as Spark 4.1 | ✅ pass | live | TestScanDuration (5/5 passed); class files identical to spark/v4.1 | - `./gradlew -DsparkVersions=3.5 -DscalaVersion=2.12 --offline :iceberg-spark:iceberg-spark-3.5_2.12:test --tests org.apache.iceberg.spark.source.TestSparkReadMetrics --tests org.apache.iceberg.spark.source.metrics.TestScanDuration` - <code>`diff` of spark/v4.1 vs spark/v3.5 ScanDuration.java, TaskScanDuration.java, TestScanDuration.java (identical)</code> </details> <details> <summary>✅ **Document** - passed</summary> ✅ No issues found. </details> <details> <summary>✅ **Lint** - passed</summary> ✅ No issues found. </details> <details> <summary>✅ **Push** - passed</summary> ✅ No issues found. </details> -- 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]
