[VL] Struct fields are read from the wrong column when two same-named struct columns meet in one projection

Open
#13,197 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
scala, spark
Domain
backend, databases

Research direction

Start by reading ExpressionConverter.bindGetStructField, identified in the issue, and trace how it resolves the root attribute and struct fields for the two repro queries. Run the repros with the default configuration and compare Gluten’s results with vanilla Spark. Done means both projections return the same field values as Spark, including when struct columns or fields share names.

Written by the indexing model from the issue text.

Description

Backend

Velox (Bolt shares the same binding code).

Bug description

When a projection's input holds two struct attributes with the same name but different field layouts, Gluten reads struct fields from the wrong one. ExpressionConverter.bindGetStructField re-resolves the root attribute of a GetStructField chain by name over the whole input and keeps the last match, so l.s.x and r.s.x are both bound against whichever s comes last.

Repro with the default configuration:

spark.sql("select id, named_struct('x', id, 'y', id * 100) as s from range(5)").write.parquet("/tmp/l")
spark.sql("select id, named_struct('y', id * 100, 'x', id) as s from range(5)").write.parquet("/tmp/r")
spark.read.parquet("/tmp/l").createOrReplaceTempView("l")
spark.read.parquet("/tmp/r").createOrReplaceTempView("r")
spark.sql("select l.s.x, l.s.y, r.s.x, r.s.y from l join r on l.id = r.id").show()

Vanilla Spark returns [1, 100, 1, 100] for id 1. Gluten returns [100, 1, 1, 100].

The same function also looks each field up by name and keeps the last match, which misreads structs with duplicate field names. The Velox generate rewrite builds such a struct from the generator output aliases, so select v.* from (select id, array(named_struct('p', id, 'q', id * 10)) as arr from range(5)) lateral view inline(arr) v as x, x returns [10, 10] for id 1 instead of [1, 10].

Gluten version

main (ca7a0a4e4)

Spark version

Spark 3.5

This issue was written with the assistance of AI (Claude Opus).

Dominant language
Scala
Stars
1.6k
Forks
679
Avg merge
4d 16h
Merged PRs (30d)
84

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/gluten

All issues in apache/gluten

Similar issues

More Scala issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.