This repository has been archived by the owner on Sep 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jiangnan
committed
May 5, 2019
1 parent
6bf8f53
commit a18fff9
Showing
8 changed files
with
153 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...o/github/iamazy/elasticsearch/dsl/sql/parser/query/method/mapping/MappingQueryParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package io.github.iamazy.elasticsearch.dsl.sql.parser.query.method.mapping; | ||
|
||
|
||
import io.github.iamazy.elasticsearch.dsl.sql.exception.ElasticSql2DslException; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest; | ||
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; | ||
|
||
/** | ||
* @author iamazy | ||
* @date 2019/5/5 | ||
* @descrition | ||
**/ | ||
public class MappingQueryParser { | ||
|
||
public static Object parse(String sql) { | ||
String[] descItems = StringUtils.split(sql, " "); | ||
GetFieldMappingsRequest getFieldMappingsRequest = new GetFieldMappingsRequest(); | ||
GetMappingsRequest getMappingsRequest = new GetMappingsRequest(); | ||
if (descItems.length == 2) { | ||
String[] items = descItems[1].split("/"); | ||
switch (items.length) { | ||
case 2: { | ||
getFieldMappingsRequest.indices(items[0]); | ||
getFieldMappingsRequest.fields(items[1]); | ||
return getFieldMappingsRequest; | ||
} | ||
case 1: | ||
default: { | ||
getMappingsRequest.indices(items[0]); | ||
return getMappingsRequest; | ||
} | ||
} | ||
} else { | ||
throw new ElasticSql2DslException("[syntax error] desc must have table name or table/field name"); | ||
} | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/test/java/io/github/iamazy/elasticsearch/dsl/sql/DescTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.github.iamazy.elasticsearch.dsl.sql; | ||
|
||
import io.github.iamazy.elasticsearch.dsl.sql.model.ElasticSqlParseResult; | ||
import io.github.iamazy.elasticsearch.dsl.sql.parser.ElasticSql2DslParser; | ||
import org.junit.Test; | ||
|
||
/** | ||
* @author iamazy | ||
* @date 2019/5/5 | ||
* @descrition | ||
**/ | ||
public class DescTest { | ||
|
||
@Test | ||
public void test3(){ | ||
String sql="desc device_info"; | ||
ElasticSql2DslParser sql2DslParser=new ElasticSql2DslParser(); | ||
ElasticSqlParseResult parseResult = sql2DslParser.parse(sql); | ||
} | ||
} |