diff --git a/src/main/java/io/github/iamazy/elasticsearch/dsl/sql/druid/ElasticSqlExprParser.java b/src/main/java/io/github/iamazy/elasticsearch/dsl/sql/druid/ElasticSqlExprParser.java index 1958c15..49e4207 100644 --- a/src/main/java/io/github/iamazy/elasticsearch/dsl/sql/druid/ElasticSqlExprParser.java +++ b/src/main/java/io/github/iamazy/elasticsearch/dsl/sql/druid/ElasticSqlExprParser.java @@ -2,13 +2,8 @@ import com.alibaba.druid.sql.ast.SQLExpr; import com.alibaba.druid.sql.ast.expr.*; -import com.alibaba.druid.sql.ast.statement.SQLSelectQuery; import com.alibaba.druid.sql.parser.*; -import com.alibaba.druid.util.FnvHash; -import com.alibaba.druid.util.JdbcConstants; import com.google.common.collect.Lists; - -import java.math.BigInteger; import java.util.List; /** diff --git a/src/main/java/io/github/iamazy/elasticsearch/dsl/sql/model/ElasticSqlParseResult.java b/src/main/java/io/github/iamazy/elasticsearch/dsl/sql/model/ElasticSqlParseResult.java index bed16bf..aeb8679 100644 --- a/src/main/java/io/github/iamazy/elasticsearch/dsl/sql/model/ElasticSqlParseResult.java +++ b/src/main/java/io/github/iamazy/elasticsearch/dsl/sql/model/ElasticSqlParseResult.java @@ -28,6 +28,7 @@ import java.io.IOException; import java.util.*; +import java.util.stream.Collectors; /** @@ -103,8 +104,9 @@ public SearchResponse toResponse(RestHighLevelClient restHighLevelClient, Reques public SearchRequest toRequest() { SearchRequest searchRequest = new SearchRequest(); - if (CollectionUtils.isNotEmpty(indices)) { - searchRequest.indices(indices.toArray(new String[0])); + List indexList=indices.parallelStream().map(index->index.replace("`","")).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(indexList)) { + searchRequest.indices(indexList.toArray(new String[0])); } if (StringUtils.isNotBlank(type)) { searchRequest.types(type); diff --git a/src/main/java/io/github/iamazy/elasticsearch/dsl/sql/parser/sql/QueryFromParser.java b/src/main/java/io/github/iamazy/elasticsearch/dsl/sql/parser/sql/QueryFromParser.java index 13c6a8e..54465b6 100644 --- a/src/main/java/io/github/iamazy/elasticsearch/dsl/sql/parser/sql/QueryFromParser.java +++ b/src/main/java/io/github/iamazy/elasticsearch/dsl/sql/parser/sql/QueryFromParser.java @@ -1,6 +1,5 @@ package io.github.iamazy.elasticsearch.dsl.sql.parser.sql; -import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr; import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr; import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr; import com.alibaba.druid.sql.ast.expr.SQLQueryExpr; @@ -55,11 +54,6 @@ private void extractFrom(SQLExprTableSource tableSource,ElasticDslContext dslCon dslContext.getParseResult().setType(idxExpr.getName()); return; } - if(tableSource.getExpr() instanceof SQLBinaryOpExpr){ - String index=tableSource.getExpr().toString().replace(" ",""); - dslContext.getParseResult().setIndices(Lists.newArrayList(index)); - return; - } throw new ElasticSql2DslException("[syntax error] From table should like [index].[type]"); } diff --git a/src/test/java/io/github/iamazy/elasticsearch/dsl/sql/SqlParserSelectFieldTest.java b/src/test/java/io/github/iamazy/elasticsearch/dsl/sql/SqlParserSelectFieldTest.java index 870764a..6c14d0b 100644 --- a/src/test/java/io/github/iamazy/elasticsearch/dsl/sql/SqlParserSelectFieldTest.java +++ b/src/test/java/io/github/iamazy/elasticsearch/dsl/sql/SqlParserSelectFieldTest.java @@ -2,9 +2,10 @@ import io.github.iamazy.elasticsearch.dsl.sql.model.ElasticSqlParseResult; import io.github.iamazy.elasticsearch.dsl.sql.parser.ElasticSql2DslParser; -import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; import org.junit.Test; +import java.util.Arrays; + /** * @author iamazy * @date 2019/2/20 @@ -75,10 +76,11 @@ public void test2(){ @Test public void test3(){ - String sql="select * from apple-aaa order by minPrice desc, advicePrice asc"; + String sql="select * from `apple-aaa-01-.*` order by minPrice desc, advicePrice asc"; ElasticSql2DslParser sql2DslParser=new ElasticSql2DslParser(); ElasticSqlParseResult parseResult = sql2DslParser.parse(sql); System.out.println(parseResult.toPrettyDsl(parseResult.toRequest())); + System.out.println(Arrays.toString(parseResult.toRequest().indices())); }