Fix client-side maxRows enforcement in ResultSet.next()#1448
Open
gopalldb wants to merge 3 commits into
Open
Conversation
Co-authored-by: Isaac Signed-off-by: Gopal Lal <gopal.lal@databricks.com>
Co-authored-by: Isaac Signed-off-by: Gopal Lal <gopal.lal@databricks.com>
Signed-off-by: Gopal Lal <gopal.lal@databricks.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add client-side
maxRowsenforcement inDatabricksResultSet.next(). Whenstatement.setMaxRows()is set,next()returnsfalseonce the row limit is reached, even if the server returns more rows. Applies uniformly to all result types (Thrift, SEA, inline, CloudFetch).Problem
The server-side
row_limit/resultRowLimitis not always honored — the server may return more rows than requested. SomeIExecutionResultimplementations (LazyThriftResult,StreamingColumnarResult,StreamingInlineArrowResult) enforce maxRows internally, butInlineJsonResultandArrowStreamResultdo not, leaving a gap.Fix
Single enforcement point at
DatabricksResultSet.next():maxRowsLimitfield cached fromparentStatement.getMaxRows()at constructionrowsReturnedcounter incremented on each successfulnext()maxRowsLimit > 0 && rowsReturned >= maxRowsLimitbefore delegating toexecutionResult.next()maxRows == 0means no limit (JDBC convention)getUpdateCount()internal iteration bypasses the limit viacountingUpdateRowsflagExisting per-implementation maxRows enforcement retained as defense-in-depth.
Test plan
testNextRespectsMaxRows— limit=3, 4th next() returns falsetestNextMaxRowsZeroNoLimit— no truncation with limit=0testNextMaxRowsNullParentNoLimit— null parent = no limittestNextMaxRowsOneEdge— limit=1 edge casetestNextMaxRowsDoesNotCallExecutionResultAfterLimit— verify no unnecessary delegationtestNextMaxRowsWithEmptyResultSet— empty result + maxRowstestNextMaxRowsGreaterThanActualRows— natural exhaustion before limittestNextMaxRowsIdempotenceAfterLimit— repeated calls after limittestGetUpdateCountBypassesMaxRows— DML counting unaffectedThis pull request was AI-assisted by Isaac.