Skip to content

Commit 8d21056

Browse files
committed
[SPARK-2050 - 2][SQL] DIV and BETWEEN should not be case sensitive.
Followup: apache#989 Author: Michael Armbrust <[email protected]> Closes apache#994 from marmbrus/caseSensitiveFunctions2 and squashes the following commits: 9d9c8ed [Michael Armbrust] Fix DIV and BETWEEN.
1 parent 8d85359 commit 8d21056

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,8 @@ private[hive] object HiveQl {
795795
val RLIKE = "(?i)RLIKE".r
796796
val REGEXP = "(?i)REGEXP".r
797797
val IN = "(?i)IN".r
798+
val DIV = "(?i)DIV".r
799+
val BETWEEN = "(?i)BETWEEN".r
798800

799801
protected def nodeToExpr(node: Node): Expression = node match {
800802
/* Attribute References */
@@ -864,7 +866,7 @@ private[hive] object HiveQl {
864866
case Token("-", left :: right:: Nil) => Subtract(nodeToExpr(left), nodeToExpr(right))
865867
case Token("*", left :: right:: Nil) => Multiply(nodeToExpr(left), nodeToExpr(right))
866868
case Token("/", left :: right:: Nil) => Divide(nodeToExpr(left), nodeToExpr(right))
867-
case Token("DIV", left :: right:: Nil) => Divide(nodeToExpr(left), nodeToExpr(right))
869+
case Token(DIV(), left :: right:: Nil) => Divide(nodeToExpr(left), nodeToExpr(right))
868870
case Token("%", left :: right:: Nil) => Remainder(nodeToExpr(left), nodeToExpr(right))
869871

870872
/* Comparisons */
@@ -885,7 +887,7 @@ private[hive] object HiveQl {
885887
case Token("TOK_FUNCTION", Token(IN(), Nil) :: value :: list) =>
886888
In(nodeToExpr(value), list.map(nodeToExpr))
887889
case Token("TOK_FUNCTION",
888-
Token("between", Nil) ::
890+
Token(BETWEEN(), Nil) ::
889891
Token("KW_FALSE", Nil) ::
890892
target ::
891893
minValue ::
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2 val_2
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0 0 0

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQuerySuite.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ import org.apache.spark.sql.hive.test.TestHive._
2525
class HiveQuerySuite extends HiveComparisonTest {
2626

2727
createQueryTest("between",
28-
"SELECT * FROM src WHERE key between 1 and 2"
29-
)
28+
"SELECT * FROM src WHERE key Between 1 and 2")
29+
30+
createQueryTest("div",
31+
"SELECT 1 DIV 2, 1 div 2, 1 dIv 2 FROM src LIMIT 1")
3032

3133
test("Query expressed in SQL") {
3234
assert(sql("SELECT 1").collect() === Array(Seq(1)))

0 commit comments

Comments
 (0)