Skip to content

Commit 051bfbb

Browse files
committed
Add huge select example to basic example v2
1 parent 5b2ad25 commit 051bfbb

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

examples/basic_example_v2/basic_example.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,25 @@ def callee(session: ydb.QuerySessionSync):
183183
return pool.retry_operation_sync(callee)
184184

185185

186+
def huge_select(pool: ydb.QuerySessionPool, path: str):
187+
def callee(session: ydb.QuerySessionSync):
188+
query = f"""
189+
PRAGMA TablePathPrefix("{path}");
190+
SELECT * from episodes;
191+
"""
192+
193+
with session.transaction().execute(
194+
query,
195+
commit_tx=True,
196+
) as result_sets:
197+
print("\n> Huge SELECT call")
198+
for result_set in result_sets:
199+
for row in result_set.rows:
200+
print("episode title:", row.title, ", air date:", row.air_date)
201+
202+
return pool.retry_operation_sync(callee)
203+
204+
186205
def drop_tables(pool: ydb.QuerySessionPool, path: str):
187206
print("\nCleaning up existing tables...")
188207
pool.execute_with_retries(DropTablesQuery.format(path))
@@ -287,3 +306,4 @@ def run(endpoint, database, path):
287306

288307
explicit_transaction_control(pool, full_path, 2, 6, 1)
289308
select_with_parameters(pool, full_path, 2, 6, 1)
309+
huge_select(pool, full_path)

examples/basic_example_v2/basic_example_async.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,25 @@ async def callee(session: ydb.aio.QuerySessionAsync):
185185
return await pool.retry_operation_async(callee)
186186

187187

188+
async def huge_select(pool: ydb.aio.QuerySessionPoolAsync, path: str):
189+
async def callee(session: ydb.aio.QuerySessionAsync):
190+
query = f"""
191+
PRAGMA TablePathPrefix("{path}");
192+
SELECT * from episodes;
193+
"""
194+
195+
async with await session.transaction().execute(
196+
query,
197+
commit_tx=True,
198+
) as result_sets:
199+
print("\n> Huge SELECT call")
200+
async for result_set in result_sets:
201+
for row in result_set.rows:
202+
print("episode title:", row.title, ", air date:", row.air_date)
203+
204+
return await pool.retry_operation_async(callee)
205+
206+
188207
async def drop_tables(pool: ydb.aio.QuerySessionPoolAsync, path: str):
189208
print("\nCleaning up existing tables...")
190209
await pool.execute_with_retries(DropTablesQuery.format(path))
@@ -289,3 +308,4 @@ async def run(endpoint, database, path):
289308

290309
await explicit_transaction_control(pool, full_path, 2, 6, 1)
291310
await select_with_parameters(pool, full_path, 2, 6, 1)
311+
await huge_select(pool, full_path)

0 commit comments

Comments
 (0)