Skip to content

Commit 7ff2696

Browse files
authored
Merge pull request #1 from dongjoon-hyun/PR-22788
Refactor the test case
2 parents 458f77a + 566d5f9 commit 7ff2696

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

sql/core/src/test/scala/org/apache/spark/sql/ColumnExpressionSuite.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import org.apache.hadoop.io.{LongWritable, Text}
2525
import org.apache.hadoop.mapreduce.lib.input.{TextInputFormat => NewTextInputFormat}
2626
import org.scalatest.Matchers._
2727

28+
import org.apache.spark.sql.catalyst.analysis.UnresolvedAttribute
2829
import org.apache.spark.sql.catalyst.expressions.NamedExpression
2930
import org.apache.spark.sql.execution.ProjectExec
3031
import org.apache.spark.sql.functions._
@@ -114,6 +115,16 @@ class ColumnExpressionSuite extends QueryTest with SharedSQLContext {
114115
Row("a") :: Nil)
115116
}
116117

118+
test("SPARK-25769 escape nested columns by backtick each of the column name") {
119+
Seq(
120+
($"a.b", "`a`.`b`"),
121+
($"`a.b`", "`a.b`"),
122+
($"`a`.b", "`a`.`b`"),
123+
($"`a.b`.c", "`a.b`.`c`")).foreach { case (columnName, sqlString) =>
124+
assert(columnName.expr.sql === sqlString)
125+
}
126+
}
127+
117128
test("alias and name") {
118129
val df = Seq((1, Seq(1, 2, 3))).toDF("a", "intList")
119130
assert(df.select(df("a").as("b")).columns.head === "b")

sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2856,21 +2856,6 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext {
28562856
checkAnswer(sql("select 26393499451 / (1e6 * 1000)"), Row(BigDecimal("26.3934994510000")))
28572857
}
28582858
}
2859-
2860-
test("SPARK-25769 escape nested columns") {
2861-
import org.apache.spark.sql.catalyst.analysis.UnresolvedAttribute
2862-
val sql1 = $"a.b".expr.asInstanceOf[UnresolvedAttribute].sql
2863-
assert(sql1 === "`a`.`b`")
2864-
2865-
val sql2 = $"`a.b`".expr.asInstanceOf[UnresolvedAttribute].sql
2866-
assert(sql2 === "`a.b`")
2867-
2868-
val sql3 = $"`a`.b".expr.asInstanceOf[UnresolvedAttribute].sql
2869-
assert(sql3 === "`a`.`b`")
2870-
2871-
val sql4 = $"`a.b`.c".expr.asInstanceOf[UnresolvedAttribute].sql
2872-
assert(sql4 === "`a.b`.`c`")
2873-
}
28742859
}
28752860

28762861
case class Foo(bar: Option[String])

0 commit comments

Comments
 (0)