You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "awelless (via GitHub)" <gi...@apache.org> on 2025/06/20 12:09:28 UTC

[PR] NIFI-14671 NIFI-14675 record path long handling improvements [nifi]

awelless opened a new pull request, #10030:
URL: https://github.com/apache/nifi/pull/10030

   <!-- 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. -->
   
   # Summary
   
   [NIFI-14671](https://issues.apache.org/jira/browse/NIFI-14671)
   [NIFI-14675](https://issues.apache.org/jira/browse/NIFI-14675)
   
   # Tracking
   
   Please complete the following tracking steps prior to pull request creation.
   
   ### Issue Tracking
   
   - [x] [Apache NiFi Jira](https://issues.apache.org/jira/browse/NIFI) issue created
   
   ### Pull Request Tracking
   
   - [x] Pull Request title starts with Apache NiFi Jira issue number, such as `NIFI-00000`
   - [x] Pull Request commit message starts with Apache NiFi Jira issue number, as such `NIFI-00000`
   
   ### Pull Request Formatting
   
   - [x] Pull Request based on current revision of the `main` branch
   - [ ] Pull Request refers to a feature branch with one commit containing changes
   
   # Verification
   
   Please indicate the verification steps performed prior to pull request creation.
   
   ### Build
   
   - [ ] Build completed using `mvn clean install -P contrib-check`
     - [x] JDK 21
   
   ### Licensing
   
   - [ ] New dependencies are compatible with the [Apache License 2.0](https://apache.org/licenses/LICENSE-2.0) according to the [License Policy](https://www.apache.org/legal/resolved.html)
   - [ ] New dependencies are documented in applicable `LICENSE` and `NOTICE` files
   
   ### Documentation
   
   - [ ] Documentation formatting appears as expected in rendered files
   


-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] NIFI-14675 record path long handling improvements [nifi]

Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory commented on code in PR #10030:
URL: https://github.com/apache/nifi/pull/10030#discussion_r2160052264


##########
nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/filter/NumericBinaryOperatorFilter.java:
##########
@@ -65,10 +65,10 @@ protected boolean test(final FieldValue fieldValue, final Object rhsValue) {
         }
 
         final String fieldName = fieldValue.getField() == null ? "<Anonymous Inner Field>" : fieldValue.getField().getFieldName();
-        final Number lhsNumber = lhsLongCompatible ? DataTypeUtils.toLong(value, fieldName) : DataTypeUtils.toDouble(value, fieldName);
-        final Number rhsNumber = rhsLongCompatible ? DataTypeUtils.toLong(rhsValue, fieldName) : DataTypeUtils.toDouble(rhsValue, fieldName);
-        return compare(lhsNumber, rhsNumber);
+        return lhsLongCompatible && rhsLongCompatible
+                ? test(DataTypeUtils.toLong(value, fieldName), DataTypeUtils.toLong(rhsValue, fieldName))
+                : test(DataTypeUtils.toDouble(value, fieldName), DataTypeUtils.toDouble(rhsValue, fieldName));
     }
 
-    protected abstract boolean compare(final Number lhsNumber, final Number rhsNumber);
+    protected abstract boolean test(final Number lhsNumber, final Number rhsNumber);

Review Comment:
   Instead of passing the untyped `Number`, separate concrete methods should be defined, one for `long` types and one for `double` types. Those separate implementations can then call the abstract `verifyComparisonResult`.



##########
nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/filter/NumericComparisonFilter.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+package org.apache.nifi.record.path.filter;
+
+import org.apache.nifi.record.path.paths.RecordPathSegment;
+
+public abstract class NumericComparisonFilter extends NumericBinaryOperatorFilter {
+
+    public NumericComparisonFilter(final RecordPathSegment lhs, final RecordPathSegment rhs) {
+        super(lhs, rhs);
+    }
+
+    @Override
+    protected final boolean test(final Number lhsNumber, final Number rhsNumber) {
+        final int comparisonResult = isLongCompatible(lhsNumber) && isLongCompatible(rhsNumber)
+                ? Long.compare(lhsNumber.longValue(), rhsNumber.longValue())
+                : Double.compare(lhsNumber.doubleValue(), rhsNumber.doubleValue());
+
+        return verifyComparisonResult(comparisonResult);
+    }
+
+    protected abstract boolean verifyComparisonResult(final int comparisonResult);
+
+    private boolean isLongCompatible(final Number value) {

Review Comment:
   This check is duplicative of existing checks in the parent class, which already determines whether the numbers are compatible with the `Long` type.



-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] NIFI-14675 record path long handling improvements [nifi]

Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory commented on PR #10030:
URL: https://github.com/apache/nifi/pull/10030#issuecomment-2991694019

   Thanks for the latest update, I agree that the existing behavior of returning an `int` should be reserved when the number is within the range of an `Integer`.


-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] NIFI-14675 record path long handling improvements [nifi]

Posted by "awelless (via GitHub)" <gi...@apache.org>.
awelless commented on PR #10030:
URL: https://github.com/apache/nifi/pull/10030#issuecomment-2991695073

   @exceptionfactory.
   After reviewing the tests I decided to preserve the original behavior in `RecordPathCompiler`. Since these value can land into a record and impact a record schema, some processors downstream can, theoretically, expect the `INT` type specifically.
   
   So, a literal number is being saved as `long` only when it doesn't fit into `int`.


-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] NIFI-14675 record path long handling improvements [nifi]

Posted by "awelless (via GitHub)" <gi...@apache.org>.
awelless commented on code in PR #10030:
URL: https://github.com/apache/nifi/pull/10030#discussion_r2161121249


##########
nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/filter/NumericBinaryOperatorFilter.java:
##########
@@ -65,10 +65,10 @@ protected boolean test(final FieldValue fieldValue, final Object rhsValue) {
         }
 
         final String fieldName = fieldValue.getField() == null ? "<Anonymous Inner Field>" : fieldValue.getField().getFieldName();
-        final Number lhsNumber = lhsLongCompatible ? DataTypeUtils.toLong(value, fieldName) : DataTypeUtils.toDouble(value, fieldName);
-        final Number rhsNumber = rhsLongCompatible ? DataTypeUtils.toLong(rhsValue, fieldName) : DataTypeUtils.toDouble(rhsValue, fieldName);
-        return compare(lhsNumber, rhsNumber);
+        return lhsLongCompatible && rhsLongCompatible
+                ? test(DataTypeUtils.toLong(value, fieldName), DataTypeUtils.toLong(rhsValue, fieldName))
+                : test(DataTypeUtils.toDouble(value, fieldName), DataTypeUtils.toDouble(rhsValue, fieldName));
     }
 
