You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by li...@apache.org on 2017/06/16 16:41:04 UTC
spark git commit: [SPARK-20931][SQL] ABS function support string type.
Repository: spark
Updated Branches:
refs/heads/master d1c333ac7 -> 53e48f73e
[SPARK-20931][SQL] ABS function support string type.
## What changes were proposed in this pull request?
ABS function support string type. Hive/MySQL support this feature.
Ref: https://github.com/apache/hive/blob/4ba713ccd85c3706d195aeef9476e6e6363f1c21/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFAbs.java#L93
## How was this patch tested?
unit tests
Author: Yuming Wang <wg...@gmail.com>
Closes #18153 from wangyum/SPARK-20931.
Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/53e48f73
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/53e48f73
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/53e48f73
Branch: refs/heads/master
Commit: 53e48f73e42bb3eea075894ff08494e0abe9d60a
Parents: d1c333a
Author: Yuming Wang <wg...@gmail.com>
Authored: Fri Jun 16 09:40:58 2017 -0700
Committer: gatorsmile <ga...@gmail.com>
Committed: Fri Jun 16 09:40:58 2017 -0700
----------------------------------------------------------------------
.../apache/spark/sql/catalyst/analysis/TypeCoercion.scala | 1 +
.../catalyst/analysis/ExpressionTypeCheckingSuite.scala | 1 -
.../src/test/resources/sql-tests/inputs/operators.sql | 3 +++
.../test/resources/sql-tests/results/operators.sql.out | 10 +++++++++-
4 files changed, 13 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/spark/blob/53e48f73/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercion.scala
----------------------------------------------------------------------
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercion.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercion.scala
index 1f21739..6082c58 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercion.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercion.scala
@@ -357,6 +357,7 @@ object TypeCoercion {
val commonType = findCommonTypeForBinaryComparison(left.dataType, right.dataType).get
p.makeCopy(Array(castExpr(left, commonType), castExpr(right, commonType)))
+ case Abs(e @ StringType()) => Abs(Cast(e, DoubleType))
case Sum(e @ StringType()) => Sum(Cast(e, DoubleType))
case Average(e @ StringType()) => Average(Cast(e, DoubleType))
case StddevPop(e @ StringType()) => StddevPop(Cast(e, DoubleType))
http://git-wip-us.apache.org/repos/asf/spark/blob/53e48f73/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/ExpressionTypeCheckingSuite.scala
----------------------------------------------------------------------
diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/ExpressionTypeCheckingSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/ExpressionTypeCheckingSuite.scala
index 744057b..2239bf8 100644
--- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/ExpressionTypeCheckingSuite.scala
+++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/ExpressionTypeCheckingSuite.scala
@@ -57,7 +57,6 @@ class ExpressionTypeCheckingSuite extends SparkFunSuite {
test("check types for unary arithmetic") {
assertError(UnaryMinus('stringField), "(numeric or calendarinterval) type")
- assertError(Abs('stringField), "requires numeric type")
assertError(BitwiseNot('stringField), "requires integral type")
}
http://git-wip-us.apache.org/repos/asf/spark/blob/53e48f73/sql/core/src/test/resources/sql-tests/inputs/operators.sql
----------------------------------------------------------------------
diff --git a/sql/core/src/test/resources/sql-tests/inputs/operators.sql b/sql/core/src/test/resources/sql-tests/inputs/operators.sql
index a8de23e..a1e8a32 100644
--- a/sql/core/src/test/resources/sql-tests/inputs/operators.sql
+++ b/sql/core/src/test/resources/sql-tests/inputs/operators.sql
@@ -85,3 +85,6 @@ select mod(7, 2), mod(7, 0), mod(0, 2), mod(7, null), mod(null, 2), mod(null, nu
select BIT_LENGTH('abc');
select CHAR_LENGTH('abc');
select OCTET_LENGTH('abc');
+
+-- abs
+select abs(-3.13), abs('-2.19');
http://git-wip-us.apache.org/repos/asf/spark/blob/53e48f73/sql/core/src/test/resources/sql-tests/results/operators.sql.out
----------------------------------------------------------------------
diff --git a/sql/core/src/test/resources/sql-tests/results/operators.sql.out b/sql/core/src/test/resources/sql-tests/results/operators.sql.out
index 85ee10b..eac3080 100644
--- a/sql/core/src/test/resources/sql-tests/results/operators.sql.out
+++ b/sql/core/src/test/resources/sql-tests/results/operators.sql.out
@@ -1,5 +1,5 @@
-- Automatically generated by SQLQueryTestSuite
--- Number of queries: 54
+-- Number of queries: 55
-- !query 0
@@ -444,3 +444,11 @@ select OCTET_LENGTH('abc')
struct<octetlength(abc):int>
-- !query 53 output
3
+
+
+-- !query 54
+select abs(-3.13), abs('-2.19')
+-- !query 54 schema
+struct<abs(-3.13):decimal(3,2),abs(CAST(-2.19 AS DOUBLE)):double>
+-- !query 54 output
+3.13 2.19
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org