Skip to content

Commit

Permalink
[SPARK-14548][SQL] Support not greater than and not less than operato…
Browse files Browse the repository at this point in the history
…r 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.
  • Loading branch information
jliwork authored and rxin committed Apr 24, 2016
1 parent 337289d commit f0f1a8a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -776,9 +776,9 @@ NSEQ: '<=>';
NEQ : '<>';
NEQJ: '!=';
LT : '<';
LTE : '<=';
LTE : '<=' | '!>';
GT : '>';
GTE : '>=';
GTE : '>=' | '!<';

PLUS: '+';
MINUS: '-';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class SqlLexical extends scala.util.parsing.combinator.lexical.StdLexical {
def normalizeKeyword(str: String): String = str.toLowerCase

delimiters += (
"@", "*", "+", "-", "<", "=", "<>", "!=", "<=", ">=", ">", "/", "(", ")",
"@", "*", "+", "-", "<", "=", "<>", "!=", "<=", "!>", ">=", "!<", ">", "/", "(", ")",
",", ";", "%", "{", "}", ":", "[", "]", ".", "&", "|", "^", "~", "<=>"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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')"))
Expand Down

0 comments on commit f0f1a8a

Please sign in to comment.