Add table_kwargs
context manager to make pandas/Dask support CrateDB's special SQL DDL options
#139
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
In certain cases where SQLAlchemy orchestration is implemented within a framework, like at this spot 1 in pandas'
SQLTable._create_table_setup
, it is not easily possible to forward SQLAlchemy dialect options at table creation time.Idea
Unlock SQLAlchemy ORM's
__table_args__
on the pandas/Daskto_sql()
interface, in order to support CrateDB's special SQL DDL options.Solution
In order to augment the SQL DDL statement to make it honor database-specific dialect options, the only way to work around the unfortunate situation is by monkey-patching the call to
sa.Table()
at runtime, relaying additional dialect options through corresponding keyword arguments in their original<dialect>_<kwarg>
format 2.Synopsis
Using a context manager incantation like
with table_kwargs(crate_partitioned_by="time")
will render aPARTITIONED BY ("time")
SQL clause, without touching the call site ofsa.Table(...)
.Documentation
Preview: https://sqlalchemy-cratedb--139.org.readthedocs.build/support.html#context-manager-table-kwargs
References
ctk load table
interface cratedb-toolkit#149Backlog
Footnotes
https://github.com/pandas-dev/pandas/blob/v2.2.2/pandas/io/sql.py#L1282-L1285 ↩
https://docs.sqlalchemy.org/en/20/core/foundation.html#sqlalchemy.sql.base.DialectKWArgs.dialect_kwargs ↩