This is an automated email from the ASF dual-hosted git repository.

exceptionfactory pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new d0c63ed736 NIFI-14675 Improved support for Long literals in Record 
Path (#10030)
d0c63ed736 is described below

commit d0c63ed7365045e597ee7f6e5dd5b3e420c97c4e
Author: Alaksiej Ščarbaty <[email protected]>
AuthorDate: Thu Jun 26 14:57:05 2025 +0200

    NIFI-14675 Improved support for Long literals in Record Path (#10030)
    
    Signed-off-by: David Handermann <[email protected]>
---
 .../nifi/record/path/filter/GreaterThanFilter.java |  6 +--
 .../path/filter/GreaterThanOrEqualFilter.java      |  6 +--
 .../nifi/record/path/filter/LessThanFilter.java    |  6 +--
 .../record/path/filter/LessThanOrEqualFilter.java  |  6 +--
 .../path/filter/NumericBinaryOperatorFilter.java   |  9 +++--
 ...hanFilter.java => NumericComparisonFilter.java} | 17 +++++----
 .../nifi/record/path/paths/RecordPathCompiler.java |  8 +++-
 .../apache/nifi/record/path/TestRecordPath.java    | 44 +++++++++++++++++++---
 8 files changed, 72 insertions(+), 30 deletions(-)

diff --git 
a/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/filter/GreaterThanFilter.java
 
b/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/filter/GreaterThanFilter.java
index 78215a44fc..4570f09f14 100644
--- 
a/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/filter/GreaterThanFilter.java
+++ 
b/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/filter/GreaterThanFilter.java
@@ -19,15 +19,15 @@ package org.apache.nifi.record.path.filter;
 
 import org.apache.nifi.record.path.paths.RecordPathSegment;
 
-public class GreaterThanFilter extends NumericBinaryOperatorFilter {
+public class GreaterThanFilter extends NumericComparisonFilter {
 
     public GreaterThanFilter(final RecordPathSegment lhs, final 
RecordPathSegment rhs) {
         super(lhs, rhs);
     }
 
     @Override
-    protected boolean compare(final Number lhsNumber, final Number rhsNumber) {
-        return Double.compare(lhsNumber.doubleValue(), 
rhsNumber.doubleValue()) > 0;
+    protected boolean verifyComparisonResult(final int comparisonResult) {
+        return comparisonResult > 0;
     }
 
     @Override
diff --git 
a/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/filter/GreaterThanOrEqualFilter.java
 
b/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/filter/GreaterThanOrEqualFilter.java
index 4276582a7b..7480a78577 100644
--- 
a/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/filter/GreaterThanOrEqualFilter.java
+++ 
b/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/filter/GreaterThanOrEqualFilter.java
@@ -19,15 +19,15 @@ package org.apache.nifi.record.path.filter;
 
 import org.apache.nifi.record.path.paths.RecordPathSegment;
 
-public class GreaterThanOrEqualFilter extends NumericBinaryOperatorFilter {
+public class GreaterThanOrEqualFilter extends NumericComparisonFilter {
 
     public GreaterThanOrEqualFilter(final RecordPathSegment lhs, final 
RecordPathSegment rhs) {
         super(lhs, rhs);
     }
 
     @Override
-    protected boolean compare(final Number lhsNumber, final Number rhsNumber) {
-        return Double.compare(lhsNumber.doubleValue(), 
rhsNumber.doubleValue()) >= 0;
+    protected boolean verifyComparisonResult(final int comparisonResult) {
+        return comparisonResult >= 0;
     }
 
     @Override
diff --git 
a/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/filter/LessThanFilter.java
 
b/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/filter/LessThanFilter.java
index 8485437a28..57220352ab 100644
--- 
a/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/filter/LessThanFilter.java
+++ 
b/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/filter/LessThanFilter.java
@@ -19,15 +19,15 @@ package org.apache.nifi.record.path.filter;
 
 import org.apache.nifi.record.path.paths.RecordPathSegment;
 
-public class LessThanFilter extends NumericBinaryOperatorFilter {
+public class LessThanFilter extends NumericComparisonFilter {
 
     public LessThanFilter(final RecordPathSegment lhs, final RecordPathSegment 
rhs) {
         super(lhs, rhs);
     }
 
     @Override
-    protected boolean compare(final Number lhsNumber, final Number rhsNumber) {
-        return Double.compare(lhsNumber.doubleValue(), 
rhsNumber.doubleValue()) < 0;
+    protected boolean verifyComparisonResult(final int comparisonResult) {
+        return comparisonResult < 0;
     }
 
     @Override
diff --git 
a/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/filter/LessThanOrEqualFilter.java
 
b/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/filter/LessThanOrEqualFilter.java
index cec9620649..b4ff482d86 100644
--- 
a/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/filter/LessThanOrEqualFilter.java
+++ 
b/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/filter/LessThanOrEqualFilter.java
@@ -19,15 +19,15 @@ package org.apache.nifi.record.path.filter;
 
 import org.apache.nifi.record.path.paths.RecordPathSegment;
 
-public class LessThanOrEqualFilter extends NumericBinaryOperatorFilter {
+public class LessThanOrEqualFilter extends NumericComparisonFilter {
 
     public LessThanOrEqualFilter(final RecordPathSegment lhs, final 
RecordPathSegment rhs) {
         super(lhs, rhs);
     }
 
     @Override
-    protected boolean compare(final Number lhsNumber, final Number rhsNumber) {
-        return Double.compare(lhsNumber.doubleValue(), 
rhsNumber.doubleValue()) <= 0;
+    protected boolean verifyComparisonResult(final int comparisonResult) {
+        return comparisonResult <= 0;
     }
 
     @Override
diff --git 
a/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/filter/NumericBinaryOperatorFilter.java
 
b/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/filter/NumericBinaryOperatorFilter.java
index f23fc5b31f..c13294f893 100644
--- 
a/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/filter/NumericBinaryOperatorFilter.java
+++ 
b/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/filter/NumericBinaryOperatorFilter.java
@@ -65,10 +65,11 @@ public abstract class NumericBinaryOperatorFilter extends 
BinaryOperatorFilter {
         }
 
         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 long lhsNumber, final long 
rhsNumber);
+    protected abstract boolean test(final double lhsNumber, final double 
rhsNumber);
 }
\ No newline at end of file
diff --git 
a/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/filter/GreaterThanFilter.java
 
b/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/filter/NumericComparisonFilter.java
similarity index 58%
copy from 
nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/filter/GreaterThanFilter.java
copy to 
nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/filter/NumericComparisonFilter.java
index 78215a44fc..455a2afaba 100644
--- 
a/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/filter/GreaterThanFilter.java
+++ 
b/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/filter/NumericComparisonFilter.java
@@ -14,24 +14,27 @@
  * 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 class GreaterThanFilter extends NumericBinaryOperatorFilter {
+public abstract class NumericComparisonFilter extends 
NumericBinaryOperatorFilter {
 
-    public GreaterThanFilter(final RecordPathSegment lhs, final 
RecordPathSegment rhs) {
+    public NumericComparisonFilter(final RecordPathSegment lhs, final 
RecordPathSegment rhs) {
         super(lhs, rhs);
     }
 
     @Override
-    protected boolean compare(final Number lhsNumber, final Number rhsNumber) {
-        return Double.compare(lhsNumber.doubleValue(), 
rhsNumber.doubleValue()) > 0;
+    protected final boolean test(final long lhsNumber, final long rhsNumber) {
+        final int comparisonResult = Long.compare(lhsNumber, rhsNumber);
+        return verifyComparisonResult(comparisonResult);
     }
 
     @Override
-    protected String getOperator() {
-        return ">";
+    protected final boolean test(final double lhsNumber, final double 
rhsNumber) {
+        final int comparisonResult = Double.compare(lhsNumber, rhsNumber);
+        return verifyComparisonResult(comparisonResult);
     }
+
+    protected abstract boolean verifyComparisonResult(final int 
comparisonResult);
 }
diff --git 
a/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/paths/RecordPathCompiler.java
 
b/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/paths/RecordPathCompiler.java
index a83eee6d9f..36e69442e4 100644
--- 
a/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/paths/RecordPathCompiler.java
+++ 
b/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/paths/RecordPathCompiler.java
@@ -219,7 +219,13 @@ public class RecordPathCompiler {
                 return new LiteralValuePath(parent, tree.getText(), absolute);
             }
             case NUMBER: {
-                return new LiteralValuePath(parent, 
Integer.parseInt(tree.getText()), absolute);
+                final long value = Long.parseLong(tree.getText());
+                if (value >= Integer.MIN_VALUE && value <= Integer.MAX_VALUE) {
+                    // Originally all numbers were treated as ints. Preserving 
this behavior for compatibility.
+                    return new LiteralValuePath(parent, (int) value, absolute);
+                }
+
+                return new LiteralValuePath(parent, value, absolute);
             }
             case PREDICATE: {
                 final Tree operatorTree = tree.getChild(0);
diff --git 
a/nifi-commons/nifi-record-path/src/test/java/org/apache/nifi/record/path/TestRecordPath.java
 
b/nifi-commons/nifi-record-path/src/test/java/org/apache/nifi/record/path/TestRecordPath.java
index 8205ef88cd..6c2fac85b6 100644
--- 
a/nifi-commons/nifi-record-path/src/test/java/org/apache/nifi/record/path/TestRecordPath.java
+++ 
b/nifi-commons/nifi-record-path/src/test/java/org/apache/nifi/record/path/TestRecordPath.java
@@ -2630,11 +2630,18 @@ public class TestRecordPath {
         @Nested
         class GreaterThan {
             @Test
-            public void supportsComparingWithLongCompatibleLiteralValues() {
+            public void supportsComparingWithIntCompatibleLiteralValues() {
                 assertMatches("/id[. > 47]", record);
                 assertNotMatches("/id[. > 48]", record);
             }
 
+            @Test
+            public void supportsComparingWithLongCompatibleLiteralValues() {
+                assertMatches("/longNumber[. > 1000000000000000000]", record);
+                assertMatches("/longNumber[. > 1234567890123456788]", record);
+                assertNotMatches("/longNumber[. > 1234567890123456789]", 
record);
+            }
+
             @Test
             public void supportsComparingWithLongCompatibleReference() {
                 record.setValue("numbers", new Integer[]{47, 48});
@@ -2665,11 +2672,19 @@ public class TestRecordPath {
         @Nested
         class GreaterThanOrEqual {
             @Test
-            public void supportsComparingWithLongCompatibleLiteralValues() {
+            public void supportsComparingWithIngCompatibleLiteralValues() {
                 assertMatches("/id[. >= 48]", record);
                 assertNotMatches("/id[. >= 49]", record);
             }
 
+            @Test
+            public void supportsComparingWithLongCompatibleLiteralValues() {
+                assertMatches("/longNumber[. >= 1234567890123456788]", record);
+                assertMatches("/longNumber[. >= 1234567890123456789]", record);
+                assertNotMatches("/longNumber[. >= 1234567890123456790]", 
record);
+                assertNotMatches("/longNumber[. >= 2000000000000000000]", 
record);
+            }
+
             @Test
             public void supportsComparingWithLongCompatibleReference() {
                 record.setValue("numbers", new Integer[]{48, 49});
@@ -2774,11 +2789,18 @@ public class TestRecordPath {
         @Nested
         class LessThan {
             @Test
-            public void supportsComparingWithLongCompatibleLiteralValues() {
+            public void supportsComparingWithIntCompatibleLiteralValues() {
                 assertMatches("/id[. < 49]", record);
                 assertNotMatches("/id[. < 48]", record);
             }
 
+            @Test
+            public void supportsComparingWithLongCompatibleLiteralValues() {
+                assertMatches("/longNumber[. < 2000000000000000000]", record);
+                assertMatches("/longNumber[. < 1234567890123456790]", record);
+                assertNotMatches("/longNumber[. < 1234567890123456789]", 
record);
+            }
+
             @Test
             public void supportsComparingWithLongCompatibleReference() {
                 record.setValue("numbers", new Integer[]{49, 48});
@@ -2809,11 +2831,19 @@ public class TestRecordPath {
         @Nested
         class LessThanOrEqual {
             @Test
-            public void supportsComparingWithLongCompatibleLiteralValues() {
+            public void supportsComparingWithIntCompatibleLiteralValues() {
                 assertMatches("/id[. <= 48]", record);
                 assertNotMatches("/id[. <= 47]", record);
             }
 
+            @Test
+            public void supportsComparingWithLongCompatibleLiteralValues() {
+                assertMatches("/longNumber[. <= 1234567890123456789]", record);
+                assertMatches("/longNumber[. <= 1234567890123456790]", record);
+                assertNotMatches("/longNumber[. <= 1234567890123456788]", 
record);
+                assertNotMatches("/longNumber[. <= 1000000000000000000]", 
record);
+            }
+
             @Test
             public void supportsComparingWithLongCompatibleReference() {
                 record.setValue("numbers", new Integer[]{48, 47});
@@ -3117,7 +3147,8 @@ public class TestRecordPath {
                 recordFieldOf("accounts", arrayTypeOf(accountDataType)),
                 recordFieldOf("numbers", arrayTypeOf(RecordFieldType.INT)),
                 recordFieldOf("friends", arrayTypeOf(RecordFieldType.STRING)),
-                recordFieldOf("bytes", arrayTypeOf(RecordFieldType.BYTE))
+                recordFieldOf("bytes", arrayTypeOf(RecordFieldType.BYTE)),
+                recordFieldOf("longNumber", RecordFieldType.LONG)
         );
     }
 
@@ -3155,7 +3186,8 @@ public class TestRecordPath {
                 }),
                 entry("numbers", new Integer[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}),
                 entry("friends", new String[]{"John", "Jane", "Jacob", 
"Judy"}),
-                entry("bytes", boxBytes("Hello 
World!".getBytes(StandardCharsets.UTF_8)))
+                entry("bytes", boxBytes("Hello 
World!".getBytes(StandardCharsets.UTF_8))),
+                entry("longNumber", 1234567890123456789L)
         );
 
         return new MapRecord(getExampleSchema(), new HashMap<>(values));

Reply via email to