Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.apache.hadoop.io.{LongWritable, Text}
import org.apache.hadoop.mapreduce.lib.input.{TextInputFormat => NewTextInputFormat}
import org.scalatest.Matchers._

import org.apache.spark.sql.catalyst.analysis.UnresolvedAttribute
import org.apache.spark.sql.catalyst.expressions.NamedExpression
import org.apache.spark.sql.execution.ProjectExec
import org.apache.spark.sql.functions._
Expand Down Expand Up @@ -114,6 +115,16 @@ class ColumnExpressionSuite extends QueryTest with SharedSQLContext {
Row("a") :: Nil)
}

test("SPARK-25769 escape nested columns by backtick each of the column name") {
Seq(
($"a.b", "`a`.`b`"),
($"`a.b`", "`a.b`"),
($"`a`.b", "`a`.`b`"),
($"`a.b`.c", "`a.b`.`c`")).foreach { case (columnName, sqlString) =>
assert(columnName.expr.sql === sqlString)
}
}

test("alias and name") {
val df = Seq((1, Seq(1, 2, 3))).toDF("a", "intList")
assert(df.select(df("a").as("b")).columns.head === "b")
Expand Down
15 changes: 0 additions & 15 deletions sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2856,21 +2856,6 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext {
checkAnswer(sql("select 26393499451 / (1e6 * 1000)"), Row(BigDecimal("26.3934994510000")))
}
}

test("SPARK-25769 escape nested columns") {
import org.apache.spark.sql.catalyst.analysis.UnresolvedAttribute
val sql1 = $"a.b".expr.asInstanceOf[UnresolvedAttribute].sql
assert(sql1 === "`a`.`b`")

val sql2 = $"`a.b`".expr.asInstanceOf[UnresolvedAttribute].sql
assert(sql2 === "`a.b`")

val sql3 = $"`a`.b".expr.asInstanceOf[UnresolvedAttribute].sql
assert(sql3 === "`a`.`b`")

val sql4 = $"`a.b`.c".expr.asInstanceOf[UnresolvedAttribute].sql
assert(sql4 === "`a.b`.`c`")
}
}

case class Foo(bar: Option[String])