forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from rxin/type
HiveTypeCoercion.WidenTypes Void to Boolean support & unit tests
- Loading branch information
Showing
2 changed files
with
71 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/test/scala/catalyst/analysis/HiveTypeCoercionSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package catalyst.analysis | ||
|
||
import org.scalatest.FunSuite | ||
|
||
import catalyst.types._ | ||
|
||
|
||
class HiveTypeCoercionSuite extends FunSuite { | ||
|
||
val rules = new HiveTypeCoercion { } | ||
import rules._ | ||
|
||
test("tightest common bound for numeric and boolean types") { | ||
def widenTest(t1: DataType, t2: DataType, tightestCommon: Option[DataType]) { | ||
var found = WidenTypes.findTightestCommonType(t1, t2) | ||
assert(found == tightestCommon, | ||
s"Expected $tightestCommon as tightest common type for $t1 and $t2, found $found") | ||
// Test both directions to make sure the widening is symmetric. | ||
found = WidenTypes.findTightestCommonType(t2, t1) | ||
assert(found == tightestCommon, | ||
s"Expected $tightestCommon as tightest common type for $t2 and $t1, found $found") | ||
} | ||
|
||
// Boolean | ||
widenTest(NullType, BooleanType, Some(BooleanType)) | ||
widenTest(BooleanType, BooleanType, Some(BooleanType)) | ||
widenTest(IntegerType, BooleanType, None) | ||
widenTest(LongType, BooleanType, None) | ||
|
||
// Integral | ||
widenTest(NullType, ByteType, Some(ByteType)) | ||
widenTest(NullType, IntegerType, Some(IntegerType)) | ||
widenTest(NullType, LongType, Some(LongType)) | ||
widenTest(ShortType, IntegerType, Some(IntegerType)) | ||
widenTest(ShortType, LongType, Some(LongType)) | ||
widenTest(IntegerType, LongType, Some(LongType)) | ||
widenTest(LongType, LongType, Some(LongType)) | ||
|
||
// Floating point | ||
widenTest(NullType, FloatType, Some(FloatType)) | ||
widenTest(NullType, DoubleType, Some(DoubleType)) | ||
widenTest(FloatType, DoubleType, Some(DoubleType)) | ||
widenTest(FloatType, FloatType, Some(FloatType)) | ||
widenTest(DoubleType, DoubleType, Some(DoubleType)) | ||
|
||
// Integral mixed with floating point. | ||
widenTest(NullType, FloatType, Some(FloatType)) | ||
widenTest(NullType, DoubleType, Some(DoubleType)) | ||
widenTest(IntegerType, FloatType, Some(FloatType)) | ||
widenTest(IntegerType, DoubleType, Some(DoubleType)) | ||
widenTest(IntegerType, DoubleType, Some(DoubleType)) | ||
widenTest(LongType, FloatType, Some(FloatType)) | ||
widenTest(LongType, DoubleType, Some(DoubleType)) | ||
} | ||
} |