Skip to content
Snippets Groups Projects
Commit f0f1a8af authored by jliwork's avatar jliwork Committed by Reynold Xin
Browse files

[SPARK-14548][SQL] Support not greater than and not less than operator in Spark SQL

!< means not less than which is equivalent to >=
!> means not greater than which is equivalent to <=

I'd to create a PR to support these two operators.

I've added new test cases in: DataFrameSuite, ExpressionParserSuite, JDBCSuite, PlanParserSuite, SQLQuerySuite

dilipbiswal viirya gatorsmile

Author: jliwork <jiali@us.ibm.com>

Closes #12316 from jliwork/SPARK-14548.
parent 337289d7
No related branches found
No related tags found
No related merge requests found
......@@ -776,9 +776,9 @@ NSEQ: '<=>';
NEQ : '<>';
NEQJ: '!=';
LT : '<';
LTE : '<=';
LTE : '<=' | '!>';
GT : '>';
GTE : '>=';
GTE : '>=' | '!<';
PLUS: '+';
MINUS: '-';
......
......@@ -134,7 +134,7 @@ class SqlLexical extends scala.util.parsing.combinator.lexical.StdLexical {
def normalizeKeyword(str: String): String = str.toLowerCase
delimiters += (
"@", "*", "+", "-", "<", "=", "<>", "!=", "<=", ">=", ">", "/", "(", ")",
"@", "*", "+", "-", "<", "=", "<>", "!=", "<=", "!>", ">=", "!<", ">", "/", "(", ")",
",", ";", "%", "{", "}", ":", "[", "]", ".", "&", "|", "^", "~", "<=>"
)
......
......@@ -126,8 +126,10 @@ class ExpressionParserSuite extends PlanTest {
assertEqual("a != b", 'a =!= 'b)
assertEqual("a < b", 'a < 'b)
assertEqual("a <= b", 'a <= 'b)
assertEqual("a !> b", 'a <= 'b)
assertEqual("a > b", 'a > 'b)
assertEqual("a >= b", 'a >= 'b)
assertEqual("a !< b", 'a >= 'b)
}
test("between expressions") {
......
......@@ -428,4 +428,13 @@ class PlanParserSuite extends PlanTest {
"Number of aliases must match the number of fields in an inline table.")
intercept[ArrayIndexOutOfBoundsException](parsePlan("values (1, 'a'), (2, 'b', 5Y)"))
}
test("simple select query with !> and !<") {
// !< is equivalent to >=
assertEqual("select a, b from db.c where x !< 1",
table("db", "c").where('x >= 1).select('a, 'b))
// !> is equivalent to <=
assertEqual("select a, b from db.c where x !> 1",
table("db", "c").where('x <= 1).select('a, 'b))
}
}
......@@ -221,6 +221,7 @@ class JDBCSuite extends SparkFunSuite
assert(checkPushdown(sql("SELECT * FROM foobar WHERE NAME <=> 'fred'")).collect().size == 1)
assert(checkPushdown(sql("SELECT * FROM foobar WHERE NAME > 'fred'")).collect().size == 2)
assert(checkPushdown(sql("SELECT * FROM foobar WHERE NAME != 'fred'")).collect().size == 2)
assert(checkPushdown(sql("SELECT * FROM foobar WHERE NAME IN ('mary', 'fred')"))
.collect().size == 2)
assert(checkPushdown(sql("SELECT * FROM foobar WHERE NAME NOT IN ('fred')"))
......
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