Skip to content

Conversation

@jayantsing-db
Copy link
Collaborator

Description

This PR introduces lazy loading support for inline Arrow results to improve memory efficiency when handling large result sets.

Previously, InlineChunkProvider would eagerly fetch all arrow batches upfront when results had hasMoreRows = true, which could lead to memory issues with large datasets. This change splits the handling into two separate paths:

  1. Lazy path (new): For Thrift-based inline Arrow results (when ARROW_BASED_SET is returned), we now use LazyThriftInlineArrowResult which fetches arrow batches on-demand as the client iterates through rows. This is similar to how LazyThriftResult works for columnar data.
  2. Remote path (existing): For URL-based Arrow results (URL_BASED_SET), we continue using ArrowStreamResult with RemoteChunkProvider which downloads chunks from cloud storage.

The InlineChunkProvider is now only used for SEA results with JSON_ARRAY format and INLINE disposition (contain all data inline {no hasMoreRows flag set}).

This will reduce memory consumption and improve performance when dealing with large inline Arrow result sets similar to #975.

Testing

  • Unit tests
  • Integration tests
  • Manual testing

Additional Notes to the Reviewer

jayantsing-db and others added 2 commits September 30, 2025 14:15
This PR introduces lazy loading support for inline Arrow results to improve memory efficiency when handling large result sets.

Previously, InlineChunkProvider would eagerly fetch all arrow batches upfront when results had hasMoreRows = true, which could lead to memory issues with large datasets. This change splits the handling into two separate paths:
1. Lazy path (new): For Thrift-based inline Arrow results (when ARROW_BASED_SET is returned), we now use LazyThriftInlineArrowResult which fetches arrow batches on-demand as the client iterates through rows. This is similar to how LazyThriftResult works for columnar data.
2. Remote path (existing): For URL-based Arrow results (URL_BASED_SET), we continue using ArrowStreamResult with RemoteChunkProvider which downloads chunks from cloud storage.

The InlineChunkProvider is now only used for SEA results with JSON_ARRAY format and INLINE disposition (contain all data inline {no hasMoreRows flag set}).

This should reduce memory consumption and improve performance when dealing with large inline Arrow result sets.
@jayantsing-db
Copy link
Collaborator Author

I need to make some changes related to JDBC spec around row count because we don't have that data point when lazily fetching the results.

@github-actions
Copy link

This PR has been marked as Stale because it has been open for 30 days with no activity. If you would like the PR to remain open, please remove the stale label or comment on the PR.

@github-actions github-actions bot added the Stale label Oct 31, 2025
@github-actions
Copy link

github-actions bot commented Nov 7, 2025

This PR was closed because it has been inactive for 7 days since being marked as stale.

@github-actions github-actions bot closed this Nov 7, 2025
@jayantsing-db jayantsing-db reopened this Dec 1, 2025

// Check if we've reached the maxRows limit
boolean hasRowLimit = maxRows > 0;
if (hasRowLimit && globalRowIndex + 1 >= maxRows) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

so globalRowIndex 0 means 1st row, and maxRows -1 would mean last row.

So, at last row, globalRowIndex +1 = maxRows, which means no more rows. We can just check == instead of >=, any reason you are doing that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You are right, we don't strictly need >= strictly (was being defensive).

return null;
}

private Schema hiveSchemaToArrowSchema(TTableSchema hiveSchema)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We are not getting arrowSchema for inline arrow result?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I haven't looked into this in detail. Arrow parsing is ported as is in this PR (no changes from existing code. The methods were moved from InlineChunkProvider which was the previous class handling this). The PR only changes data download. Let me check this separately.

if (result == null) {
return null;
}
ComplexDataTypeParser parser = new ComplexDataTypeParser();
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we need to create this for every getObject call?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, this is just existing code from method getObject(int columnIndex) in the same class. I moved it to separate method because getObject(int columnIndex) was unreadable.

To answer the question: No we shouldn't create such objects in hot paths like getObjects. But I don't want to change the scope of this PR. Will create a separate change/

@github-actions
Copy link

github-actions bot commented Jan 3, 2026

This PR has been marked as Stale because it has been open for 30 days with no activity. If you would like the PR to remain open, please remove the stale label or comment on the PR.

@jayantsing-db jayantsing-db requested a review from gopalldb January 7, 2026 22:29
Copy link
Collaborator

@nikhilsuri-db nikhilsuri-db left a comment

Choose a reason for hiding this comment

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

Do we have artefacts showing the improvement in memory usage with LazyInline Fetch?

@jayantsing-db
Copy link
Collaborator Author

Do we have artefacts showing the improvement in memory usage with LazyInline Fetch?

The improvements are identical and follow same patterns as images in #966 (comment)


// Check if we need to convert geospatial types to string when geospatial support is disabled
// This check must come before the general complex type check
if (!isGeoSpatialSupportEnabled && isGeospatialType(requiredType)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sreekanth is making changes in similar code, make sure that you don't override his changes for geospatial

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants