Skip to content

Commit 66c525c

Browse files
committed
fix: update DISTINCT query to avoid database context issues
1 parent 5e10192 commit 66c525c

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

bindings/python/examples/05_csv_import_graph.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,9 @@ def create_all_vertices(
300300
def _create_users(self, total_users: int) -> tuple[int, BenchmarkStats]:
301301
"""Create User vertices.
302302
303-
Note: Uses SELECT DISTINCT (not paginated - efficient pagination difficult)
303+
Note: Uses a DISTINCT subquery. The direct DISTINCT/ORDER BY form can
304+
resolve against the wrong database context when the target graph DB is
305+
open at the same time as the source document DB.
304306
"""
305307
print(f"Creating {total_users:,} User vertices...")
306308
stats = BenchmarkStats()
@@ -317,7 +319,10 @@ def _create_users(self, total_users: int) -> tuple[int, BenchmarkStats]:
317319
with arcadedb.open_database(
318320
str(self.data_loader.source_db_path)
319321
) as source_db:
320-
query = "SELECT DISTINCT userId FROM Rating ORDER BY userId"
322+
query = (
323+
"SELECT userId FROM (SELECT DISTINCT userId FROM Rating) "
324+
"ORDER BY userId"
325+
)
321326
for record in source_db.query("sql", query):
322327
user_id = record.get("userId")
323328
async_exec.command(
@@ -344,7 +349,10 @@ def _create_users(self, total_users: int) -> tuple[int, BenchmarkStats]:
344349
with arcadedb.open_database(
345350
str(self.data_loader.source_db_path)
346351
) as source_db:
347-
query = "SELECT DISTINCT userId FROM Rating ORDER BY userId"
352+
query = (
353+
"SELECT userId FROM (SELECT DISTINCT userId FROM Rating) "
354+
"ORDER BY userId"
355+
)
348356
batch_user_ids = []
349357

350358
for record in source_db.query("sql", query):
@@ -380,7 +388,10 @@ def _create_users(self, total_users: int) -> tuple[int, BenchmarkStats]:
380388
with arcadedb.open_database(
381389
str(self.data_loader.source_db_path)
382390
) as source_db:
383-
query = "SELECT DISTINCT userId FROM Rating ORDER BY userId"
391+
query = (
392+
"SELECT userId FROM (SELECT DISTINCT userId FROM Rating) "
393+
"ORDER BY userId"
394+
)
384395
batch_user_ids = []
385396

386397
for record in source_db.query("sql", query):

0 commit comments

Comments
 (0)