You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by JPercivall <gi...@git.apache.org> on 2016/12/04 20:38:18 UTC

[GitHub] nifi pull request #1296: NIFI-3145 Rewriting double validation in NumberPars...

GitHub user JPercivall opened a pull request:

    https://github.com/apache/nifi/pull/1296

    NIFI-3145 Rewriting double validation in NumberParsing

    Adding more tests to TestQuery

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/JPercivall/nifi NIFI-3145

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/nifi/pull/1296.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1296
    
----
commit d5c6508e7bcf1ba1cbe48fee222e1092203d3b38
Author: jpercivall <jp...@apache.org>
Date:   2016-12-04T17:44:07Z

    NIFI-3145 Rewriting double validation in NumberParsing
    
    Adding more tests to TestQuery

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi issue #1296: NIFI-3145 Rewriting double validation in NumberParsing

Posted by JPercivall <gi...@git.apache.org>.
Github user JPercivall commented on the issue:

    https://github.com/apache/nifi/pull/1296
  
    @mattyb149 I just pushed out a new commit adding the "a-f" handling and tests for it.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1296: NIFI-3145 Rewriting double validation in NumberPars...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/nifi/pull/1296


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1296: NIFI-3145 Rewriting double validation in NumberPars...

Posted by mattyb149 <gi...@git.apache.org>.
Github user mattyb149 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1296#discussion_r90884772
  
    --- Diff: nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/util/NumberParsing.java ---
    @@ -21,54 +21,57 @@
     
     public class NumberParsing {
     
    -
         public static enum ParseResultType {
             NOT_NUMBER, WHOLE_NUMBER, DECIMAL;
         }
    -    private static final String Digits     = "(\\p{Digit}+)";
    -
    -    // Double regex according to Oracle documentation: http://docs.oracle.com/javase/6/docs/api/java/lang/Double.html#valueOf%28java.lang.String%29
    -    private static final String HexDigits  = "(\\p{XDigit}+)";
    -    // an exponent is 'e' or 'E' followed by an optionally
    -    // signed decimal integer.
    -    private static final String Exp        = "[eE][+-]?"+Digits;
    -    private static final String fpRegex    =
    -            ("[\\x00-\\x20]*"+  // Optional leading "whitespace"
    -                    "[+-]?(" + // Optional sign character
    -                    "NaN|" +           // "NaN" string
    -                    "Infinity|" +      // "Infinity" string
    -
    -                    // A decimal floating-point string representing a finite positive
    -                    // number without a leading sign has at most five basic pieces:
    -                    // Digits . Digits ExponentPart FloatTypeSuffix
    -                    //
    -                    // Since this method allows integer-only strings as input
    -                    // in addition to strings of floating-point literals, the
    -                    // two sub-patterns below are simplifications of the grammar
    -                    // productions from the Java Language Specification, 2nd
    -                    // edition, section 3.10.2.
    -
    -                    // Digits ._opt Digits_opt ExponentPart_opt FloatTypeSuffix_opt
    -                    "((("+Digits+"(\\.)?("+Digits+"?)("+Exp+")?)|"+
    -
    -                    // . Digits ExponentPart_opt FloatTypeSuffix_opt
    -                    "(\\.("+Digits+")("+Exp+")?)|"+
    -
    -                    // Hexadecimal strings
    -                    "((" +
    -                    // 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt
    -                    "(0[xX]" + HexDigits + "(\\.)?)|" +
    -
    -                    // 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt
    -                    "(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" +
    -
    -                    ")[pP][+-]?" + Digits + "))" +
    -                    "[fFdD]?))" +
    -                    "[\\x00-\\x20]*");// Optional trailing "whitespace"
    -
    -    private static final Pattern DOUBLE_PATTERN = Pattern.compile(fpRegex);
    -
    -    private static final Pattern NUMBER_PATTERN = Pattern.compile("-?((\\d+)|(0[xX]" + HexDigits + "))");
    +    private static final String OptionalSign  = "[\\-\\+]?";
    +
    +    private static final String Infinity = "(Infinity)";
    +    private static final String NotANumber = "(NaN)";
    +
    +    // Base 10
    +    private static final String Base10Digits  = "\\d+";
    +    private static final String Base10Decimal  = "\\." + Base10Digits;
    +    private static final String OptionalBase10Decimal  = Base10Decimal + "?";
    +
    +    private static final String Base10Exponent      = "[eE]" + OptionalSign + Base10Digits;
    +    private static final String OptionalBase10Exponent = "(" + Base10Exponent + ")?";
    +
    +    // Hex
    +    private static final String HexIdentifier = "0[xX]";
    +
    +    private static final String HexDigits     = "[0-9A-F]+";
    --- End diff --
    
    Hex digits should accept lowercase values as well


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1296: NIFI-3145 Rewriting double validation in NumberPars...

Posted by mattyb149 <gi...@git.apache.org>.
Github user mattyb149 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1296#discussion_r90889705
  
    --- Diff: nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/util/NumberParsing.java ---
    @@ -21,54 +21,57 @@
     
     public class NumberParsing {
     
    -
         public static enum ParseResultType {
             NOT_NUMBER, WHOLE_NUMBER, DECIMAL;
         }
    -    private static final String Digits     = "(\\p{Digit}+)";
    -
    -    // Double regex according to Oracle documentation: http://docs.oracle.com/javase/6/docs/api/java/lang/Double.html#valueOf%28java.lang.String%29
    -    private static final String HexDigits  = "(\\p{XDigit}+)";
    -    // an exponent is 'e' or 'E' followed by an optionally
    -    // signed decimal integer.
    -    private static final String Exp        = "[eE][+-]?"+Digits;
    -    private static final String fpRegex    =
    -            ("[\\x00-\\x20]*"+  // Optional leading "whitespace"
    -                    "[+-]?(" + // Optional sign character
    -                    "NaN|" +           // "NaN" string
    -                    "Infinity|" +      // "Infinity" string
    -
    -                    // A decimal floating-point string representing a finite positive
    -                    // number without a leading sign has at most five basic pieces:
    -                    // Digits . Digits ExponentPart FloatTypeSuffix
    -                    //
    -                    // Since this method allows integer-only strings as input
    -                    // in addition to strings of floating-point literals, the
    -                    // two sub-patterns below are simplifications of the grammar
    -                    // productions from the Java Language Specification, 2nd
    -                    // edition, section 3.10.2.
    -
    -                    // Digits ._opt Digits_opt ExponentPart_opt FloatTypeSuffix_opt
    -                    "((("+Digits+"(\\.)?("+Digits+"?)("+Exp+")?)|"+
    -
    -                    // . Digits ExponentPart_opt FloatTypeSuffix_opt
    -                    "(\\.("+Digits+")("+Exp+")?)|"+
    -
    -                    // Hexadecimal strings
    -                    "((" +
    -                    // 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt
    -                    "(0[xX]" + HexDigits + "(\\.)?)|" +
    -
    -                    // 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt
    -                    "(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" +
    -
    -                    ")[pP][+-]?" + Digits + "))" +
    -                    "[fFdD]?))" +
    -                    "[\\x00-\\x20]*");// Optional trailing "whitespace"
    -
    -    private static final Pattern DOUBLE_PATTERN = Pattern.compile(fpRegex);
    -
    -    private static final Pattern NUMBER_PATTERN = Pattern.compile("-?((\\d+)|(0[xX]" + HexDigits + "))");
    +    private static final String OptionalSign  = "[\\-\\+]?";
    +
    +    private static final String Infinity = "(Infinity)";
    --- End diff --
    
    Ah, I see it's only for the regex, not an actual token. I take that back :)  However in the future we may want to consider using the lexer/parser classes (invoking a lower-level rule) so we don't have multiple ways of recognizing the elements.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi issue #1296: NIFI-3145 Rewriting double validation in NumberParsing

Posted by mattyb149 <gi...@git.apache.org>.
Github user mattyb149 commented on the issue:

    https://github.com/apache/nifi/pull/1296
  
    Reviewing...


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi issue #1296: NIFI-3145 Rewriting double validation in NumberParsing

Posted by mattyb149 <gi...@git.apache.org>.
Github user mattyb149 commented on the issue:

    https://github.com/apache/nifi/pull/1296
  
    +1 LGTM, tested various double representations and operations. Thank you! Merging to master


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---