Skip to content
Snippets Groups Projects
Commit 8d210560 authored by Michael Armbrust's avatar Michael Armbrust
Browse files

[SPARK-2050 - 2][SQL] DIV and BETWEEN should not be case sensitive.

Followup: #989

Author: Michael Armbrust <michael@databricks.com>

Closes #994 from marmbrus/caseSensitiveFunctions2 and squashes the following commits:

9d9c8ed [Michael Armbrust] Fix DIV and BETWEEN.
parent 8d85359f
No related branches found
No related tags found
No related merge requests found
...@@ -795,6 +795,8 @@ private[hive] object HiveQl { ...@@ -795,6 +795,8 @@ private[hive] object HiveQl {
val RLIKE = "(?i)RLIKE".r val RLIKE = "(?i)RLIKE".r
val REGEXP = "(?i)REGEXP".r val REGEXP = "(?i)REGEXP".r
val IN = "(?i)IN".r val IN = "(?i)IN".r
val DIV = "(?i)DIV".r
val BETWEEN = "(?i)BETWEEN".r
protected def nodeToExpr(node: Node): Expression = node match { protected def nodeToExpr(node: Node): Expression = node match {
/* Attribute References */ /* Attribute References */
...@@ -864,7 +866,7 @@ private[hive] object HiveQl { ...@@ -864,7 +866,7 @@ private[hive] object HiveQl {
case Token("-", left :: right:: Nil) => Subtract(nodeToExpr(left), nodeToExpr(right)) case Token("-", left :: right:: Nil) => Subtract(nodeToExpr(left), nodeToExpr(right))
case Token("*", left :: right:: Nil) => Multiply(nodeToExpr(left), nodeToExpr(right)) case Token("*", left :: right:: Nil) => Multiply(nodeToExpr(left), nodeToExpr(right))
case Token("/", left :: right:: Nil) => Divide(nodeToExpr(left), nodeToExpr(right)) case Token("/", left :: right:: Nil) => Divide(nodeToExpr(left), nodeToExpr(right))
case Token("DIV", left :: right:: Nil) => Divide(nodeToExpr(left), nodeToExpr(right)) case Token(DIV(), left :: right:: Nil) => Divide(nodeToExpr(left), nodeToExpr(right))
case Token("%", left :: right:: Nil) => Remainder(nodeToExpr(left), nodeToExpr(right)) case Token("%", left :: right:: Nil) => Remainder(nodeToExpr(left), nodeToExpr(right))
/* Comparisons */ /* Comparisons */
...@@ -885,7 +887,7 @@ private[hive] object HiveQl { ...@@ -885,7 +887,7 @@ private[hive] object HiveQl {
case Token("TOK_FUNCTION", Token(IN(), Nil) :: value :: list) => case Token("TOK_FUNCTION", Token(IN(), Nil) :: value :: list) =>
In(nodeToExpr(value), list.map(nodeToExpr)) In(nodeToExpr(value), list.map(nodeToExpr))
case Token("TOK_FUNCTION", case Token("TOK_FUNCTION",
Token("between", Nil) :: Token(BETWEEN(), Nil) ::
Token("KW_FALSE", Nil) :: Token("KW_FALSE", Nil) ::
target :: target ::
minValue :: minValue ::
......
2 val_2
0 0 0
...@@ -25,8 +25,10 @@ import org.apache.spark.sql.hive.test.TestHive._ ...@@ -25,8 +25,10 @@ import org.apache.spark.sql.hive.test.TestHive._
class HiveQuerySuite extends HiveComparisonTest { class HiveQuerySuite extends HiveComparisonTest {
createQueryTest("between", createQueryTest("between",
"SELECT * FROM src WHERE key between 1 and 2" "SELECT * FROM src WHERE key Between 1 and 2")
)
createQueryTest("div",
"SELECT 1 DIV 2, 1 div 2, 1 dIv 2 FROM src LIMIT 1")
test("Query expressed in SQL") { test("Query expressed in SQL") {
assert(sql("SELECT 1").collect() === Array(Seq(1))) assert(sql("SELECT 1").collect() === Array(Seq(1)))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment