Repository navigation
refactor: Fetch rows through a pluggable row sink - #638
Conversation
`PqResultImpl::fetch_into()` now drives the fetch loop (stepping through results and parameter groups, interrupt checks, completion) and hands each row-bearing `PGresult` to a `PqRowSink`. The data frame builder becomes the first sink, `PqDataFrameSink`, a thin adapter that serves its own `PqDataFrame` as the result source. Column data sources now read the sink's current row instead of row 0, so a sink can take results with more than one row. The interrupt check every 1024 rows moves from `DbDataFrame::advance()` into the loop. Behavior is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5LPjEzyaTRpXAuS6g
Question: what should
|
Compute No_NA from NA-producing cells, including NaN and integer overflow, and keep all chunk and view state in R objects, so no C finalizer is needed. Limit the new warnings to the new type mapping, to keep the legacy results identical. Write the row sink against the begin() signature proposed on #638, leave interrupt checks to fetch_into(), and amend the sink contract for chunked rows mode. Chain fixed-size index blocks, note the _cache changes in phase 5, drop the domain special case because the server reports base types, and add an open question on fixing the type cache on the default path. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd4c819TffvkRZJ1V2T
`begin()` now receives the cached names, type OIDs, type modifiers, and R data types instead of a `PGresult`, which was NULL for completed immediate queries. The cache stores `PQfmod()` from the first result that describes the columns; later results are still checked for names and OIDs only, so data frames behave as before. `fetch_into()` checks that the query is bound and is limited by the sink's `remaining()` alone. The header now documents when `begin()` runs, that each result holds one row today, what chunked rows mode still needs, and how sinks handle interrupts and errors. A new test pins the columns of an immediate query whose first statement has none. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5LPjEzyaTRpXAuS6g
`begin()` refers to the live column cache, so a sink copies what it needs. The type modifiers come from `PQdescribePrepared()` for prepared queries. Only a throw from `append()` redelivers its row; a throw from `step()` or the interrupt check loses the rows appended in that call. Local column counts no longer shadow the cache member `ncols_`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5LPjEzyaTRpXAuS6g
Accepted limitationsThese remain after two rounds of clean review and the ALTREP session's review. Each is documented in
Behavior that Generated by Claude Code |
Describe the row sink exactly as #638 provides it: begin() with names, OIDs, type modifiers, and types from the column cache, fetch_into() without a row limit, and interrupt checks in the fetch loop. Define NA-producing cells by the storage type's NA, including the legacy NAs, grow the chained data and index blocks geometrically, and state the fixed cost per column. Gate chunked rows mode on the build alone, with every sink adapted first, and add the rules for duplicating views and the attributes the sink sets. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd4c819TffvkRZJ1V2T
* refactor: Fetch rows into a pluggable row sink 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 * test: Fetch past the initial rows across parameter sets Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7atAZVq1J42WzXJpS * docs: Correct MariaRowSink and MariaRow header comments Note that MariaDataFrameSink is the known exception to the no-longjmp rule. Describe where the `fields` metadata of begin() comes from. Comment out the unused parameter names of the default begin(). Tighten the lifetime of the pointer returned by value_bytes(). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7atAZVq1J42WzXJpS * chore: Auto-update from GitHub Actions Run: https://github.com/r-dbi/RMariaDB/actions/runs/46289260868 * test: Compare the fetched placeholder values portably across servers Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7atAZVq1J42WzXJpS --------- Co-authored-by: Claude <[email protected]>
|
Resolve conflicts. |
Resolves the conflict in `PqResultImpl::fetch_rows()`: `main` now raises the "Don't need to call dbFetch() for statements" warning through `defer_warning()` (#669) and dropped nothing else the row sink needs. The warning moves into `fetch_into()` with `defer_warning()`, and the unused row-count argument of `fetch_rows()` from `main` is not carried over. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5LPjEzyaTRpXAuS6g
|
I merged The full test suite against PostgreSQL 16 with Generated by Claude Code |
This PR turns
PqResultImpl::fetch_rows()into a fetch loop,PqResultImpl::fetch_into(PqRowSink& sink), that feeds a pluggable row sink (PqRowSink, new insrc/PqRowSink.h). The loop checks that the query is bound and drivesstep(), the parameter groups fromdbBind(), the interrupt check every 1024 rows, completion, and the "Don't need to call dbFetch() for statements" warning. The data frame builder becomes the first sink.PqDataFrameSinkis a thin adapter that owns aPqDataFrameand acts as its result source. It is not a subclass, becausepeek_first_row()keeps usingPqDataFramewithPqResultImplas the source.fetch_rows()builds that sink, callsfetch_into(), and adds the oids as before. The behavior is meant to stay exactly the same.Why: this is the seam that native Arrow fetch (#631) and ALTREP result columns (#632, phase 0 of
design/altrep-columns.md) share. Each of them adds another sink later. This PR adds no Arrow or ALTREP code.The interface contract, documented in
src/PqRowSink.h:begin(names, oids, fmods, types)runs once perfetch_into()call, before the firstappend(). It gets the column cache as the laststep()left it. The column cache now also storesPQfmod(), taken from the first description of the columns. For a prepared query that isPQdescribePrepared(), and for an immediate query it is the first result with columns. Later results are still checked for the same names and OIDs only, so data frames behave as before (the open question is linked below). The cache is final at that point, with one exception. In an immediate multi-statement query whose first row-bearing result has no columns, a later statement fills the cache during the loop. The arguments refer to that live cache, so the sink copies what it needs inbegin(). The data frame sink keeps zero columns in that case, which is the existing behavior, and a new test intest-immediate.Rpins it.append(const PGresult* res)gets every row-bearing result whole. Today each result holds exactly one row (single-row mode). The loop ownsresand clears it right after the call, so the sink copies what it needs and keeps no pointer into it. A TODO records that chunked rows mode needsfetch_into()to keep a row offset into the result, for example withappend(res, first_row, n_rows), beforePQsetChunkedRowsMode()is used. That is because the loop checks the limit only before eachappend().PqDataFrameSinkalready reads every row ofres:PqResultSourcegainedget_row(),PqColumnDataSourcereads that row instead of row 0, andget_result()now returnsconst PGresult*.remaining()returns how many rows the sink still accepts, or -1 for no limit. It is the only limit of the loop, sofetch_into()takes non_max.unwind_protect(). After a throw, the caller offetch_into()discards the sink. Ifappend()throws, the next fetch delivers that row again. Ifstep()or the interrupt check throws, the rows already appended in that call count as fetched and are lost with the sink. That is the existing behavior.What moved: the interrupt check left
DbDataFrame::advance()and now sits in the loop. It runs at the same point as before, afterstep()and after the row count goes up.nrows_now goes up byPQntuples()of each appended result, which is 1 today. The unusedint& nout-parameter offetch_rows()is gone.Tests were run against a local PostgreSQL 16, on a private database.
devtools::test()gives the same results before and after the change: all 9193 existing expectations pass, plus the 5 in the new test (which also pass againstmain), 11 are skipped (9 DBItest skips and 2 timezone tests that need another database), and nothing fails. A probe script covers the following, for prepared and immediate queries:dbHasCompleted()anddbGetRowCount()after each fetchdbBind()groups, one of them empty, and a rebindIts output is identical before and after the change, apart from the
now()timestamp. The full suite and the probe also pass with the package built under AddressSanitizer and UBSan, with no reports. That run was at commit 26bf0aa. The last commit only changes comments and renames two local variables, and after ittest-immediate.Randtest-dbGetQuery.Rpass again. The changed C++ lines are formatted withgit clang-formatagainst.clang-format, and the test withair. No R code changed.Open question: what
begin()receives. The PR implements the recommended option.🤖 Generated with Claude Code
https://claude.ai/code/session_01Hr1rd5LPjEzyaTRpXAuS6g