ModelAnalyzeRule strips the MDL catalog/schema prefix from column names, breaking derived literal columns
Describe the bug
ModelAnalyzeRule removes the MDL catalog/schema prefix from column names with a plain substring replace. When a derived column's name contains that prefix — for example, a column produced by a string literal — the rewritten name no longer matches the input schema and planning fails.
This is the same class of problem as #2761 (which covers the final rendered SQL string), but in the analyzer, and it is not addressed by #2762.
The code is the "handle Wren View" branch of rewrite_column_qualifier in core/wren-core/core/src/logical_plan/analyze/model_anlayze.rs (L1014-1018 on 8276ae41):
// handle Wren View
let name = name.replace(
self.analyzed_wren_mdl.wren_mdl().catalog_schema_prefix(),
"",
);To Reproduce
Using the core test fixture core/wren-core/core/tests/data/mdl.json (catalog test, schema test), call transform_sql_with_ctx in Mode::Unparse with:
SELECT * FROM (SELECT 'test.test.x' FROM test.test.customer) tResult:
ModelAnalyzeRule
caused by
Schema error: No field named t."Utf8(""x"")". Valid fields are t."Utf8(""test.test.x"")".The derived column is named Utf8("test.test.x"); the replace turns the outer reference into Utf8("x"), which does not exist.
Expected behavior
The query plans and unparses normally, e.g.
SELECT t."Utf8(""test.test.x"")" FROM (SELECT 'test.test.x' FROM (...) AS customer) AS tRemoving the replace in the branch above yields exactly this output for the query, so that call is the cause.
Additional context
- Aliasing the literal avoids the error (
SELECT t.v FROM (SELECT 'test.test.x' AS v FROM test.test.customer) tworks), so the trigger is a column whose auto-generated name embeds the prefix. map_column_and_rewrite_qualifierin the same file applies the samename.replace(catalog_schema_prefix(), "")to unqualified columns (around L965). I have not confirmed a reproducer for that path, but it is worth reviewing alongside this fix.- A fix probably wants to strip the prefix only from the column's qualifier (
TableReference) rather than substring-matching the column name.
Source: Canner/WrenAI