Skip to content

Commit 832f7b5

Browse files
aarthy-dkclaude
andcommitted
fix: match SQL Server schema names case-sensitively in profiling DDF
On SQL Server's default (case-insensitive) collation, a table group whose configured schema case differs from the database's actual case (e.g. 'common' vs 'Common') silently broke Freshness monitor generation and Data Catalog stats. Profiling stamps profile_results.schema_name with the entered literal while the DDF stamps data_table_chars/data_column_chars with the DB's actual case, so the case-sensitive PostgreSQL joins between them returned nothing; Volume_Trend (data_table_chars only) still worked, masking it. Add COLLATE Latin1_General_BIN to the schema comparison in the mssql get_schema_ddf so matching is case-sensitive, consistent with TestGen's case-sensitive joins and the other flavors. Migration 0194 realigns existing table_group_schema values to the DB's actual case (from data_table_chars), scoped to mssql connections, single unambiguous schema, case-only differences. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 7797ba9 commit 832f7b5

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
SET SEARCH_PATH TO {SCHEMA_NAME};
2+
3+
-- Schema-name matching in the SQL Server DDF query is now case-sensitive,
4+
-- consistent with TestGen's case-sensitive joins and the other flavors.
5+
-- A case-insensitive source previously accepted a table
6+
-- group whose configured schema name differed in case from the database;
7+
-- such a group would now match no tables on its next profiling run.
8+
--
9+
-- data_table_chars.schema_name holds the case the source database actually
10+
-- reported (it is populated from the DDF's c.table_schema, not the entered
11+
-- value), so realign table_group_schema to that case. Guards:
12+
-- * only mssql connections -- the DDF change was made only for that flavor,
13+
-- * only when the catalog reports a single unambiguous schema for the group,
14+
-- * only a case-only difference (LOWER() match), never a different schema,
15+
-- * '<>' is case-sensitive in PostgreSQL, so correct rows are left untouched.
16+
-- After this, the group's next profiling run stamps profile_results with the
17+
-- corrected case, realigning the case-sensitive downstream joins.
18+
UPDATE table_groups tg
19+
SET table_group_schema = actual.schema_name
20+
FROM (
21+
SELECT table_groups_id, MIN(schema_name) AS schema_name
22+
FROM data_table_chars
23+
WHERE drop_date IS NULL
24+
GROUP BY table_groups_id
25+
HAVING COUNT(DISTINCT schema_name) = 1
26+
) actual
27+
WHERE actual.table_groups_id = tg.id
28+
AND tg.table_group_schema <> actual.schema_name
29+
AND LOWER(tg.table_group_schema) = LOWER(actual.schema_name)
30+
AND EXISTS (
31+
SELECT 1 FROM connections cn
32+
WHERE cn.connection_id = tg.connection_id
33+
AND cn.sql_flavor = 'mssql'
34+
);

testgen/template/flavors/mssql/data_chars/get_schema_ddf.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,5 @@ SELECT
5454
FROM information_schema.columns c
5555
LEFT JOIN approx_cts a ON c.table_schema = a.schema_name AND c.table_name = a.table_name
5656
LEFT JOIN information_schema.tables it ON c.table_schema = it.table_schema AND c.table_name = it.table_name
57-
WHERE c.table_schema = '{DATA_SCHEMA}' {TABLE_CRITERIA}
57+
WHERE c.table_schema = '{DATA_SCHEMA}' COLLATE Latin1_General_BIN {TABLE_CRITERIA}
5858
ORDER BY c.table_schema, c.table_name, c.ordinal_position;

0 commit comments

Comments
 (0)