Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-43841][SQL] Handle candidate attributes with no prefix in StringUtils#orderSuggestedIdentifiersBySimilarity #41353

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ object StringUtils extends Logging {
sorted.map(_._2)
} else {
// More than one relation
sorted.map(x => s"${x._1}.${x._2}")
sorted.map(x => if (x._1.isEmpty) s"${x._2}" else s"${x._1}.${x._2}")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,11 @@ class StringUtilsSuite extends SparkFunSuite with SQLHelper {
assert(quoteIfNeeded("_") === "_")
assert(quoteIfNeeded("") === "``")
}

test("SPARK-43841: mix of multipart and single-part identifiers") {
val baseString = "b"
val testStrings = Seq("c1", "v1.c2", "v2.c2") // mix of multipart and single-part
val expectedOutput = Seq("c1", "v1.c2", "v2.c2")
assert(orderSuggestedIdentifiersBySimilarity(baseString, testStrings) === expectedOutput)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,33 @@ class QueryCompilationErrorsSuite
)
}
}

test("SPARK-43841: Unresolved attribute in select of full outer join with USING") {
withTempView("v1", "v2") {
sql("create or replace temp view v1 as values (1, 2) as (c1, c2)")
sql("create or replace temp view v2 as values (2, 3) as (c1, c2)")

val query =
"""select b
|from v1
|full outer join v2
|using (c1)
|""".stripMargin

checkError(
exception = intercept[AnalysisException] {
sql(query)
},
errorClass = "UNRESOLVED_COLUMN.WITH_SUGGESTION",
parameters = Map(
"proposal" -> "`c1`, `v1`.`c2`, `v2`.`c2`",
"objectName" -> "`b`"),
context = ExpectedContext(
fragment = "b",
start = 7, stop = 7)
)
}
}
}

class MyCastToString extends SparkUserDefinedFunction(
Expand Down