Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f231da8

Browse files
committed
NLPchina#131 bug fix complex_nested on left side on binaryOp
1 parent bf45675 commit f231da8

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ private Where findWhere(SQLExpr where) throws SqlParseException {
8383
private boolean isCond(SQLBinaryOpExpr expr) {
8484
SQLExpr leftSide = expr.getLeft();
8585
if(leftSide instanceof SQLMethodInvokeExpr){
86-
return isAllowedMethodOnConditionLeft((SQLMethodInvokeExpr) leftSide);
86+
return isAllowedMethodOnConditionLeft((SQLMethodInvokeExpr) leftSide,expr.getOperator());
8787
}
8888
return leftSide instanceof SQLIdentifierExpr || leftSide instanceof SQLPropertyExpr || leftSide instanceof SQLVariantRefExpr;
8989
}
9090

91-
private boolean isAllowedMethodOnConditionLeft(SQLMethodInvokeExpr method) {
92-
return method.getMethodName().toLowerCase().equals("nested");
91+
private boolean isAllowedMethodOnConditionLeft(SQLMethodInvokeExpr method, SQLBinaryOperator operator) {
92+
return method.getMethodName().toLowerCase().equals("nested") && !operator.isLogical();
9393
}
9494

9595
public void parseWhere(SQLExpr expr, Where where) throws SqlParseException {

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,17 @@ public void fieldsAsNumbersOnWhere() throws SqlParseException {
771771
Assert.assertEquals("3", condition.getName());
772772
}
773773

774+
775+
@Test
776+
public void complexNestedAndOtherQuery() throws SqlParseException {
777+
String query = "select * from x where nested('path',path.x=3) and y=3";
778+
Select select = parser.parseSelect((SQLQueryExpr) queryToExpr(query));
779+
LinkedList<Where> wheres = select.getWhere().getWheres();
780+
Assert.assertEquals(2, wheres.size());
781+
Assert.assertEquals("AND path NESTED_COMPLEX AND ( AND path.x EQ 3 ) ",wheres.get(0).toString());
782+
Assert.assertEquals("AND y EQ 3",wheres.get(1).toString());
783+
}
784+
774785
private SQLExpr queryToExpr(String query) {
775786
return new ElasticSqlExprParser(query).expr();
776787
}

0 commit comments

Comments
 (0)