|
4 | 4 | import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr;
|
5 | 5 | import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
6 | 6 | import com.alibaba.druid.sql.ast.expr.SQLQueryExpr;
|
| 7 | +import org.elasticsearch.index.query.BoolQueryBuilder; |
7 | 8 | import org.junit.Assert;
|
8 | 9 | import org.junit.BeforeClass;
|
9 | 10 | import org.junit.Test;
|
|
15 | 16 | import org.nlpcn.es4sql.parse.FieldMaker;
|
16 | 17 | import org.nlpcn.es4sql.parse.ScriptFilter;
|
17 | 18 | import org.nlpcn.es4sql.parse.SqlParser;
|
| 19 | +import org.nlpcn.es4sql.query.maker.QueryMaker; |
18 | 20 |
|
19 | 21 | import java.io.IOException;
|
20 | 22 | import java.sql.SQLFeatureNotSupportedException;
|
@@ -529,7 +531,7 @@ public void nestedFieldOnWhereNoPathSimpleField() throws SqlParseException {
|
529 | 531 | Where where = select.getWhere().getWheres().get(0);
|
530 | 532 | Assert.assertTrue("where should be condition", where instanceof Condition);
|
531 | 533 | Condition condition = (Condition) where;
|
532 |
| - Assert.assertTrue("condition should be nested",condition.isNested()); |
| 534 | + Assert.assertTrue("condition should be nested", condition.isNested()); |
533 | 535 | Assert.assertEquals("message",condition.getNestedPath());
|
534 | 536 | Assert.assertEquals("message.name",condition.getName());
|
535 | 537 | }
|
@@ -701,7 +703,7 @@ public void termsWithStringTest() throws SqlParseException {
|
701 | 703 | Condition condition = (Condition) select.getWhere().getWheres().get(0);
|
702 | 704 | Object[] values = (Object[]) condition.getValue();
|
703 | 705 | Assert.assertEquals("a",values[0]);
|
704 |
| - Assert.assertEquals("b",values[1]); |
| 706 | + Assert.assertEquals("b", values[1]); |
705 | 707 | }
|
706 | 708 |
|
707 | 709 | @Test
|
@@ -763,11 +765,20 @@ public void fieldsAsNumbersOnWhere() throws SqlParseException {
|
763 | 765 | LinkedList<Where> wheres = select.getWhere().getWheres();
|
764 | 766 | Assert.assertEquals(1, wheres.size());
|
765 | 767 | Where where = wheres.get(0);
|
766 |
| - Assert.assertEquals(Condition.class,where.getClass()); |
| 768 | + Assert.assertEquals(Condition.class, where.getClass()); |
767 | 769 | Condition condition = (Condition) where;
|
768 | 770 | Assert.assertEquals("3", condition.getName());
|
769 | 771 | }
|
770 | 772 |
|
| 773 | + @Test |
| 774 | + public void likeTestWithEscaped() throws SqlParseException { |
| 775 | + String query = "select * from x where name like '[_]hey_%[%]'"; |
| 776 | + Select select = parser.parseSelect((SQLQueryExpr) queryToExpr(query)); |
| 777 | + BoolQueryBuilder explan = QueryMaker.explan(select.getWhere()); |
| 778 | + String filterAsString = explan.toString(); |
| 779 | + Assert.assertTrue(filterAsString.contains("_hey?*%")); |
| 780 | + } |
| 781 | + |
771 | 782 |
|
772 | 783 | @Test
|
773 | 784 | public void complexNestedAndOtherQuery() throws SqlParseException {
|
|
0 commit comments