ydb-platform / ydb-sqlalchemy

YQL Dialect for SQLAlchemy
Apache License 2.0
18 stars 5 forks source link

Implement ScanQuery #50

Closed LuckySting closed 1 month ago

LuckySting commented 1 month ago

Problem

For some reasons user may want to retrieve large amount of data from the table. Now it is possible only through the online read only transaction and it leads to TruncatedResponseError. Moreover such approach affects OLTP queries.

The YDB has special mechanism to do OLAP queries using snapshots called ScanQuery.

In this PR

In this PR I add an execution option to enable ScanQuery mode.

Example


with engine.begin() as connection:
    connection.execution_options(ydb_scan_query=True)  # Enable ScanQuery mode on connection
    cursor = connection.execute(sa.select(table))  # Fetch rows using ScanQuery

    for chunk in cursor.partitions(1000):  # gRPC stream iteration supported
        print(chunk)