You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kie.apache.org by "Rikkola (via GitHub)" <gi...@apache.org> on 2025/09/19 05:55:35 UTC
[PR] Consolidate field accessors: merge primitive types and reduce code complexity [incubator-kie-drools]
Rikkola opened a new pull request, #6460:
URL: https://github.com/apache/incubator-kie-drools/pull/6460
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
**Thank you for submitting this pull request**
**NOTE!:** Double-check the target branch for this PR.
The default is `main` so it will target Drools 8 / Kogito.
**Ports** If a forward-port or a backport is needed, paste the forward port PR here
* [link](https://www.example.com)
**Issue**: _(please edit the GitHub Issues link if it exists)_
* [link](https://www.example.com)
**referenced Pull Requests**: _(please edit the URLs of referenced pullrequests if they exist)_
* paste the link(s) from GitHub here
* link 2
* link 3 etc.
<details>
<summary>
How to replicate CI configuration locally?
</summary>
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](https://github.com/kiegroup/github-action-build-chain) to handle cross repository builds and be sure that we always use latest version of the code for each repository.
[build-chain tool](https://github.com/kiegroup/github-action-build-chain) 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](https://github.com/kiegroup/github-action-build-chain#local-execution) details to get more information about it.
</details>
<details>
<summary>
How to retest this PR or trigger a specific build:
</summary>
- for <b>pull request and downstream checks</b>
- Push a new commit to the PR. An empty commit would be enough.
- for a <b>full downstream build</b>
- for <b>github actions</b> job: add the label `run_fdb`
- for <b>Jenkins PR check only</b>
- If you are an ASF committer for KIE podling, login to Jenkins (https://ci-builds.apache.org/job/KIE/job/drools/), go to the specific PR job, and click on `Build Now` button.
</details>
--
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] Consolidate field accessors: merge primitive types and reduce code complexity [incubator-kie-drools]
Posted by "kie-ci3 (via GitHub)" <gi...@apache.org>.
kie-ci3 commented on PR #6460:
URL: https://github.com/apache/incubator-kie-drools/pull/6460#issuecomment-3311009811
**PR job** `#3` was: **UNSTABLE**
Possible explanation: This should be test failures
<details>
<summary><b>Reproducer</b></summary>
build-chain build full_downstream -f 'https://raw.githubusercontent.com/${AUTHOR:apache}/incubator-kie-kogito-pipelines/${BRANCH:main}/.ci/buildchain-config-pr-cdb.yaml' -o 'bc' -p apache/incubator-kie-drools -u https://github.com/apache/incubator-kie-drools/pull/6460 --skipParallelCheckout
NOTE: To install the build-chain tool, please refer to https://github.com/kiegroup/github-action-build-chain#local-execution
</details>
Please look here: https://ci-builds.apache.org/job/KIE/job/drools/job/main/job/pullrequest_jobs/job/drools-pr/job/PR-6460/3/display/redirect
**Test results:**
- PASSED: 15564
- FAILED: 1
Those are the test failures:
<details>
<summary><a href="https://ci-builds.apache.org/job/KIE/job/drools/job/main/job/pullrequest_jobs/job/drools-pr/job/PR-6460/3/testReport/maven.invoker.it/kie-project-simple/kie_project_simple/">maven.invoker.it.kie-project-simple.kie-project-simple</a></summary>
The build exited with code 143. See /home/jenkins/jenkins-agent/workspace/llrequest_jobs_drools-pr_PR-6460/kogito-pipelines/bc/apache_incubator-kie-drools/drools-test-coverage/drools-test-coverage-jars/drools-test-coverage-jars-with-invoker/target/it/kie-project-simple/build.log for details.
</details>
--
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] Consolidate field accessors: merge primitive types and reduce code complexity [incubator-kie-drools]
Posted by "Rikkola (via GitHub)" <gi...@apache.org>.
Rikkola commented on code in PR #6460:
URL: https://github.com/apache/incubator-kie-drools/pull/6460#discussion_r2361898106
##########
drools-base/src/main/java/org/drools/base/rule/Declaration.java:
##########
@@ -235,42 +235,29 @@ public Object getValue(ValueResolver valueResolver, FactHandle fh) {
public Object getValue(ValueResolver valueResolver,
final Object object) {
- return this.readAccessor.getValue( valueResolver, object );
+ return this.readAccessor.getValue(valueResolver, object);
}
- public char getCharValue(ValueResolver valueResolver,
- final Object object) {
- return this.readAccessor.getCharValue(valueResolver, object);
- }
-
- public int getIntValue(ValueResolver valueResolver,
- final Object object) {
- return this.readAccessor.getIntValue(valueResolver, object);
- }
-
- public byte getByteValue(ValueResolver valueResolver,
+ public long getWholeNumberValue(ValueResolver valueResolver,
final Object object) {
- return this.readAccessor.getByteValue(valueResolver, object);
+ return this.readAccessor.getWholeNumberValue(valueResolver, object);
}
- public short getShortValue(ValueResolver valueResolver,
- final Object object) {
- return this.readAccessor.getShortValue(valueResolver, object);
- }
-
- public long getLongValue(ValueResolver valueResolver,
- final Object object) {
- return this.readAccessor.getLongValue(valueResolver, object);
+ public double getDecimalValue(ValueResolver valueResolver,
+ final Object object) {
+ return this.readAccessor.getDecimalValue(valueResolver, object);
}
- public float getFloatValue(ValueResolver valueResolver,
- final Object object) {
- return this.readAccessor.getFloatValue(valueResolver, object);
+ @Deprecated // TODO ask why this is needed in OOPathQueries, based on the tests at least
+ public double getDoubleValue(ValueResolver valueResolver,
+ final Object object) {
+ return this.readAccessor.getDecimalValue(valueResolver, object);
Review Comment:
Checking if my latest changes allow these to be removed. The thing is nothing fails when short and char versions are removed.
--
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] Consolidate field accessors: merge primitive types and reduce code complexity [incubator-kie-drools]
Posted by "Rikkola (via GitHub)" <gi...@apache.org>.
Rikkola commented on code in PR #6460:
URL: https://github.com/apache/incubator-kie-drools/pull/6460#discussion_r2361913249
##########
drools-base/src/main/java/org/drools/base/base/extractors/BaseObjectClassFieldReader.java:
##########
@@ -151,6 +109,10 @@ public String getNativeReadMethodName() {
Class<?> type = getExtractToClass();
if (!type.isPrimitive()) {
return "getValue";
+ } else if (type == int.class || type == long.class || type == short.class || type == byte.class || type == char.class) {
+ return "getWholeNumberValue";
+ } else if (type == float.class || type == double.class) {
+ return "getDecimalValue";
}
return "get" + type.getName().substring(0, 1).toUpperCase() + type.getName().substring(1) + "Value";
Review Comment:
In two locations we do "get" + type + "Value" to get the method name. This is currently only the fall back for Booleans if I am not wrong.
--
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] Consolidate field accessors: merge primitive types and reduce code complexity [incubator-kie-drools]
Posted by "Rikkola (via GitHub)" <gi...@apache.org>.
Rikkola commented on code in PR #6460:
URL: https://github.com/apache/incubator-kie-drools/pull/6460#discussion_r2361953444
##########
drools-base/src/main/java/org/drools/base/rule/Declaration.java:
##########
@@ -235,42 +235,29 @@ public Object getValue(ValueResolver valueResolver, FactHandle fh) {
public Object getValue(ValueResolver valueResolver,
final Object object) {
- return this.readAccessor.getValue( valueResolver, object );
+ return this.readAccessor.getValue(valueResolver, object);
}
- public char getCharValue(ValueResolver valueResolver,
- final Object object) {
- return this.readAccessor.getCharValue(valueResolver, object);
- }
-
- public int getIntValue(ValueResolver valueResolver,
- final Object object) {
- return this.readAccessor.getIntValue(valueResolver, object);
- }
-
- public byte getByteValue(ValueResolver valueResolver,
+ public long getWholeNumberValue(ValueResolver valueResolver,
final Object object) {
- return this.readAccessor.getByteValue(valueResolver, object);
+ return this.readAccessor.getWholeNumberValue(valueResolver, object);
}
- public short getShortValue(ValueResolver valueResolver,
- final Object object) {
- return this.readAccessor.getShortValue(valueResolver, object);
- }
-
- public long getLongValue(ValueResolver valueResolver,
- final Object object) {
- return this.readAccessor.getLongValue(valueResolver, object);
+ public double getDecimalValue(ValueResolver valueResolver,
+ final Object object) {
+ return this.readAccessor.getDecimalValue(valueResolver, object);
}
- public float getFloatValue(ValueResolver valueResolver,
- final Object object) {
- return this.readAccessor.getFloatValue(valueResolver, object);
+ @Deprecated // TODO ask why this is needed in OOPathQueries, based on the tests at least
+ public double getDoubleValue(ValueResolver valueResolver,
+ final Object object) {
+ return this.readAccessor.getDecimalValue(valueResolver, object);
Review Comment:
Ok, after my latest changes these do not cause OOPathQueries any issues. Removing these.
--
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] Consolidate field accessors: merge primitive types and reduce code complexity [incubator-kie-drools]
Posted by "kie-ci3 (via GitHub)" <gi...@apache.org>.
kie-ci3 commented on PR #6460:
URL: https://github.com/apache/incubator-kie-drools/pull/6460#issuecomment-3310837173
**PR job** `#2` was: **UNSTABLE**
Possible explanation: This should be test failures
<details>
<summary><b>Reproducer</b></summary>
build-chain build full_downstream -f 'https://raw.githubusercontent.com/${AUTHOR:apache}/incubator-kie-kogito-pipelines/${BRANCH:main}/.ci/buildchain-config-pr-cdb.yaml' -o 'bc' -p apache/incubator-kie-drools -u https://github.com/apache/incubator-kie-drools/pull/6460 --skipParallelCheckout
NOTE: To install the build-chain tool, please refer to https://github.com/kiegroup/github-action-build-chain#local-execution
</details>
Please look here: https://ci-builds.apache.org/job/KIE/job/drools/job/main/job/pullrequest_jobs/job/drools-pr/job/PR-6460/2/display/redirect
**Test results:**
- PASSED: 15537
- FAILED: 1
Those are the test failures:
<details>
<summary><a href="https://ci-builds.apache.org/job/KIE/job/drools/job/main/job/pullrequest_jobs/job/drools-pr/job/PR-6460/2/testReport/org.kie.maven.plugin.it/kie-maven-plugin-test-kjar-13/kie_maven_plugin_test_kjar_13/">org.kie.maven.plugin.it.kie-maven-plugin-test-kjar-13.kie-maven-plugin-test-kjar-13</a></summary>
The build exited with code 143. See /home/jenkins/workspace/llrequest_jobs_drools-pr_PR-6460/kogito-pipelines/bc/apache_incubator-kie-drools/kie-maven-plugin/target/it/kie-maven-plugin-test-kjar-13/build.log for details.
</details>
--
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] Consolidate field accessors: merge primitive types and reduce code complexity [incubator-kie-drools]
Posted by "mariofusco (via GitHub)" <gi...@apache.org>.
mariofusco merged PR #6460:
URL: https://github.com/apache/incubator-kie-drools/pull/6460
--
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] Consolidate field accessors: merge primitive types and reduce code complexity [incubator-kie-drools]
Posted by "Rikkola (via GitHub)" <gi...@apache.org>.
Rikkola commented on code in PR #6460:
URL: https://github.com/apache/incubator-kie-drools/pull/6460#discussion_r2361886866
##########
drools-mvel/src/main/java/org/drools/mvel/accessors/BaseDecimalClassFieldReader.java:
##########
@@ -24,7 +24,7 @@
import org.drools.base.base.BaseClassFieldReader;
import org.drools.base.base.ValueType;
-public abstract class BaseCharClassFieldReader extends BaseClassFieldReader {
+public abstract class BaseDecimalClassFieldReader extends BaseClassFieldReader {
Review Comment:
I am using new names Decimal and WholeNumber. This made helped when refactoring to catch the locations where the code was generated against the removed and updated methods/classes, but we can rename these to Double and Long if wanted.
##########
drools-mvel/src/main/java/org/drools/mvel/asm/ClassFieldAccessorFactory.java:
##########
@@ -347,7 +347,28 @@ protected static void buildGetMethod(final Class< ? > originalClass,
Type.getMethodDescriptor( getterMethod ),
false);
}
- mv.visitInsn( Type.getType( fieldType ).getOpcode( Opcodes.IRETURN ) );
+ if (getterMethod.getReturnType() != overridingMethod.getReturnType()) {
+ if (getterMethod.getReturnType() == float.class && overridingMethod.getReturnType() == double.class) {
+ mv.visitInsn(Opcodes.F2D); // Convert float to double
+ // Clean up precision artifacts from float-to-double conversion
+ mv.visitMethodInsn(Opcodes.INVOKESTATIC,
+ "org/drools/util/FloatHelper",
+ "cleanDouble",
+ "(D)D",
+ false);
+ } else if (getterMethod.getReturnType() == double.class && overridingMethod.getReturnType() == float.class) {
+ mv.visitInsn(Opcodes.D2F); // Convert double to float
+ } else if (getterMethod.getReturnType() == byte.class && overridingMethod.getReturnType() == long.class) {
+ mv.visitInsn(Opcodes.I2L); // Convert byte to long (byte->int->long handled by JVM)
+ } else if (getterMethod.getReturnType() == short.class && overridingMethod.getReturnType() == long.class) {
+ mv.visitInsn(Opcodes.I2L); // Convert short to long (short->int->long handled by JVM)
+ } else if (getterMethod.getReturnType() == int.class && overridingMethod.getReturnType() == long.class) {
+ mv.visitInsn(Opcodes.I2L); // Convert int to long
+ } else if (getterMethod.getReturnType() == char.class && overridingMethod.getReturnType() == long.class) {
+ mv.visitInsn(Opcodes.I2L); // Convert char to long (char->int->long handled by JVM)
+ }
+ }
+ mv.visitInsn( Type.getType( overridingMethod.getReturnType() ).getOpcode( Opcodes.IRETURN ) );
Review Comment:
One of the concerns is if this slows things down? Since I suspect the benefits before and after this PR was that there was direct access to the value and now we need to convert.
--
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] Consolidate field accessors: merge primitive types and reduce code complexity [incubator-kie-drools]
Posted by "Rikkola (via GitHub)" <gi...@apache.org>.
Rikkola commented on PR #6460:
URL: https://github.com/apache/incubator-kie-drools/pull/6460#issuecomment-3310735743
I will run the stress tests on this change to see the impact.
--
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