You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "CurtHagenlocher (via GitHub)" <gi...@apache.org> on 2026/05/17 21:52:41 UTC

[PR] feat(csharp/src/Apache.Arrow.Adbc/C): bring driver exporter to parity with importer [arrow-adbc]

CurtHagenlocher opened a new pull request, #4318:
URL: https://github.com/apache/arrow-adbc/pull/4318

   Wires up exporter callbacks that were either missing or unreachable:
   
     - `StatementSetOption` (1.0.0 gap): a managed driver behind the exporter never received `SetOption()` calls. The importer always issued them via `AdbcStatement.SetOption` / `BulkIngest`.
     - `StatementExecuteSchema`, `ConnectionCancel`, `StatementCancel` (1.1.0): the exporter previously returned `NotImplemented` for any version >= 1.1.0; `AdbcDriverInit` now also populates the v1.1.0 fields that map onto existing managed APIs and leaves the rest null so the importer's defaults take effect. Adds matching `Cancel()` overrides on `ImportedAdbcConnection` / `ImportedAdbcStatement` so the C-ABI is actually exercised end-to-end; previously the base classes threw `NotImplemented` before ever calling into the driver.
     - Extends `ExportedDriverRoundTripTests` with cases for `SetOption`, both `Cancel` paths, `ExecuteSchema` (verifies it doesn't run the query), and a regression test that proves 1.1.0-only callbacks are gated by the negotiated version.
   
   Adds two projects under `csharp/test/AotInterop/`:
   
     - Apache.Arrow.Adbc.TestFixture.Native: net10 library published with `PublishAot=true`. Exports `AdbcDriverInit` (UnmanagedCallersOnly) that delegates to `CAdbcDriverExporter` wrapped around a deterministic managed `FixtureDriver`. The fixture echoes its inputs (SQL query, statement options, database/connection options) through the result schema so a consumer can assert that each ADBC API call survived the C-ABI hop.
     - Apache.Arrow.Adbc.TestFixture.Tests: net10 xUnit test project that loads the AOT-published .dll via `CAdbcDriverImporter.Load(path)` and exercises the round-trip. Tests use `SkippableFact` and read the path from `ADBC_TEST_AOT_FIXTURE_PATH` so the suite stays green locally when no AOT artifact is present.
   
   Together these projects test BOTH halves of csharp/src/Apache.Arrow.Adbc/C: the export path inside the AOT'd native lib AND the import path in the managed test process. They also serve as an AOT-compatibility canary — trim-unsafe reflection or missing exports anywhere in core ADBC will fail this build.
   
   Enables the csharp-aot job in .github/workflows/csharp.yml (previously `if: false`, referencing a non-existent project). The job runs on windows-2022 only for now because of the MSVC linker dependency for NativeAOT on Windows.
   
   Will look at enabling this on non-Windows platforms in a subsequent PR.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(csharp/src/Apache.Arrow.Adbc/C): bring driver exporter to parity with importer [arrow-adbc]

Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on PR #4318:
URL: https://github.com/apache/arrow-adbc/pull/4318#issuecomment-4483435301

   I'm curious, is there a use case for exporting .NET based drivers as shared libraries now? I think when we discussed before there was some concern that (like Go) the runtime may pose issues


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(csharp/src/Apache.Arrow.Adbc/C): bring driver exporter to parity with importer [arrow-adbc]

Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on PR #4318:
URL: https://github.com/apache/arrow-adbc/pull/4318#issuecomment-4483640986

   That's fair! (Though re: Spark, stay tuned :wink:)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(csharp/src/Apache.Arrow.Adbc/C): bring driver exporter to parity with importer [arrow-adbc]

Posted by "CurtHagenlocher (via GitHub)" <gi...@apache.org>.
CurtHagenlocher commented on code in PR #4318:
URL: https://github.com/apache/arrow-adbc/pull/4318#discussion_r3255562559


##########
csharp/src/Apache.Arrow.Adbc/C/CAdbcDriverExporter.cs:
##########
@@ -502,6 +518,63 @@ private unsafe static AdbcStatusCode SetStatementSqlQuery(CAdbcStatement* native
             }
         }
 
