graflo.db.sql.alchemy¶
A :class:SqlMetadataProvider backed by SQLAlchemy reflection.
PostgreSQL reads its own catalogue directly, which is faster and exposes column
comments. Every other engine arrives here instead: SQLAlchemy's Inspector
answers the same seven questions against SQLite, MySQL, DuckDB, Snowflake,
BigQuery or anything else with a dialect installed, so schema inference is a
property of the engine's reflection support rather than of GraFlo.
What varies between engines is not the questions but how much of the answer is
there. A warehouse typically declares no foreign keys — BigQuery's are
unenforced and often absent entirely — so edge detection falls back to the
name-based inference in :mod:graflo.db.sql.inference_utils. That is a real
degradation on denormalised schemas, not a bug: a star schema is not 3NF, and
nothing in the catalogue says which columns were meant to be joins.
Attributes¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
SqlAlchemyMetadataProvider
¶
Bases: SqlMetadataProvider
Reflect schema metadata from any engine SQLAlchemy has a dialect for.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
engine
|
Engine
|
A live SQLAlchemy |
required |
default_schema
|
str | None
|
Namespace used when a call passes |
None
|
Source code in graflo/db/sql/alchemy.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
Attributes¶
default_schema = default_schema
instance-attribute
¶
engine = engine
instance-attribute
¶
inspector
property
¶
Methods:¶
__init__(engine, *, default_schema=None)
¶
get_foreign_keys(table_name, schema_name=None)
¶
Source code in graflo/db/sql/alchemy.py
get_primary_keys(table_name, schema_name=None)
¶
Source code in graflo/db/sql/alchemy.py
get_table_columns(table_name, schema_name=None)
¶
Source code in graflo/db/sql/alchemy.py
get_table_row_count_estimate(table_name, schema_name=None)
¶
Exact COUNT(*); SQLAlchemy exposes no portable estimate.
PostgreSQL answers this from pg_class.reltuples without scanning.
There is no dialect-neutral equivalent, and the count is only used to
rank tables, so a failure returns None rather than aborting
introspection over a table that is large or unreadable.
Source code in graflo/db/sql/alchemy.py
get_table_sample_rows(table_name, schema_name=None, limit=5)
¶
Rows ordered by the primary key when there is one, so a repeated sample of unchanged data is the same sample.
Source code in graflo/db/sql/alchemy.py
get_tables(schema_name=None)
¶
get_unique_columns(table_name, schema_name=None)
¶
Single-column uniqueness only, matching the PostgreSQL path.
A multi-column unique constraint says nothing about any one of its columns being unique, so folding it in here would mark columns unique that are not.