Open
Description
I have a query: select A from B where (A ~ 'fish')
which when tree walking with an ExpressionVisitor, I end up in void visit(RegExpMatchOperator regExpMatchOperator) {...}
, the parent of the regExpMatchOperator
is the PlainSelect
, and not the ParenthesedExpressionList
Test Case (which fails on the final assertion):
import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.expression.operators.relational.ParenthesedExpressionList;
import net.sf.jsqlparser.expression.operators.relational.RegExpMatchOperator;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.statement.select.PlainSelect;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class RegexpMatchesTest {
@Test
void parentIsExpected() throws JSQLParserException {
var parsed = CCJSqlParserUtil.parse("select A from B where (A ~ 'fish')");
assertThat(parsed).isInstanceOf(PlainSelect.class);
var select = (PlainSelect) parsed;
assertThat(select.getWhere()).isInstanceOf(ParenthesedExpressionList.class);
var parenthesis = (ParenthesedExpressionList<?>) select.getWhere();
assertThat(parenthesis.getFirst()).isInstanceOf(RegExpMatchOperator.class);
var regExpMatchOperator = (RegExpMatchOperator) parenthesis.getFirst();
assertThat(regExpMatchOperator.getParent()).isSameAs(parenthesis);
}
}
My expectation is that the parent node of the regex operator should be the parenthesis object, not the plain select
Metadata
Metadata
Assignees
Labels
No labels