You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by GitBox <gi...@apache.org> on 2018/01/19 06:29:51 UTC

[GitHub] chetanmeh commented on a change in pull request #1: SLING-6506 - Handling of UNION'd queries in Sling Log Tracer

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:
users@infra.apache.org


With regards,
Apache Git Services