Commit 9844c4c
authored
Fix client-side maxRows enforcement in ResultSet.next() (#1448)
## Summary
Add client-side `maxRows` enforcement in `DatabricksResultSet.next()`.
When `statement.setMaxRows()` is set, `next()` returns `false` once 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`/`resultRowLimit` is not always honored — the
server may return more rows than requested. Some `IExecutionResult`
implementations (`LazyThriftResult`, `StreamingColumnarResult`,
`StreamingInlineArrowResult`) enforce maxRows internally, but
`InlineJsonResult` and `ArrowStreamResult` do not, leaving a gap.
### Fix
Single enforcement point at `DatabricksResultSet.next()`:
- `maxRowsLimit` field cached from `parentStatement.getMaxRows()` at
construction
- `rowsReturned` counter incremented on each successful `next()`
- Check `maxRowsLimit > 0 && rowsReturned >= maxRowsLimit` before
delegating to `executionResult.next()`
- `maxRows == 0` means no limit (JDBC convention)
- `getUpdateCount()` internal iteration bypasses the limit via
`countingUpdateRows` flag
Existing per-implementation maxRows enforcement retained as
defense-in-depth.
## Test plan
- [x] `testNextRespectsMaxRows` — limit=3, 4th next() returns false
- [x] `testNextMaxRowsZeroNoLimit` — no truncation with limit=0
- [x] `testNextMaxRowsNullParentNoLimit` — null parent = no limit
- [x] `testNextMaxRowsOneEdge` — limit=1 edge case
- [x] `testNextMaxRowsDoesNotCallExecutionResultAfterLimit` — verify no
unnecessary delegation
- [x] `testNextMaxRowsWithEmptyResultSet` — empty result + maxRows
- [x] `testNextMaxRowsGreaterThanActualRows` — natural exhaustion before
limit
- [x] `testNextMaxRowsIdempotenceAfterLimit` — repeated calls after
limit
- [x] `testGetUpdateCountBypassesMaxRows` — DML counting unaffected
- [x] Independent verification: 7/7 PASS (Agent C, black-box from spec)
- [x] Full suite: 62 tests pass
This pull request was AI-assisted by Isaac.
---------
Signed-off-by: Gopal Lal <gopal.lal@databricks.com>1 parent 7de2cf4 commit 9844c4c
12 files changed
Lines changed: 269 additions & 316 deletions
File tree
- src
- main/java/com/databricks/jdbc/api
- impl
- arrow
- thrift
- internal
- test/java/com/databricks/jdbc/api/impl
- arrow
- thrift
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
| |||
Lines changed: 86 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
85 | 95 | | |
86 | 96 | | |
87 | 97 | | |
| |||
121 | 131 | | |
122 | 132 | | |
123 | 133 | | |
| 134 | + | |
124 | 135 | | |
125 | 136 | | |
126 | 137 | | |
| |||
142 | 153 | | |
143 | 154 | | |
144 | 155 | | |
| 156 | + | |
145 | 157 | | |
146 | 158 | | |
147 | 159 | | |
| |||
189 | 201 | | |
190 | 202 | | |
191 | 203 | | |
| 204 | + | |
192 | 205 | | |
193 | 206 | | |
194 | 207 | | |
| |||
220 | 233 | | |
221 | 234 | | |
222 | 235 | | |
| 236 | + | |
223 | 237 | | |
224 | 238 | | |
225 | 239 | | |
| |||
251 | 265 | | |
252 | 266 | | |
253 | 267 | | |
| 268 | + | |
254 | 269 | | |
255 | 270 | | |
256 | 271 | | |
| |||
271 | 286 | | |
272 | 287 | | |
273 | 288 | | |
| 289 | + | |
274 | 290 | | |
275 | 291 | | |
276 | 292 | | |
277 | 293 | | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
278 | 305 | | |
279 | 306 | | |
280 | 307 | | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
281 | 328 | | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
282 | 335 | | |
283 | 336 | | |
284 | 337 | | |
| |||
321 | 374 | | |
322 | 375 | | |
323 | 376 | | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
324 | 391 | | |
325 | 392 | | |
326 | 393 | | |
| |||
662 | 729 | | |
663 | 730 | | |
664 | 731 | | |
665 | | - | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
666 | 735 | | |
667 | 736 | | |
668 | 737 | | |
| |||
691 | 760 | | |
692 | 761 | | |
693 | 762 | | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
694 | 768 | | |
695 | 769 | | |
696 | 770 | | |
| |||
731 | 805 | | |
732 | 806 | | |
733 | 807 | | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
734 | 812 | | |
735 | 813 | | |
736 | 814 | | |
| |||
1958 | 2036 | | |
1959 | 2037 | | |
1960 | 2038 | | |
1961 | | - | |
1962 | | - | |
| 2039 | + | |
| 2040 | + | |
| 2041 | + | |
| 2042 | + | |
| 2043 | + | |
| 2044 | + | |
| 2045 | + | |
1963 | 2046 | | |
1964 | 2047 | | |
1965 | 2048 | | |
| |||
Lines changed: 0 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | 3 | | |
5 | 4 | | |
6 | 5 | | |
| |||
21 | 20 | | |
22 | 21 | | |
23 | 22 | | |
24 | | - | |
25 | 23 | | |
26 | 24 | | |
27 | 25 | | |
| |||
42 | 40 | | |
43 | 41 | | |
44 | 42 | | |
45 | | - | |
46 | 43 | | |
47 | 44 | | |
48 | 45 | | |
| |||
115 | 112 | | |
116 | 113 | | |
117 | 114 | | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | 115 | | |
126 | 116 | | |
127 | 117 | | |
| |||
163 | 153 | | |
164 | 154 | | |
165 | 155 | | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | 156 | | |
173 | 157 | | |
174 | 158 | | |
| |||
Lines changed: 0 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | 3 | | |
5 | 4 | | |
6 | 5 | | |
| |||
35 | 34 | | |
36 | 35 | | |
37 | 36 | | |
38 | | - | |
39 | 37 | | |
40 | 38 | | |
41 | 39 | | |
| |||
58 | 56 | | |
59 | 57 | | |
60 | 58 | | |
61 | | - | |
62 | 59 | | |
63 | 60 | | |
64 | 61 | | |
| |||
163 | 160 | | |
164 | 161 | | |
165 | 162 | | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | 163 | | |
174 | 164 | | |
175 | 165 | | |
| |||
209 | 199 | | |
210 | 200 | | |
211 | 201 | | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | 202 | | |
219 | 203 | | |
220 | 204 | | |
| |||
Lines changed: 1 addition & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | 3 | | |
5 | 4 | | |
6 | 5 | | |
| |||
54 | 53 | | |
55 | 54 | | |
56 | 55 | | |
57 | | - | |
58 | 56 | | |
59 | 57 | | |
60 | 58 | | |
| |||
78 | 76 | | |
79 | 77 | | |
80 | 78 | | |
81 | | - | |
82 | | - | |
83 | 79 | | |
84 | 80 | | |
85 | 81 | | |
| |||
105 | 101 | | |
106 | 102 | | |
107 | 103 | | |
108 | | - | |
| 104 | + | |
109 | 105 | | |
110 | | - | |
111 | 106 | | |
112 | 107 | | |
113 | 108 | | |
| |||
184 | 179 | | |
185 | 180 | | |
186 | 181 | | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | 182 | | |
195 | 183 | | |
196 | 184 | | |
| |||
243 | 231 | | |
244 | 232 | | |
245 | 233 | | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | 234 | | |
253 | 235 | | |
254 | 236 | | |
| |||
0 commit comments