morningman opened a new pull request, #71211:
URL: https://github.com/apache/doris/pull/71211

   ### Background
   
   Doris resolves column names regardless of case: a table looks a name up in 
`Table.nameToColumn`, a map ordered by `String.CASE_INSENSITIVE_ORDER`, and 
Nereids binds a name to every slot equal to it ignoring case. A file table 
function (`s3()`, `hdfs()`, `file()`) takes its schema from a file: for every 
format but JSON it lower-cases each column name and refuses two names that 
lower-case alike, and BE then finds each column in the file by its name with 
ASCII letters folded. Lance datasets, read through the connector plugin, keep 
their spelling and go through the same duplicate check, as external catalog 
schemas do in `SchemaCacheValue.validateSchema`.
   
   ### What problem does this PR solve?
   
   Issue Number: None
   Related PR: #70903 (shared the duplicate check with the Lance plugin path; 
its review comment r4676105431 reported the mismatch), #51341 (introduced the 
lower-cased file column names and the check), #67166 (gave nested STRUCT fields 
their ROOT lower-case runtime names)
   PR Type: Bugfix
   
   Problem Summary:
   
   The duplicate checks lower-case names with the JVM's default locale, while 
resolution compares ignoring case, so columns such as `Σ` and `ς` (equal 
ignoring case, with different lower cases) pass the check and then no name 
picks out either; on a Turkish-locale FE, so do `id` and `ID`. And a Parquet or 
ORC column named `Σ` is shown as `σ`, which BE does not find in the file, so 
every row reads NULL. This PR tells column names apart as Spark does: two names 
are the same when they are equal ignoring case and their `Locale.ROOT` lower 
cases are equal. A name that is the same as no column still resolves ignoring 
case, so every spelling that resolved before still does, and file column names 
fold only their ASCII letters, as BE does.
   
   ```sql
   -- column_case_sigma.lance has the columns row_id, Σ and ς; 
sigma_only.parquet has row_id and Σ (10, 20)
   SELECT row_id, `Σ`, `σ`, `ς` FROM s3("uri" = 
"s3://warehouse/lance/column_case_sigma.lance", ..., "format" = "lance");
   SELECT * FROM s3("uri" = "s3://warehouse/casedemo/sigma_only.parquet", ..., 
"format" = "parquet");
   ```
   
   | Statement | Before | After |
   |---|---|---|
   | Lance ``SELECT row_id, `Σ`, `σ`, `ς` `` | `Σ is ambiguous: Σ#1, Σ#2.` | 
`1, 10, 10, 100` and `2, 20, 20, 200` |
   | Parquet `SELECT *` | column `σ`: `NULL`, `NULL` | column `Σ`: `10`, `20` |
   
   ### Details
   
   - **Change map:** 577 changed lines: production code +149/-66 in 6 files; 
tests +320/-8 (FE unit tests, a regression suite, its fixtures and their 
builder); generated `.out` +34. The production code has three parts:
     1. The rule, `ColumnNames` (70 lines), and its users: the binder in 
`ExpressionAnalyzer` (+41/-40, the four single-slot binders now share one 
tiered lookup), `Table.getColumn` and `ExternalTable.getColumn`.
     2. The duplicate checks: both callers in the file table function and 
`SchemaCacheValue.validateSchema`.
     3. ASCII-only folding of file column names in `fillColumns` (one line).
   - **Frequency:** Always, for names with non-ASCII letters that have case: a 
Parquet or ORC column with such an uppercase letter reads NULL, and pairs such 
as `Σ`/`ς`, `ı`/`i`, `ſ`/`s` or `µ`/`μ` cannot be named. On a Turkish- or 
Azerbaijani-locale FE, also `id`/`ID` (by the code; not run under that locale).
   - **Root cause:** Three comparisons disagree: the duplicate checks 
(`ExternalFileTableValuedFunction.addColumnLowerName`, 
`SchemaCacheValue.validateSchema`) compare default-locale lower cases; 
resolution (`Table.nameToColumn`, `ExternalTable.getColumn`, the binder) 
compares ignoring case, under which `ς` equals `σ`; and `fillColumns` names a 
file column by its Java lower case, while BE folds only ASCII letters 
(`column_has_name` in `be/src/format_v2/column_mapper.cpp`), so `σ` never finds 
the file's `Σ`.
   - **Why existing tests missed it:** The unit tests of the duplicate checks 
(`S3TableValuedFunctionTest`, `PluginFileFormatTableValuedFunctionTest`) use 
ASCII pairs only, which every comparison treats alike, and 
`ExpressionAnalyzerTest` binds no names that differ in non-ASCII case. The 
regression suites (`test_lance_s3_tvf`, `test_hdfs_parquet_group6`) use ASCII 
names only.
   - **Fix:** Duplicate checks refuse names with equal ROOT lower cases. The 