+#if NET5_0_OR_GREATER
+        [UnmanagedCallersOnly]
+#endif
+        private unsafe static AdbcStatusCode SetStatementOption(CAdbcStatement* nativeStatement, byte* name, byte* value, CAdbcError* error)
+        {
+            try
+            {
+                if (name == null) throw new ArgumentNullException(nameof(name));
+
+                GCHandle gch = GCHandle.FromIntPtr((IntPtr)nativeStatement->private_data);
+                AdbcStatement stub = (AdbcStatement)gch.Target!;
+
+                stub.SetOption(MarshalExtensions.PtrToStringUTF8(name)!, MarshalExtensions.PtrToStringUTF8(value)!);
+                return AdbcStatusCode.Success;

Review Comment:
   Maybe it should be okay for value to be null? Rather than worry about that for now, I'll aim for consistency with the preexisting call sites. Also, the need for a `!` operator suggests that the C# definition also expects a not-null value.
   
   I've separately changed the shared error-handling code to turn `ArgumentException` into `AdbcStatusCode.InvalidArgument`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(csharp/src/Apache.Arrow.Adbc/C): bring driver exporter to parity with importer [arrow-adbc]

Posted by "CurtHagenlocher (via GitHub)" <gi...@apache.org>.
CurtHagenlocher merged PR #4318:
URL: https://github.com/apache/arrow-adbc/pull/4318


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(csharp/src/Apache.Arrow.Adbc/C): bring driver exporter to parity with importer [arrow-adbc]

Posted by "CurtHagenlocher (via GitHub)" <gi...@apache.org>.
CurtHagenlocher commented on PR #4318:
URL: https://github.com/apache/arrow-adbc/pull/4318#issuecomment-4483212291

   @davidhcoe it would be great if you could review this.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(csharp/src/Apache.Arrow.Adbc/C): bring driver exporter to parity with importer [arrow-adbc]

Posted by "CurtHagenlocher (via GitHub)" <gi...@apache.org>.
CurtHagenlocher commented on PR #4318:
URL: https://github.com/apache/arrow-adbc/pull/4318#issuecomment-4483469874

   > I'm curious, is there a use case for exporting .NET based drivers as shared libraries now? I think when we discussed before there was some concern that (like Go) the runtime may pose issues
   
   My sense is that the situation isn't intrinsically better than or worse than Go; in both cases, you have a component in the process with its own garbage collector and threads that don't interact with any other component -- including the main process. Someone who's okay with that and prefers to code in C# should have the opportunity to do so.
   
   It may also be that someone has an application which is stuck on older .NET and might like to use a driver compiled against a newer version -- because of performance, or because it has better support for HTTP/2, or because it depends on features not easily available on the older platform. AOT-compiling the driver lets them continue to use .NET while also leveraging the newer version. (Disclaimer: we have not yet done any performance tests to see how that part pans out, but our data-related applications in general tend to be about 30% faster on .NET 8 than on .NET 4.8.)
   
   I've also found -- at least on Windows -- that the debugging experience with an AOT-compiled .NET driver is notably better than it is with a Go driver.
   
   Finally, we have a Spark driver in the `HiveServer2` project, and wouldn't it be nice to ship a "native" driver based on that without doing any additional work?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(csharp/src/Apache.Arrow.Adbc/C): bring driver exporter to parity with importer [arrow-adbc]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #4318:
URL: https://github.com/apache/arrow-adbc/pull/4318#discussion_r3255553180


##########
csharp/src/Apache.Arrow.Adbc/C/CAdbcDriverExporter.cs:
##########
@@ -502,6 +518,63 @@ private unsafe static AdbcStatusCode SetStatementSqlQuery(CAdbcStatement* native
             }
         }
 
+#if NET5_0_OR_GREATER
+        [UnmanagedCallersOnly]
+#endif
+        private unsafe static AdbcStatusCode SetStatementOption(CAdbcStatement* nativeStatement, byte* name, byte* value, CAdbcError* error)
+        {
+            try
+            {
+                if (name == null) throw new ArgumentNullException(nameof(name));
+
+                GCHandle gch = GCHandle.FromIntPtr((IntPtr)nativeStatement->private_data);
+                AdbcStatement stub = (AdbcStatement)gch.Target!;
+
+                stub.SetOption(MarshalExtensions.PtrToStringUTF8(name)!, MarshalExtensions.PtrToStringUTF8(value)!);
+                return AdbcStatusCode.Success;

Review Comment:
   `SetStatementOption` validates `name` but not `value`. If a driver manager passes a null `value` pointer, this ends up calling `PtrToStringUTF8(value)!` and then `stub.SetOption(..., null)` (or throws later), which is inconsistent with other SetOption entry points (e.g. `ConnectionStub.SetOption` checks `value == null`). Consider adding an explicit `if (value == null) throw new ArgumentNullException(nameof(value));` (or mapping to an `AdbcException` with `InvalidArgument`) so the exported ABI returns a predictable status/message.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org