get_columns() missing @reflection.cache causes a warehouse round-trip on every reflection call
Valutazione
- Difficoltà
- 1/5
- Tempo stimato
- Meno di un'ora
- Idoneità per principianti
- 92/100
Direzione di ricerca
Iniziate in src/databricks/sqlalchemy/base.py, in get_columns(), quindi confrontate la relativa gestione della reflection con get_pk_constraint() e i dialect upstream menzionati nell’issue. Eseguite chiamate ripetute con lo stesso info_cache e verificate che la cache venga popolata e che il round-trip verso il warehouse avvenga una sola volta.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
DatabricksDialect.get_columns() is missing the @reflection.cache decorator, so it never participates in SQLAlchemy's reflection cache. Every call issues a fresh GetColumns round-trip to the warehouse, however many times the same table is reflected through the same Inspector.
This is the sibling of #72 (get_foreign_keys()), which is addressed in #74. get_columns() is a separate occurrence of the same omission and is not covered by that PR.
Expected behaviour
Like get_pk_constraint(), has_table(), get_table_names(), get_view_names(), get_materialized_view_names(), get_temp_view_names(), get_schema_names() and get_table_comment() — and like get_columns() in SQLAlchemy's own SQLite, PostgreSQL and MySQL dialects, all three of which are decorated — repeated reflection of the same table through one Inspector should cost one round-trip, not one per call.
Inspector.get_columns() explicitly threads the cache through to the dialect (sqlalchemy/engine/reflection.py):
with self._operation_context() as conn:
col_defs = self.dialect.get_columns(
conn, table_name, schema, info_cache=self.info_cache, **kw
)
The info_cache kwarg arrives, lands in **kwargs, and is discarded.
Actual behaviour
Reproduced against main (SQLAlchemy 2.0.52), stubbing out the transport so the call count is directly observable:
info_cache = {}
for _ in range(3):
dialect.get_columns(conn, "t", None, info_cache=info_cache)
| method | calls | server round-trips | info_cache keys |
|---|---|---|---|
get_columns() |
3 | 3 | [] — never populated |
get_pk_constraint() |
3 | 1 | [('get_pk_constraint', ('t',), (('schema', None),))] |
Note the cost is not always a single statement: when cur.columns() returns an empty list, get_columns() follows up with DESCRIBE TABLE EXTENDED to distinguish a genuinely column-less table from a missing one (base.py:156). For such tables an uncached call is two round-trips, repeated every time.
Callers that reuse one Inspector across many lookups feel this directly — Alembic's autogenerate is the common case, as is any long-lived application that reflects per request.
Root cause
src/databricks/sqlalchemy/base.py:139 — get_columns() lacks @reflection.cache. Compare get_pk_constraint() at line 212, which is decorated.
Fix
Add @reflection.cache to get_columns().
Two things worth noting for whoever picks this up, both checked:
- Caching is safe with respect to
Inspector._instantiate_types(), which mutates the returned column dicts in place. It is guarded byif not isinstance(coltype, TypeEngine), so re-running it over an already-instantiated cached list is a no-op. This is the same situation the upstream dialects are in. get_indexes()is also undecorated but returns theEMPTY_INDEXconstant without touching the server, so it needs no cache.get_columns()is the only remaining method where the omission costs a round-trip.
I'm happy to open a PR for this if it's welcome.
- Lingua principale
- Python
- Stelle
- 24
- Fork
- 20
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di databricks/databricks-sqlalchemy
-
get_foreign_keys() missing @reflection.cache causes excessive DESCRIBE TABLE EXTENDED queriesForse già presa @TangoEnSkai l’ha presa 45 giorni fa. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
TypeError when using Enum columns with the Databricks dialect (all 2.0.x releases)Forse già presa @TangoEnSkai l’ha presa 44 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 64/100
databricks/databricks-sqlalchemy#77 · 2 commenti ·
-
Unable to insert Python lists into ARRAY<STRING> columns using pandas to_sqlForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
databricks/databricks-sqlalchemy#73 · 1 commento ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
Tutte le issue di databricks/databricks-sqlalchemy
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 3 giorni
-
Negation with "not" and "no" is ignored during sentiment analysisForse già presa @vivek-3728 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
techcsispit/mess-mood#11 · 1 commento ·
-
changelog investigate
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
ramnes/notion-sdk-py#408 ·
-
good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
btclib-org/btclib-wallet#267 ·
I maintainer di solito rispondono entro 1 giorno
-
good first issue tech-debt
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
knnmelprop/YAADO#111 ·