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 @@ -800,9 +800,13 @@ abstract class BinaryOperator extends BinaryExpression with ExpectsInputTypes wi

override def inputTypes: Seq[AbstractDataType] = Seq(inputType, inputType)

protected def sameType(left: DataType, right: DataType): Boolean = {
DataTypeUtils.sameType(left, right)
}

override def checkInputDataTypes(): TypeCheckResult = {
// First check whether left and right have the same type, then check if the type is acceptable.
if (!DataTypeUtils.sameType(left.dataType, right.dataType)) {
if (!sameType(left.dataType, right.dataType)) {
DataTypeMismatch(
errorSubClass = "BINARY_OP_DIFF_TYPES",
messageParameters = Map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,11 @@ abstract class BinaryComparison extends BinaryOperator with Predicate {
// finitely enumerable. The allowable types are checked below by checkInputDataTypes.
override def inputType: AbstractDataType = AnyDataType

// For value comparison, the struct field name and nullability does not matter.
protected override def sameType(left: DataType, right: DataType): Boolean = {
DataType.equalsStructurally(left, right, ignoreNullability = true)
}

final override val nodePatterns: Seq[TreePattern] = Seq(BINARY_COMPARISON)

override lazy val canonicalized: Expression = {
Expand Down
22 changes: 0 additions & 22 deletions sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2755,28 +2755,6 @@ class SQLQuerySuite extends QueryTest with SharedSparkSession with AdaptiveSpark
start = 0,
stop = 45)
)

withTable("t", "S") {
sql("CREATE TABLE t(c struct<f:int>) USING parquet")
sql("CREATE TABLE S(C struct<F:int>) USING parquet")
checkAnswer(sql("SELECT * FROM t, S WHERE t.c.f = S.C.F"), Seq.empty)
val query = "SELECT * FROM t, S WHERE c = C"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this is no longer an issue as binary comparison doesn't care about field names now.

checkError(
exception = intercept[AnalysisException] {
sql(query)
},
condition = "DATATYPE_MISMATCH.BINARY_OP_DIFF_TYPES",
sqlState = None,
parameters = Map(
"sqlExpr" -> "\"(c = C)\"",
"left" -> "\"STRUCT<f: INT>\"",
"right" -> "\"STRUCT<F: INT>\""),
context = ExpectedContext(
fragment = "c = C",
start = 25,
stop = 29
))
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2830,4 +2830,11 @@ class SubquerySuite extends QueryTest
Row(1, false) :: Row(2, false) :: Row(3, true) :: Nil)
}
}

test("SPARK-51738: IN subquery with struct type") {
checkAnswer(
sql("SELECT foo IN (SELECT struct(1 a)) FROM (SELECT struct(1 b) foo)"),
Row(true)
)
}
}