Skip to content

feat(): Adding 'finishingTime' to QueryStatistics#27420

Merged
spershin merged 1 commit intoprestodb:masterfrom
spershin:export-D97861145
Mar 24, 2026
Merged

feat(): Adding 'finishingTime' to QueryStatistics#27420
spershin merged 1 commit intoprestodb:masterfrom
spershin:export-D97861145

Conversation

@spershin
Copy link
Copy Markdown
Contributor

@spershin spershin commented Mar 24, 2026

Summary:
We noticed that finishing stage can take a sinigificant amount of time to completed and is added to the execution time.
For troubleshooting and debugging it would be good to expose the 'finishingTime'.
This change is adding 'finishingTime' to QueryStatistics, so it can be used further in events and event listeners.

Differential Revision: D97861145

Release Notes

Please follow release notes guidelines and fill in the release notes below.

== NO RELEASE NOTE ==

Summary by Sourcery

Expose query finishing time in query statistics and propagate it through query monitoring and tests.

New Features:

  • Add a finishingTime field to QueryStatistics to capture query finishing duration.

Tests:

  • Update existing event listener tests and test data to account for the new finishingTime statistic.

Summary:
We noticed that finishing stage can take a sinigificant amount of time to completed and is added to the execution time.
For troubleshooting and debugging it would be good to expose the 'finishingTime'.
This change is adding 'finishingTime' to QueryStatistics, so it can be used further in events and event listeners.

Differential Revision: D97861145
@spershin spershin requested a review from a team as a code owner March 24, 2026 01:51
@prestodb-ci prestodb-ci added the from:Meta PR from Meta label Mar 24, 2026
@linux-foundation-easycla
Copy link
Copy Markdown

CLA Missing ID CLA Not Signed

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Mar 24, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds a new finishingTime field to QueryStatistics and threads it through query monitoring and test helpers so query events can expose finishing stage duration.

Class diagram for updated QueryStatistics and its use in QueryMonitor

classDiagram
    class QueryStatistics {
        - Duration planningTime
        - Optional~Duration~ analysisTime
        - Duration executionTime
        - Duration finishingTime
        - int peakRunningTasks
        - long peakUserMemoryBytes
        - long peakTotalNonRevocableMemoryBytes
        + QueryStatistics(Duration planningTime, Optional~Duration~ analysisTime, Duration executionTime, Duration finishingTime, int peakRunningTasks, long peakUserMemoryBytes, long peakTotalNonRevocableMemoryBytes, long totalCpuTimeSecs, long totalScheduledTimeSecs, long totalBlockedTimeSecs, long totalAllocationBytes, long peakTotalMemoryBytes, long peakTaskTotalMemoryBytes, int totalTasks, int runningTasks, int completedTasks, int failedTasks, int totalDrivers, int queuedDrivers, int runningDrivers, int blockedDrivers, int completedDrivers, double cumulativeUserMemory, double cumulativeTotalMemory, double cumulativeCpuTimeSecs, double cumulativeScheduledTimeSecs, double cumulativeBlockedTimeSecs)
        + Duration getPlanningTime()
        + Optional~Duration~ getAnalysisTime()
        + Duration getExecutionTime()
        + Duration getFinishingTime()
        + int getPeakRunningTasks()
        + long getPeakUserMemoryBytes()
        + long getPeakTotalNonRevocableMemoryBytes()
    }

    class QueryMonitor {
        + void queryImmediateFailureEvent(BasicQueryInfo queryInfo, ExecutionFailureInfo failure)
        - QueryStatistics createQueryStatistics(QueryInfo queryInfo)
        - QueryStatistics createQueryStatistics(BasicQueryInfo basicQueryInfo)
    }

    QueryMonitor ..> QueryStatistics : creates_with_finishingTime
    QueryInfo --> QueryStatistics : stats_source
    BasicQueryInfo --> QueryStatistics : basic_stats_source
    QueryInfo ..> QueryMonitor : used_by
    BasicQueryInfo ..> QueryMonitor : used_by
Loading

File-Level Changes

Change Details Files
Extend QueryStatistics to include a non-optional finishingTime duration and expose it via accessor.
  • Add a finishingTime Duration field to QueryStatistics and initialize it via the constructor
  • Validate finishingTime with requireNonNull alongside other timing fields
  • Expose finishingTime via a new getFinishingTime() accessor
presto-spi/src/main/java/com/facebook/presto/spi/eventlistener/QueryStatistics.java
Populate finishingTime in QueryStatistics instances constructed by QueryMonitor, using real stats where available and zero otherwise.
  • Update QueryMonitor.queryImmediateFailureEvent to pass a zero finishingTime when building QueryStatistics for immediate failures
  • Update QueryMonitor.createQueryStatistics(QueryInfo) to map queryStats.getFinishingTime() into the new finishingTime parameter
  • Update QueryMonitor.createQueryStatistics(BasicQueryInfo) to pass a zero finishingTime when detailed stats are not available
presto-main-base/src/main/java/com/facebook/presto/event/QueryMonitor.java
Adjust tests and test fixtures to account for the new finishingTime parameter on QueryStatistics.
  • Update TestEventListenerManager.createDummyQueryStatistics to provide a non-zero finishingTime for dummy statistics
  • Update PrestoEventData test fixture to include a finishingTime Duration in its QueryStatistics construction
presto-main/src/test/java/com/facebook/presto/eventlistener/TestEventListenerManager.java
presto-openlineage-event-listener/src/test/java/com/facebook/presto/plugin/openlineage/PrestoEventData.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • Adding a non-optional finishingTime parameter to the QueryStatistics constructor in the SPI is a breaking change for any external event listeners constructing this type; consider adding an overloaded constructor (or a builder) that supplies a default value to preserve binary/source compatibility.
  • For cases where a meaningful finishing phase does not exist (e.g., immediate failure paths), you currently pass Duration.ofMillis(0); consider whether an Optional<Duration> would better distinguish 'no finishing phase' from 'zero-duration finishing phase', or at least clarify and consistently apply the convention across all call sites.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Adding a non-optional `finishingTime` parameter to the `QueryStatistics` constructor in the SPI is a breaking change for any external event listeners constructing this type; consider adding an overloaded constructor (or a builder) that supplies a default value to preserve binary/source compatibility.
- For cases where a meaningful finishing phase does not exist (e.g., immediate failure paths), you currently pass `Duration.ofMillis(0)`; consider whether an `Optional<Duration>` would better distinguish 'no finishing phase' from 'zero-duration finishing phase', or at least clarify and consistently apply the convention across all call sites.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@spershin spershin changed the title feat(): Adding 'finishingTime' to QueryStatistics. feat(): Adding 'finishingTime' to QueryStatistics Mar 24, 2026
@spershin spershin requested a review from amitkdutta March 24, 2026 16:15
@spershin spershin merged commit f4b55fe into prestodb:master Mar 24, 2026
114 of 121 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants