[ 
https://issues.apache.org/jira/browse/SLING-6506?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16331809#comment-16331809
 ] 

ASF GitHub Bot commented on SLING-6506:
---------------------------------------

chetanmeh commented on a change in pull request #1: SLING-6506 - Handling of 
UNION'd queries in Sling Log Tracer
URL: 
https://github.com/apache/sling-org-apache-sling-tracer/pull/1#discussion_r162545771
 
 

 ##########
 File path: src/main/java/org/apache/sling/tracer/internal/JSONRecording.java
 ##########
 @@ -387,16 +388,44 @@ public void record(Level level, String logger, 
FormattingTuple tuple) {
                     if 
("org.apache.jackrabbit.oak.query.QueryImpl".equals(logger)
                             && msg.startsWith("query plan ")){
                         //logDebug("query execute " + statement);
-                        plan = msg.substring("query plan ".length());
+                        if (subPlans == 0) {
+                            plan = msg.substring("query plan ".length());
+                        } else {
+                            subPlans--;
+                        }
                     } else if 
("org.apache.jackrabbit.oak.query.UnionQueryImpl".equals(logger)
                             && msg.contains("query union plan") && args.length 
> 0){
                         // LOG.debug("query union plan {}", getPlan());
                         plan = nullSafeString(args[0]);
+
+                        // Determine number of sub-queries in this UNION query 
so they can be ignored
+                        int tmp = count(plan, "*/ union ");
+                        if (tmp > 0) {
+                            subPlans = tmp + 1;
+                        }
                     }
                 }
             }
         }
 
+        /**
+         * Counts the number of instances the needle in the haystack.
+         * @param haystack the string to count the occurrences of the needle 
in.
+         * @param needle the string to count the number of occurrences of.
+         * @return the number of occurences the needle appears in the haystack.
+         */
+        private int count(final String haystack, final String needle) {
 
 Review comment:
   Liked the analogy!

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


> Sling Log Tracer queries reports Plan that does not match Query statement
> -------------------------------------------------------------------------
>
>                 Key: SLING-6506
>                 URL: https://issues.apache.org/jira/browse/SLING-6506
>             Project: Sling
>          Issue Type: Bug
>    Affects Versions: Log Tracer 0.0.2
>            Reporter: David Gonzalez
>            Assignee: Chetan Mehrotra
>            Priority: Major
>             Fix For: Log Tracer 1.0.8
>
>         Attachments: tracer-error-output.txt, tracer-error-screencap.png
>
>
> The Queries data set from Sling Log Tracer (1.0.2) may report the wrong Query 
> plan for the query.  
> {noformat}
> "query": "//*[jcr:contains(., 
> '\"/content/dam/we-retail/en/people/mens/men_1.jpg\"')]",
> "plan": "[nt:unstructured] as [a] /* 
> lucene:ntBaseLucene(/oak:index/ntBaseLucene) 
> dam:resolvedPath:/content/dam/we-retail/en/people/mens/men_1.jpg where 
> [a].[dam:resolvedPath] = '/content/dam/we-retail/en/people/mens/men_1.jpg' */"
> {noformat}
> Attached raw tracer output from Felix console.
> Explaining the query statement via Oak gives a different (and correct) plan.
> /cc [~chetanm]



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to