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

Rust API #1685

Merged
merged 3 commits into from
Jun 21, 2023
Merged

Rust API #1685

merged 3 commits into from
Jun 21, 2023

Conversation

benjaminwinger
Copy link
Collaborator

A few issues are outstanding, but I think it's close enough for review.

Implements a rust API using the cxx crate, which was chosen over bindgen since it makes it possible to translate C++ exceptions into rust errors, and provides a bunch of extra safety checks.

The rust build runs make debug/make release to get the kuzu libraries, and then passes those libraries to cargo to link to the rust library. This process should be transparent to any rust applications using kuzu with the obvious exception that they will need kuzu's build dependencies.

Rust is const by default, which led to me making several functions const which didn't need to not be const.

Outstanding issues:

  • Linking to kuzu in build.rs is fragile and platform-specific (since for static libraries it also needs to link the dependencies explicitly):
    • It's working on Linux, but I've tested it on windows and found some problems which I'm still looking into (naming differences, and a different stdlib).
    • For some reason, when linking the rust tests it fails with undefined symbol errors if they aren't also linked to libssl/libcrypto. I've hidden this behaviour behind a KUZU_TESTING environment variable since it doesn't appear to affect rust software building against the kuzu crate.
  • There are some test failures I ran into which may indicate underlying problems with kuzu:
    • Fetching Null values from the database is causing a buffer manager failure (kuzu/src/include/storage/buffer_manager/bm_file_handle.h:173: kuzu::storage::PageState* kuzu::storage::BMFileHandle::getPageState(kuzu::common::page_idx_t): Assertion `pageIdx < numPages && pageStates[pageIdx]' failed). This might be related to WITH NULL segmentation fault #1643.
    • Passing VarLists as parameters for node creation and querying the result gives back an empty list (presumably unsupported? Add List-type literal and parameter #557 (comment), but unlike other unsupported types it's not giving an error, which is at least inconsistent behaviour).
  • I haven't set anything up for deployment to crates.io (the process is relatively straightforward, and could probably be done from CI).
  • QueryResult behaves a little unusually since it embeds the iterator in itself, which leads to things like rust's Display trait not being able to be used since toString mutates the QueryResult (instead I added a display(&mut self) method). I feel like it would make more sense for the QueryResult to have a const function which produces an iterator, but I'm not sure how easy of a change that would be.
  • Currently this can only be built against kuzu when it's compiled with the bundled source code. Having the crate link against the release binaries by using environment variables to specify where they are would be possible except that the headers are different, so the kuzu_rs.h shim would need to import kuzu.h instead of main/kuzu.h, etc. (could probably be handled with some macros).
  • A few types are not implemented (RECURSIVE_REL, SERIAL, ARROW_COLUMN, MAP, UNION).

Makefile Outdated
@@ -107,6 +107,16 @@ nodejstest: arrow
cd $(ROOT_DIR)/tools/nodejs_api/ && \
npm test

rust-test:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think our naming convension is not to add a '-' between the language name and test. (e.g. nodesjstest rather than nodejs-test)
So rename to rusttest

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

db_string: Value::String("Hello World".to_string()), "STRING",
db_bool: Value::Bool(true), "BOOLEAN",
// Causes buffer manager failure
// db_null_string: Value::Null(LogicalType::String), "STRING",
Copy link
Collaborator

Choose a reason for hiding this comment

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

As we discussed, we currently don't support giving null/list values to parameters of preparedStatement.
you can remove this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@@ -34,6 +34,9 @@ jobs:
- name: Node.js test
run: CC=gcc CXX=g++ make nodejstest NUM_THREADS=32

- name: Rust test
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's test rust on clang and windows as well.

@benjaminwinger benjaminwinger force-pushed the rust-api branch 2 times, most recently from a31c6e6 to 601de13 Compare June 19, 2023 21:57
@benjaminwinger
Copy link
Collaborator Author

I added a rustfmt check. Is it fine to have it separate like the clang-formatting-check, or now that there's multiple (maybe more in future: #1464) should the formatting checks be grouped together as multiple steps in a single job?

@mewim
Copy link
Collaborator

mewim commented Jun 19, 2023

It is fine to have separate format checks. Since checking format is a very simple job, maybe we should consider running it on GitHub runner instead of self-hosted moving forward?

@benjaminwinger benjaminwinger force-pushed the rust-api branch 2 times, most recently from 949302c to 9b23b64 Compare June 20, 2023 12:50
The rust API needs to call them from a const context.
@benjaminwinger benjaminwinger merged commit c37c9bb into master Jun 21, 2023
7 checks passed
@benjaminwinger benjaminwinger deleted the rust-api branch June 21, 2023 15:38
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.

None yet

3 participants