Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -75,7 +75,7 @@ trait NamedExpression extends Expression {
* multiple qualifiers, it is possible that there are other possible way to refer to this
* attribute.
*/
def qualifiedName: String = (qualifier :+ name).mkString(".")
def qualifiedName: String = (qualifier :+ name).map(quoteIfNeeded).mkString(".")

/**
* Optional qualifier for the expression.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,24 @@ class AnalysisErrorSuite extends AnalysisTest {
"[`a`, `b`, `c`, `d`, `e`]"
:: Nil)

errorTest(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you invoke errorClassTest(). This will allow to make the test independent from error message text, so, tech editors could edit error-classes.json and don't depend on Spark's tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

"SPARK-39783: backticks in error message for candidate column with dots",
// This selects a column that does not exist,
// the error message suggest the existing column with correct backticks
testRelation6.select($"`the`.`id`"),
"[UNRESOLVED_COLUMN.WITH_SUGGESTION] A column or function parameter with name `the`.`id` " +
"cannot be resolved. Did you mean one of the following? [`the.id`]"
:: Nil)

errorTest(
"SPARK-39783: backticks in error message for candidate struct column",
// This selects a column that does not exist,
// the error message suggest the existing column with correct backticks
nestedRelation2.select($"`top.aField`"),
"[UNRESOLVED_COLUMN.WITH_SUGGESTION] A column or function parameter with name `top.aField` " +
"cannot be resolved. Did you mean one of the following? [`top`]"
:: Nil)

test("SPARK-35080: Unsupported correlated equality predicates in subquery") {
val a = AttributeReference("a", IntegerType)()
val b = AttributeReference("b", IntegerType)()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ object TestRelations {

val testRelation5 = LocalRelation(AttributeReference("i", StringType)())

val testRelation6 = LocalRelation(AttributeReference("the.id", LongType)())

val nestedRelation = LocalRelation(
AttributeReference("top", StructType(
StructField("duplicateField", StringType) ::
Expand Down
27 changes: 27 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/DatasetSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1992,6 +1992,33 @@ class DatasetSuite extends QueryTest
}
}

test("SPARK-39783: Fix error messages for columns with dots/periods") {
forAll(dotColumnTestModes) { (caseSensitive, colName) =>
val ds = Seq(SpecialCharClass("1", "2")).toDS
withSQLConf(SQLConf.CASE_SENSITIVE.key -> caseSensitive) {
val errorMsg = intercept[AnalysisException] {
// Note: ds(colName) has different semantics than ds.select(colName)
ds.select(colName)
}
assert(errorMsg.getMessage.contains(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, use checkError().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

s"A column or function parameter with name `${colName.replace(".", "`.`")}` " +
s"cannot be resolved. Did you mean one of the following? [`field.1`, `field 2`]"))
}
}
}

test("SPARK-39783: backticks in error message for candidate column with dots") {
checkError(
exception = intercept[AnalysisException] {
Seq(0).toDF("the.id").select("the.id")
},
errorClass = "UNRESOLVED_COLUMN.WITH_SUGGESTION",
sqlState = None,
parameters = Map(
"objectName" -> "`the`.`id`",
"proposal" -> "`the.id`"))
}

test("groupBy.as") {
val df1 = Seq(DoubleData(1, "one"), DoubleData(2, "two"), DoubleData(3, "three")).toDS()
.repartition($"id").sortWithinPartitions("id")
Expand Down