You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by we...@apache.org on 2022/06/15 08:05:35 UTC
[spark] branch branch-3.2 updated: [SPARK-39355][SQL] Single column uses quoted to construct UnresolvedAttribute
This is an automated email from the ASF dual-hosted git repository.
wenchen pushed a commit to branch branch-3.2
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-3.2 by this push:
new 333df858946 [SPARK-39355][SQL] Single column uses quoted to construct UnresolvedAttribute
333df858946 is described below
commit 333df858946226c1b5eac6a5fc75c559ee4430e3
Author: sychen <sy...@ctrip.com>
AuthorDate: Wed Jun 15 16:02:46 2022 +0800
[SPARK-39355][SQL] Single column uses quoted to construct UnresolvedAttribute
Use `UnresolvedAttribute.quoted` in `Alias.toAttribute` to avoid calling `UnresolvedAttribute.apply` causing `ParseException`.
```sql
SELECT *
FROM (
SELECT '2022-06-01' AS c1
) a
WHERE c1 IN (
SELECT date_add('2022-06-01', 0)
);
```
```
Error in query:
mismatched input '(' expecting {<EOF>, '.', '-'}(line 1, pos 8)
== SQL ==
date_add(2022-06-01, 0)
--------^^^
```
No
add UT
Closes #36740 from cxzl25/SPARK-39355.
Authored-by: sychen <sy...@ctrip.com>
Signed-off-by: Wenchen Fan <we...@databricks.com>
---
.../expressions/aggregate/interfaces.scala | 2 +-
.../catalyst/expressions/namedExpressions.scala | 2 +-
.../scala/org/apache/spark/sql/SubquerySuite.scala | 28 ++++++++++++++++++++++
3 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/interfaces.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/interfaces.scala
index 6c22d87923c..35a2e2e51cc 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/interfaces.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/interfaces.scala
@@ -117,7 +117,7 @@ case class AggregateExpression(
// This is a bit of a hack. Really we should not be constructing this container and reasoning
// about datatypes / aggregation mode until after we have finished analysis and made it to
// planning.
- UnresolvedAttribute(aggregateFunction.toString)
+ UnresolvedAttribute.quoted(aggregateFunction.toString)
}
def filterAttributes: AttributeSet = filter.map(_.references).getOrElse(AttributeSet.empty)
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/namedExpressions.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/namedExpressions.scala
index 71f193e5107..96833d599ba 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/namedExpressions.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/namedExpressions.scala
@@ -206,7 +206,7 @@ case class Alias(child: Expression, name: String)(
if (resolved) {
AttributeReference(name, child.dataType, child.nullable, metadata)(exprId, qualifier)
} else {
- UnresolvedAttribute(name)
+ UnresolvedAttribute.quoted(name)
}
}
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/SubquerySuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/SubquerySuite.scala
index 277cb1bcebc..0e266b45ac9 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/SubquerySuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/SubquerySuite.scala
@@ -1921,4 +1921,32 @@ class SubquerySuite extends QueryTest with SharedSparkSession with AdaptiveSpark
}.getMessage.contains("Correlated column is not allowed in predicate"))
}
}
+
+ test("SPARK-39355: Single column uses quoted to construct UnresolvedAttribute") {
+ checkAnswer(
+ sql("""
+ |SELECT *
+ |FROM (
+ | SELECT '2022-06-01' AS c1
+ |) a
+ |WHERE c1 IN (
+ | SELECT date_add('2022-06-01', 0)
+ |)
+ |""".stripMargin),
+ Row("2022-06-01"))
+ checkAnswer(
+ sql("""
+ |SELECT *
+ |FROM (
+ | SELECT '2022-06-01' AS c1
+ |) a
+ |WHERE c1 IN (
+ | SELECT date_add(a.c1.k1, 0)
+ | FROM (
+ | SELECT named_struct('k1', '2022-06-01') AS c1
+ | ) a
+ |)
+ |""".stripMargin),
+ Row("2022-06-01"))
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org