Skip to content

Commit 32cb792

Browse files
committed
add literals within brackets to valid identifiers NLPchina#127
1 parent 7cf05c1 commit 32cb792

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ else if(lexer.token() == Token.LBRACKET){
6868
lexer.nextToken();
6969
String prefix = "";
7070
while(lexer.token()!=Token.RBRACKET){
71-
if(lexer.token() != Token.IDENTIFIER && lexer.token()!=Token.INDEX){
71+
if(lexer.token() != Token.IDENTIFIER && lexer.token()!=Token.INDEX && lexer.token()!=Token.LITERAL_CHARS){
7272
throw new ParserException("All items between Brackets should be identifiers , got:" +lexer.token());
7373
}
7474
identifier.append(prefix);

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,17 @@ public void scriptOnFilterWithParams() throws SqlParseException {
759759

760760
}
761761

762-
762+
@Test
763+
public void fieldsAsNumbersOnWhere() throws SqlParseException {
764+
String query = "select * from x where ['3'] > 2";
765+
Select select = parser.parseSelect((SQLQueryExpr) queryToExpr(query));
766+
LinkedList<Where> wheres = select.getWhere().getWheres();
767+
Assert.assertEquals(1, wheres.size());
768+
Where where = wheres.get(0);
769+
Assert.assertEquals(Condition.class,where.getClass());
770+
Condition condition = (Condition) where;
771+
int i=1;
772+
}
763773

764774
private SQLExpr queryToExpr(String query) {
765775
return new ElasticSqlExprParser(query).expr();

0 commit comments

Comments
 (0)