From e0a3628a1052544beb395b26c1f5764836f9461d Mon Sep 17 00:00:00 2001 From: Wenchen Fan Date: Fri, 29 May 2015 13:52:46 +0800 Subject: [PATCH] improve error message --- .../spark/sql/catalyst/util/TypeUtils.scala | 6 ++-- .../ExpressionTypeCheckingSuite.scala | 36 +++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/TypeUtils.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/TypeUtils.scala index 81efb8b21e7f6..26df4fbfcf316 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/TypeUtils.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/TypeUtils.scala @@ -28,7 +28,7 @@ object TypeUtils { if (t.isInstanceOf[NumericType] || t == NullType) { TypeCheckResult.success } else { - TypeCheckResult.fail(s"$caller need numeric type(int, long, double, etc.), not $t") + TypeCheckResult.fail(s"$caller accepts numeric types, not $t") } } @@ -36,7 +36,7 @@ object TypeUtils { if (t.isInstanceOf[IntegralType] || t == NullType) { TypeCheckResult.success } else { - TypeCheckResult.fail(s"$caller need integral type(short, int, long, etc.), not $t") + TypeCheckResult.fail(s"$caller accepts integral types, not $t") } } @@ -44,7 +44,7 @@ object TypeUtils { if (t.isInstanceOf[AtomicType] || t == NullType) { TypeCheckResult.success } else { - TypeCheckResult.fail(s"$caller need atomic type(binary, boolean, numeric, etc), not $t") + TypeCheckResult.fail(s"$caller accepts non-complex types, not $t") } } diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionTypeCheckingSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionTypeCheckingSuite.scala index 9fdefc5301b8e..c241d05063efd 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionTypeCheckingSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionTypeCheckingSuite.scala @@ -45,11 +45,11 @@ class ExpressionTypeCheckingSuite extends FunSuite { } test("check types for unary arithmetic") { - checkError(UnaryMinus('b), "operator - need numeric type") + checkError(UnaryMinus('b), "operator - accepts numeric type") checkAnalysis(Sqrt('b)) // We will cast String to Double for sqrt - checkError(Sqrt('c), "function sqrt need numeric type") - checkError(Abs('b), "function abs need numeric type") - checkError(BitwiseNot('b), "operator ~ need integral type") + checkError(Sqrt('c), "function sqrt accepts numeric type") + checkError(Abs('b), "function abs accepts numeric type") + checkError(BitwiseNot('b), "operator ~ accepts integral type") } test("check types for binary arithmetic") { @@ -73,18 +73,18 @@ class ExpressionTypeCheckingSuite extends FunSuite { checkError(MaxOf('a, 'c), msg) checkError(MinOf('a, 'c), msg) - checkError(Add('c, 'c), "operator + need numeric type") - checkError(Subtract('c, 'c), "operator - need numeric type") - checkError(Multiply('c, 'c), "operator * need numeric type") - checkError(Divide('c, 'c), "operator / need numeric type") - checkError(Remainder('c, 'c), "operator % need numeric type") + checkError(Add('c, 'c), "operator + accepts numeric type") + checkError(Subtract('c, 'c), "operator - accepts numeric type") + checkError(Multiply('c, 'c), "operator * accepts numeric type") + checkError(Divide('c, 'c), "operator / accepts numeric type") + checkError(Remainder('c, 'c), "operator % accepts numeric type") - checkError(BitwiseAnd('c, 'c), "operator & need integral type") - checkError(BitwiseOr('c, 'c), "operator | need integral type") - checkError(BitwiseXor('c, 'c), "operator ^ need integral type") + checkError(BitwiseAnd('c, 'c), "operator & accepts integral type") + checkError(BitwiseOr('c, 'c), "operator | accepts integral type") + checkError(BitwiseXor('c, 'c), "operator ^ accepts integral type") - checkError(MaxOf('d, 'd), "function maxOf need atomic type") - checkError(MinOf('d, 'd), "function minOf need atomic type") + checkError(MaxOf('d, 'd), "function maxOf accepts non-complex type") + checkError(MinOf('d, 'd), "function minOf accepts non-complex type") } test("check types for predicates") { @@ -104,10 +104,10 @@ class ExpressionTypeCheckingSuite extends FunSuite { checkError(GreaterThan('a, 'c), msg) checkError(GreaterThanOrEqual('a, 'c), msg) - checkError(LessThan('d, 'd), "operator < need atomic type") - checkError(LessThanOrEqual('d, 'd), "operator <= need atomic type") - checkError(GreaterThan('d, 'd), "operator > need atomic type") - checkError(GreaterThanOrEqual('d, 'd), "operator >= need atomic type") + checkError(LessThan('d, 'd), "operator < accepts non-complex type") + checkError(LessThanOrEqual('d, 'd), "operator <= accepts non-complex type") + checkError(GreaterThan('d, 'd), "operator > accepts non-complex type") + checkError(GreaterThanOrEqual('d, 'd), "operator >= accepts non-complex type") checkError(If('a, 'a, 'a), "type of predicate expression in If should be boolean") checkError(If('c, 'a, 'b), "differing types in If, IntegerType != StringType")