New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NIFI-6117: Fix BIGINT handling in DataTypeUtils #3371
Conversation
Thanks @mattyb149 for your quick fix! Other numerical types use isNumberTypeCompatible method for compatibility check. Can we use that one for BigInt, too? |
@mattyb149 In order to align with other numeric types, I suggest separating the existing isIntegral method like below. public static boolean isBigIntTypeCompatible(final Object value) {
return isNumberTypeCompatible(value, s -> isIntegral(s))
}
// We need something similar to isIntegral, but the value can be larger than the max long.
// So let's extract the String validation part like this.
private static boolean isIntegral(final String value) {
if (value == null || value.isEmpty()) {
return false;
}
int initialPosition = 0;
final char firstChar = value.charAt(0);
if (firstChar == '+' || firstChar == '-') {
initialPosition = 1;
if (value.length() == 1) {
return false;
}
}
for (int i = initialPosition; i < value.length(); i++) {
if (!Character.isDigit(value.charAt(i))) {
return false;
}
}
return true;
}
// This one works as is. But we can use the same isIntegral(String) part.
private static boolean isIntegral(final String value, final long minValue, final long maxValue) {
if (!isIntegral(value)) {
return false;
}
try {
final long longValue = Long.parseLong(value);
return longValue >= minValue && longValue <= maxValue;
} catch (final NumberFormatException nfe) {
// In case the value actually exceeds the max value of a Long
return false;
}
} |
@mattyb149 just wanted to check. Are you still working on this? Thanks! |
I want to finish this out but haven't had the time, I can try to incorporate your comments this week, or if you'd like to do so, I can patch and review/merge in place, totally up to you :) |
This closes apache#3371. Signed-off-by: Koji Kawamura <ijokarumawak@apache.org>
Ok, I submitted a PR to your branch. Please check it. I'm +1 with this PR once mine is merged too :) |
Follow numeric type conversion convention used for other integral types.
+1 LGTM, thanks for getting this across the finish line. Merging to master |
Follow numeric type conversion convention used for other integral types. Signed-off-by: Matthew Burgess <mattyb149@apache.org> This closes #3371
Follow numeric type conversion convention used for other integral types. Signed-off-by: Matthew Burgess <mattyb149@apache.org> This closes #3371
Follow numeric type conversion convention used for other integral types. Signed-off-by: Matthew Burgess <mattyb149@apache.org> This closes apache#3371
Thank you for submitting a contribution to Apache NiFi.
In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:
For all changes:
Is there a JIRA ticket associated with this PR? Is it referenced
in the commit message?
Does your PR title start with NIFI-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
Has your PR been rebased against the latest commit within the target branch (typically master)?
Is your initial contribution a single, squashed commit?
For code changes:
For documentation related changes:
Note:
Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.