Skip to content

Commit d3077bb

Browse files
committed
Merge pull request #49 from jheimbouch/master
Fix for Operator precedence (A or B) and (C or D)
2 parents e3d9403 + fa80b21 commit d3077bb

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/main/java/org/nlpcn/es4sql/parse/SqlParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private void parseWhere(SQLBinaryOpExpr expr, SQLBinaryOpExpr sub, Where where)
103103
if (isCond(sub)) {
104104
explanCond(expr.operator.name, sub, where);
105105
} else {
106-
if (sub.operator.priority < expr.operator.priority) {
106+
if (sub.operator.priority > expr.operator.priority) {
107107
Where subWhere = new Where(expr.getOperator().name);
108108
where.addWhere(subWhere);
109109
parseWhere(sub, subWhere);

src/test/java/org/nlpcn/es4sql/QueryTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,24 @@ public void orderByDescTest() throws IOException, SqlParseException, SQLFeatureN
404404
Assert.assertTrue("The list is not ordered descending", sortedAges.equals(ages));
405405
}
406406

407+
@Test
408+
public void testMultipartWhere() throws IOException, SqlParseException, SQLFeatureNotSupportedException{
409+
SearchHits response = query(String.format("SELECT * FROM %s/account WHERE (firstname LIKE 'opal' OR firstname like 'rodriquez') AND (state like 'oh' OR state like 'hi')", TEST_INDEX));
410+
Assert.assertEquals(2, response.getTotalHits());
411+
}
412+
413+
@Test
414+
public void testMultipartWhere2() throws IOException, SqlParseException, SQLFeatureNotSupportedException{
415+
SearchHits response = query(String.format("SELECT * FROM %s/account where ((account_number > 200 and account_number < 300) or gender like 'm') and (state like 'hi' or address like 'avenue')", TEST_INDEX));
416+
Assert.assertEquals(11, response.getTotalHits());
417+
}
418+
419+
@Test
420+
public void testMultipartWhere3() throws IOException, SqlParseException, SQLFeatureNotSupportedException{
421+
SearchHits response = query(String.format("SELECT * FROM %s/account where ((account_number > 25 and account_number < 75) and age >35 ) and (state like 'md' or (address like 'avenue' or address like 'street'))", TEST_INDEX));
422+
Assert.assertEquals(7, response.getTotalHits());
423+
}
424+
407425
private SearchHits query(String query) throws SqlParseException, SQLFeatureNotSupportedException, SQLFeatureNotSupportedException {
408426
SearchDao searchDao = MainTestSuite.getSearchDao();
409427
SearchRequestBuilder select = (SearchRequestBuilder)searchDao.explain(query);

0 commit comments

Comments
 (0)