Skip to content
This repository has been archived by the owner on Sep 4, 2019. It is now read-only.

Commit

Permalink
fix #4
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangnan committed Jun 5, 2019
1 parent 82e52d5 commit a5baf42
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;


/**
Expand Down Expand Up @@ -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<String> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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]");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()));
}


Expand Down

0 comments on commit a5baf42

Please sign in to comment.