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(python): support use of KùzuDB via pl.read_database #14822

Merged

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented Mar 2, 2024

Quite happy with how the ConnectionExecutor abstraction is holding up as it only required a few minor tweaks to add support for kuzu1 graph database queries (which make use of the Cypher2 query language).

Registered it as having Arrow-aware return, so we will always load results efficiently (eg: not via the row iterator), and also made a PR on their side adding direct Polars export support to their QueryResult object; we don't need to wait on that here though, as we can use their existing Arrow export directly (see: kuzudb/kuzu#2985).

Example

df = pl.read_database(
    query = "MATCH (a:User)-[f:Follows]->(b:User) RETURN a.name, f.since, b.name",
    connection = kuzu_connection,
)
# shape: (4, 3)
# ┌─────────┬─────────┬─────────┐
# │ a.name  ┆ f.since ┆ b.name  │
# │ ---     ┆ ---     ┆ ---     │
# │ str     ┆ i64     ┆ str     │
# ╞═════════╪═════════╪═════════╡
# │ Adam    ┆ 2020    ┆ Karissa │
# │ Adam    ┆ 2020    ┆ Zhang   │
# │ Karissa ┆ 2021    ┆ Zhang   │
#  ...

Footnotes

  1. KùzuDB: https://kuzudb.com/

  2. Cypher: https://kuzudb.com/docusaurus/cypher/

@alexander-beedie alexander-beedie marked this pull request as ready for review March 2, 2024 20:55
@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars labels Mar 2, 2024
@alexander-beedie alexander-beedie force-pushed the read-kuzu-graph-database branch 3 times, most recently from 90d8a93 to f5e1d1a Compare March 2, 2024 21:11
@alexander-beedie alexander-beedie changed the title feat(python): support use of the "kuzu" graph database via pl.read_database feat(python): support use of the KùzuDB graph database via pl.read_database Mar 2, 2024
@alexander-beedie alexander-beedie changed the title feat(python): support use of the KùzuDB graph database via pl.read_database feat(python): support use of KùzuDB via pl.read_database Mar 2, 2024
@alexander-beedie alexander-beedie force-pushed the read-kuzu-graph-database branch 2 times, most recently from 8033c82 to 96edb8d Compare March 2, 2024 21:22
Copy link

codecov bot commented Mar 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.94%. Comparing base (5a5abdc) to head (c89d9a5).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14822      +/-   ##
==========================================
- Coverage   80.95%   80.94%   -0.02%     
==========================================
  Files        1327     1327              
  Lines      172080   172081       +1     
  Branches     2452     2453       +1     
==========================================
- Hits       139305   139283      -22     
- Misses      32305    32328      +23     
  Partials      470      470              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@stinodego stinodego left a comment

Choose a reason for hiding this comment

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

Looks good overall, I think it's nice to add support for this.

A nitpick / some general questions.

py-polars/polars/io/database.py Show resolved Hide resolved
py-polars/polars/io/database.py Show resolved Hide resolved
py-polars/pyproject.toml Show resolved Hide resolved
@alexander-beedie
Copy link
Collaborator Author

alexander-beedie commented Mar 3, 2024

I'll fix the Windows test shortly 🤔

Update: done.

@alexander-beedie alexander-beedie force-pushed the read-kuzu-graph-database branch 2 times, most recently from 4e84ef9 to 21e4a27 Compare March 3, 2024 06:30
Copy link
Member

@stinodego stinodego left a comment

Choose a reason for hiding this comment

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

All right, nice! Thanks Alex.

@alexander-beedie alexander-beedie merged commit baacf3d into pola-rs:main Mar 3, 2024
12 checks passed
@alexander-beedie alexander-beedie deleted the read-kuzu-graph-database branch March 3, 2024 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-io-database Area: reading/writing to databases enhancement New feature or an improvement of an existing feature python Related to Python Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants