Explorar el Código

query condition parser reform

spuerx hace 9 años
padre
commit
d06b0f48d0

+ 16 - 14
src/main/java/org/elasticsearch/dsl/ElasticDslBuilder.java

@@ -16,26 +16,28 @@ public class ElasticDslBuilder {
         this.queryExpr = queryExpr;
     }
 
-    //SQL解析器的顺序不能改变
-    private static final List<ElasticSqlParser> sqlParseProcessors = ImmutableList.of(
-            //解析SQL指定的索引和文档类型
-            QueryFromParser::parseQueryIndicesAndTypes,
-            //解析SQL查询指定的where条件
-            QueryWhereConditionParser::parseFilterCondition,
-            //解析SQL排序条件
-            QueryOrderConditionParser::parseOrderCondition,
-            //解析SQL查询指定的字段
-            QuerySelectFieldListParser::parseSelectFieldList
-
-    );
+    private List<ElasticSqlParser> buildSqlParserChain() {
+        //SQL解析器的顺序不能改变
+        return ImmutableList.of(
+                //解析SQL指定的索引和文档类型
+                new QueryFromParser(),
+                //解析SQL查询指定的where条件
+                new QueryWhereConditionParser(),
+                //解析SQL排序条件
+                new QueryOrderConditionParser(),
+                //解析SQL查询指定的字段
+                new QuerySelectFieldListParser(),
+                //解析SQL的分页条数
+                new QueryLimitSizeParser()
+        );
+    }
 
     public ElasticDslContext build() {
         ElasticDslContext dslContext = new ElasticDslContext(queryExpr);
         if (queryExpr.getSubQuery().getQuery() instanceof ElasticSqlSelectQueryBlock) {
-            sqlParseProcessors.stream().forEach(sqlParser -> sqlParser.parse(dslContext));
+            buildSqlParserChain().stream().forEach(sqlParser -> sqlParser.parse(dslContext));
             return dslContext;
         }
         throw new ElasticSql2DslException("[syntax error] ElasticSql only support Select Sql, but get: " + queryExpr.getSubQuery().getQuery().getClass());
     }
-
 }

+ 12 - 4
src/main/java/org/elasticsearch/dsl/ElasticDslContext.java

@@ -4,6 +4,7 @@ import com.alibaba.druid.sql.ast.expr.SQLQueryExpr;
 import org.apache.commons.collections.CollectionUtils;
 import org.elasticsearch.ElasticMockClient;
 import org.elasticsearch.action.search.SearchRequestBuilder;
+import org.elasticsearch.client.Client;
 import org.elasticsearch.index.query.BoolFilterBuilder;
 import org.elasticsearch.index.query.FilterBuilders;
 import org.elasticsearch.index.query.QueryBuilders;
