Skip to content
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

Merged
merged 15 commits into from
Nov 7, 2023

Conversation

thomasmueller
Copy link
Member

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:

  • some upstream UI tools depend on the query plans to have a certain form, which would break,
  • it would make the patch even larger,
  • the Lucene query string might contain double quotes, which would then be escaped, and so the output hard to read

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.

Copy link
Contributor

@nfsantos nfsantos left a 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.

thomasmueller and others added 5 commits November 3, 2023 18:16
…/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>
Copy link
Contributor

@nfsantos nfsantos left a 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.

if (language != null) {
return "xpath".equals(language);
}
query = query.trim().toLowerCase(Locale.ENGLISH);
Copy link
Contributor

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.

Copy link
Member Author

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();
Copy link
Contributor

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.

Copy link
Member Author

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.

if (xpath) {
return formatXPath(query);
} else {
return formatSQL(query);
Copy link
Contributor

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.

Copy link
Member Author

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 == '"') {
Copy link
Contributor

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.

Copy link
Member Author

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);
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Copy link

sonarcloud bot commented Nov 7, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 18 Code Smells

87.3% 87.3% Coverage
0.0% 0.0% Duplication

warning 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.
Read more here

Copy link
Contributor

@amit-jain amit-jain left a 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.

@thomasmueller thomasmueller merged commit 04f3c97 into trunk Nov 7, 2023
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants