Skip to content

Commit a5d7b1e

Browse files
committed
#80 bugfixes - dotSupport and newLine support. 1.4.2
1 parent 8d2ed11 commit a5d7b1e

File tree

6 files changed

+16
-9
lines changed

6 files changed

+16
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Install as plugin:
1919

2020
### Elasticsearch 1.6.X
2121
````
22-
./bin/plugin -u https://github.com/NLPchina/elasticsearch-sql/releases/download/1.4.1/elasticsearch-sql-1.4.1.zip --install sql
22+
./bin/plugin -u https://github.com/NLPchina/elasticsearch-sql/releases/download/1.4.2/elasticsearch-sql-1.4.2.zip --install sql
2323
````
2424

2525
After doing this, you need to restart the Elasticsearch server. Otherwise you may get errors like `Invalid index name [sql], must not start with '']; ","status":400}`.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>org.nlpcn</groupId>
55
<artifactId>elasticsearch-sql</artifactId>
6-
<version>1.4.1</version>
6+
<version>1.4.2</version>
77
<packaging>jar</packaging>
88
<description>Query elasticsearch using SQL</description>
99
<name>elasticsearch-sql</name>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,6 @@ public void scanIdentifier() {
8888

8989

9090
private boolean isElasticIdentifierChar(char ch) {
91-
return ch == '*' || ch == ':' || ch == '-' || isIdentifierChar(ch);
91+
return ch == '*' || ch == ':' || ch == '-' || ch == '.' || isIdentifierChar(ch);
9292
}
9393
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ private List<Field> getConnectedFields(List<Condition> conditions, String alias)
437437
fields.add(new Field(condition.getName().replaceFirst(prefix,""),null));
438438
}
439439
else {
440-
if(! ((condition.getValue() instanceof SQLPropertyExpr)||(condition.getValue() instanceof String))){
440+
if(! ((condition.getValue() instanceof SQLPropertyExpr)||(condition.getValue() instanceof SQLIdentifierExpr)||(condition.getValue() instanceof String))){
441441
throw new SqlParseException("conditions on join should be one side is firstTable second Other , condition was:" + condition.toString());
442442
}
443443
String aliasDotValue = condition.getValue().toString();
@@ -517,7 +517,7 @@ private void removeAliasPrefix(Where where, String alias) {
517517
private void addIfConditionRecursive(Where where, List<Condition> conditions) throws SqlParseException {
518518
if(where instanceof Condition){
519519
Condition cond = (Condition) where;
520-
if( ! ((cond.getValue() instanceof SQLPropertyExpr)|| (cond.getValue() instanceof String))){
520+
if( ! ((cond.getValue() instanceof SQLIdentifierExpr) ||(cond.getValue() instanceof SQLPropertyExpr)|| (cond.getValue() instanceof String))){
521521
throw new SqlParseException("conditions on join should be one side is secondTable OPEAR firstTable, condition was:" + cond.toString());
522522
}
523523
conditions.add(cond);

src/main/java/org/nlpcn/es4sql/query/ESActionFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ public class ESActionFactory {
4545
* @return Query object.
4646
*/
4747
public static QueryAction create(Client client, String sql) throws SqlParseException, SQLFeatureNotSupportedException {
48-
String firstWord = sql.substring(0, sql.indexOf(' '));
48+
sql = sql.replaceAll("\n"," ");
49+
String firstWord = sql.substring(0, sql.indexOf(' '));
4950
switch (firstWord.toUpperCase()) {
5051
case "SELECT":
5152
SQLQueryExpr sqlExpr = (SQLQueryExpr) toSqlExpr(sql);

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,14 @@ public void innerQueryTestTwoQueries() throws SqlParseException {
394394
Assert.assertEquals(2,select.getSubQueries().size());
395395
}
396396

397-
397+
@Test
398+
public void indexWithDotsAndHyphen() throws SqlParseException {
399+
String query = "select * from data-2015.08.22";
400+
SQLExpr sqlExpr = queryToExpr(query);
401+
Select select = parser.parseSelect((SQLQueryExpr) sqlExpr);
402+
Assert.assertEquals(1,select.getFrom().size());
403+
Assert.assertEquals("data-2015.08.22",select.getFrom().get(0).getIndex());
404+
}
398405

399406
private SQLExpr queryToExpr(String query) {
400407
return new ElasticSqlExprParser(query).expr();
@@ -410,8 +417,7 @@ private boolean conditionExist(List<Condition> conditions, String from, String t
410417
boolean fromIsEqual = condition.getName().equals(from);
411418
if(!fromIsEqual) continue;
412419

413-
SQLPropertyExpr value = (SQLPropertyExpr) condition.getValue();
414-
String[] valueAliasAndField = value.toString().split("\\.",2);
420+
String[] valueAliasAndField = condition.getValue().toString().split("\\.",2);
415421
boolean toFieldNameIsEqual = valueAliasAndField[1].equals(toField);
416422
boolean toAliasIsEqual = valueAliasAndField[0].equals(toAlias);
417423
boolean toIsEqual = toAliasIsEqual && toFieldNameIsEqual;

0 commit comments

Comments
 (0)