Skip to content

Commit 2e3788f

Browse files
author
ci bot
committed
Merge branch 'fix/mssql-schema-case-sensitive' into 'enterprise'
fix: match SQL Server schema names case-sensitively in profiling DDF See merge request dkinternal/testgen/dataops-testgen!551
2 parents 3f22175 + fd04203 commit 2e3788f

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)