-
Notifications
You must be signed in to change notification settings - Fork 86
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
Wrap pybind11 API and and Fix #1106 #1124
Merged
+202
−82
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tools/python_api/py_database.cpp → tools/python_api/src_cpp/py_database.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from ._kuzu import * | ||
# The following imports will override C++ implementations with Python | ||
# implementations. | ||
from .connection import * | ||
from .query_result import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from .query_result import QueryResult | ||
from . import _kuzu | ||
|
||
|
||
class Connection: | ||
def __init__(self, database, num_threads=0): | ||
self.database = database | ||
self._connection = _kuzu.Connection(database, num_threads) | ||
|
||
def set_max_threads_for_exec(self, num_threads): | ||
self._connection.set_max_threads_for_exec(num_threads) | ||
|
||
def execute(self, query, parameters=[]): | ||
return QueryResult(self, self._connection.execute(query, parameters)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
class QueryResult: | ||
def __init__(self, connection, query_result): | ||
self.connection = connection | ||
self._query_result = query_result | ||
self.is_closed = False | ||
|
||
def __del__(self): | ||
self.close() | ||
|
||
def check_for_query_result_close(self): | ||
if self.is_closed: | ||
raise Exception("Query result is closed") | ||
|
||
def has_next(self): | ||
self.check_for_query_result_close() | ||
return self._query_result.hasNext() | ||
|
||
def get_next(self): | ||
self.check_for_query_result_close() | ||
return self._query_result.getNext() | ||
|
||
def write_to_csv(self, filename, delimiter=',', escapeCharacter='"', newline='\n'): | ||
self.check_for_query_result_close() | ||
self._query_result.writeToCSV( | ||
filename, delimiter, escapeCharacter, newline) | ||
|
||
def close(self): | ||
if self.is_closed: | ||
return | ||
self._query_result.close() | ||
# Allows the connection to be garbage collected if the query result | ||
# is closed manually by the user. | ||
self.connection = None | ||
self.is_closed = True | ||
|
||
def get_as_df(self): | ||
self.check_for_query_result_close() | ||
return self._query_result.getAsDF() | ||
|
||
def get_column_data_types(self): | ||
self.check_for_query_result_close() | ||
return self._query_result.getColumnDataTypes() | ||
|
||
def get_column_names(self): | ||
self.check_for_query_result_close() | ||
return self._query_result.getColumnNames() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
from tools.python_api import _kuzu as kuzu | ||
import sys | ||
sys.path.append('../build/') | ||
import kuzu | ||
|
||
databaseDir = "path to database file" | ||
db = kuzu.database(databaseDir) | ||
conn = kuzu.connection(db) | ||
db = kuzu.Database(databaseDir) | ||
conn = kuzu.Connection(db) | ||
query = "MATCH (a:person) RETURN *;" | ||
result = conn.execute(query) | ||
while result.hasNext(): | ||
print(result.getNext()) | ||
while result.has_next(): | ||
print(result.get_next()) | ||
result.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather not use GLOB, but list all necessary files here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed the C++ target to use the explicit path instead of using GLOB. But I think we can keep the GLOB for Python files since CMake is not actually running any build script against the Python files. It is just copying the files to the build directory.