Fixes ISSUE-13473: Ensure MSSQL columns query filters to tables and views (#15530)

* Update queries.py and utils.py to ingest table and view descriptions

* Ensure MSSQL columns query filters to tables and views

* Fix linters

---------

Co-authored-by: Pablo Takara <pjt1991@gmail.com>
This commit is contained in:
Kent Chenery 2024-03-13 01:56:30 +13:00 committed by GitHub
parent a87161a9ed
commit 34b727f6c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 13 deletions

View File

@ -46,27 +46,27 @@ MSSQL_GET_TABLE_COMMENTS = textwrap.dedent(
SELECT obj.name AS table_name,
ep.value AS table_comment,
s.name AS "schema"
FROM sys.tables AS obj
FROM sys.objects AS obj
LEFT JOIN sys.extended_properties AS ep
ON obj.object_id = ep.major_id AND ep.minor_id = 0
ON obj.object_id = ep.major_id AND ep.minor_id = 0 AND ep.name = 'MS_Description'
JOIN sys.schemas AS s
ON obj.schema_id = s.schema_id
WHERE ep.name = 'MS_Description'
WHERE
obj.type IN ('U', 'V') /* User tables and views */
"""
)
MSSQL_ALL_VIEW_DEFINITIONS = textwrap.dedent(
"""
select
definition view_def,
views.name view_name,
sch.name "schema"
from sys.sql_modules as mod,
sys.views as views,
sys.schemas as sch
where
mod.object_id=views.object_id and
views.schema_id=sch.schema_id
SELECT
definition view_def,
views.name view_name,
sch.name "schema"
FROM sys.sql_modules as mod
INNER JOIN sys.views as views
ON mod.object_id = views.object_id
INNER JOIN sys.schemas as sch
ON views.schema_id = sch.schema_id
"""
)

View File

@ -124,6 +124,7 @@ def get_columns(
Column("minor_id", Integer, primary_key=True),
Column("name", String, primary_key=True),
Column("value", String),
Column("class_desc", String),
schema="sys",
)
sys_columns = alias(
@ -181,6 +182,8 @@ def get_columns(
onclause=sql.and_(
extended_properties.c.major_id == sys_columns.c.object_id,
extended_properties.c.minor_id == sys_columns.c.column_id,
extended_properties.c.class_desc == "OBJECT_OR_COLUMN",
extended_properties.c.name == "MS_Description",
),
isouter=True,
)