This is an automated email from the ASF dual-hosted git repository.
cloud-fan pushed a commit to branch branch-4.2
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-4.2 by this push:
new f1f1be984cdf [SPARK-56426][SQL] Fix SQL failure when LATERAL VIEW
column alias contains dot in name
f1f1be984cdf is described below
commit f1f1be984cdf2b95b0aa8991b529976396668fd8
Author: Eric Yang <[email protected]>
AuthorDate: Thu May 28 19:32:29 2026 +0800
[SPARK-56426][SQL] Fix SQL failure when LATERAL VIEW column alias contains
dot in name
### What changes were proposed in this pull request?
In `ResolveGenerate`, generator output column names were extracted via
`UnresolvedAttribute.name`, which wraps any name containing a dot in backtick
characters (e.g. `"skill.inst"` → `` "`skill.inst`" ``). This string was then
passed directly to `makeGeneratorOutput` as the resolved attribute name,
embedding literal backtick characters into the column name.
The fix uses `nameParts.head` instead, which returns the raw identifier
text without display-formatting.
### Why are the changes needed?
Using a backtick-quoted identifier with a dot as a `LATERAL VIEW` column
alias causes an `UNRESOLVED_COLUMN` error at analysis time:
```sql
SELECT id, `skill.inst`
FROM VALUES (1, array('a', 'b')) AS t(id, skills)
LATERAL VIEW explode(skills) skills_table AS `skill.inst`
-- ERROR: [UNRESOLVED_COLUMN] `skill.inst` cannot be resolved.
-- Did you mean: `skills_table`.```skill.inst```
```
The triple-backtick suggestion reveals that the resolved attribute name
contains literal backtick characters, caused by `UnresolvedAttribute.name`
being misused as a raw identifier extractor rather than for display only.
**This worked in previous versions, e.g., Spark 3.1.x.**
### Does this PR introduce _any_ user-facing change?
Yes. Queries using a backtick-quoted `LATERAL VIEW` column alias containing
a dot (e.g. `` `a.b` ``) now execute correctly instead of failing with
`UNRESOLVED_COLUMN`.
### How was this patch tested?
Added a test case in `SQLQuerySuite` covering `LATERAL VIEW` with a
dot-containing column alias.
### Was this patch authored or co-authored using generative AI tooling?
No.
Closes #55282 from jiwen624/fix-lateral-view-dot-alias.
Authored-by: Eric Yang <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
(cherry picked from commit cecb314c9f0c497a3f2be5bfedebbedc3fb80d06)
Signed-off-by: Wenchen Fan <[email protected]>
---
.../spark/sql/catalyst/analysis/Analyzer.scala | 10 +++++++++-
.../apache/spark/sql/GeneratorFunctionSuite.scala | 22 ++++++++++++++++++++++
2 files changed, 31 insertions(+), 1 deletion(-)
diff --git
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
index 3f8ce7e8b70a..df28d708623e 100644
---
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
+++
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
@@ -3361,7 +3361,15 @@ class Analyzer(
throw QueryCompilationErrors.nestedGeneratorError(g.generator)
}
g.copy(generatorOutput =
- GeneratorResolution.makeGeneratorOutput(g.generator,
g.generatorOutput.map(_.name)))
+ GeneratorResolution.makeGeneratorOutput(
+ g.generator, g.generatorOutput.map {
+ case ua: UnresolvedAttribute =>
+ // LATERAL VIEW parser always emits single-part names via
+ // UnresolvedAttribute.quoted; assert to fail loudly if that
ever changes.
+ assert(ua.nameParts.length == 1, s"unexpected multi-part name:
${ua.nameParts}")
+ ua.nameParts.head
+ case a => a.name
+ }))
}
}
}
diff --git
a/sql/core/src/test/scala/org/apache/spark/sql/GeneratorFunctionSuite.scala
b/sql/core/src/test/scala/org/apache/spark/sql/GeneratorFunctionSuite.scala
index 58f399bf797f..1944b5679c84 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/GeneratorFunctionSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/GeneratorFunctionSuite.scala
@@ -796,6 +796,28 @@ class GeneratorFunctionSuite extends SharedSparkSession {
.elementType.asInstanceOf[StructType].fieldNames.toSeq
assert(fields2 === Seq("value", "key"))
}
+
+ test("SPARK-56426: LATERAL VIEW column alias with dot in name should resolve
correctly") {
+ // Single-alias: explode with a dotted alias
+ checkAnswer(
+ sql(
+ """
+ |SELECT id, `skill.inst`
+ |FROM VALUES (1, array('a', 'b')) AS t(id, skills)
+ |LATERAL VIEW explode(skills) skills_table AS `skill.inst`
+ """.stripMargin),
+ Row(1, "a") :: Row(1, "b") :: Nil)
+
+ // Multi-alias: inline with multiple dotted aliases
+ checkAnswer(
+ sql(
+ """
+ |SELECT `a.b`, `c.d`
+ |FROM (SELECT 1) t
+ |LATERAL VIEW inline(array(named_struct('f1', 10, 'f2', 'hello')))
gen AS `a.b`, `c.d`
+ """.stripMargin),
+ Row(10, "hello") :: Nil)
+ }
}
case class EmptyGenerator() extends Generator with LeafLike[Expression] {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]