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
Next Next commit
refactor
  • Loading branch information
jiangxb1987 committed Apr 18, 2018
commit 55eefe0883ad8aec6a79f56a42085ea645e8eecb
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,22 @@ object TypeCoercion {
})
}

/**
* Whether the data type contains StringType.
*/
def hasStringType(dt: DataType): Boolean = dt match {
case StringType => true
case ArrayType(et, _) => hasStringType(et)
// Add StructType if we support string promotion for struct fields in the future.
case _ => false
}

private def findWiderCommonType(types: Seq[DataType]): Option[DataType] = {
// findWiderTypeForTwo doesn't satisfy the associative law, i.e. (a op b) op c may not equal
// to a op (b op c). This is only a problem for StringType. Excluding StringType,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is only a problem for StringType or nested StringType in ArrayType. Excluding these types, ...

// findWiderTypeForTwo satisfies the associative law. For instance, (TimestampType,
// IntegerType, StringType) should have StringType as the wider common type.
val (stringTypes, nonStringTypes) = types.partition { t =>
t == StringType || t == ArrayType(StringType)
}
val (stringTypes, nonStringTypes) = types.partition(hasStringType(_))
(stringTypes.distinct ++ nonStringTypes).foldLeft[Option[DataType]](Some(NullType))((r, c) =>
r match {
case Some(d) => findWiderTypeForTwo(d, c)
Expand Down