Repository navigation
Expand file tree
/
Copy pathASTNodeAccessImplTest.java
More file actions
59 lines (52 loc) · 2.07 KB
/
Copy pathASTNodeAccessImplTest.java
File metadata and controls
59 lines (52 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2024 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.parser;
import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.expression.AnalyticExpression;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.statement.select.PlainSelect;
import net.sf.jsqlparser.statement.select.Select;
import net.sf.jsqlparser.statement.select.SelectItem;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
class ASTNodeAccessImplTest {
@Test
void testGetParent() throws JSQLParserException {
String sqlStr = "select listagg(sellerid)\n"
+ "within group (order by sellerid)\n"
+ "over() AS list from winsales;";
PlainSelect select = (PlainSelect) CCJSqlParserUtil.parse(sqlStr);
AnalyticExpression expression =
(AnalyticExpression) select.getSelectItem(0).getExpression();
assertInstanceOf(SelectItem.class, expression.getParent());
assertEquals(select, expression.getParent(Select.class));
}
@Test
void testGetWherePositionIssue1339() throws JSQLParserException {
// WHERE expression at line 4 column 7
String sqlStr = "select listagg(sellerid)\n"
+ "within group (order by sellerid)\n"
+ "over() AS list from winsales\n"
+ "WHERE a=b\n"
+ "ORDER BY 1;";
PlainSelect select = (PlainSelect) CCJSqlParserUtil.parse(sqlStr);
Expression whereExpression = select.getWhere();
final Node node = whereExpression.getASTNode();
if (node != null) {
Token token = node.jjtGetFirstToken();
Assertions.assertEquals(4, token.beginLine);
Assertions.assertEquals(7, token.beginColumn);
} else {
throw new RuntimeException("Node not found.");
}
}
}