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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]