Skip to content

Commit 98e03d4

Browse files
feat: link all Expression AST Nodes
- fixes #1339 Signed-off-by: Andreas Reichel <[email protected]>
1 parent 4c4ff28 commit 98e03d4

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

Diff for: src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt

+6-6
Original file line numberDiff line numberDiff line change
@@ -4412,12 +4412,14 @@ First First():
44124412

44134413
Expression Expression() #Expression :
44144414
{
4415-
Expression retval = null;
4415+
Expression expression = null;
44164416
}
44174417
{
4418-
retval=XorExpression()
4419-
4420-
{ return retval; }
4418+
expression=XorExpression()
4419+
{
4420+
linkAST(expression,jjtThis);
4421+
return expression;
4422+
}
44214423
}
44224424

44234425
Expression XorExpression():
@@ -4613,7 +4615,6 @@ Expression SQLCondition():
46134615
| left = SimpleExpression() { result = left; }
46144616
[
46154617
LOOKAHEAD(2) (
4616-
(
46174618
LOOKAHEAD(ExcludesExpression()) result=ExcludesExpression(left)
46184619
|
46194620
LOOKAHEAD(IncludesExpression()) result=IncludesExpression(left)
@@ -4633,7 +4634,6 @@ Expression SQLCondition():
46334634
LOOKAHEAD(IsDistinctExpression()) result=IsDistinctExpression(left)
46344635
|
46354636
result=SimilarToExpression(left)
4636-
)
46374637
)
46384638
]
46394639
)

Diff for: src/test/java/net/sf/jsqlparser/parser/ASTNodeAccessImplTest.java

+23
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111

1212
import net.sf.jsqlparser.JSQLParserException;
1313
import net.sf.jsqlparser.expression.AnalyticExpression;
14+
import net.sf.jsqlparser.expression.Expression;
1415
import net.sf.jsqlparser.statement.select.PlainSelect;
1516
import net.sf.jsqlparser.statement.select.Select;
1617
import net.sf.jsqlparser.statement.select.SelectItem;
18+
import org.junit.jupiter.api.Assertions;
1719
import org.junit.jupiter.api.Test;
1820

1921
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -33,4 +35,25 @@ void testGetParent() throws JSQLParserException {
3335
assertInstanceOf(SelectItem.class, expression.getParent());
3436
assertEquals(select, expression.getParent(Select.class));
3537
}
38+
39+
@Test
40+
void testGetWherePositionIssue1339() throws JSQLParserException {
41+
// WHERE expression at line 4 column 7
42+
String sqlStr = "select listagg(sellerid)\n"
43+
+ "within group (order by sellerid)\n"
44+
+ "over() AS list from winsales\n"
45+
+ "WHERE a=b\n"
46+
+ "ORDER BY 1;";
47+
PlainSelect select = (PlainSelect) CCJSqlParserUtil.parse(sqlStr);
48+
Expression whereExpression = select.getWhere();
49+
50+
final SimpleNode node = whereExpression.getASTNode();
51+
if (node != null) {
52+
Token token = node.jjtGetFirstToken();
53+
Assertions.assertEquals(4, token.beginLine);
54+
Assertions.assertEquals(7, token.beginColumn);
55+
} else {
56+
throw new RuntimeException("Node not found.");
57+
}
58+
}
3659
}

0 commit comments

Comments
 (0)