Skip to content

Conversation

@wendigo
Copy link
Contributor

@wendigo wendigo commented Jun 14, 2025

This prevents OOM exception when retrieving huge results

Relates to #26013

Description

Additional context and related issues

Release notes

( ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
(x) Release notes are required, with the following suggested text:

## CLI
* Allow configuring `--max-buffered-rows` and `--max-queued-rows` in the CLI. ({issue}`26015`)

This prevents OOM exception when retrieving huge results
@cla-bot cla-bot bot added the cla-signed label Jun 14, 2025
@wendigo wendigo requested review from Copilot and losipiuk June 15, 2025 11:34
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces configurable limits for queued and buffered rows in the CLI to avoid out-of-memory errors when processing large result sets.

  • Adds new CLI options --max-buffered-rows and --max-queued-rows with defaults.
  • Propagates these settings through ClientOptions, Console, QueryRunner, Query, and OutputHandler.
  • Updates tests to supply the new constructor arguments and recognize the new options.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
client/trino-cli/src/main/java/io/trino/cli/ClientOptions.java Declares maxBufferedRows and maxQueuedRows CLI options
client/trino-cli/src/main/java/io/trino/cli/Console.java Passes new options into QueryRunner construction
client/trino-cli/src/main/java/io/trino/cli/QueryRunner.java Adds fields and constructor parameters for row limits
client/trino-cli/src/main/java/io/trino/cli/Query.java Propagates new limits to output handlers
client/trino-cli/src/main/java/io/trino/cli/OutputHandler.java Replaces static row‐limit constants with configurable fields
client/trino-cli/src/test/java/io/trino/cli/TestClientOptions.java Recognizes new option names in tests
client/trino-cli/src/test/java/io/trino/cli/TestQueryRunner.java Supplies new constructor parameters in test setup
Comments suppressed due to low confidence (1)

client/trino-cli/src/test/java/io/trino/cli/TestClientOptions.java:387

  • [nitpick] There are no tests validating that the new --max-buffered-rows and --max-queued-rows options actually affect buffering and queuing behavior. Consider adding tests for boundary conditions and default values.
case "maxQueuedRows":

private void discardResults()
{
try (OutputHandler handler = new OutputHandler(new NullPrinter())) {
try (OutputHandler handler = new OutputHandler(new NullPrinter(), 100, 100)) {
Copy link

Copilot AI Jun 15, 2025

Choose a reason for hiding this comment

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

In discardResults(), the hard-coded limits (100, 100) do not use the configured maxQueuedRows and maxBufferedRows. This will lead to inconsistent behavior compared to other paths—pass the instance fields instead of constants.

Suggested change
try (OutputHandler handler = new OutputHandler(new NullPrinter(), 100, 100)) {
try (OutputHandler handler = new OutputHandler(new NullPrinter(), maxQueuedRows, maxBufferedRows)) {

Copilot uses AI. Check for mistakes.
clientSession,
false);
false,
1000,
Copy link

Copilot AI Jun 15, 2025

Choose a reason for hiding this comment

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

[nitpick] The magic numbers (1000, 500) in this test could drift from production defaults. Consider using named constants or referencing ClientOptions defaults to keep the test in sync when defaults change.

Copilot uses AI. Check for mistakes.
session,
clientOptions.debug)) {
clientOptions.debug,
clientOptions.maxQueuedRows,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have a check for those two configs? i,e at least should greater than 0.

case "outputFormatInteractive":
case "pager":
case "ignoreErrors":
case "editingMode":
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, can we have a unsupported test

@losipiuk
Copy link
Member

@wendigo this is super technical. Can't we just monitor how big rows are and automatically adjust based on that?

@wendigo
Copy link
Contributor Author

wendigo commented Jun 23, 2025

@losipiuk i was thinking about that but there is no easy way of calculating row size hence it's not possible to bound it

@wendigo wendigo merged commit f934f85 into master Jul 3, 2025
49 checks passed
@wendigo wendigo deleted the serafin/cli-configurable branch July 3, 2025 12:56
@github-actions github-actions bot added this to the 477 milestone Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants