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 1f688fe1117fe3f1b5958c718f4d96263f0309aa..93b9057a238162a2607f95534377f5ee2900e1fb 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 @@ -233,6 +233,11 @@ private[hive] object HiveQl { } } catch { case e: Exception => throw new ParseException(sql, e) + case e: NotImplementedError => sys.error( + s""" + |Unsupported language features in query: $sql + |${dumpTree(getAst(sql))} + """.stripMargin) } } @@ -865,6 +870,17 @@ private[hive] object HiveQl { IsNull(nodeToExpr(child)) case Token("TOK_FUNCTION", Token("IN", Nil) :: value :: list) => In(nodeToExpr(value), list.map(nodeToExpr)) + case Token("TOK_FUNCTION", + Token("between", Nil) :: + Token("KW_FALSE", Nil) :: + target :: + minValue :: + maxValue :: Nil) => + + val targetExpression = nodeToExpr(target) + And( + GreaterThanOrEqual(targetExpression, nodeToExpr(minValue)), + LessThanOrEqual(targetExpression, nodeToExpr(maxValue))) /* Boolean Logic */ case Token(AND(), left :: right:: Nil) => And(nodeToExpr(left), nodeToExpr(right)) diff --git a/sql/hive/src/test/resources/golden/between-0-df3cf89fcf2ef64199a582fae14a3321 b/sql/hive/src/test/resources/golden/between-0-df3cf89fcf2ef64199a582fae14a3321 new file mode 100644 index 0000000000000000000000000000000000000000..dcd1d8643e3cb5e0b9ecf5df66e8909573c5f5f5 --- /dev/null +++ b/sql/hive/src/test/resources/golden/between-0-df3cf89fcf2ef64199a582fae14a3321 @@ -0,0 +1 @@ +2 val_2 diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQuerySuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQuerySuite.scala index 87a92d83383ab0f2b4fbc9ca110e2e44d8898d62..1a2b2f89182ae19b0abb0b4740b7b27779bdd2a3 100644 --- a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQuerySuite.scala +++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQuerySuite.scala @@ -24,6 +24,10 @@ import org.apache.spark.sql.hive.test.TestHive._ */ class HiveQuerySuite extends HiveComparisonTest { + createQueryTest("between", + "SELECT * FROM src WHERE key between 1 and 2" + ) + test("Query expressed in SQL") { assert(sql("SELECT 1").collect() === Array(Seq(1))) }