Skip to content
Closed
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
rebase master
  • Loading branch information
OopsOutOfMemory committed Jun 12, 2015
commit 7a209d7d02af0fc6427a967ac35145bc5e3e3383
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,14 @@ object HiveTypeCoercion {
}

/**
* Implicit promote the AtomicType to StringType if
* one of the data type in (dt1, dt2) is StringType, and the other is not either
* BooleanType or BinaryType, the TightestCommonType should be StringType
* eg: 1. CaseWhenLike case when ... then dt1 else dt2 end
* 2. Coalesce(null, dt1, dt2)
* Similar to [[findTightestCommonType]], if can not find the TightestCommonType, try to use
* [[findTightestCommonTypeToString]] to find the TightestCommonType.
*/
private def promoteToStringType(t1: DataType, t2: DataType): Option[DataType] = (t1, t2) match {
case (t1: StringType, t2: AtomicType) if (t2 != BinaryType && t2 != BooleanType) =>
Some(StringType)

case (t1: AtomicType, t2: StringType) if (t1 != BinaryType && t1 != BooleanType) =>
Some(StringType)

case _ => None
}

private def findTightestCommonTypeAndPromoteToString(types: Seq[DataType]): Option[DataType] = {
types.foldLeft[Option[DataType]](Some(NullType))((r, c) => r match {
case None => None
case Some(d) =>
findTightestCommonTypeOfTwo(d, c).orElse(promoteToStringType(d, c))
findTightestCommonTypeOfTwo(d, c).orElse(findTightestCommonTypeToString(d, c))
})
}

Expand Down