You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "r1b (via GitHub)" <gi...@apache.org> on 2026/01/22 05:44:15 UTC

[PR] NIFI-15474 Support timestamp truncation in RecordPath DSL [nifi]

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

   <!-- 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-15474](https://issues.apache.org/jira/browse/NIFI-15474)
   
   # 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`
   - [x] Pull request contains [commits signed](https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits) with a registered key indicating `Verified` status
   
   ### Pull Request Formatting
   
   - [x] Pull Request based on current revision of the `main` branch
   - [x] 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
   
   - [x] Build completed using `./mvnw clean install -P contrib-check`
     - [x] JDK 21
     - [ ] JDK 25
   
   ### Licensing
   
   - [x] 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)
   - [x] New dependencies are documented in applicable `LICENSE` and `NOTICE` files
   
   ### Documentation
   
   - [x] 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-15474 Support timestamp truncation in RecordPath DSL [nifi]

Posted by "pvillard31 (via GitHub)" <gi...@apache.org>.
pvillard31 closed pull request #10796: NIFI-15474 Support timestamp truncation in RecordPath DSL
URL: https://github.com/apache/nifi/pull/10796


-- 
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-15474 Support timestamp truncation in RecordPath DSL [nifi]

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


##########
nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/math/MathDivideOperator.java:
##########
@@ -0,0 +1,34 @@
+/*
+ * 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.math;
+
+public class MathDivideOperator implements MathBinaryOperator {
+    @Override
+    public Long operate(Long n, Long m) {
+        return n / m;

Review Comment:
   ```suggestion
           if (m == 0L) {
               throw new ArithmeticException("Division by zero in RecordPath divide function");
           }
           return n / m;
   ```



##########
nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/math/MathDivideOperator.java:
##########
@@ -0,0 +1,34 @@
+/*
+ * 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.math;
+
+public class MathDivideOperator implements MathBinaryOperator {
+    @Override
+    public Long operate(Long n, Long m) {
+        return n / m;
+    }
+
+    @Override
+    public Double operate(Double n, Double m) {
+        return n / m;

Review Comment:
   ```suggestion
           if (m == 0.0) {
               throw new ArithmeticException("Division by zero in RecordPath divide function");
           }
           return n / m;
   ```



##########
nifi-commons/nifi-record-path/src/test/java/org/apache/nifi/record/path/TestRecordPath.java:
##########
@@ -3187,7 +3427,9 @@ private static Record createExampleRecord() {
                 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("longNumber", 1234567890123456789L)
+                entry("shortNumber", (short) 123),
+                entry("longNumber", 1234567890123456789L),
+                entry("floatNumber", 123.45)

Review Comment:
   ```suggestion
                   entry("floatNumber", 123.45f)
   ```



##########
nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/functions/Divide.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * 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.functions;
+
+import org.apache.nifi.record.path.FieldValue;
+import org.apache.nifi.record.path.RecordPathEvaluationContext;
+import org.apache.nifi.record.path.math.MathBinaryEvaluator;
+import org.apache.nifi.record.path.paths.RecordPathSegment;
+
+import java.util.stream.Stream;
+
+public class Divide extends RecordPathSegment {
+    private final RecordPathSegment lhsPath;
+    private final RecordPathSegment rhsPath;
+    private final MathBinaryEvaluator divide = MathBinaryEvaluator.divide();
+
+    public Divide(final RecordPathSegment lhsPath, final RecordPathSegment rhsPath, final boolean absolute) {
+        super("divide", null, absolute);
+        this.lhsPath = lhsPath;
+        this.rhsPath = rhsPath;
+    }
+
+    @Override
+    public Stream<FieldValue> evaluate(RecordPathEvaluationContext context) {
+        final FieldValue lhs = lhsPath.evaluate(context).findFirst().orElseThrow();
+        final FieldValue rhs = rhsPath.evaluate(context).findFirst().orElseThrow();

Review Comment:
   ```suggestion
           final FieldValue lhs = lhsPath.evaluate(context).findFirst()
               .orElseThrow(() -> new IllegalArgumentException("divide function requires a left-hand operand"));
           final FieldValue rhs = rhsPath.evaluate(context).findFirst()
               .orElseThrow(() -> new IllegalArgumentException("divide function requires a right-hand operand"));
   ```



##########
nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/functions/Multiply.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * 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.functions;
+
+import org.apache.nifi.record.path.FieldValue;
+import org.apache.nifi.record.path.RecordPathEvaluationContext;
+import org.apache.nifi.record.path.math.MathBinaryEvaluator;
+import org.apache.nifi.record.path.paths.RecordPathSegment;
+
+import java.util.stream.Stream;
+
+public class Multiply extends RecordPathSegment {
+    private final RecordPathSegment lhsPath;
+    private final RecordPathSegment rhsPath;
+    private final MathBinaryEvaluator multiply = MathBinaryEvaluator.multiply();
+
+    public Multiply(final RecordPathSegment lhsPath, final RecordPathSegment rhsPath, final boolean absolute) {
+        super("multiply", null, absolute);
+        this.lhsPath = lhsPath;
+        this.rhsPath = rhsPath;
+    }
+
+    @Override
+    public Stream<FieldValue> evaluate(RecordPathEvaluationContext context) {
+        final FieldValue lhs = lhsPath.evaluate(context).findFirst().orElseThrow();
+        final FieldValue rhs = rhsPath.evaluate(context).findFirst().orElseThrow();

Review Comment:
   ```suggestion
           final FieldValue lhs = lhsPath.evaluate(context).findFirst()
               .orElseThrow(() -> new IllegalArgumentException("multiply function requires a left-hand operand"));
           final FieldValue rhs = rhsPath.evaluate(context).findFirst()
               .orElseThrow(() -> new IllegalArgumentException("multiply function requires a right-hand operand"));
   ```



-- 
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-15474 Support timestamp truncation in RecordPath DSL [nifi]

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


##########
nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/functions/Divide.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * 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.functions;
+
+import org.apache.nifi.record.path.FieldValue;
+import org.apache.nifi.record.path.RecordPathEvaluationContext;
+import org.apache.nifi.record.path.math.MathBinaryEvaluator;
+import org.apache.nifi.record.path.paths.RecordPathSegment;
+
+import java.util.stream.Stream;
+
+public class Divide extends RecordPathSegment {
+    private final RecordPathSegment lhsPath;
+    private final RecordPathSegment rhsPath;
+    private final MathBinaryEvaluator divide = MathBinaryEvaluator.divide();
+
+    public Divide(final RecordPathSegment lhsPath, final RecordPathSegment rhsPath, final boolean absolute) {
+        super("divide", null, absolute);
+        this.lhsPath = lhsPath;
+        this.rhsPath = rhsPath;
+    }
+
+    @Override
+    public Stream<FieldValue> evaluate(RecordPathEvaluationContext context) {
+        final FieldValue lhs = lhsPath.evaluate(context).findFirst().orElseThrow();
+        final FieldValue rhs = rhsPath.evaluate(context).findFirst().orElseThrow();
+
+        if (lhs.getValue() == null || rhs.getValue() == null) {
+            return Stream.of();

Review Comment:
   Using `orElseThrow()` without a supplier throws `NoSuchElementException` with no message, making debugging difficult. Consider providing explicit error messages:
   
   ```suggestion
           final FieldValue lhs = lhsPath.evaluate(context).findFirst()
               .orElseThrow(() -> new IllegalArgumentException("divide function requires a left-hand operand"));
           final FieldValue rhs = rhsPath.evaluate(context).findFirst()
               .orElseThrow(() -> new IllegalArgumentException("divide function requires a right-hand operand"));
   ```



-- 
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-15474 Support timestamp truncation in RecordPath DSL [nifi]

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


##########
nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/functions/Divide.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * 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.functions;
+
+import org.apache.nifi.record.path.FieldValue;
+import org.apache.nifi.record.path.RecordPathEvaluationContext;
+import org.apache.nifi.record.path.math.MathBinaryEvaluator;
+import org.apache.nifi.record.path.paths.RecordPathSegment;
+
+import java.util.stream.Stream;
+
+public class Divide extends RecordPathSegment {
+    private final RecordPathSegment lhsPath;
+    private final RecordPathSegment rhsPath;
+    private final MathBinaryEvaluator divide = MathBinaryEvaluator.divide();
+
+    public Divide(final RecordPathSegment lhsPath, final RecordPathSegment rhsPath, final boolean absolute) {
+        super("divide", null, absolute);
+        this.lhsPath = lhsPath;
+        this.rhsPath = rhsPath;
+    }
+
+    @Override
+    public Stream<FieldValue> evaluate(RecordPathEvaluationContext context) {
+        final FieldValue lhs = lhsPath.evaluate(context).findFirst().orElseThrow();
+        final FieldValue rhs = rhsPath.evaluate(context).findFirst().orElseThrow();
+
+        if (lhs.getValue() == null || rhs.getValue() == null) {
+            return Stream.of();

Review Comment:
   Using `orElseThrow()` without a supplier throws `NoSuchElementException` with no message, making debugging difficult. Consider providing explicit error messages:
   
   ```suggestion
           final FieldValue lhs = lhsPath.evaluate(context).findFirst()
               .orElseThrow(() -> new IllegalArgumentException("divide function requires a left-hand operand"));
           final FieldValue rhs = rhsPath.evaluate(context).findFirst()
               .orElseThrow(() -> new IllegalArgumentException("divide function requires a right-hand operand"));
   ```



-- 
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-15474 Support timestamp truncation in RecordPath DSL [nifi]

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

   thanks @pvillard31 - I have applied the suggested changes with additional tests


-- 
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