Skip to content

Commit ee25738

Browse files
committed
Add huge select example to basic example v2
1 parent 766e863 commit ee25738

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
@@ -191,6 +191,25 @@ def callee(session: ydb.QuerySessionSync):
191191
return pool.retry_operation_sync(callee)
192192

193193

194+
def huge_select(pool: ydb.QuerySessionPool, path: str):
195+
def callee(session: ydb.QuerySessionSync):
196+
query = f"""
197+
PRAGMA TablePathPrefix("{path}");
198+
SELECT * from episodes;
199+
"""
200+
201+
with session.transaction().execute(
202+
query,
203+
commit_tx=True,
204+
) as result_sets:
205+
print("\n> Huge SELECT call")
206+
for result_set in result_sets:
207+
for row in result_set.rows:
208+
print("episode title:", row.title, ", air date:", row.air_date)
209+
210+
return pool.retry_operation_sync(callee)
211+
212+
194213
def drop_tables(pool: ydb.QuerySessionPool, path: str):
195214
print("\nCleaning up existing tables...")
196215
pool.execute_with_retries(DropTablesQuery.format(path))
@@ -301,3 +320,4 @@ def run(endpoint, database, path):
301320

302321
explicit_transaction_control(pool, full_path, 2, 6, 1)
303322
select_with_parameters(pool, full_path, 2, 6, 1)
323+
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
@@ -193,6 +193,25 @@ async def callee(session: ydb.aio.QuerySessionAsync):
193193
return await pool.retry_operation_async(callee)
194194

195195

196+
async def huge_select(pool: ydb.aio.QuerySessionPoolAsync, path: str):
197+
async def callee(session: ydb.aio.QuerySessionAsync):
198+
query = f"""
199+
PRAGMA TablePathPrefix("{path}");
200+
SELECT * from episodes;
201+
"""
202+
203+
async with await session.transaction().execute(
204+
query,
205+
commit_tx=True,
206+
) as result_sets:
207+
print("\n> Huge SELECT call")
208+
async for result_set in result_sets:
209+
for row in result_set.rows:
210+
print("episode title:", row.title, ", air date:", row.air_date)
211+
212+
return await pool.retry_operation_async(callee)
213+
214+
196215
async def drop_tables(pool: ydb.aio.QuerySessionPoolAsync, path: str):
197216
print("\nCleaning up existing tables...")
198217
await pool.execute_with_retries(DropTablesQuery.format(path))
@@ -303,3 +322,4 @@ async def run(endpoint, database, path):
303322

304323
await explicit_transaction_control(pool, full_path, 2, 6, 1)
305324
await select_with_parameters(pool, full_path, 2, 6, 1)
325+
await huge_select(pool, full_path)

0 commit comments

Comments
 (0)