You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kie.apache.org by "baldimir (via GitHub)" <gi...@apache.org> on 2024/03/05 09:37:44 UTC
[PR] [kie-issues#986] Coerce object to String in executable model codegen [incubator-kie-drools]
baldimir opened a new pull request, #5761:
URL: https://github.com/apache/incubator-kie-drools/pull/5761
Fixes https://github.com/apache/incubator-kie-issues/issues/986
For binary expression, only numeric arithmetic operations were considered during code generation.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [kie-issues#986] Coerce object to String in executable model codegen [incubator-kie-drools]
Posted by "gitgabrio (via GitHub)" <gi...@apache.org>.
gitgabrio commented on code in PR #5761:
URL: https://github.com/apache/incubator-kie-drools/pull/5761#discussion_r1512647550
##########
drools-model/drools-model-codegen/src/main/java/org/drools/model/codegen/execmodel/generator/expressiontyper/ExpressionTyper.java:
##########
@@ -224,16 +225,19 @@ private Optional<TypedExpression> toTypedExpressionRec(Expression drlxExpr) {
TypedExpression left = optLeft.get();
TypedExpression right = optRight.get();
- ArithmeticCoercedExpression.ArithmeticCoercedExpressionResult coerced;
- try {
- coerced = new ArithmeticCoercedExpression(left, right, operator).coerce();
- } catch (ArithmeticCoercedExpression.ArithmeticCoercedExpressionException e) {
- logger.error("Failed to coerce : {}", e.getInvalidExpressionErrorResult());
- return empty();
- }
+ // Can be a binary expression of non-numeric types, like String + customType, etc.
+ if (ClassUtils.isNumericClass(left.getRawClass()) || ClassUtils.isNumericClass(right.getRawClass())) {
Review Comment:
Yes, but `ArithmeticCoercionExpression` should be returned only with number/string elements; otherwise, a different expression is needed.
With the above, when one of the element is a number and the other is not a number nor a string, the code will throw an exception and return an empty Optional.
Instead, when one element is number and the other is not a number nor a string, I think it should anyway return a BynaryExpr (as at line 242).
Is that clear ? Does this make sense ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [kie-issues#986] Coerce object to String in executable model codegen [incubator-kie-drools]
Posted by "mariofusco (via GitHub)" <gi...@apache.org>.
mariofusco merged PR #5761:
URL: https://github.com/apache/incubator-kie-drools/pull/5761
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [kie-issues#986] Coerce object to String in executable model codegen [incubator-kie-drools]
Posted by "gitgabrio (via GitHub)" <gi...@apache.org>.
gitgabrio commented on code in PR #5761:
URL: https://github.com/apache/incubator-kie-drools/pull/5761#discussion_r1512619029
##########
drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/TypeCoercionTest.java:
##########
@@ -612,4 +612,30 @@ public void testFloatOperation() {
assertThat(list.size()).isEqualTo(1);
assertThat(list.get(0)).isEqualTo("Mario");
}
+
+ @Test
Review Comment:
Hi @baldimir
COuld you please add a similar test where one of the two components is a number ?
##########
drools-model/drools-model-codegen/src/main/java/org/drools/model/codegen/execmodel/generator/expressiontyper/ExpressionTyper.java:
##########
@@ -224,16 +225,19 @@ private Optional<TypedExpression> toTypedExpressionRec(Expression drlxExpr) {
TypedExpression left = optLeft.get();
TypedExpression right = optRight.get();
- ArithmeticCoercedExpression.ArithmeticCoercedExpressionResult coerced;
- try {
- coerced = new ArithmeticCoercedExpression(left, right, operator).coerce();
- } catch (ArithmeticCoercedExpression.ArithmeticCoercedExpressionException e) {
- logger.error("Failed to coerce : {}", e.getInvalidExpressionErrorResult());
- return empty();
- }
+ // Can be a binary expression of non-numeric types, like String + customType, etc.
+ if (ClassUtils.isNumericClass(left.getRawClass()) || ClassUtils.isNumericClass(right.getRawClass())) {
Review Comment:
Thanks @baldimir
But IIUC the `ArithmeticCoercedExpression` requires one part to be a number and the other a String. With the above if, the code checks only if one of the elements is a number, but does not verify if the other is a String. If it is not, the following
`coerced = new ArithmeticCoercedExpression(left, right, operator).coerce();`
would throw an exception (IINW)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [kie-issues#986] Coerce object to String in executable model codegen [incubator-kie-drools]
Posted by "gitgabrio (via GitHub)" <gi...@apache.org>.
gitgabrio commented on code in PR #5761:
URL: https://github.com/apache/incubator-kie-drools/pull/5761#discussion_r1512647550
##########
drools-model/drools-model-codegen/src/main/java/org/drools/model/codegen/execmodel/generator/expressiontyper/ExpressionTyper.java:
##########
@@ -224,16 +225,19 @@ private Optional<TypedExpression> toTypedExpressionRec(Expression drlxExpr) {
TypedExpression left = optLeft.get();
TypedExpression right = optRight.get();
- ArithmeticCoercedExpression.ArithmeticCoercedExpressionResult coerced;
- try {
- coerced = new ArithmeticCoercedExpression(left, right, operator).coerce();
- } catch (ArithmeticCoercedExpression.ArithmeticCoercedExpressionException e) {
- logger.error("Failed to coerce : {}", e.getInvalidExpressionErrorResult());
- return empty();
- }
+ // Can be a binary expression of non-numeric types, like String + customType, etc.
+ if (ClassUtils.isNumericClass(left.getRawClass()) || ClassUtils.isNumericClass(right.getRawClass())) {
Review Comment:
Yes, but `ArithmeticCoercionExpression` should be returned only with number/string elements; otherwise, a different expression is needed. But with the above, when the one of the element is a number anbd the other is not a number nor a string, the code will throw an exception and return an empty.
Instead, when one element is number and the other is not a number nor a string, I think it should anyway return a BynaryExpr (as at line 242). Is that clear ? Does this make sense ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [kie-issues#986] Coerce object to String in executable model codegen [incubator-kie-drools]
Posted by "baldimir (via GitHub)" <gi...@apache.org>.
baldimir commented on code in PR #5761:
URL: https://github.com/apache/incubator-kie-drools/pull/5761#discussion_r1512716724
##########
drools-model/drools-model-codegen/src/main/java/org/drools/model/codegen/execmodel/generator/expressiontyper/ExpressionTyper.java:
##########
@@ -224,16 +225,19 @@ private Optional<TypedExpression> toTypedExpressionRec(Expression drlxExpr) {
TypedExpression left = optLeft.get();
TypedExpression right = optRight.get();
- ArithmeticCoercedExpression.ArithmeticCoercedExpressionResult coerced;
- try {
- coerced = new ArithmeticCoercedExpression(left, right, operator).coerce();
- } catch (ArithmeticCoercedExpression.ArithmeticCoercedExpressionException e) {
- logger.error("Failed to coerce : {}", e.getInvalidExpressionErrorResult());
- return empty();
- }
+ // Can be a binary expression of non-numeric types, like String + customType, etc.
+ if (ClassUtils.isNumericClass(left.getRawClass()) || ClassUtils.isNumericClass(right.getRawClass())) {
Review Comment:
Updated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [kie-issues#986] Coerce object to String in executable model codegen [incubator-kie-drools]
Posted by "gitgabrio (via GitHub)" <gi...@apache.org>.
gitgabrio commented on code in PR #5761:
URL: https://github.com/apache/incubator-kie-drools/pull/5761#discussion_r1513994713
##########
drools-model/drools-model-codegen/src/main/java/org/drools/model/codegen/execmodel/generator/expressiontyper/ExpressionTyper.java:
##########
@@ -224,16 +225,19 @@ private Optional<TypedExpression> toTypedExpressionRec(Expression drlxExpr) {
TypedExpression left = optLeft.get();
TypedExpression right = optRight.get();
- ArithmeticCoercedExpression.ArithmeticCoercedExpressionResult coerced;
- try {
- coerced = new ArithmeticCoercedExpression(left, right, operator).coerce();
- } catch (ArithmeticCoercedExpression.ArithmeticCoercedExpressionException e) {
- logger.error("Failed to coerce : {}", e.getInvalidExpressionErrorResult());
- return empty();
- }
+ // Can be a binary expression of non-numeric types, like String + customType, etc.
+ if (ClassUtils.isNumericClass(left.getRawClass()) || ClassUtils.isNumericClass(right.getRawClass())) {
Review Comment:
Thanks, good to me!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [kie-issues#986] Coerce object to String in executable model codegen [incubator-kie-drools]
Posted by "baldimir (via GitHub)" <gi...@apache.org>.
baldimir commented on code in PR #5761:
URL: https://github.com/apache/incubator-kie-drools/pull/5761#discussion_r1513037407
##########
drools-model/drools-model-codegen/src/main/java/org/drools/model/codegen/execmodel/generator/expressiontyper/ExpressionTyper.java:
##########
@@ -224,16 +225,19 @@ private Optional<TypedExpression> toTypedExpressionRec(Expression drlxExpr) {
TypedExpression left = optLeft.get();
TypedExpression right = optRight.get();
- ArithmeticCoercedExpression.ArithmeticCoercedExpressionResult coerced;
- try {
- coerced = new ArithmeticCoercedExpression(left, right, operator).coerce();
- } catch (ArithmeticCoercedExpression.ArithmeticCoercedExpressionException e) {
- logger.error("Failed to coerce : {}", e.getInvalidExpressionErrorResult());
- return empty();
- }
+ // Can be a binary expression of non-numeric types, like String + customType, etc.
+ if (ClassUtils.isNumericClass(left.getRawClass()) || ClassUtils.isNumericClass(right.getRawClass())) {
Review Comment:
Please see my latest changes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [kie-issues#986] Coerce object to String in executable model codegen [incubator-kie-drools]
Posted by "baldimir (via GitHub)" <gi...@apache.org>.
baldimir commented on code in PR #5761:
URL: https://github.com/apache/incubator-kie-drools/pull/5761#discussion_r1512696705
##########
drools-model/drools-model-codegen/src/main/java/org/drools/model/codegen/execmodel/generator/expressiontyper/ExpressionTyper.java:
##########
@@ -224,16 +225,19 @@ private Optional<TypedExpression> toTypedExpressionRec(Expression drlxExpr) {
TypedExpression left = optLeft.get();
TypedExpression right = optRight.get();
- ArithmeticCoercedExpression.ArithmeticCoercedExpressionResult coerced;
- try {
- coerced = new ArithmeticCoercedExpression(left, right, operator).coerce();
- } catch (ArithmeticCoercedExpression.ArithmeticCoercedExpressionException e) {
- logger.error("Failed to coerce : {}", e.getInvalidExpressionErrorResult());
- return empty();
- }
+ // Can be a binary expression of non-numeric types, like String + customType, etc.
+ if (ClassUtils.isNumericClass(left.getRawClass()) || ClassUtils.isNumericClass(right.getRawClass())) {
Review Comment:
I am simplifying this more. I will push new changes in few mins.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [kie-issues#986] Coerce object to String in executable model codegen [incubator-kie-drools]
Posted by "baldimir (via GitHub)" <gi...@apache.org>.
baldimir commented on code in PR #5761:
URL: https://github.com/apache/incubator-kie-drools/pull/5761#discussion_r1512696705
##########
drools-model/drools-model-codegen/src/main/java/org/drools/model/codegen/execmodel/generator/expressiontyper/ExpressionTyper.java:
##########
@@ -224,16 +225,19 @@ private Optional<TypedExpression> toTypedExpressionRec(Expression drlxExpr) {
TypedExpression left = optLeft.get();
TypedExpression right = optRight.get();
- ArithmeticCoercedExpression.ArithmeticCoercedExpressionResult coerced;
- try {
- coerced = new ArithmeticCoercedExpression(left, right, operator).coerce();
- } catch (ArithmeticCoercedExpression.ArithmeticCoercedExpressionException e) {
- logger.error("Failed to coerce : {}", e.getInvalidExpressionErrorResult());
- return empty();
- }
+ // Can be a binary expression of non-numeric types, like String + customType, etc.
+ if (ClassUtils.isNumericClass(left.getRawClass()) || ClassUtils.isNumericClass(right.getRawClass())) {
Review Comment:
I am simplifying this more.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [kie-issues#986] Coerce object to String in executable model codegen [incubator-kie-drools]
Posted by "baldimir (via GitHub)" <gi...@apache.org>.
baldimir commented on PR #5761:
URL: https://github.com/apache/incubator-kie-drools/pull/5761#issuecomment-1979043982
Based on feedback, I redid the changes a bit. There were concerns, that it is not clear what side effects the original ArithmeticCoercionExpression class has, when reading/debugging the code. So I reorganized it a bit.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [kie-issues#986] Coerce object to String in executable model codegen [incubator-kie-drools]
Posted by "baldimir (via GitHub)" <gi...@apache.org>.
baldimir commented on code in PR #5761:
URL: https://github.com/apache/incubator-kie-drools/pull/5761#discussion_r1512624566
##########
drools-model/drools-model-codegen/src/main/java/org/drools/model/codegen/execmodel/generator/expressiontyper/ExpressionTyper.java:
##########
@@ -224,16 +225,19 @@ private Optional<TypedExpression> toTypedExpressionRec(Expression drlxExpr) {
TypedExpression left = optLeft.get();
TypedExpression right = optRight.get();
- ArithmeticCoercedExpression.ArithmeticCoercedExpressionResult coerced;
- try {
- coerced = new ArithmeticCoercedExpression(left, right, operator).coerce();
- } catch (ArithmeticCoercedExpression.ArithmeticCoercedExpressionException e) {
- logger.error("Failed to coerce : {}", e.getInvalidExpressionErrorResult());
- return empty();
- }
+ // Can be a binary expression of non-numeric types, like String + customType, etc.
+ if (ClassUtils.isNumericClass(left.getRawClass()) || ClassUtils.isNumericClass(right.getRawClass())) {
Review Comment:
This is just a check to find out if one of the inputs is a number. Other type checks are within the ArithmeticCoercedExpression.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [kie-issues#986] Coerce object to String in executable model codegen [incubator-kie-drools]
Posted by "baldimir (via GitHub)" <gi...@apache.org>.
baldimir commented on code in PR #5761:
URL: https://github.com/apache/incubator-kie-drools/pull/5761#discussion_r1512626456
##########
drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/TypeCoercionTest.java:
##########
@@ -612,4 +612,30 @@ public void testFloatOperation() {
assertThat(list.size()).isEqualTo(1);
assertThat(list.get(0)).isEqualTo("Mario");
}
+
+ @Test
Review Comment:
There are existing tests added as part of the PR that introduced the ArithmeticCoercedExpression. https://github.com/apache/incubator-kie-drools/commit/5512f7294ea9b54e15d60786e3e42f5486b46ee4
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org