Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

mattyb149
Copy link
Contributor

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:

  • Have you ensured that the full suite of tests is executed via mvn -Pcontrib-check clean install at the root nifi folder?
  • Have you written or updated unit tests to verify your changes?
  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?
  • If applicable, have you updated the LICENSE file, including the main LICENSE file under nifi-assembly?
  • If applicable, have you updated the NOTICE file, including the main NOTICE file found under nifi-assembly?
  • If adding new Properties, have you added .displayName in addition to .name (programmatic access) for each of the new properties?

For documentation related changes:

  • Have you ensured that format looks appropriate for the output in which it is rendered?

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.

@ijokarumawak
Copy link
Member

Thanks @mattyb149 for your quick fix!

Other numerical types use isNumberTypeCompatible method for compatibility check. Can we use that one for BigInt, too?

@ijokarumawak
Copy link
Member

@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;
        }
    }

@ijokarumawak
Copy link
Member

@mattyb149 just wanted to check. Are you still working on this? Thanks!

@mattyb149
Copy link
Contributor Author

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

ijokarumawak pushed a commit to ijokarumawak/nifi that referenced this pull request Mar 25, 2019
This closes apache#3371.

Signed-off-by: Koji Kawamura <ijokarumawak@apache.org>
@ijokarumawak
Copy link
Member

Ok, I submitted a PR to your branch. Please check it. I'm +1 with this PR once mine is merged too :)

mattyb149 and others added 2 commits March 26, 2019 10:38
Follow numeric type conversion convention used for other integral types.
@mattyb149
Copy link
Contributor Author

+1 LGTM, thanks for getting this across the finish line. Merging to master

@asfgit asfgit closed this in cae01d5 Mar 26, 2019
asfgit pushed a commit that referenced this pull request Apr 1, 2019
Follow numeric type conversion convention used for other integral types.

Signed-off-by: Matthew Burgess <mattyb149@apache.org>

This closes #3371
asfgit pushed a commit that referenced this pull request Apr 3, 2019
Follow numeric type conversion convention used for other integral types.

Signed-off-by: Matthew Burgess <mattyb149@apache.org>

This closes #3371
rwithers pushed a commit to rwithers/nifi that referenced this pull request May 3, 2019
Follow numeric type conversion convention used for other integral types.

Signed-off-by: Matthew Burgess <mattyb149@apache.org>

This closes apache#3371
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants