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

Clean expression stack before resolving project list #1059

Merged
merged 1 commit into from
Feb 19, 2025

Conversation

LantaoJin
Copy link
Member

@LantaoJin LantaoJin commented Feb 18, 2025

Description

Issue described in #1058.
Root cause is missing reset expression stack before resolving project list.

Related Issues

Resolves #1058

Check List

  • Updated documentation (docs/ppl-lang/README.md)
  • Implemented unit tests
  • Implemented tests for combination with other commands
  • New added source code should include a copyright header
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Sorry, something went wrong.

Signed-off-by: Lantao Jin <ltjin@amazon.com>
Comment on lines +220 to +222
public void resetNamedParseExpressions() {
getNamedParseExpressions().retainAll(emptyList());
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Add a new reset method to replace context.retainAllNamedParseExpressions(e -> e);
context.retainAllNamedParseExpressions(e -> e); (reset expression stack) is remarkably prone to oversight, consequently leading to errors.

Copy link
Member

Choose a reason for hiding this comment

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

Frequent clearing of the expression stack could potentially affect the overall query execution time, especially for large or complex queries. Can it happen?

Copy link
Member Author

Choose a reason for hiding this comment

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

Frequent clearing of the expression stack could potentially affect the overall query execution time, especially for large or complex queries. Can it happen?

No. The overhead of stack management operations is statistically insignificant compared to core processing tasks.

@@ -460,6 +464,9 @@ public LogicalPlan visitProject(Project node, CatalystPlanContext context) {
context.withProjectedFields(node.getProjectList());
}
LogicalPlan child = visitFirstChild(node, context);

// reset expression stack before resolving project
context.resetNamedParseExpressions();
Copy link
Member Author

Choose a reason for hiding this comment

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

This reset calling in visitProject is the key fix.

@@ -371,6 +373,8 @@ public LogicalPlan visitSubqueryAlias(SubqueryAlias node, CatalystPlanContext co
@Override
public LogicalPlan visitAggregation(Aggregation node, CatalystPlanContext context) {
visitFirstChild(node, context);
// clean before to go
context.resetNamedParseExpressions();
Copy link
Member Author

Choose a reason for hiding this comment

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

Missing reset calling in visitAggregation as well. This is not the fix for "Fields command" issue. But after the "Fields command" fixed, below scalar subquery will throw MISSING_GROUP_BY exception. This line is to fix the potential problem.

 source = $outerTable as o
 | where id = [
     source = $innerTable as i | where o.id = i.uid | stats max(i.uid)
   ]
 | fields o.id, o.name

See the new tests I added in FlintSparkPPLScalarSubqueryITSuite

@LantaoJin
Copy link
Member Author

Could you help to review this? @YANG-DB @qianheng-aws

@YANG-DB
Copy link
Member

YANG-DB commented Feb 18, 2025

Thanks for the quick fix

@LantaoJin LantaoJin merged commit 09aba20 into opensearch-project:main Feb 19, 2025
5 checks passed
@ykmr1224
Copy link
Collaborator

@LantaoJin Please backport to 0.x if it is not a breaking change. We started similar branching as sql repository.

@penghuo penghuo added the backport 0.x Backport to 0.x branch (stable branch) label Feb 19, 2025
opensearch-trigger-bot bot pushed a commit that referenced this pull request Feb 19, 2025
Signed-off-by: Lantao Jin <ltjin@amazon.com>
(cherry picked from commit 09aba20)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
LantaoJin pushed a commit that referenced this pull request Feb 20, 2025
(cherry picked from commit 09aba20)

Signed-off-by: Lantao Jin <ltjin@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 0.x Backport to 0.x branch (stable branch)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Fields command is not being obeyed while table alias is used
5 participants