-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
178 additions
and
72 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ bazel-* | |
|
||
test_temp/ | ||
build/ | ||
cmake-build-debug/ | ||
|
||
### Python | ||
# Byte-compiled / optimized / DLL files | ||
|
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.
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
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,29 @@ | ||
class QueryResult: | ||
def __init__(self, connection, query_result): | ||
self.connection = connection | ||
self._query_result = query_result | ||
|
||
def __del__(self): | ||
self._query_result.close() | ||
|
||
def has_next(self): | ||
return self._query_result.hasNext() | ||
|
||
def get_next(self): | ||
return self._query_result.getNext() | ||
|
||
def write_to_csv(self, filename, delimiter=',', escapeCharacter='"', newline='\n'): | ||
self._query_result.writeToCSV( | ||
filename, delimiter, escapeCharacter, newline) | ||
|
||
def close(self): | ||
self._query_result.close() | ||
|
||
def get_as_df(self): | ||
return self._query_result.getAsDF() | ||
|
||
def get_column_data_types(self): | ||
return self._query_result.getColumnDataTypes() | ||
|
||
def get_column_names(self): | ||
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) | ||
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
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,23 @@ | ||
import subprocess | ||
import sys | ||
|
||
|
||
def test_query_result_close(get_tmp_path): | ||
code = [ | ||
'import sys', | ||
'sys.path.append("../build/")', | ||
'import kuzu', | ||
'db = kuzu.database("' + get_tmp_path + '")', | ||
'conn = kuzu.connection(db)', | ||
'conn.execute(\'CREATE NODE TABLE person (ID INT64, fName STRING, gender INT64,\ | ||
isStudent BOOLEAN, isWorker BOOLEAN, age INT64, eyeSight DOUBLE,\ | ||
birthdate DATE, registerTime TIMESTAMP, lastJobDuration INTERVAL,\ | ||
workedHours INT64[], usedNames STRING[], courseScoresPerTerm INT64[][],\ | ||
PRIMARY KEY (ID))\')', | ||
'conn.execute(\'COPY person FROM \"../../../dataset/tinysnb/vPerson.csv\" (HEADER=true)\')', | ||
'result = conn.execute("MATCH (a:person) WHERE a.ID = 0 RETURN a.isStudent;")', | ||
# 'result.close()', | ||
] | ||
code = ';'.join(code) | ||
result = subprocess.run([sys.executable, '-c', code]) | ||
assert result.returncode == 0 |
Oops, something went wrong.