Skip to content
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.
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 @@ -1836,13 +1836,25 @@ class Analyzer(
}

private def commonNaturalJoinProcessing(
left: LogicalPlan,
right: LogicalPlan,
joinType: JoinType,
joinNames: Seq[String],
condition: Option[Expression]) = {
val leftKeys = joinNames.map(keyName => left.output.find(_.name == keyName).get)
val rightKeys = joinNames.map(keyName => right.output.find(_.name == keyName).get)
left: LogicalPlan,
right: LogicalPlan,
joinType: JoinType,
joinNames: Seq[String],
condition: Option[Expression]) = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These 5 lines are just formatting changes.

val leftKeys = joinNames.map { keyName =>
val joinColumn = left.output.find(attr => resolver(attr.name, keyName))
assert(
joinColumn.isDefined,
s"$keyName should exist in ${left.output.map(_.name).mkString(",")}")
joinColumn.get
}
val rightKeys = joinNames.map { keyName =>
val joinColumn = right.output.find(attr => resolver(attr.name, keyName))
assert(
joinColumn.isDefined,
s"$keyName should exist in ${right.output.map(_.name).mkString(",")}")
joinColumn.get
}
val joinPairs = leftKeys.zip(rightKeys)

val newCondition = (condition ++ joinPairs.map(EqualTo.tupled)).reduceOption(And)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,34 @@ class ResolveNaturalJoinSuite extends AnalysisTest {
assert(error.message.contains(
"using columns ['d] can not be resolved given input columns: [b, a, c]"))
}

test("using join with a case sensitive analyzer") {
val expected = r1.join(r2, Inner, Some(EqualTo(a, a))).select(a, b, c)

{
val usingPlan = r1.join(r2, UsingJoin(Inner, Seq(UnresolvedAttribute("a"))), None)
checkAnalysis(usingPlan, expected, caseSensitive = true)
}

{
val usingPlan = r1.join(r2, UsingJoin(Inner, Seq(UnresolvedAttribute("A"))), None)
assertAnalysisError(
usingPlan,
Seq("using columns ['A] can not be resolved given input columns: [b, a, c, a]"))
}
}

test("using join with a case insensitive analyzer") {
val expected = r1.join(r2, Inner, Some(EqualTo(a, a))).select(a, b, c)

{
val usingPlan = r1.join(r2, UsingJoin(Inner, Seq(UnresolvedAttribute("a"))), None)
checkAnalysis(usingPlan, expected, caseSensitive = false)
}

{
val usingPlan = r1.join(r2, UsingJoin(Inner, Seq(UnresolvedAttribute("A"))), None)
checkAnalysis(usingPlan, expected, caseSensitive = false)
}
}
}