ydb-platform / ydb-sqlalchemy

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

Use DataQuery in Compiler instead of render DECLARE in DBAPI #21

Closed LuckySting closed 7 months ago

LuckySting commented 7 months ago

Problem

Now rendering of a DECLARE clause happens in the Cursor.execute, which is bad because of the following.

  1. At the execution stage the information about the bound variable is incomplete, it impossible to use powerful SQLAlchemy type engine, so we able only guess about the bound variable type by the value.
  2. It becomes harder to change the Cursor implementation, because you have to implement the DECLARE rendering again.
  3. It is impossible to use SQLAlchemy caching of rendered queries, because the query becomes completely rendered right before the execution.

Suggested solution

Move rendering of a DECLARE clause to the Compilation stage, use information about the table and SQLAlchemy Type engine to determine types.

Workaround

It's impossible to render the DECLARE clause at the Compilation stage, because of "postcompile" variables. Instead it is possible to determine types of the bound variables right before the execution and pass it to the DataQuery.

Results

All tests are passed, even those that were previously failed.