You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by ma...@apache.org on 2014/12/02 23:26:11 UTC
spark git commit: [SPARK-4670] [SQL] wrong symbol for bitwise not
Repository: spark
Updated Branches:
refs/heads/master f6df609dc -> 1f5ddf17e
[SPARK-4670] [SQL] wrong symbol for bitwise not
We should use `~` instead of `-` for bitwise NOT.
Author: Daoyuan Wang <da...@intel.com>
Closes #3528 from adrian-wang/symbol and squashes the following commits:
affd4ad [Daoyuan Wang] fix code gen test case
56efb79 [Daoyuan Wang] ensure bitwise NOT over byte and short persist data type
f55fbae [Daoyuan Wang] wrong symbol for bitwise not
Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/1f5ddf17
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/1f5ddf17
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/1f5ddf17
Branch: refs/heads/master
Commit: 1f5ddf17e831ad9717f0f4b60a727a3381fad4f9
Parents: f6df609
Author: Daoyuan Wang <da...@intel.com>
Authored: Tue Dec 2 14:25:12 2014 -0800
Committer: Michael Armbrust <mi...@databricks.com>
Committed: Tue Dec 2 14:25:12 2014 -0800
----------------------------------------------------------------------
.../sql/catalyst/expressions/arithmetic.scala | 20 ++++++++++----------
.../expressions/ExpressionEvaluationSuite.scala | 15 +++++++++++++++
2 files changed, 25 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/spark/blob/1f5ddf17/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala
----------------------------------------------------------------------
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala
index 7ec18b8..61c26c5 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala
@@ -42,7 +42,7 @@ case class Sqrt(child: Expression) extends UnaryExpression {
override def toString = s"SQRT($child)"
override def eval(input: Row): Any = {
- n1(child, input, ((na,a) => math.sqrt(na.toDouble(a))))
+ n1(child, input, (na,a) => math.sqrt(na.toDouble(a)))
}
}
@@ -138,7 +138,7 @@ case class BitwiseAnd(left: Expression, right: Expression) extends BinaryArithme
case ShortType => (evalE1.asInstanceOf[Short] & evalE2.asInstanceOf[Short]).toShort
case IntegerType => evalE1.asInstanceOf[Int] & evalE2.asInstanceOf[Int]
case LongType => evalE1.asInstanceOf[Long] & evalE2.asInstanceOf[Long]
- case other => sys.error(s"Unsupported bitwise & operation on ${other}")
+ case other => sys.error(s"Unsupported bitwise & operation on $other")
}
}
@@ -153,7 +153,7 @@ case class BitwiseOr(left: Expression, right: Expression) extends BinaryArithmet
case ShortType => (evalE1.asInstanceOf[Short] | evalE2.asInstanceOf[Short]).toShort
case IntegerType => evalE1.asInstanceOf[Int] | evalE2.asInstanceOf[Int]
case LongType => evalE1.asInstanceOf[Long] | evalE2.asInstanceOf[Long]
- case other => sys.error(s"Unsupported bitwise | operation on ${other}")
+ case other => sys.error(s"Unsupported bitwise | operation on $other")
}
}
@@ -168,7 +168,7 @@ case class BitwiseXor(left: Expression, right: Expression) extends BinaryArithme
case ShortType => (evalE1.asInstanceOf[Short] ^ evalE2.asInstanceOf[Short]).toShort
case IntegerType => evalE1.asInstanceOf[Int] ^ evalE2.asInstanceOf[Int]
case LongType => evalE1.asInstanceOf[Long] ^ evalE2.asInstanceOf[Long]
- case other => sys.error(s"Unsupported bitwise ^ operation on ${other}")
+ case other => sys.error(s"Unsupported bitwise ^ operation on $other")
}
}
@@ -181,7 +181,7 @@ case class BitwiseNot(child: Expression) extends UnaryExpression {
def dataType = child.dataType
override def foldable = child.foldable
def nullable = child.nullable
- override def toString = s"-$child"
+ override def toString = s"~$child"
override def eval(input: Row): Any = {
val evalE = child.eval(input)
@@ -189,11 +189,11 @@ case class BitwiseNot(child: Expression) extends UnaryExpression {
null
} else {
dataType match {
- case ByteType => (~(evalE.asInstanceOf[Byte])).toByte
- case ShortType => (~(evalE.asInstanceOf[Short])).toShort
- case IntegerType => ~(evalE.asInstanceOf[Int])
- case LongType => ~(evalE.asInstanceOf[Long])
- case other => sys.error(s"Unsupported bitwise ~ operation on ${other}")
+ case ByteType => (~evalE.asInstanceOf[Byte]).toByte
+ case ShortType => (~evalE.asInstanceOf[Short]).toShort
+ case IntegerType => ~evalE.asInstanceOf[Int]
+ case LongType => ~evalE.asInstanceOf[Long]
+ case other => sys.error(s"Unsupported bitwise ~ operation on $other")
}
}
}
http://git-wip-us.apache.org/repos/asf/spark/blob/1f5ddf17/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionEvaluationSuite.scala
----------------------------------------------------------------------
diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionEvaluationSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionEvaluationSuite.scala
index 25f5642..cd2f67f 100644
--- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionEvaluationSuite.scala
+++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionEvaluationSuite.scala
@@ -42,6 +42,21 @@ class ExpressionEvaluationSuite extends FunSuite {
checkEvaluation(Literal(1) + Literal(1), 2)
}
+ test("unary BitwiseNOT") {
+ checkEvaluation(BitwiseNot(1), -2)
+ assert(BitwiseNot(1).dataType === IntegerType)
+ assert(BitwiseNot(1).eval(EmptyRow).isInstanceOf[Int])
+ checkEvaluation(BitwiseNot(1.toLong), -2.toLong)
+ assert(BitwiseNot(1.toLong).dataType === LongType)
+ assert(BitwiseNot(1.toLong).eval(EmptyRow).isInstanceOf[Long])
+ checkEvaluation(BitwiseNot(1.toShort), -2.toShort)
+ assert(BitwiseNot(1.toShort).dataType === ShortType)
+ assert(BitwiseNot(1.toShort).eval(EmptyRow).isInstanceOf[Short])
+ checkEvaluation(BitwiseNot(1.toByte), -2.toByte)
+ assert(BitwiseNot(1.toByte).dataType === ByteType)
+ assert(BitwiseNot(1.toByte).eval(EmptyRow).isInstanceOf[Byte])
+ }
+
/**
* Checks for three-valued-logic. Based on:
* http://en.wikipedia.org/wiki/Null_(SQL)#Comparisons_with_NULL_and_the_three-valued_logic_.283VL.29
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org