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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to