Commit 373c5a51 authored by terrymanu's avatar terrymanu
Browse files

for #2084, use logicalOperator rule to get logicalOperator

parent 9a4e0069
Loading
Loading
Loading
Loading
+5 −14
Original line number Diff line number Diff line
@@ -59,27 +59,18 @@ public final class PredicateExtractor implements OptionalSQLSegmentExtractor {
    }
    
    private Optional<OrPredicateSegment> extractRecursiveWithLogicalOperator(final ParserRuleContext exprNode, final Map<ParserRuleContext, Integer> parameterMarkerIndexes) {
        Optional<Integer> index = getLogicalOperatorIndex(exprNode);
        if (!index.isPresent()) {
        Optional<ParserRuleContext> logicalOperatorNode = ExtractorUtils.findFirstChildNodeNoneRecursive(exprNode, RuleName.LOGICAL_OPERATOR);
        if (!logicalOperatorNode.isPresent()) {
            return extractRecursiveWithParen(exprNode, parameterMarkerIndexes);
        }
        Optional<OrPredicateSegment> leftPredicate = extractRecursiveWithLogicalOperator((ParserRuleContext) exprNode.getChild(index.get() - 1), parameterMarkerIndexes);
        Optional<OrPredicateSegment> rightPredicate = extractRecursiveWithLogicalOperator((ParserRuleContext) exprNode.getChild(index.get() + 1), parameterMarkerIndexes);
        Optional<OrPredicateSegment> leftPredicate = extractRecursiveWithLogicalOperator((ParserRuleContext) exprNode.getChild(0), parameterMarkerIndexes);
        Optional<OrPredicateSegment> rightPredicate = extractRecursiveWithLogicalOperator((ParserRuleContext) exprNode.getChild(2), parameterMarkerIndexes);
        if (leftPredicate.isPresent() && rightPredicate.isPresent()) {
            return Optional.of(mergePredicate(leftPredicate.get(), rightPredicate.get(), exprNode.getChild(index.get()).getText()));
            return Optional.of(mergePredicate(leftPredicate.get(), rightPredicate.get(), logicalOperatorNode.get().getText()));
        }
        return leftPredicate.isPresent() ? leftPredicate : rightPredicate;
    }
    
    private Optional<Integer> getLogicalOperatorIndex(final ParserRuleContext exprNode) {
        for (int i = 0; i < exprNode.getChildCount(); i++) {
            if (LogicalOperator.isLogicalOperator(exprNode.getChild(i).getText())) {
                return Optional.of(i);
            }
        }
        return Optional.absent();
    }
    
    private Optional<OrPredicateSegment> extractRecursiveWithParen(final ParserRuleContext exprNode, final Map<ParserRuleContext, Integer> parameterMarkerIndexes) {
        Optional<Integer> index = getLeftParenIndex(exprNode);
        if (index.isPresent()) {
+2 −0
Original line number Diff line number Diff line
@@ -119,6 +119,8 @@ public enum RuleName {
    
    BIT_EXPR("BitExpr"),
    
    LOGICAL_OPERATOR("LogicalOperator"),
    
    FROM_CLAUSE("FromClause"),
    
    WHERE_CLAUSE("WhereClause"),
+6 −5
Original line number Diff line number Diff line
@@ -95,18 +95,19 @@ indexName
    ;

expr
    : expr logicalOperator_ expr
    : expr logicalOperator expr
    | expr XOR expr
    | notOperator_ expr
    | LP_ expr RP_
    | booleanPrimary_
    ;

notOperator_
    : NOT | NOT_
logicalOperator
    : OR | OR_ | AND | AND_
    ;

logicalOperator_
    : OR | OR_ | XOR | AND | AND_
notOperator_
    : NOT | NOT_
    ;

booleanPrimary_