Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(csharp): adding C# functionality #697

Merged
merged 37 commits into from
Jun 7, 2023

Conversation

davidhcoe
Copy link
Contributor

@davidhcoe davidhcoe commented May 22, 2023

Introduces C# functionality for ADBC, including base classes for

  • AdbcDriver
  • AdbcDatabase
  • AdbcConnection
  • AdbcStatement

Also adds a FlightSql implementation

Currently tied to Arrow 13.0.0. Uses a submodule to pull in the Arrow library until the latest NuGet is released.

@github-actions
Copy link

⚠️ Please follow the Conventional Commits format in CONTRIBUTING.md for PR titles.

@lidavidm lidavidm changed the title adding C# functionality feat(csharp): adding C# functionality May 22, 2023
@lidavidm
Copy link
Member

Cool!

It's been >15 years since I last touched C♯, so this will take me a while to review (or I will have to see if Weston or someone else can help).

@eerhardt eerhardt self-requested a review May 22, 2023 20:09
Copy link
Member

@lidavidm lidavidm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a general pass (I haven't looked at the native interop)

Copy link
Member

@lidavidm lidavidm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Admittedly I'm only giving things a cursory look. Even if there's a few parts I'm not sure about, I'd be in favor of merging sooner rather than later and continuing to cycle on things in later PRs.

@davidhcoe davidhcoe marked this pull request as draft June 1, 2023 13:32
@davidhcoe davidhcoe marked this pull request as ready for review June 2, 2023 16:54
@CurtHagenlocher
Copy link
Contributor

Admittedly I'm only giving things a cursory look. Even if there's a few parts I'm not sure about, I'd be in favor of merging sooner rather than later and continuing to cycle on things in later PRs.

Is there a target date yet for a 0.5 release? I think there's a bunch of stuff that would need to have cleaned up before then.

@lidavidm
Copy link
Member

lidavidm commented Jun 6, 2023

Mid-late June, but we could omit this from the release (it wouldn't be part of it anyways unless/until we wire it into the release scripts)

@davidhcoe
Copy link
Contributor Author

Is this far enough we can commit this iteration?

@lidavidm
Copy link
Member

lidavidm commented Jun 6, 2023

Also note the pre-commit CI failures (mostly: trim trailing whitespace, and make sure the Apache license header is added to new files), then I think it's ready to merge (can we start filing follow-up issues?)

@@ -0,0 +1,60 @@
<!--
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a .sln file in the root like there is for arrow/csharp?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, interesting. yes. It turns out that a root level .gitignore was preventing the one I had from being added

<!-- AssemblyInfo properties -->
<PropertyGroup>
<Product>Apache Arrow ADBC library</Product>
<Copyright>Copyright 2016-2019 The Apache Software Foundation</Copyright>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2023? Or 2022-2023? (The root has a file which says just 2022.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied over what was in the Arrow one, but changed to 2022-2023. unless @lidavidm has an opinion on it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm we should update the Arrow one but 2022-2023 is fine here

<Product>Apache Arrow ADBC library</Product>
<Copyright>Copyright 2016-2019 The Apache Software Foundation</Copyright>
<Company>The Apache Software Foundation</Company>
<Version>0.1.0</Version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this reflect the release version of ADBC (which will next be 0.5, I think?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only intended for it to be the iteration of this check-in; not necessarily where ADBC is. but, I will defer to @lidavidm on this one as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can update it later (but it would be fine to put 0.5.0 here)

* limitations under the License.
*/

#if NETSTANDARD
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider removing via the project file like the Arrow project does.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to do that because I cant add an actual extension to Marshal since it's static


namespace Apache.Arrow.Adbc.Interop
{
internal readonly struct NativeDelegate<T>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider renaming the file to match the class.

If you look at a recent in-progress change for Arrow (apache/arrow#35810) there's some pertinent work and discussion related to NativeDelegate:

  1. It's not needed for .NET >= 5.0 due to the ability to declare a function as [UnmanagedCallersOnly]
  2. The native delegates have been typed somewhat incorrectly, and in particular would produce the wrong outcome when building a 32-bit version for non-Windows platforms.

The proposed solutions are

  1. Only use NativeDelegate when targeting older .NET
  2. Make the actual delegate fields in the structs be private and give them different calling conventions depending on the version of .NET.

That said, the change is still in progress and not final, and there's no reason the same change can't be made here after the initial commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed the file - TBD on the other items for now?

@lidavidm
Copy link
Member

lidavidm commented Jun 7, 2023

It looks like there's still whitespace errors: https://github.com/apache/arrow-adbc/actions/runs/5196453814/jobs/9377170741?pr=697

if you set up pre-commit, you can run pre-commit in the repo root then commit the changes

@lidavidm
Copy link
Member

lidavidm commented Jun 7, 2023

There's still license header issues; if need be you can add paths to https://github.com/apache/arrow-adbc/blob/main/dev/release/rat_exclude_files.txt

Copy link
Member

@lidavidm lidavidm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should merge here, but I'll let others take a look first

Comment on lines +33 to +37
csharp/Apache.Arrow.Adbc.sln
csharp/src/Apache.Arrow.Adbc.FlightSql/Apache.Arrow.Adbc.FlightSql.csproj
csharp/src/Apache.Arrow.Adbc/Apache.Arrow.Adbc.csproj
csharp/test/Apache.Arrow.Adbc.FlightSql.Tests/Apache.Arrow.Adbc.FlightSql.Tests.csproj
csharp/test/Apache.Arrow.Adbc.Tests/Apache.Arrow.Adbc.Tests.csproj
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know these rat_exclude_files support wildcards. Can we just have:

Suggested change
csharp/Apache.Arrow.Adbc.sln
csharp/src/Apache.Arrow.Adbc.FlightSql/Apache.Arrow.Adbc.FlightSql.csproj
csharp/src/Apache.Arrow.Adbc/Apache.Arrow.Adbc.csproj
csharp/test/Apache.Arrow.Adbc.FlightSql.Tests/Apache.Arrow.Adbc.FlightSql.Tests.csproj
csharp/test/Apache.Arrow.Adbc.Tests/Apache.Arrow.Adbc.Tests.csproj
*.sln
*.csproj

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressing this in #824

/// </param>
public static AdbcDriver Load(string file)
{
if (file[0] == '/')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the plan for Linux? Might be good to have a follow-up issue for supporting Linux.

AdbcDriverInit init = Marshal.GetDelegateForFunctionPointer<AdbcDriverInit>(symbol);
NativeAdbcDriver driver = new NativeAdbcDriver();
NativeAdbcError error = new NativeAdbcError();
byte result = init(1000000, ref driver, ref error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we ignoring the error here? And above in the MacInterop.

public PinnedArray(IArrowArray array)
{
_array = array;
pinnedHandles = new MemoryHandle[GetHandleCount(array.Data)];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to make this a List<MemoryHandle> instead, so we don't have to count all the handles first, and then pin them?

@davidhcoe
Copy link
Contributor Author

chatted with Eric on the side -- he is good to close this PR and incorporate his comments in to a different PR. I've noted them for tracking.

@eerhardt
Copy link
Contributor

eerhardt commented Jun 7, 2023

@lidavidm - It looks like I have merge permissions here since I'm a committer on apache/arrow. But I'm unsure on the process. Can I just click the green button in GitHub? In apache/arrow there is a python script I run: dev/merge_arrow_pr.py, but I'm not seeing it here.

If you want to merge this PR, please go ahead.

@lidavidm
Copy link
Member

lidavidm commented Jun 7, 2023

Yup, we just use the button here.

@lidavidm lidavidm merged commit ad07ba2 into apache:main Jun 7, 2023
@lidavidm
Copy link
Member

lidavidm commented Jun 7, 2023

Thanks @davidhcoe @eerhardt @CurtHagenlocher!

@lidavidm lidavidm added this to the ADBC Libraries 0.5.0 milestone Jun 7, 2023
@lidavidm
Copy link
Member

lidavidm commented Jun 7, 2023

If possible - can we create GitHub issues for followups? (I suppose you may have your own work queue but it'd be nice to make at least some of that public)

@davidhcoe davidhcoe deleted the dev/davidhcoe/adbc-csharp branch June 15, 2023 15:44
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.

4 participants