Skip to content

refactor: Fetch rows into a pluggable row sink - #644

Merged
krlmlr merged 7 commits into
mainfrom
claude/row-sink
Nov 29, 2026
Merged

krlmlr merged 7 commits into
mainfrom
claude/row-sink

Conversation

@krlmlr

@krlmlr krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

This separates the fetch loop from what consumes the rows, modeled on RPostgres#638, as decided in #587 (comment) ("Refactor, independently of #641"). Behavior is unchanged.

Interface

  • src/MariaRowSink.h defines the abstract MariaRowSink:
    • begin(names, types, fields) runs once per fetch, after execute, also for a result without rows or columns. fields holds a MariaFieldInfo per column (MySQL type, flags, length, decimals, charset). The arguments refer to the live cache, so a sink copies what it needs.
    • append(MariaRowView& row) is called once per fetched row. The view is valid only during the call.
    • remaining() returns -1 for unbounded; 0 stops the loop. The loop checks it before each fetch.
  • The header documents the contract: interrupt checks stay in the loop (every 1024 rows, as before), a sink must not longjmp past C++ objects, and it states which rows are lost when append() throws versus when step() or the interrupt check throws.
  • MariaRowView (src/MariaRow.h) is the read-only face of the bound row: ncols(), type(j), is_null(j), value_int(), value_int64(), value_double(), value_bool(), value_mysql_time(), value_length() and value_bytes(). value_bytes() wraps the existing fetch_buffer() / mysql_stmt_fetch_column() logic, so sinks never call libmysql themselves. A comment marks where fix: Correct values and parameter types for placeholder columns with MySQL servers #641's fixed buffer with refetch fits: only fetch_buffer(), value_bytes() and setup() change.
  • MariaResultPrep::fetch_into(MariaRowSink&) owns the loop: bound and complete checks, step() through parameter sets, row counting, interrupt checks, and the logic from fix: Results of a closed connection fail cleanly instead of crashing #624, fix: Raise warnings only after the C++ code is done with the result #632 and fix: A query on a disconnected connection fails with a clear error #640, unchanged. fetch() is now a data frame sink, then fetch_into(), then get_data().
  • MariaDataFrameSink (src/MariaDataFrameSink.{h,cpp}) is the first sink. The R conversions moved there from MariaRow.cpp.

Why

Verification

  • The full suite passes locally against MariaDB 10.11.
  • New test in test-queries.R: 250 bound rows fetched with n = 0, n = 3, then the rest, across parameter sets.
  • saveRDS() output of main and this branch is identical for 9 column types (with NULLs and zero dates), n = -1, 0, 1, 2, 5, chunked fetches across parameter sets, rebinding, and a statement fetch.
  • Benchmark, 1e6 rows × (INT, DOUBLE, VARCHAR(20)) with n = Inf, median of 7 runs in each of 3 interleaved processes: main 0.294 / 0.302 / 0.300 s, this branch 0.278 / 0.267 / 0.301 s.

Notes

https://claude.ai/code/session_01Hr1rd7atAZVq1J42WzXJpS


Generated by Claude Code

MariaResultPrep::fetch_into() owns the fetch loop:
the bound check, stepping through the parameter sets, row counting and interrupt checks.
A MariaRowSink receives the column metadata in begin() and each row in append(),
through a MariaRowView over the bound result buffers.
The data frame builder becomes the first sink, MariaDataFrameSink,
and fetch() returns its data frame unchanged.
Modeled on r-dbi/RPostgres#638.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd7atAZVq1J42WzXJpS

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

"MySQL server" job on 8831d5c (job 141429450511): 25 failed. 23 are main's pre-existing MySQL failures (#638, fixed by #641). The other 2 were this PR's new test in test-queries.R, which used a bare SELECT ? and so hit #638's VARCHAR typing on MySQL. 1cf38d6 compares the values with as.integer(), because the test is about the row flow across parameter sets, not placeholder typing. It passes locally on MariaDB.


Generated by Claude Code

Resolve the conflict in src/MariaResultPrep.cpp: keep the fetch_into()
structure and MariaFieldInfo capture, and pass the UNSIGNED_FLAG from
#639 at every variable_type_from_field_type() call site.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd7atAZVq1J42WzXJpS

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

rcc: ubuntu-26.04 (4.2) on a39d148 (job 141437196474): 9174 passed, 7 failed, all in test-bind-nonfinite.R, which came from main (#623, #636). The cause is as.Date(<numeric>) without origin, which needs R ≥ 4.3. This is not caused by this PR; it is filed as #647.


Generated by Claude Code

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

"MySQL server" job on a39d148 (job 141437196479): 9127 passed, 3 failed. All 3 are load_data_local_infile tests in test-bind-nonfinite.R from main, which run although local infile is disabled for the MySQL server in CI. The #638 failures are now skipped on main (#643). Not caused by this PR; added to #647.


Generated by Claude Code

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Matrix result on a39d148 (run 46290940563): 23 of 26 jobs green, plus one re-run.

Clean review: nothing above Low; the Lows are fixed. Marking ready.


Generated by Claude Code

@krlmlr
krlmlr marked this pull request as ready for review November 29, 2026 18:13
@krlmlr
krlmlr merged commit 65e17c3 into main Nov 29, 2026
55 of 61 checks passed
@krlmlr
krlmlr deleted the claude/row-sink branch November 29, 2026 18:43
krlmlr pushed a commit that referenced this pull request Nov 29, 2026
refactor: Fill the chunk store through the row sink interface of #644.
MariaChunkSink appends each row of MariaResultPrep::fetch_into() to a MariaChunk,
and get_data() returns the data frame of ALTREP columns as before.
The fetch loop, MariaRow and MariaRowView are main's,
so layer 1's own loop and MariaRow::append_to() are gone.
MariaDataFrameSink has no user left and is removed.

The chunk stores fixed-width values as the MariaRowView accessors return them,
so BIT(1) and INT UNSIGNED (#639) follow main.
The date and time conversions use the arithmetic of MariaDataFrameSink,
so that the values are bit for bit the same.
The chunk keeps the MariaFieldInfo of begin() instead of its own copy of the fields.

The setup of the output when result metadata appears only after execution
(9578270, 3b01c61) is kept on top of main's update_metadata(),
and the contract in MariaRowSink.h describes it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd7atAZVq1J42WzXJpS
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.

2 participants