Loading sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/extractor/impl/dml/PredicateExtractor.java +5 −14 Original line number Diff line number Diff line Loading @@ -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()) { Loading sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/extractor/util/RuleName.java +2 −0 Original line number Diff line number Diff line Loading @@ -119,6 +119,8 @@ public enum RuleName { BIT_EXPR("BitExpr"), LOGICAL_OPERATOR("LogicalOperator"), FROM_CLAUSE("FromClause"), WHERE_CLAUSE("WhereClause"), Loading sharding-core/sharding-core-parse/sharding-core-parse-mysql/src/main/antlr4/imports/mysql/BaseRule.g4 +6 −5 Original line number Diff line number Diff line Loading @@ -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_ Loading Loading
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/extractor/impl/dml/PredicateExtractor.java +5 −14 Original line number Diff line number Diff line Loading @@ -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()) { Loading
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/extractor/util/RuleName.java +2 −0 Original line number Diff line number Diff line Loading @@ -119,6 +119,8 @@ public enum RuleName { BIT_EXPR("BitExpr"), LOGICAL_OPERATOR("LogicalOperator"), FROM_CLAUSE("FromClause"), WHERE_CLAUSE("WhereClause"), Loading
sharding-core/sharding-core-parse/sharding-core-parse-mysql/src/main/antlr4/imports/mysql/BaseRule.g4 +6 −5 Original line number Diff line number Diff line Loading @@ -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_ Loading