sezruby opened a new pull request, #13809: URL: https://github.com/apache/gluten/pull/13809
## What changes are proposed in this pull request? With `spark.sql.caseSensitive=false` (the default), a native Delta write stores the names of nested struct fields in lower case. For a column `Info STRUCT<userId: BIGINT, homeAddr: STRUCT<zipCode: BIGINT>>`, the file gets `Info.userid` and `Info.homeaddr.zipcode`. Vanilla Spark writes `userId` and `homeAddr.zipCode`: it keeps the case of every field name and only resolves names case-insensitively. Top-level names are not affected. A reader that matches field names case-sensitively, such as Spark with `spark.sql.caseSensitive=true` or PyArrow, then finds no `userId` in these files and reads nulls. **Cause.** A native Delta write opens its files with `VeloxFormatWriterInjects.createOutputWriter`, and the native writer names the fields of a file after the schema it gets there (`updateFieldNameAndIdRecursive` in Velox's `dwio/parquet/writer/Writer.cpp`). That schema is built with `SparkArrowUtil.toArrowSchema`. Since #7304, `toArrowField` lower-cases nested struct field names the way the Substrait plan does, so that a plan can resolve the fields it reads. **Change.** - `SparkArrowUtil.toArrowSchema` and `toArrowField` get overloads that take `normalizeFieldNames`. The existing signatures keep normalizing, so the other callers don't change. - `VeloxFormatWriterInjects` passes `normalizeFieldNames = false`. The batches the writer receives may still carry the lower-case names of the plan. Velox's `Writer::write` only checks that their type is equivalent to the file schema, which ignores names, and imports their columns by position. So only the field names of the file change. This covers writes through `VeloxFormatWriterInjects`, which native Delta writes use. Not changed here: - A native write of a Parquet table (`WriteFilesExecTransformer`) has the same lower-casing, but builds its file schema differently: `SubstraitToVeloxPlanConverter::toVeloxPlan(WriteRel)` takes the column types, including nested names, from the input plan. - The Iceberg native write (`IcebergDataWriteFactory`) and the Bolt backend build their own schemas. Related: #13251 / #13326 (`from_json`) and #13795 / #13796 (`to_json`) handle the same lower-casing in other operators. ## How was this patch tested? - New `SparkArrowUtilSuite`: nested names of structs, arrays of structs and map values are normalized by default and kept with `normalizeFieldNames = false`, under both case settings. Passes locally. - New `DeltaNativeWriteSuite` test "native delta write keeps the case of nested field names", for Delta 3.3 and Delta 4: a native Delta write of nested camelCase fields (struct, array of struct, map value struct) under `caseSensitive=false`. It checks that every data file was written by Velox with the original nested names and no lower-cased ones, and that a case-sensitive read returns the values. It needs the native library and runs in CI; it was not run locally. - The same write run natively on Linux x86-64 (Spark 3.5.5, Delta 3.3.2, a 2026-11-24 nightly bundle): without this change the files have `userid`, `homeaddr.zipcode`, `itemid`, `itemcount`, and a case-sensitive read returns nulls; with it the files keep the original names and the read returns the values. - `backends-velox` main and test code compile for Spark 3.5 / Delta 3.3 and Spark 4.0 / Delta 4. 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