-    protected abstract boolean compare(final Number lhsNumber, final Number rhsNumber);
+    protected abstract boolean test(final Number lhsNumber, final Number rhsNumber);

Review Comment:
   The concern was that not all subclasses of `NumericBinaryOperatorFilter` would care about the specific types. But since there are only comparison operators for now, we should be good with introducing 2 separate methods for longs and doubles.
   Changed.



-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] NIFI-14671 NIFI-14675 record path long handling improvements [nifi]

Posted by "awelless (via GitHub)" <gi...@apache.org>.
awelless commented on code in PR #10030:
URL: https://github.com/apache/nifi/pull/10030#discussion_r2158822362


##########
nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/filter/NumericBinaryOperatorFilter.java:
##########
@@ -65,10 +65,10 @@ protected boolean test(final FieldValue fieldValue, final Object rhsValue) {
         }
 
         final String fieldName = fieldValue.getField() == null ? "<Anonymous Inner Field>" : fieldValue.getField().getFieldName();
-        final Number lhsNumber = lhsLongCompatible ? DataTypeUtils.toLong(value, fieldName) : DataTypeUtils.toDouble(value, fieldName);

Review Comment:
   The result of this expression was always upcasted to`Double`, even when the first branch was chosen.
   To remediate this we should separate conversion to longs and doubles.



-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org