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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.

run: CC=gcc CXX=g++ make rusttest NUM_THREADS=32

- name: Generate coverage report
run: |
lcov -c -d ./ --no-external -o cover.info &&\
Expand Down Expand Up @@ -131,6 +134,16 @@ jobs:
- name: Check test format
run: python3 scripts/run-clang-format.py --clang-format-executable /usr/bin/clang-format-11 -r test/

rustfmt-check:
name: rustfmt check
runs-on: kuzu-self-hosted-testing
steps:
- uses: actions/checkout@v3

- name: Check api format
working-directory: tools/rust_api
run: cargo fmt --check

benchmark:
name: benchmark
needs: [gcc-build-test, clang-build-test]
Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ nodejstest: arrow
cd $(ROOT_DIR)/tools/nodejs_api/ && \
npm test

rusttest:
ifeq ($(OS),Windows_NT)
cd $(ROOT_DIR)/tools/rust_api && \
set KUZU_TESTING=1 && \
cargo test -- --test-threads=1
else
cd $(ROOT_DIR)/tools/rust_api && \
KUZU_TESTING=1 cargo test -- --test-threads=1
endif

clean-python-api:
ifeq ($(OS),Windows_NT)
if exist tools\python_api\build rmdir /s /q tools\python_api\build
Expand Down
1 change: 1 addition & 0 deletions examples/rust/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
268 changes: 268 additions & 0 deletions examples/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions examples/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "kuzu-rust-example"
version = "0.1.0"
edition = "2021"

[dependencies]
kuzu = {path="../../tools/rust_api"}
24 changes: 24 additions & 0 deletions examples/rust/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use kuzu::{Connection, Database, Error};

fn main() -> Result<(), Error> {
let db = Database::new(
std::env::args()
.nth(1)
.expect("The first CLI argument should be the database path"),
0,
)?;
let connection = Connection::new(&db)?;

// Create schema.
connection.query("CREATE NODE TABLE Person(name STRING, age INT64, PRIMARY KEY(name));")?;
// Create nodes.
connection.query("CREATE (:Person {name: 'Alice', age: 25});")?;
connection.query("CREATE (:Person {name: 'Bob', age: 30});")?;

// Execute a simple query.
let mut result = connection.query("MATCH (a:Person) RETURN a.name AS NAME, a.age AS AGE;")?;

// Print query result.
println!("{}", result.display());
Ok(())
}
2 changes: 1 addition & 1 deletion src/common/types/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ nodeID_t RelVal::getDstNodeID() const {
return dstNodeIDVal->getValue<nodeID_t>();
}

std::string RelVal::getLabelName() {
std::string RelVal::getLabelName() const {
return labelVal->getValue<std::string>();
}

Expand Down
4 changes: 2 additions & 2 deletions src/include/c_api/kuzu.h
Original file line number Diff line number Diff line change
Expand Up @@ -882,12 +882,12 @@ KUZU_C_API char* kuzu_rel_val_to_string(kuzu_rel_val* rel_val);
*/
KUZU_C_API void kuzu_query_summary_destroy(kuzu_query_summary* query_summary);
/**
* @brief Returns the compilation time of the given query summary.
* @brief Returns the compilation time of the given query summary in milliseconds.
* @param query_summary The query summary to get compilation time.
*/
KUZU_C_API double kuzu_query_summary_get_compiling_time(kuzu_query_summary* query_summary);
/**
* @brief Returns the execution time of the given query summary.
* @brief Returns the execution time of the given query summary in milliseconds.
* @param query_summary The query summary to get execution time.
*/
KUZU_C_API double kuzu_query_summary_get_execution_time(kuzu_query_summary* query_summary);
Expand Down
2 changes: 1 addition & 1 deletion src/include/common/types/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ class RelVal {
/**
* @return the name of the RelVal.
*/
KUZU_API std::string getLabelName();
KUZU_API std::string getLabelName() const;
/**
* @return the value of the RelVal in string format.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/include/main/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class Connection {
KUZU_API std::string getRelPropertyNames(const std::string& relTableName);

/**
* @brief interrupts all queries currently executed within this connection.
* @brief interrupts all queries currently executing within this connection.
*/
KUZU_API void interrupt();

Expand Down
Loading
Loading