binder first binds the accepted slots of the same name and, only when there are 
none, the slots equal ignoring case, as before; both `getColumn` methods 
likewise prefer the column of the same name. A name thus binds a subset of what 
it bound before: what was unambiguous is unchanged, and a name ambiguous 
between columns like `Σ` and `ς` now picks the one it names. `fillColumns` 
folds only ASCII letters (Guava `Ascii.toLowerCase`), as BE does. BE is 
unchanged.
   - **Other paths and branches:** Unchanged: CREATE TABLE, VIEW, MTMV and 
schema change refuse duplicates by `CASE_INSENSITIVE_ORDER`, which is stricter; 
connector INSERT column lists (`BindSink.findColumn`) and `SELECT * 
EXCEPT/REPLACE` still match ignoring case, which matters only for tables 
holding columns like `Σ` and `ς`. Not fixed: a STRUCT field named `Σ` in a 
Parquet or ORC file still reads NULL (seen before and after), because FE sends 
nested fields to BE by their ROOT lower-case runtime names (#67166); that needs 
BE-side matching, left for a follow-up. branch-4.0, 4.1 and 4.2 lower-case file 
column names with the default locale since #51341, so they have both bugs.
   - **Behavior change:** File columns whose names have non-ASCII uppercase 
letters keep them (`Σ`, not `σ`) in `DESC FUNCTION`, result headers and CTAS 
tables; ASCII letters still fold. A Turkish-locale FE refuses `id`/`ID` in 
external catalogs and file table functions, as other FEs do.
   
   ### Testing
   
   - FE unit tests, run locally on this commit with checkstyle on: 59 classes 
and 615 tests pass, including the new `ColumnNamesTest` and cases, every 
`nereids/rules/analysis` test, the `*TableValuedFunctionTest` classes and the 
callers of `validateSchema`.
   - Reverting each part on a copy fails its tests with the old symptom (`Σ is 
ambiguous: Σ#1, Σ#2.`, `Unknown column 'KIRMIZI'`, `[username, σ, ς]`, `ς` 
returned for `Σ`, `id`/`ID` accepted under tr-TR); the unmutated controls pass.
   - Regression, on a local cluster (BE at `8ede923c73a`, whose column matching 
is the same as at the base) with a stand-in for the External pipeline's MinIO 
serving the committed fixtures: the new 
`external_table_p0/tvf/test_s3_tvf_column_name_case` (`.out` from 
`-forceGenOut`, matching the fixture values) and `test_lance_s3_tvf` pass; with 
the FE before this change, the new suite fails with `Σ is ambiguous: Σ#1, 
Σ#2.`. Like `test_lance_s3_tvf`, it runs in the External pipeline.
   - By hand: `sigma_only.parquet` and `sigma_only.orc` read `NULL` before and 
`10`, `20` after; on an internal table with columns `Σ` and `kırmızı`, `σ`, `ς` 
and `KIRMIZI` resolve the same before and after.
   
   ### Notes for Reviewers
   
   - `Table.nameToColumn` keeps `CASE_INSENSITIVE_ORDER`: `OlapTable` uses the 
map directly, and an internal table cannot hold two names that map takes for 
one. `Table.getColumn` scans the full schema only when the map's hit is not the 
same name, and accepts a hit by `getDefineName()` because `OlapTable` keys 
materialized-index columns by define name.
   - The fallback to the old match goes beyond Spark, which would not resolve 
`KIRMIZI` to a column `kırmızı`; it keeps every existing spelling working.
   - The binder applies the qualifier filter inside each tier, so `t2.KIRMIZI` 
still binds `t2.kırmızı` when another relation has `kirmizi`. A scope of over 
500 slots keeps its ROOT upper-case buckets and filters them.
   
   ### Release note
   
   Column names that differ only in non-ASCII letters, such as `Σ` and `ς`, are 
now told apart the way Spark does, so each can be queried by name. A Parquet or 
ORC column read with `s3()`, `hdfs()` or `file()` whose name has a non-ASCII 
uppercase letter keeps that letter and reads its values instead of NULL. An FE 
whose default locale is Turkish now treats `id` and `ID` as the same name, like 
other FEs.
   
   ### Check List (For Author)
   
   - Behavior changed: Yes (see Details)
   - Does this need documentation: No
   - Pre-submission status: Ready
   
   ### AI Disclosure
   
   - Tool: Claude Code (Claude Opus 5.5)
   - Generated: code, tests, fixtures, this description
   - Human review: not stated
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to