Skip to content

Commit

Permalink
Merge pull request #109 from ottboy4/elastic2.0
Browse files Browse the repository at this point in the history
Fixed double nots in 2.0.0 version.
  • Loading branch information
eliranmoyal committed Nov 11, 2015
2 parents 19c6d87 + 4b616a6 commit b6ab5f2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
3 changes: 1 addition & 2 deletions src/main/java/org/nlpcn/es4sql/parse/SqlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -553,9 +553,8 @@ private void negateWhere(Where where) throws SqlParseException {
cond.setOpear(cond.getOpear().negative());
} else {
negateWhere(sub);
sub.setConn(sub.getConn().negative());
}

sub.setConn(sub.getConn().negative());
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/nlpcn/es4sql/query/maker/QueryMaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public class QueryMaker extends Maker {
*/
public static BoolQueryBuilder explan(Where where) throws SqlParseException {
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
while (where.getWheres().size() == 1) {
where = where.getWheres().getFirst();
}
new QueryMaker().explanWhere(boolQuery, where);
return boolQuery;
}
Expand All @@ -29,9 +32,6 @@ private QueryMaker() {
}

private void explanWhere(BoolQueryBuilder boolQuery, Where where) throws SqlParseException {
while (where.getWheres().size() == 1) {
where = where.getWheres().getFirst();
}
if (where instanceof Condition) {
addSubQuery(boolQuery, where, (QueryBuilder) make((Condition) where));
} else {
Expand Down
10 changes: 3 additions & 7 deletions src/test/java/org/nlpcn/es4sql/QueryTest.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
package org.nlpcn.es4sql;

import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.expr.SQLQueryExpr;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;

import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.aggregations.support.format.ValueFormatter;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.junit.Assert;
import org.junit.Test;
import org.nlpcn.es4sql.domain.Select;
import org.nlpcn.es4sql.exception.SqlParseException;
import org.nlpcn.es4sql.query.SqlElasticSearchRequestBuilder;

import javax.naming.directory.SearchControls;
import java.io.IOException;
import java.sql.SQLFeatureNotSupportedException;
import java.text.ParseException;
Expand Down Expand Up @@ -238,6 +231,9 @@ public void doubleNotTest() throws IOException, SqlParseException, SQLFeatureNot
for (SearchHit hit : response4.getHits()) {
Assert.assertEquals("m", hit.getSource().get("gender").toString().toLowerCase());
}

SearchHits response5 = query(String.format("SELECT * FROM %s/account WHERE NOT (gender = 'm' OR gender = 'f')", TEST_INDEX));
Assert.assertEquals(0, response5.getTotalHits());
}

@Test
Expand Down

0 comments on commit b6ab5f2

Please sign in to comment.