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
Apply code review comments
  • Loading branch information
dilipbiswal committed Oct 8, 2015
commit cf976a679c96de9a0db18b14f216c34ee1753662
Original file line number Diff line number Diff line change
Expand Up @@ -305,24 +305,18 @@ object HiveTypeCoercion {

/**
* Convert all expressions in in() list to the left operator type
* except when the left operator type is NullType. In case when left hand
* operator type is NullType create a Literal(Null).
* except when the left operator type is NullType.
*/
object InConversion extends Rule[LogicalPlan] {
def apply(plan: LogicalPlan): LogicalPlan = plan resolveExpressions {
// Skip nodes who's children have not been resolved yet.
case e if !e.childrenResolved => e

case i @ In(a, b) if (a.dataType == NullType) =>
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 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
}
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 @@ -154,7 +154,6 @@ class AnalysisSuite extends AnalysisTest {
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"))
assertAnalysisError(plan, Seq("data type mismatch: Arguments must be same type"))
}
}