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
Prev Previous commit
Next Next commit
Raise an error if the inlist contains incompatible types
  • Loading branch information
dilipbiswal committed Oct 8, 2015
commit d33e786d08919eceb81a29ca26f0e4c289f6713b
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,12 @@ object HiveTypeCoercion {
case e if !e.childrenResolved => e

case i @ In(a, b) if (a.dataType == NullType) =>
Literal.create(null, BooleanType)
var inTypes:Seq[DataType] = Seq.empty
b.foreach(e => inTypes = inTypes ++ Seq(e.dataType))
findWiderCommonType(inTypes) match {
case Some(finalDataType) => Literal.create(null, BooleanType)
case None => i
}
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of returning literal null, I think we should just wider the types, as it does fix the bug(we can add a rule in Optimizer to return null for this case).

the code can be:

case i @ In(a, b) if b.exists(_.dataType != a.dataType) =>
  findWiderCommonType(i.children.map(_.dataType)) match {
    case Some(finalDataType) => i.withNewChildren(i.children.map(Cast(_, finalDataType)))
    case None => i
  }


case i @ In(a, b) if b.exists(_.dataType != a.dataType) =>
i.makeCopy(Array(a, b.map(Cast(_, a.dataType))))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,18 @@ class AnalysisSuite extends AnalysisTest {
)
assertAnalysisSuccess(plan)
}

test("SPARK-8654: different types in inlist but can be converted to a commmon type") {
val plan = Project(Alias(In(Literal(null), Seq(Literal(1), Literal(1.2345))), "a")() :: Nil,
LocalRelation()
)
assertAnalysisSuccess(plan)
}

test("SPARK-8654: check type compatibility error") {
val plan = Project(Alias(In(Literal(null), Seq(Literal(true), Literal(1))), "a")() :: Nil,
LocalRelation()
)
assertAnalysisError(plan,Seq("cannot resolve 'null IN (true,1)' due to data type mismatch: Arguments must be same type"))
}
}