Repository navigation
[Go][Format] initial attempt at wrapping adbc for database/sql - #97
Conversation
|
See arrow-adbc/c/validation/adbc_validation.c Lines 268 to 279 in 1ca2d2d Disabling autocommit begins a transaction; commit/rollback also begin a transaction; enabling autocommit also runs a commit. |
|
Gotcha, so the interfaces should allow setting options on an existing connection, not only setting options before initializing it. I'll make the adjustment. |
|
@lidavidm Do we have any constants for setting the Isolation level of the transactions yet? If not, the golang values are:
With the documentation that if a driver does not support a given isolation level, an error may be returned. This is in addition to a |
|
We don't, it probably makes sense to define them |
|
@lidavidm Added them to this PR, let me know if you have any comments / issues with them. Thanks! |
| /// \brief The name of the canonical option for whether the current | ||
| /// transaction should be restricted to being a read-only transaction. | ||
| #define ADBC_CONNECTION_OPTION_TRANSACTION_READ_ONLY \ | ||
| "adbc.connection.transaction.readonly" |
There was a problem hiding this comment.
Interesting, so Golang has you explicitly manage transactions. DBAPI/JDBC/ODBC have "auto commit on" and you implicitly manage transactions (by disabling autocommit, then calling commit/rollback). In these APIs, readonly is a property of the connection, not the transaction. Given that the rest of the APIs are patterned after DBAPI/JDBC/ODBC, I think this would make more sense as a connection property as well.
There was a problem hiding this comment.
Interesting, okay. I'll change the option to be adbc.connection.readonly instead of adbc.connection.transaction.readonly
There was a problem hiding this comment.
updated, let me know if there's anything else you'd like me to modify.
…4625) ### Problem `rows.Next` returned `array.String.Value` (and `LargeString`/`Binary`/`LargeBinary`) directly as the `driver.Value`. Those are zero-copy values that alias the underlying Arrow data buffer. `database/sql` retains the `driver.Value`s after `Next` returns — and after the underlying record batch (and its buffer) is released. For ADBC results the batch buffers are C-owned, so once the batch is released the value reads back as garbage. Minimal reproduction: reading a `VARCHAR` from a DuckDB ADBC query through this `sqldriver` returns a corrupted string (e.g. `"\xb6|:u\x14\x7f\x00"`, stale memory) instead of the actual text. Reading the same result directly at the Arrow level (before release) is correct, which localizes the problem to `rows.Next` handing back an alias rather than an owned value. ### What changed Copy string/binary values into Go-owned memory (`strings.Clone` / `bytes.Clone`) so they outlive the record batch. ### Why it surfaced now The zero-copy return predates this (it's been in `rows.Next` since the original `database/sql` wrapper, #97). It was surfaced by the arrow-go v18.7 bump — specifically apache/arrow-go#793, which replaced the `nativeCRecordBatchReader` finalizer with deterministic atomic Retain/Release. C memory is now freed promptly when the batch is released instead of lazily at GC, so the latent aliasing became a use-after-free. --------- Signed-off-by: iremcaginyurtturk <[email protected]>
Here's my first shot at creating the wrapper. After this I'll look into actually creating an implementation to write tests with.
However, I did come across one thing: There are
CommitandRollbackmethods for a connection, but there's nothing to actually begin a transaction. Nor anything specific for defining transaction options such as Isolation level or Read-Only etc.For Go's
sqlpackage there needs to be aBeginTxmethod on a connection which also shouldn't require creating a new connection (ie: start a new connection with autocommit turned off?) So i'm not sure of the best way to implement this in the current framework we have.