Cypher : fix profile and explain corrupting returned values#3406
Cypher : fix profile and explain corrupting returned values#3406lvca merged 3 commits intoArcadeData:mainfrom
Conversation
Summary of ChangesHello @ExtReMLapin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses critical issues with how Cypher's EXPLAIN and PROFILE commands interact with the system's result handling and REST API. The changes ensure that execution plan information is correctly formatted and delivered in dedicated fields, preventing unintended data exposure and improving the accuracy of query profiling. This significantly enhances the debugging and performance analysis capabilities for Cypher queries. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses the issues with EXPLAIN and PROFILE in Cypher queries. The changes correctly utilize ExplainResultSet for EXPLAIN and attach profiling information as an execution plan for PROFILE, which prevents corrupting the result set. The new OpenCypherExplainExecutionPlan class is a clean way to wrap the plan text. The test updates are thorough and correctly reflect the new behavior. I've added a few suggestions to improve code clarity, consistency, and documentation in the new implementation.
| * Executes the query with profiling enabled. | ||
| * Returns the query results along with execution metrics. | ||
| * The query is executed to collect real metrics, but only the profiling | ||
| * information is returned (actual query results are discarded). | ||
| * Returns an {@link ExplainResultSet} so the server handler populates the | ||
| * dedicated {@code explain} field in the JSON response. | ||
| * | ||
| * @return result set containing results and profiling metrics | ||
| * @return result set containing profiling metrics via {@code getExecutionPlan()} | ||
| */ |
There was a problem hiding this comment.
The Javadoc for the profile() method is misleading. It incorrectly states that query results are discarded and that an ExplainResultSet is returned. The implementation actually returns the query results in an InternalResultSet, with profiling information attached as an execution plan. Please update the documentation to reflect the actual behavior.
/**
* Executes the query with profiling enabled.
* Returns the query results along with execution metrics. The profiling information
* is available via {@link com.arcadedb.query.sql.executor.ResultSet#getExecutionPlan()}.
*
* @return a result set containing the query results, with profiling metrics available in the execution plan.
*/| while (resultSet.hasNext()) | ||
| results.add(resultSet.next()); |
There was a problem hiding this comment.
While syntactically correct, using while loops without braces can be error-prone. If another statement is added to the loop body in the future without adding braces, it will execute outside the loop, potentially causing bugs. It's safer to always use braces for clarity and to prevent future errors.
while (resultSet.hasNext()) {
results.add(resultSet.next());
}| final boolean hasWithBeforeMatch2 = hasWithPrecedingMatch(); | ||
|
|
||
| final boolean hasVLP2 = hasVariableLengthPath(); | ||
| if (physicalPlan != null && physicalPlan.getRootOperator() != null && !hasUnwindBeforeMatch && !hasWithBeforeMatch2 && !hasVLP2) { | ||
| if (physicalPlan != null && physicalPlan.getRootOperator() != null && !hasUnwindBeforeMatch && !hasWithBeforeMatch2 && !hasVLP2) | ||
| rootStep = buildExecutionStepsWithOptimizer(context); | ||
| } else { | ||
| else | ||
| rootStep = buildExecutionSteps(context); |
There was a problem hiding this comment.
There are a couple of issues in this block that affect readability and maintainability:
- The local variables
hasWithBeforeMatch2andhasVLP2use a2suffix, which is inconsistent with similarly named variables in theexecute()method. This seems to be a copy-paste artifact. - The
if-elsestatement lacks braces, which is generally discouraged for safety and consistency.
I'd suggest renaming the variables and adding braces.
final boolean hasWithBeforeMatch = hasWithPrecedingMatch();
final boolean hasVLP = hasVariableLengthPath();
if (physicalPlan != null && physicalPlan.getRootOperator() != null && !hasUnwindBeforeMatch && !hasWithBeforeMatch && !hasVLP) {
rootStep = buildExecutionStepsWithOptimizer(context);
} else {
rootStep = buildExecutionSteps(context);
}
server/src/main/java/com/arcadedb/server/http/handler/PostCommandHandler.java
Outdated
Show resolved
Hide resolved
…andHandler.java Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
Awesome, thanks! |
🧪 CI InsightsHere's what we observed from your CI run for 754ff84. 🟢 All jobs passed!But CI Insights is watching 👀 |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3406 +/- ##
==========================================
+ Coverage 62.12% 62.63% +0.51%
==========================================
Files 1249 1250 +1
Lines 84354 84359 +5
Branches 17312 17316 +4
==========================================
+ Hits 52406 52840 +434
+ Misses 24639 24241 -398
+ Partials 7309 7278 -31 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
* fix explain and profile * Fixed profile blocking data return * Update server/src/main/java/com/arcadedb/server/http/handler/PostCommandHandler.java Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --------- Co-authored-by: Pierre F <no@p.e> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> (cherry picked from commit b4b5a7c)
What does this PR do?
Fixes #3405
Before this fix, using with cypher EXPLAIN or PROFILE was not storing anything in the dedicated REST fields.
It was storing the profile or explain result in the records fields, mixing up with the data returned from the query.
Using profile was even "leaking" data that was never asked to be returned.
claude wrote all the code, I just tested it