Skip to content

Commit

Permalink
#80 bugfixes - dotSupport and newLine support. 1.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
eliranmoyal committed Oct 5, 2015
1 parent 8d2ed11 commit a5d7b1e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Install as plugin:

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

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}`.
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.nlpcn</groupId>
<artifactId>elasticsearch-sql</artifactId>
<version>1.4.1</version>
<version>1.4.2</version>
<packaging>jar</packaging>
<description>Query elasticsearch using SQL</description>
<name>elasticsearch-sql</name>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/nlpcn/es4sql/parse/ElasticLexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ public void scanIdentifier() {


private boolean isElasticIdentifierChar(char ch) {
return ch == '*' || ch == ':' || ch == '-' || isIdentifierChar(ch);
return ch == '*' || ch == ':' || ch == '-' || ch == '.' || isIdentifierChar(ch);
}
}
4 changes: 2 additions & 2 deletions src/main/java/org/nlpcn/es4sql/parse/SqlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ private List<Field> getConnectedFields(List<Condition> conditions, String alias)
fields.add(new Field(condition.getName().replaceFirst(prefix,""),null));
}
else {
if(! ((condition.getValue() instanceof SQLPropertyExpr)||(condition.getValue() instanceof String))){
if(! ((condition.getValue() instanceof SQLPropertyExpr)||(condition.getValue() instanceof SQLIdentifierExpr)||(condition.getValue() instanceof String))){
throw new SqlParseException("conditions on join should be one side is firstTable second Other , condition was:" + condition.toString());
}
String aliasDotValue = condition.getValue().toString();
Expand Down Expand Up @@ -517,7 +517,7 @@ private void removeAliasPrefix(Where where, String alias) {
private void addIfConditionRecursive(Where where, List<Condition> conditions) throws SqlParseException {
if(where instanceof Condition){
Condition cond = (Condition) where;
if( ! ((cond.getValue() instanceof SQLPropertyExpr)|| (cond.getValue() instanceof String))){
if( ! ((cond.getValue() instanceof SQLIdentifierExpr) ||(cond.getValue() instanceof SQLPropertyExpr)|| (cond.getValue() instanceof String))){
throw new SqlParseException("conditions on join should be one side is secondTable OPEAR firstTable, condition was:" + cond.toString());
}
conditions.add(cond);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/nlpcn/es4sql/query/ESActionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public class ESActionFactory {
* @return Query object.
*/
public static QueryAction create(Client client, String sql) throws SqlParseException, SQLFeatureNotSupportedException {
String firstWord = sql.substring(0, sql.indexOf(' '));
sql = sql.replaceAll("\n"," ");
String firstWord = sql.substring(0, sql.indexOf(' '));
switch (firstWord.toUpperCase()) {
case "SELECT":
SQLQueryExpr sqlExpr = (SQLQueryExpr) toSqlExpr(sql);
Expand Down
12 changes: 9 additions & 3 deletions src/test/java/org/nlpcn/es4sql/SqlParserTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,14 @@ public void innerQueryTestTwoQueries() throws SqlParseException {
Assert.assertEquals(2,select.getSubQueries().size());
}


@Test
public void indexWithDotsAndHyphen() throws SqlParseException {
String query = "select * from data-2015.08.22";
SQLExpr sqlExpr = queryToExpr(query);
Select select = parser.parseSelect((SQLQueryExpr) sqlExpr);
Assert.assertEquals(1,select.getFrom().size());
Assert.assertEquals("data-2015.08.22",select.getFrom().get(0).getIndex());
}

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

SQLPropertyExpr value = (SQLPropertyExpr) condition.getValue();
String[] valueAliasAndField = value.toString().split("\\.",2);
String[] valueAliasAndField = condition.getValue().toString().split("\\.",2);
boolean toFieldNameIsEqual = valueAliasAndField[1].equals(toField);
boolean toAliasIsEqual = valueAliasAndField[0].equals(toAlias);
boolean toIsEqual = toAliasIsEqual && toFieldNameIsEqual;
Expand Down

0 comments on commit a5d7b1e

Please sign in to comment.