You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2019/11/14 01:58:53 UTC

[GitHub] [incubator-shardingsphere] terrymanu commented on a change in pull request #3508: Extract recursive with logical operation

terrymanu commented on a change in pull request #3508: Extract recursive with logical operation
URL: https://github.com/apache/incubator-shardingsphere/pull/3508#discussion_r346094253
 
 

 ##########
 File path: shardingsphere-sql-parser/shardingsphere-sql-parser-common/src/main/java/org/apache/shardingsphere/sql/parser/core/extractor/impl/dml/PredicateExtractor.java
 ##########
 @@ -64,20 +64,53 @@
         Preconditions.checkState(exprNode.isPresent());
         return extractRecursiveWithLogicalOperation(exprNode.get(), parameterMarkerIndexes);
     }
-    
+
     private Optional<OrPredicateSegment> extractRecursiveWithLogicalOperation(final ParserRuleContext exprNode, final Map<ParserRuleContext, Integer> parameterMarkerIndexes) {
         Optional<ParserRuleContext> logicalOperatorNode = ExtractorUtils.findFirstChildNodeNoneRecursive(exprNode, RuleName.LOGICAL_OPERATOR);
         if (!logicalOperatorNode.isPresent()) {
             return extractRecursiveWithParen(exprNode, parameterMarkerIndexes);
         }
-        Optional<OrPredicateSegment> leftPredicate = extractRecursiveWithLogicalOperation((ParserRuleContext) exprNode.getChild(0), parameterMarkerIndexes);
-        Optional<OrPredicateSegment> rightPredicate = extractRecursiveWithLogicalOperation((ParserRuleContext) exprNode.getChild(2), parameterMarkerIndexes);
+        Optional<OrPredicateSegment> leftPredicate = extractPredicateSegment(exprNode, extractOperatorNode(exprNode, 0), 0, parameterMarkerIndexes);
+        Optional<OrPredicateSegment> rightPredicate = extractPredicateSegment(exprNode, extractOperatorNode(exprNode, 2), 2, parameterMarkerIndexes);
         if (leftPredicate.isPresent() && rightPredicate.isPresent()) {
             return Optional.of(mergePredicate(leftPredicate.get(), rightPredicate.get(), logicalOperatorNode.get().getText()));
         }
         return leftPredicate.isPresent() ? leftPredicate : rightPredicate;
     }
-    
+
+    private ParserRuleContext extractOperatorNode(final ParserRuleContext exprNode, final int childIndex) {
+        ParserRuleContext operatorNode = (ParserRuleContext) exprNode.getChild(childIndex);
+        while (ExtractorUtils.findFirstChildNodeNoneRecursive(operatorNode, RuleName.LOGICAL_OPERATOR).isPresent()) {
+            operatorNode = (ParserRuleContext) operatorNode.getChild(childIndex);
+        }
+        return operatorNode;
 
 Review comment:
   return value should be name as `result`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services