@@ -17,7 +18,7 @@ public class ElasticDslContext {
     /*取数开始位置*/
     private int from = 0;
     /*取数大小*/
-    private int size = 100;
+    private int size = 15;
     /*查询索引*/
     private List<String> indices;
     /*查询文档类*/
@@ -105,8 +106,16 @@ public class ElasticDslContext {
         return queryExpr;
     }
 
+    public String toDsl(Client client) {
+        return toRequest(client).toString();
+    }
+
     public String toDsl() {
-        SearchRequestBuilder requestBuilder = new SearchRequestBuilder(ElasticMockClient.get());
+        return toDsl(ElasticMockClient.get());
+    }
+
+    public SearchRequestBuilder toRequest(Client client) {
+        SearchRequestBuilder requestBuilder = new SearchRequestBuilder(client);
 
         if (size > 100) {
             requestBuilder.setFrom(from).setSize(100);
@@ -135,8 +144,7 @@ public class ElasticDslContext {
         if (CollectionUtils.isNotEmpty(queryFieldList)) {
             requestBuilder.setFetchSource(queryFieldList.toArray(new String[queryFieldList.size()]), null);
         }
-
-        return requestBuilder.toString();
+        return requestBuilder;
     }
 
     @Override

+ 1 - 3
src/main/java/org/elasticsearch/dsl/parser/ElasticSqlParseUtil.java

@@ -49,11 +49,9 @@ public class ElasticSqlParseUtil {
     }
 
     public static boolean isValidBinOperator(SQLBinaryOperator binaryOperator) {
-        return binaryOperator == SQLBinaryOperator.BooleanAnd
-                || binaryOperator == SQLBinaryOperator.Equality
+        return binaryOperator == SQLBinaryOperator.Equality
                 || binaryOperator == SQLBinaryOperator.NotEqual
                 || binaryOperator == SQLBinaryOperator.LessThanOrGreater
-                || binaryOperator == SQLBinaryOperator.BooleanOr
                 || binaryOperator == SQLBinaryOperator.GreaterThan
                 || binaryOperator == SQLBinaryOperator.GreaterThanOrEqual
                 || binaryOperator == SQLBinaryOperator.LessThan

+ 24 - 5
src/main/java/org/elasticsearch/dsl/parser/QueryFromParser.java

@@ -1,20 +1,39 @@
 package org.elasticsearch.dsl.parser;
 
+import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
+import com.alibaba.druid.sql.ast.expr.SQLBinaryOperator;
+import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
 import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
 import com.google.common.collect.ImmutableList;
 import org.elasticsearch.dsl.ElasticDslContext;
 import org.elasticsearch.dsl.exception.ElasticSql2DslException;
 import org.elasticsearch.sql.ElasticSqlSelectQueryBlock;
 
-public class QueryFromParser {
-    public static void parseQueryIndicesAndTypes(ElasticDslContext dslContext) {
+public class QueryFromParser implements ElasticSqlParser {
+    @Override
+    public void parse(ElasticDslContext dslContext) {
         ElasticSqlSelectQueryBlock queryBlock = (ElasticSqlSelectQueryBlock) dslContext.getQueryExpr().getSubQuery().getQuery();
         if (queryBlock.getFrom() instanceof SQLExprTableSource) {
             SQLExprTableSource tableSource = (SQLExprTableSource) queryBlock.getFrom();
             dslContext.setQueryAs(tableSource.getAlias());
-            dslContext.setIndices(ImmutableList.of(tableSource.getExpr().toString()));
-        } else {
-            throw new ElasticSql2DslException("[syntax error] From table source should be [SQLExprTableSource],but get: " + queryBlock.getFrom().getClass());
+
+            if (tableSource.getExpr() instanceof SQLIdentifierExpr) {
+                dslContext.setIndices(ImmutableList.of(((SQLIdentifierExpr) tableSource.getExpr()).getName()));
+                return;
+            }
+            if (tableSource.getExpr() instanceof SQLBinaryOpExpr) {
+                SQLBinaryOpExpr idxExpr = (SQLBinaryOpExpr) tableSource.getExpr();
+
+                if (!(idxExpr.getLeft() instanceof SQLIdentifierExpr)
+                        || !(idxExpr.getRight() instanceof SQLIdentifierExpr)
+                        || idxExpr.getOperator() != SQLBinaryOperator.Divide) {
+                    throw new ElasticSql2DslException("[syntax error] From table should like [index]/[type]");
+                }
+                dslContext.setIndices(ImmutableList.of(((SQLIdentifierExpr) idxExpr.getLeft()).getName()));
+                dslContext.setTypes(ImmutableList.of(((SQLIdentifierExpr) idxExpr.getRight()).getName()));
+                return;
+            }
         }
+        throw new ElasticSql2DslException("[syntax error] From table source should be [SQLExprTableSource],but get: " + queryBlock.getFrom().getClass());
     }
 }

+ 27 - 0
src/main/java/org/elasticsearch/dsl/parser/QueryLimitSizeParser.java

@@ -0,0 +1,27 @@
+package org.elasticsearch.dsl.parser;
+
+import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr;
+import org.elasticsearch.dsl.ElasticDslContext;
+import org.elasticsearch.dsl.exception.ElasticSql2DslException;
+import org.elasticsearch.sql.ElasticSqlSelectQueryBlock;
+
+public class QueryLimitSizeParser implements ElasticSqlParser {
+    @Override
+    public void parse(ElasticDslContext dslContext) {
+        ElasticSqlSelectQueryBlock queryBlock = (ElasticSqlSelectQueryBlock) dslContext.getQueryExpr().getSubQuery().getQuery();
+        if (queryBlock.getLimit() != null) {
+            if (!(queryBlock.getLimit().getOffset() instanceof SQLIntegerExpr)) {
+                throw new ElasticSql2DslException("[syntax error] Sql limit expr offset should be a non-negative number");
+            }
+            dslContext.setFrom(((SQLIntegerExpr) queryBlock.getLimit().getOffset()).getNumber().intValue());
+
+            if (!(queryBlock.getLimit().getRowCount() instanceof SQLIntegerExpr)) {
+                throw new ElasticSql2DslException("[syntax error] Sql limit expr row count should be a non-negative number");
+            }
+            dslContext.setSize(((SQLIntegerExpr) queryBlock.getLimit().getRowCount()).getNumber().intValue());
+        } else {
+            dslContext.setFrom(0);
+            dslContext.setSize(15);
+        }
+    }
+}

+ 6 - 5
src/main/java/org/elasticsearch/dsl/parser/QueryOrderConditionParser.java

@@ -17,8 +17,9 @@ import org.elasticsearch.sql.ElasticSqlSelectQueryBlock;
 
 import java.util.List;
 
-public class QueryOrderConditionParser {
-    public static void parseOrderCondition(ElasticDslContext dslContext) {
+public class QueryOrderConditionParser implements ElasticSqlParser {
+    @Override
+    public void parse(ElasticDslContext dslContext) {
         ElasticSqlSelectQueryBlock queryBlock = (ElasticSqlSelectQueryBlock) dslContext.getQueryExpr().getSubQuery().getQuery();
         SQLOrderBy sqlOrderBy = queryBlock.getOrderBy();
         if (sqlOrderBy != null && CollectionUtils.isNotEmpty(sqlOrderBy.getItems())) {
@@ -31,7 +32,7 @@ public class QueryOrderConditionParser {
         }
     }
 
-    private static SortBuilder parseOrderCondition(SQLSelectOrderByItem orderByItem, String queryAs) {
+    private SortBuilder parseOrderCondition(SQLSelectOrderByItem orderByItem, String queryAs) {
         if (orderByItem.getExpr() instanceof SQLPropertyExpr || orderByItem.getExpr() instanceof SQLIdentifierExpr) {
             return parseCondition(orderByItem.getExpr(), queryAs, idfName -> {
                 if (SQLOrderingSpecification.ASC == orderByItem.getType()) {
@@ -64,7 +65,7 @@ public class QueryOrderConditionParser {
         throw new ElasticSql2DslException("[syntax error] ElasticSql cannot support sort type: " + orderByItem.getExpr().getClass());
     }
 
-    private static void checkNvlMethod(SQLMethodInvokeExpr nvlInvokeExpr) {
+    private void checkNvlMethod(SQLMethodInvokeExpr nvlInvokeExpr) {
         if (!"nvl".equalsIgnoreCase(nvlInvokeExpr.getMethodName())) {
             throw new ElasticSql2DslException("[syntax error] ElasticSql sort condition only support nvl method invoke");
         }
@@ -98,7 +99,7 @@ public class QueryOrderConditionParser {
         }
     }
 
-    private static SortBuilder parseCondition(SQLExpr sqlExpr, String queryAs, ConditionSortBuilder sortBuilder) {
+    private SortBuilder parseCondition(SQLExpr sqlExpr, String queryAs, ConditionSortBuilder sortBuilder) {
         List<SortBuilder> tmpSortList = Lists.newLinkedList();
         ElasticSqlIdfParser.parseSqlIdentifier(sqlExpr, queryAs, idfName -> {
             FieldSortBuilder originalSort = sortBuilder.buildSort(idfName);

+ 4 - 2
src/main/java/org/elasticsearch/dsl/parser/QuerySelectFieldListParser.java

@@ -6,10 +6,12 @@ import org.elasticsearch.sql.ElasticSqlSelectQueryBlock;
 
 import java.util.List;
 
-public class QuerySelectFieldListParser {
+public class QuerySelectFieldListParser implements ElasticSqlParser {
+
     public static final String SQL_FIELD_MATCH_ALL = "*";
 
-    public static void parseSelectFieldList(ElasticDslContext dslContext) {
+    @Override
+    public void parse(ElasticDslContext dslContext) {
         ElasticSqlSelectQueryBlock queryBlock = (ElasticSqlSelectQueryBlock) dslContext.getQueryExpr().getSubQuery().getQuery();
 
         List<String> selectFields = Lists.newLinkedList();

+ 100 - 22
src/main/java/org/elasticsearch/dsl/parser/QueryWhereConditionParser.java

@@ -6,41 +6,88 @@ import com.google.common.collect.Lists;
 import org.apache.commons.collections.CollectionUtils;
 import org.elasticsearch.dsl.ElasticDslContext;
 import org.elasticsearch.dsl.exception.ElasticSql2DslException;
+import org.elasticsearch.index.query.BoolFilterBuilder;
 import org.elasticsearch.index.query.FilterBuilder;
 import org.elasticsearch.index.query.FilterBuilders;
 import org.elasticsearch.sql.ElasticSqlSelectQueryBlock;
 
 import java.util.List;
 
-public class QueryWhereConditionParser {
-    public static void parseFilterCondition(ElasticDslContext dslContext) {
+public class QueryWhereConditionParser implements ElasticSqlParser {
+    @Override
+    public void parse(ElasticDslContext dslContext) {
         ElasticSqlSelectQueryBlock queryBlock = (ElasticSqlSelectQueryBlock) dslContext.getQueryExpr().getSubQuery().getQuery();
         if (queryBlock.getWhere() != null) {
-            FilterBuilder sqlWhereFilter = parseFilterCondition(dslContext, queryBlock.getWhere());
-            dslContext.boolFilter().must(sqlWhereFilter);
+            SqlCondition sqlCondition = parseFilterCondition(dslContext, queryBlock.getWhere());
+            if (!sqlCondition.isAndOr()) {
+                dslContext.boolFilter().must(sqlCondition.getFilterList().get(0));
+            } else {
+                sqlCondition.getFilterList().stream().forEach(filter -> {
+                    if (sqlCondition.getOperator() == SQLBinaryOperator.BooleanAnd) {
+                        dslContext.boolFilter().must(filter);
+                    }
+                    if (sqlCondition.getOperator() == SQLBinaryOperator.BooleanOr) {
+                        dslContext.boolFilter().should(filter);
+                    }
+                });
+            }
         }
     }
 
-    private static FilterBuilder parseFilterCondition(ElasticDslContext dslContext, SQLExpr sqlExpr) {
+    private SqlCondition parseFilterCondition(ElasticDslContext dslContext, SQLExpr sqlExpr) {
         if (sqlExpr instanceof SQLBinaryOpExpr) {
             SQLBinaryOpExpr sqlBinOpExpr = (SQLBinaryOpExpr) sqlExpr;
             SQLBinaryOperator binaryOperator = sqlBinOpExpr.getOperator();
+            if (SQLBinaryOperator.BooleanAnd == binaryOperator || SQLBinaryOperator.BooleanOr == binaryOperator) {
+                SqlCondition leftCondition = parseFilterCondition(dslContext, sqlBinOpExpr.getLeft());
+                SqlCondition rightCondition = parseFilterCondition(dslContext, sqlBinOpExpr.getRight());
 
-            if (ElasticSqlParseUtil.isValidBinOperator(binaryOperator)) {
-                //AND OR
-                if (SQLBinaryOperator.BooleanAnd == binaryOperator || SQLBinaryOperator.BooleanOr == binaryOperator) {
-                    FilterBuilder leftFilter = parseFilterCondition(dslContext, sqlBinOpExpr.getLeft());
-                    FilterBuilder rightFilter = parseFilterCondition(dslContext, sqlBinOpExpr.getRight());
-                    if (SQLBinaryOperator.BooleanAnd == binaryOperator) {
-                        return FilterBuilders.boolFilter().must(leftFilter).must(rightFilter);
-                    } else {
-                        return FilterBuilders.boolFilter().should(leftFilter).should(rightFilter);
-                    }
+                List<FilterBuilder> curFilterList = Lists.newArrayList();
+
+                if (!leftCondition.isAndOr() || leftCondition.operator == binaryOperator) {
+                    curFilterList.addAll(leftCondition.getFilterList());
+                } else {
+                    BoolFilterBuilder subBoolFilter = FilterBuilders.boolFilter();
+                    leftCondition.getFilterList().stream().forEach(filter -> {
+                        if (leftCondition.getOperator() == SQLBinaryOperator.BooleanAnd) {
+                            subBoolFilter.must(filter);
+                        }
+                        if (leftCondition.getOperator() == SQLBinaryOperator.BooleanOr) {
+                            subBoolFilter.should(filter);
+                        }
+                    });
+                    curFilterList.add(subBoolFilter);
                 }
 
+                if (!rightCondition.isAndOr() || rightCondition.operator == binaryOperator) {
+                    curFilterList.addAll(rightCondition.getFilterList());
+                } else {
+                    BoolFilterBuilder subBoolFilter = FilterBuilders.boolFilter();
+                    rightCondition.getFilterList().stream().forEach(filter -> {
+                        if (rightCondition.getOperator() == SQLBinaryOperator.BooleanAnd) {
+                            subBoolFilter.must(filter);
+                        }
+                        if (rightCondition.getOperator() == SQLBinaryOperator.BooleanOr) {
+                            subBoolFilter.should(filter);
+                        }
+                    });
+                    curFilterList.add(subBoolFilter);
+                }
+                return new SqlCondition(curFilterList, binaryOperator);
+            }
+        }
+        return new SqlCondition(parseAtomFilterCondition(dslContext, sqlExpr));
+    }
+
+    private FilterBuilder parseAtomFilterCondition(ElasticDslContext dslContext, SQLExpr sqlExpr) {
+        if (sqlExpr instanceof SQLBinaryOpExpr) {
+            SQLBinaryOpExpr sqlBinOpExpr = (SQLBinaryOpExpr) sqlExpr;
+            SQLBinaryOperator binaryOperator = sqlBinOpExpr.getOperator();
+
+            if (ElasticSqlParseUtil.isValidBinOperator(binaryOperator)) {
                 //以下是二元运算,左边必须是变量
                 if (!(sqlBinOpExpr.getLeft() instanceof SQLPropertyExpr || sqlBinOpExpr.getLeft() instanceof SQLIdentifierExpr)) {
-                    throw new ElasticSql2DslException("[syntax error] Equality expr left part should be a param name");
+                    throw new ElasticSql2DslException("[syntax error] Binary operation expr left part should be a param name");
                 }
 
                 //EQ NEQ
@@ -104,15 +151,14 @@ public class QueryWhereConditionParser {
             });
         } else if (sqlExpr instanceof SQLBetweenExpr) {
             SQLBetweenExpr betweenExpr = (SQLBetweenExpr) sqlExpr;
-            if ((!(betweenExpr.getBeginExpr() instanceof SQLIntegerExpr) && !(betweenExpr.getBeginExpr() instanceof SQLNumberExpr))
-                    || (!(betweenExpr.getEndExpr() instanceof SQLIntegerExpr) && !(betweenExpr.getEndExpr() instanceof SQLNumberExpr))) {
-                throw new ElasticSql2DslException(String.format("[syntax error] Can not support between arg type : begin >%s end> %s",
-                        betweenExpr.getBeginExpr().getClass(), betweenExpr.getEndExpr().getClass()));
-            }
 
             Object from = ElasticSqlParseUtil.transferSqlArg(betweenExpr.getBeginExpr());
             Object to = ElasticSqlParseUtil.transferSqlArg(betweenExpr.getEndExpr());
 
+            if (from == null || to == null) {
+                throw new ElasticSql2DslException("[syntax error] Between Expr only support one of [number,date] arg type");
+            }
+
             return parseCondition(betweenExpr.getTestExpr(), dslContext.getQueryAs(), idfName -> {
                 return FilterBuilders.rangeFilter(idfName).gte(from).lte(to);
             });
@@ -120,7 +166,7 @@ public class QueryWhereConditionParser {
         throw new ElasticSql2DslException("[syntax error] Can not support Op type: " + sqlExpr.getClass());
     }
 
-    private static FilterBuilder parseCondition(SQLExpr sqlExpr, String queryAs, ConditionFilterBuilder filterBuilder) {
+    private FilterBuilder parseCondition(SQLExpr sqlExpr, String queryAs, ConditionFilterBuilder filterBuilder) {
         List<FilterBuilder> tmpFilterList = Lists.newLinkedList();
         ElasticSqlIdfParser.parseSqlIdentifier(sqlExpr, queryAs, idfName -> {
             FilterBuilder originalFilter = filterBuilder.buildFilter(idfName);
@@ -140,4 +186,36 @@ public class QueryWhereConditionParser {
     private interface ConditionFilterBuilder {
         FilterBuilder buildFilter(String idfName);
     }
+
+    private class SqlCondition {
+        //是否AND/OR运算
+        private boolean isAndOr = false;
+        //运算符
+        private SQLBinaryOperator operator;
+        //条件集合
+        private List<FilterBuilder> filterList;
+
+        public SqlCondition(FilterBuilder atomFilter) {
+            filterList = Lists.newArrayList(atomFilter);
+            isAndOr = false;
+        }
+
+        public SqlCondition(List<FilterBuilder> filterList, SQLBinaryOperator operator) {
+            this.filterList = filterList;
+            isAndOr = true;
+            this.operator = operator;
+        }
+
+        public boolean isAndOr() {
+            return isAndOr;
+        }
+
+        public SQLBinaryOperator getOperator() {
+            return operator;
+        }
+
+        public List<FilterBuilder> getFilterList() {
+            return filterList;
+        }
+    }
 }

+ 18 - 1
src/main/java/org/elasticsearch/sql/ElasticSqlSelectParser.java

@@ -1,7 +1,8 @@
 package org.elasticsearch.sql;
 
 import com.alibaba.druid.sql.ast.SQLSetQuantifier;
-import com.alibaba.druid.sql.ast.statement.SQLSelectQuery;
+import com.alibaba.druid.sql.ast.statement.*;
+import com.alibaba.druid.sql.parser.ParserException;
 import com.alibaba.druid.sql.parser.SQLExprParser;
 import com.alibaba.druid.sql.parser.SQLSelectParser;
 import com.alibaba.druid.sql.parser.Token;
@@ -56,4 +57,20 @@ public class ElasticSqlSelectParser extends SQLSelectParser {
 
         return queryRest(queryBlock);
     }
+
+    @Override
+    public SQLTableSource parseTableSource() {
+        if (lexer.token() != Token.IDENTIFIER) {
+            throw new ParserException("[syntax error] from table source should be a identifier");
+        }
+
+        SQLExprTableSource tableReference = new SQLExprTableSource();
+        parseTableSourceQueryTableExpr(tableReference);
+        SQLTableSource tableSrc = parseTableSourceRest(tableReference);
+        if (lexer.hasComment() && lexer.isKeepComments()) {
+            tableSrc.addAfterComment(lexer.readAndResetComments());
+        }
+
+        return tableSrc;
+    }
 }

+ 18 - 43
src/test/java/org/elasticsearch/SqlParserTest.java

@@ -1,16 +1,17 @@
 package org.elasticsearch;
 
-import junit.framework.TestCase;
 import org.apache.commons.collections.CollectionUtils;
 import org.elasticsearch.dsl.ElasticDslContext;
 import org.elasticsearch.dsl.parser.ElasticSql2DslParser;
 import org.junit.Assert;
+import org.junit.Test;
 
 
-public class SqlParserTest extends TestCase {
+public class SqlParserTest {
 
+    @Test
     public void testParseSelectFieldWithQueryAs() {
-        String sql = "select b.id,bookCategory,b.bookStatus,clazz.sortNo,b.clazz.cid from book b where c = 1";
+        String sql = "select b.id,bookCategory,b.bookStatus,clazz.sortNo,b.clazz.cid from book b where b.type = 'AV'";
         ElasticSql2DslParser sql2DslParser = new ElasticSql2DslParser(sql);
         ElasticDslContext dslContext = sql2DslParser.parse();
 
@@ -22,6 +23,7 @@ public class SqlParserTest extends TestCase {
         Assert.assertEquals(dslContext.getQueryFieldList().get(4), "clazz.cid");
     }
 
+    @Test
     public void testParseSelectFieldWithoutQueryAs() {
         String sql = "select b.id,bookCategory,b.bookStatus,clazz.sortNo,clazz.cid from book where c = 1";
         ElasticSql2DslParser sql2DslParser = new ElasticSql2DslParser(sql);
@@ -35,6 +37,7 @@ public class SqlParserTest extends TestCase {
         Assert.assertEquals(dslContext.getQueryFieldList().get(4), "clazz.cid");
     }
 
+    @Test
     public void testParseSelectFieldMatchAll_01() {
         String sql = "select * from book where c = 1";
         ElasticSql2DslParser sql2DslParser = new ElasticSql2DslParser(sql);
@@ -44,6 +47,7 @@ public class SqlParserTest extends TestCase {
         Assert.assertTrue(CollectionUtils.isEmpty(dslContext.getQueryFieldList()));
     }
 
+    @Test
     public void testParseSelectFieldMatchAll_02() {
         String sql = "select b.* from book b";
         ElasticSql2DslParser sql2DslParser = new ElasticSql2DslParser(sql);
@@ -53,6 +57,7 @@ public class SqlParserTest extends TestCase {
         Assert.assertTrue(CollectionUtils.isEmpty(dslContext.getQueryFieldList()));
     }
 
+    @Test
     public void testParseSelectFieldMatchAll_03() {
         String sql = "select b.n.* from book b";
         ElasticSql2DslParser sql2DslParser = new ElasticSql2DslParser(sql);
@@ -63,53 +68,23 @@ public class SqlParserTest extends TestCase {
         Assert.assertTrue("n.*".equals(dslContext.getQueryFieldList().get(0)));
     }
 
+    @Test
     public void testParseInFilterCondition_01() {
-        String sql = "select * from book bk where bk.status in ('ONLINE','DONE') and productCategory='802'";
+        String sql = "select * from book bk where bk.status in ('SALES') and category='b'"
+                + " and (bk.bookType in ('AV') or salesArea = '4')"
+                + " and requestType=2";
 
         ElasticSql2DslParser sql2DslParser = new ElasticSql2DslParser(sql);
         ElasticDslContext dslContext = sql2DslParser.parse();
         System.out.println(dslContext.toString());
     }
 
-    public void testParseEqFilterCondition_01() {
-        //String sql = "select * from book bk where (bk.price = 10.2 or bk.category not in ('AV', 'H')) and bk.status in ('ONLINE', 'DONE')";
-
-        String sql = "select p.id,p.productCategory,p.displayName from product_v9 p "
-                + "where p.productCategory in ('901','902') and p.userGroupArray in ('NEW_USER', 'DEFAULT') and salesArea not in(2,3,4) "
-                + " and p.productStatus in ('ONLINE', 'PAUSE', 'TEMPORARY_FULL', 'PREVIEW')"
-                + " and p.sourceType = '9' and (p.productType='LOAN_REQUEST' or (p.price > 100 and p.price <= 200))"
-                + " and p.price between 1 and 1000";
-
-
-        ElasticSql2DslParser sql2DslParser = new ElasticSql2DslParser(sql);
-        ElasticDslContext dslContext = sql2DslParser.parse();
-        System.out.println(dslContext.toString());
-    }
-
-    public void testParseFilterCondition() {
-        //String sql = "select * from book b where b.status='ONLINE'"; //SQLBinaryOpExpr
-        //String sql = "select * from book b where c in (1,2,3)";    //SQLInListExpr
-        //String sql = "select * from book b where c not in (1,2,3)"; //SQLInListExpr
-        String sql = "select * from book b where c between 1 and 3"; //SQLBetweenExpr
-
-        ElasticSql2DslParser sql2DslParser = new ElasticSql2DslParser(sql);
-        ElasticDslContext dslContext = sql2DslParser.parse();
-
-        System.out.println(dslContext.toString());
-    }
-
-    public void testParseIsNullFilter() {
-        String sql = "select * from book b where b.cls is not null"; //SQLBetweenExpr
-
-        ElasticSql2DslParser sql2DslParser = new ElasticSql2DslParser(sql);
-        ElasticDslContext dslContext = sql2DslParser.parse();
-
-        System.out.println(dslContext.toString());
-    }
-
-    public void testParseOrderCondition() {
-        String sql = "select * from book b where b.status = 'ONLINE' order by nvl(b.sortNo,-1) asc";
-        //String sql = "select * from book b where b.status = 'ONLINE' order by b.sortNo asc,b.bbs desc";
+    @Test
+    public void testParseNestCondition() {
+        String sql = "select id,bookStatus,updatedAt,bookClassifications from book/basic dd where"
+                + " bookCategory = '802'"
+                + " and bookClassifications.classificationId > 0"
+                + " order by id desc,nvl(bookClassifications.sortNo, 999, 'min') asc";
 
         ElasticSql2DslParser sql2DslParser = new ElasticSql2DslParser(sql);
         ElasticDslContext dslContext = sql2DslParser.parse();