Skip to content

JSQLParser 5.1: Incorrect Parent node #2194

Open
@davyboyhayes

Description

@davyboyhayes

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions