Repository navigation
Reflection: Report column nullability, and filter views by schema - #315
aminghadersohi wants to merge 3 commits into
Conversation
- get_columns reads information_schema.columns.is_nullable instead of reporting every column, primary keys included, as nullable. - get_view_names filters by the requested schema; the schema was passed as a parameter the query never used, so views of all schemas came back. - has_table reports views as well as tables, matching SQLAlchemy 2.0's Inspector.has_table, and get_view_definition is implemented. - Reflection honours the schema URL parameter that get_table_names already uses, instead of falling back to doc.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
CrateDB up to 6.0 reports information_schema.columns.is_nullable as a
BOOLEAN; later versions report 'YES'/'NO', and bool('NO') is True, so
primary key and NOT NULL columns reflected as nullable. Accept both.
Give the mocked get_columns cursor a three-column description and use
crate:///?schema=sales, so the tests also pass on SQLAlchemy 1.3/1.4.
Add a live reflection test.
|
Hi @aminghadersohi, Once it's rebased and CI is green, we'll review it. Let us know if you'd like a hand with the rebase. Best, |
Problem
Several reflection methods return wrong results against a live CrateDB (verified on 5.10.16 with SQLAlchemy 2.0.52):
get_columnshard-codesnullable=True, so a primary key orNOT NULLcolumn reflects as nullable.information_schema.columns.is_nullablereports the real value.get_view_namespasses the schema as a parameter, but the query has no placeholder for it, so views of every schema are returned for any schema.has_tableonly checks base tables. SQLAlchemy 2.0'sInspector.has_tablealso reports views.get_view_definitionis not implemented (NotImplementedError), althoughinformation_schema.views.view_definitionexists.crate://host/?schema=sales,get_table_names()lists tables fromsales, butget_columns,get_pk_constraintandget_view_namesquerydoc. A listed table then reflects no columns and no primary key.Change
get_columnsselectsis_nullable(ordered byordinal_position) and returns it asnullable. CrateDB up to 6.0 reportsis_nullableas aBOOLEAN, while 6.4 and later report'YES'/'NO'text (wherebool('NO')would beTrue), so both forms are accepted.get_view_namesfilters ontable_schema = ?.get_view_definitionreadsinformation_schema.views.has_tablemakes one query againstinformation_schema.tableswithtable_type IN ('BASE TABLE', 'VIEW'). CrateDB lists views there too, so the bulk tests' call counts stay the same._reflection_schemahelper resolves the schema in this order: the explicit argument, then the URLschemaparameter, then the default. The reflection methods above use it.Tests
'YES'/'NO'forms), view listing and definition,has_tableon a view, and URL-schema resolution forget_columns,get_pk_constraintandget_view_names.test_get_view_namesandtest_has_tablenow expect the new SQL. The mockedget_columnscursor describes all three selected columns, and the URL-schema tests usecrate:///?schema=sales, so they also pass on SQLAlchemy 1.3 and 1.4.tests/reflection_test.py: a live test (testcontainers) that a primary key and aNOT NULLcolumn reflect as not nullable.poe lintis clean andintegration.pypasses. pytest gives 209 passed on SQLAlchemy 2.1.1, 195 passed on 1.4.54, and 132 passed on 1.3.24. On 1.3 there is one failure,test_schema.py::test_correct_schema, which fails the same way onmain.has_tableon a view, the view definition, and URL-schema column/PK reflection.