Skip to content

Commit

Permalink
Implemented Rust API
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminwinger committed Jun 20, 2023
1 parent 5cde420 commit 4666bc4
Show file tree
Hide file tree
Showing 23 changed files with 3,164 additions and 4 deletions.
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
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(())
}
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
4 changes: 2 additions & 2 deletions src/include/main/query_summary.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ class QuerySummary {

public:
/**
* @return query compiling time.
* @return query compiling time in milliseconds.
*/
KUZU_API double getCompilingTime() const;
/**
* @return query execution time.
* @return query execution time in milliseconds.
*/
KUZU_API double getExecutionTime() const;
bool getIsExplain() const;
Expand Down
2 changes: 2 additions & 0 deletions tools/rust_api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target
Cargo.lock
Loading

0 comments on commit 4666bc4

Please sign in to comment.