aboutsummaryrefslogtreecommitdiff
path: root/sql/hive
diff options
context:
space:
mode:
authorravipesala <ravindra.pesala@huawei.com>2014-10-28 13:36:06 -0700
committerMichael Armbrust <michael@databricks.com>2014-10-28 13:36:06 -0700
commit5807cb40ae178f0395c71b967f02aee853ef8bc9 (patch)
treeaf22a7b77a4b106b5cd93ae711e43e78936ed048 /sql/hive
parent6c1b981c3fad671bff4795f061bd40e111956621 (diff)
downloadspark-5807cb40ae178f0395c71b967f02aee853ef8bc9.tar.gz
spark-5807cb40ae178f0395c71b967f02aee853ef8bc9.tar.bz2
spark-5807cb40ae178f0395c71b967f02aee853ef8bc9.zip
[SPARK-3814][SQL] Support for Bitwise AND(&), OR(|) ,XOR(^), NOT(~) in Spark HQL and SQL
Currently there is no support of Bitwise & , | in Spark HiveQl and Spark SQL as well. So this PR support the same. I am closing https://github.com/apache/spark/pull/2926 as it has conflicts to merge. And also added support for Bitwise AND(&), OR(|) ,XOR(^), NOT(~) And I handled all review comments in that PR Author: ravipesala <ravindra.pesala@huawei.com> Closes #2961 from ravipesala/SPARK-3814-NEW4 and squashes the following commits: a391c7a [ravipesala] Rebase with master
Diffstat (limited to 'sql/hive')
-rw-r--r--sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala4
-rw-r--r--sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala24
2 files changed, 28 insertions, 0 deletions
diff --git a/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala b/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala
index aa80b2f04d..ed07a28039 100644
--- a/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala
+++ b/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala
@@ -956,6 +956,7 @@ private[hive] object HiveQl {
/* Arithmetic */
case Token("-", child :: Nil) => UnaryMinus(nodeToExpr(child))
+ case Token("~", child :: Nil) => BitwiseNot(nodeToExpr(child))
case Token("+", left :: right:: Nil) => Add(nodeToExpr(left), nodeToExpr(right))
case Token("-", left :: right:: Nil) => Subtract(nodeToExpr(left), nodeToExpr(right))
case Token("*", left :: right:: Nil) => Multiply(nodeToExpr(left), nodeToExpr(right))
@@ -963,6 +964,9 @@ private[hive] object HiveQl {
case Token(DIV(), left :: right:: Nil) =>
Cast(Divide(nodeToExpr(left), nodeToExpr(right)), LongType)
case Token("%", left :: right:: Nil) => Remainder(nodeToExpr(left), nodeToExpr(right))
+ case Token("&", left :: right:: Nil) => BitwiseAnd(nodeToExpr(left), nodeToExpr(right))
+ case Token("|", left :: right:: Nil) => BitwiseOr(nodeToExpr(left), nodeToExpr(right))
+ case Token("^", left :: right:: Nil) => BitwiseXor(nodeToExpr(left), nodeToExpr(right))
case Token("TOK_FUNCTION", Token(SQRT(), Nil) :: arg :: Nil) => Sqrt(nodeToExpr(arg))
/* Comparisons */
diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala
index fbe6ac765c..a4aea31d3f 100644
--- a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala
+++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala
@@ -75,4 +75,28 @@ class SQLQuerySuite extends QueryTest {
sql("SELECT a.key FROM (SELECT key FROM src) `a`"),
sql("SELECT `key` FROM src").collect().toSeq)
}
+
+ test("SPARK-3814 Support Bitwise & operator") {
+ checkAnswer(
+ sql("SELECT case when 1&1=1 then 1 else 0 end FROM src"),
+ sql("SELECT 1 FROM src").collect().toSeq)
+ }
+
+ test("SPARK-3814 Support Bitwise | operator") {
+ checkAnswer(
+ sql("SELECT case when 1|0=1 then 1 else 0 end FROM src"),
+ sql("SELECT 1 FROM src").collect().toSeq)
+ }
+
+ test("SPARK-3814 Support Bitwise ^ operator") {
+ checkAnswer(
+ sql("SELECT case when 1^0=1 then 1 else 0 end FROM src"),
+ sql("SELECT 1 FROM src").collect().toSeq)
+ }
+
+ test("SPARK-3814 Support Bitwise ~ operator") {
+ checkAnswer(
+ sql("SELECT case when ~1=-2 then 1 else 0 end FROM src"),
+ sql("SELECT 1 FROM src").collect().toSeq)
+ }
}