-
Notifications
You must be signed in to change notification settings - Fork 388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OAK-10527 Improve readability of the explain query output #1187
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not look at the tests, just have a minor comment.
oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryFormatter.java
Outdated
Show resolved
Hide resolved
oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryFormatter.java
Show resolved
Hide resolved
oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndex.java
Outdated
Show resolved
Hide resolved
oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryFormatter.java
Outdated
Show resolved
Hide resolved
oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryFormatter.java
Show resolved
Hide resolved
oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryFormatter.java
Outdated
Show resolved
Hide resolved
oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java
Show resolved
Hide resolved
oak-core/src/test/java/org/apache/jackrabbit/oak/query/QueryFormatterTest.java
Outdated
Show resolved
Hide resolved
…/nodetype/NodeTypeIndex.java Co-authored-by: Fabrizio Fortino <fabrizio.fortino@gmail.com>
…rmatter.java Co-authored-by: Fabrizio Fortino <fabrizio.fortino@gmail.com>
…rmatter.java Co-authored-by: Fabrizio Fortino <fabrizio.fortino@gmail.com>
…rmatterTest.java Co-authored-by: Fabrizio Fortino <fabrizio.fortino@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few more comments.
oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryFormatter.java
Outdated
Show resolved
Hide resolved
oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryFormatter.java
Show resolved
Hide resolved
if (language != null) { | ||
return "xpath".equals(language); | ||
} | ||
query = query.trim().toLowerCase(Locale.ENGLISH); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we do not want any locale related interpretation, it's better to use Locale.ROOT.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Locale.ENGLISH is safe according to https://stackoverflow.com/questions/10336730/which-locale-should-i-specify-when-i-call-stringtolowercase . We use that in other parts too, so I would keep this.
} | ||
// union queries | ||
while (query.startsWith("(")) { | ||
query = query.substring("(".length()).trim(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe replace with substring(1)
since we are just removing the first character? I understand the reason for this convention when it is a word, prevents mistakes, but when it's only a single character, maybe it is simpler to use 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used this for consistency, and to prevent errors in maintenance.
oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryFormatter.java
Outdated
Show resolved
Hide resolved
oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryFormatter.java
Outdated
Show resolved
Hide resolved
if (xpath) { | ||
return formatXPath(query); | ||
} else { | ||
return formatSQL(query); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not sure here if the language is sql. If language is specified, add a check that it is either sql or xpath. If we autodetect, then can we check if it is sql by looking at if it starts with select
? That way, we could have a nice error message saying that we do not recognize the language instead of failing with a syntax error or returning a string with newlines added in random places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could have a nice error message saying that we do not recognize the language
I don't see a need for this currently. The current use case is debug log, where we actually always know which language it is.
I do want to re-use this in the near future for http://oakutils.appspot.com/generate/index where the language detection is (unfortunately) incorrect.
StringBuilder buff = new StringBuilder(query); | ||
for (int i = 0; i < buff.length(); i++) { | ||
char c = buff.charAt(i); | ||
if (c == '\'' || c == '"') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be transformed into a switch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. But that wouldn't necessarily be better. I prefer the "if else" in this case.
@@ -121,22 +121,17 @@ public void unionSortResultCount() throws Exception { | |||
root.commit(); | |||
|
|||
List<Integer> nodes = Lists.newArrayList(); | |||
Random r = new Random(); | |||
int seed = -2; | |||
Random r = new Random(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? You want the test to be deterministic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
Kudos, SonarCloud Quality Gate passed! 0 Bugs 87.3% Coverage The version of Java (11.0.21) you have used to run this analysis is deprecated and we will stop accepting it soon. Please update to at least Java 17. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Haven't looked at the tests carefully though.
I had a to change a lot of tests, because they depended (too much) on implementation details.
Even thought this would be a good idea, I did not switch to Json output so far, because:
So basically, first the upstream UI tools would
The Elasticsearch query is Json, which wouldn't need to be escaped if we add it as a child object.