This is an automated email from the ASF dual-hosted git repository. thomasm pushed a commit to branch OAK-10527 in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
The following commit(s) were added to refs/heads/OAK-10527 by this push: new 1c3f7ce29c OAK-10527 Improve readability of the explain query output 1c3f7ce29c is described below commit 1c3f7ce29c9615d7fec1cdb73233513445dda07f Author: Thomas Mueller <thom...@apache.org> AuthorDate: Mon Nov 6 10:07:46 2023 +0100 OAK-10527 Improve readability of the explain query output --- .../java/org/apache/jackrabbit/oak/query/QueryFormatter.java | 2 ++ .../org/apache/jackrabbit/oak/query/QueryFormatterTest.java | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryFormatter.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryFormatter.java index 8333e434d6..aeff6cf269 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryFormatter.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryFormatter.java @@ -97,6 +97,7 @@ public class QueryFormatter { while (++i < buff.length() && buff.charAt(i) == ' ') { // skip } + i--; } else if (c == ' ') { String sub = buff.substring(i, Math.min(i + 10, buff.length())); if (sub.startsWith(" and ") @@ -126,6 +127,7 @@ public class QueryFormatter { while (++i < buff.length() && buff.charAt(i) == ' ') { // skip } + i--; } else if (c == ' ') { String sub = buff.substring(i, Math.min(i + 10, buff.length())); if (startsWithIgnoreCase(sub, " and ") diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/query/QueryFormatterTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/query/QueryFormatterTest.java index ad7a62231f..78fe042d41 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/query/QueryFormatterTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/query/QueryFormatterTest.java @@ -89,8 +89,12 @@ public class QueryFormatterTest { } } String query = buff.toString(); - QueryFormatter.format(query, "xpath"); - QueryFormatter.format(query, "sql"); + String x1 = QueryFormatter.format(query, "xpath"); + String x2 = QueryFormatter.format(x1, "xpath"); + assertEquals(x1, x2); + String s1 = QueryFormatter.format(query, "sql"); + String s2 = QueryFormatter.format(s1, "sql"); + assertEquals(s1, s2); } } @@ -151,6 +155,8 @@ public class QueryFormatterTest { @Test public void alreadyFormatted() { + assertEquals("jcr:root[\n '[hello]']", + QueryFormatter.format("jcr:root[\n '[hello]']", "xpath")); assertEquals("/jcr:root//*[\n" + " @a=1\n" + " and @b=2\n"