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

[kie-issues#969]: Negated value in accumulate function ends with Invalid expression error #5762

Merged
merged 7 commits into from
Mar 7, 2024

Conversation

yesamer
Copy link
Contributor

@yesamer yesamer commented Mar 5, 2024

Closes: apache/incubator-kie-issues#969

accumulate ($p: Person (getName().startsWith("M")); 
                     $sum : sum(-$p.getAge()))

This case leads to an Invalid expression -$p.getAge() error.

That is because the UnaryExpression types are not managed in the AccumulateVisitor logic.
To fix the issue, I managed that case relying on the existing BinaryExpression logic management, which fits well for the UnaryExpression case according to my analysis.
Please correct me if I'm wrong @lucamolteni @mariofusco.

In addition, we added a check to ensure that the accumulate function always has no more than one parameter (kudos to @gitgabrio ). I added that check for the executable Model case only

How to replicate CI configuration locally?

Build Chain tool does "simple" maven build(s), the builds are just Maven commands, but because the repositories relates and depends on each other and any change in API or class method could affect several of those repositories there is a need to use build-chain tool to handle cross repository builds and be sure that we always use latest version of the code for each repository.

build-chain tool is a build tool which can be used on command line locally or in Github Actions workflow(s), in case you need to change multiple repositories and send multiple dependent pull requests related with a change you can easily reproduce the same build by executing it on Github hosted environment or locally in your development environment. See local execution details to get more information about it.

How to retest this PR or trigger a specific build:
  • for pull request and downstream checks

    • Push a new commit to the PR. An empty commit would be enough.
  • for a full downstream build

    • for github actions job: add the label run_fdb
  • for Jenkins PR check only

Copy link
Contributor

@gitgabrio gitgabrio left a comment

Choose a reason for hiding this comment

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

HI @yesamer
There is a System.out.println to remove. And maybe a small refactoring/enforcement


Results results = createKieBuilder(str).getResults();
if (testRunType.isExecutableModel()) {
System.out.println(results.getMessages(Message.Level.ERROR).get(0).getText());
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @yesamer
Could you please remove this System.out.println ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -406,10 +414,10 @@ private boolean parameterNeedsConvertionToMethodCallExpr(Expression accumulateFu
return accumulateFunctionParameter.isMethodCallExpr() || accumulateFunctionParameter.isArrayAccessExpr() || accumulateFunctionParameter.isFieldAccessExpr();
}

private Optional<NewBinding> binaryExprParameter(PatternDescr basePattern, AccumulateDescr.AccumulateFunctionCallDescr function, MethodCallExpr functionDSL, String bindingId, String accumulateFunctionParameterStr) {
private Optional<NewBinding> binaryOrUnaryExprParameter(PatternDescr basePattern, AccumulateDescr.AccumulateFunctionCallDescr function, MethodCallExpr functionDSL, String bindingId, String accumulateFunctionParameterStr) {
Copy link
Contributor

@gitgabrio gitgabrio Mar 5, 2024

Choose a reason for hiding this comment

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

HI @yesamer
Would it make sense to rename it as bindingParameter or similar ?

  1. if, by chance, we discover that another kind of expression has to be managed here, the method name would become awfull
  2. usually, the method name express the returned object
  3. IINW, nothing prevent this method to be invoked by somehting different then a BinaryExpr or a UnaryExpr (if it is implicitily so, I think there should be a check/guard somehow)

WDYT ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, done!

@yesamer yesamer changed the title [ki-issues#969]: Negated value in accumulate function ends with Invalid expression error [kie-issues#969]: Negated value in accumulate function ends with Invalid expression error Mar 5, 2024
Copy link
Contributor

@gitgabrio gitgabrio left a comment

Choose a reason for hiding this comment

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

Thanks @yesamer LGTM!

@yesamer yesamer merged commit 2ac36ac into apache:main Mar 7, 2024
9 checks passed
@yesamer yesamer deleted the kie-issues#969 branch March 7, 2024 06:31
yesamer added a commit to yesamer/drools that referenced this pull request Mar 7, 2024
…lid expression error (apache#5762)

* Added Unary Expression management

* Improved DroolsMvelParserTest

* Typo

* Exception message updated

* Code review

* Code review

(cherry picked from commit 2ac36ac)
baldimir pushed a commit that referenced this pull request Mar 7, 2024
rgdoliveira pushed a commit to rgdoliveira/drools that referenced this pull request Mar 11, 2024
…lid expression error (apache#5762)

* Added Unary Expression management

* Improved DroolsMvelParserTest

* Typo

* Exception message updated

* Code review

* Code review
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Negated value in accumulate function ends with Invalid expression error
4 participants