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 @@ -157,7 +157,8 @@ case class In(value: Expression, list: Seq[Expression]) extends Predicate {
require(list != null, "list should not be null")

override def checkInputDataTypes(): TypeCheckResult = {
val mismatchOpt = list.find(l => !DataType.equalsStructurally(l.dataType, value.dataType))
val mismatchOpt = list.find(l => !DataType.equalsStructurally(l.dataType, value.dataType,
ignoreNullability = true))
if (mismatchOpt.isDefined) {
list match {
case ListQuery(_, _, _, childOutputs) :: Nil =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,22 +298,24 @@ object DataType {
* Returns true if the two data types share the same "shape", i.e. the types (including
* nullability) are the same, but the field names don't need to be the same.
Copy link
Member

Choose a reason for hiding this comment

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

This comments need an update too.

*/
def equalsStructurally(from: DataType, to: DataType): Boolean = {
def equalsStructurally(from: DataType, to: DataType,
ignoreNullability: Boolean = false): Boolean = {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: the indents.

(from, to) match {
case (left: ArrayType, right: ArrayType) =>
equalsStructurally(left.elementType, right.elementType) &&
left.containsNull == right.containsNull
(ignoreNullability || left.containsNull == right.containsNull)

case (left: MapType, right: MapType) =>
equalsStructurally(left.keyType, right.keyType) &&
equalsStructurally(left.valueType, right.valueType) &&
left.valueContainsNull == right.valueContainsNull
(ignoreNullability || left.valueContainsNull == right.valueContainsNull)

case (StructType(fromFields), StructType(toFields)) =>
fromFields.length == toFields.length &&
fromFields.zip(toFields)
.forall { case (l, r) =>
equalsStructurally(l.dataType, r.dataType) && l.nullable == r.nullable
equalsStructurally(l.dataType, r.dataType) &&
(ignoreNullability || l.nullable == r.nullable)
}

case (fromDataType, toDataType) => fromDataType == toDataType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -950,4 +950,9 @@ class SubquerySuite extends QueryTest with SharedSQLContext {
assert(join.duplicateResolved)
assert(optimizedPlan.resolved)
}

test("SPARK-23316: AnalysisException after max iteration reached for IN query") {
// before the fix this would throw AnalysisException
spark.range(10).where("(id,id) in (select id, null from range(3))").count
}
}