Skip to content
Snippets Groups Projects
Commit 032d6632 authored by Michael Armbrust's avatar Michael Armbrust Committed by Reynold Xin
Browse files

[SQL] Implement between in hql

Author: Michael Armbrust <michael@databricks.com>

Closes #804 from marmbrus/between and squashes the following commits:

ae24672 [Michael Armbrust] add golden answer.
d9997ef [Michael Armbrust] Implement between in hql.
9bd4433 [Michael Armbrust] Better error on parse failures.
parent fa6de408
No related branches found
No related tags found
No related merge requests found
......@@ -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))
......
2 val_2
......@@ -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)))
}
......
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