From e4a3e096432f43087c499d69bcbb4f2a013269a7 Mon Sep 17 00:00:00 2001 From: jpercivall Date: Wed, 19 Oct 2016 14:29:28 -0400 Subject: [PATCH] NIFI-1662 Adding proper UI regex support for decimals in EL This closes #1018 --- .../language/antlr/AttributeExpressionLexer.g | 3 +-- .../expression/language/TestQuery.java | 1 + .../asciidoc/expression-language-guide.adoc | 11 ++++++++--- .../js/jquery/nfeditor/languages/nfel.js | 19 ++++++++++++++++++- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/nifi-commons/nifi-expression-language/src/main/antlr3/org/apache/nifi/attribute/expression/language/antlr/AttributeExpressionLexer.g b/nifi-commons/nifi-expression-language/src/main/antlr3/org/apache/nifi/attribute/expression/language/antlr/AttributeExpressionLexer.g index 34ef48be56..12704dd98e 100644 --- a/nifi-commons/nifi-expression-language/src/main/antlr3/org/apache/nifi/attribute/expression/language/antlr/AttributeExpressionLexer.g +++ b/nifi-commons/nifi-expression-language/src/main/antlr3/org/apache/nifi/attribute/expression/language/antlr/AttributeExpressionLexer.g @@ -81,8 +81,7 @@ WHOLE_NUMBER : ('0'..'9')+; DECIMAL : ('0'..'9')+ '.' ('0'..'9')* EXP? | '.' ('0'..'9')+ EXP? - | ('0'..'9')+ EXP - | ('0'..'9')+ ; + | ('0'..'9')+ EXP; fragment EXP : ('e'|'E') ('+'|'-')? ('0'..'9')+ ; diff --git a/nifi-commons/nifi-expression-language/src/test/java/org/apache/nifi/attribute/expression/language/TestQuery.java b/nifi-commons/nifi-expression-language/src/test/java/org/apache/nifi/attribute/expression/language/TestQuery.java index 01183eceb2..eee88f7a63 100644 --- a/nifi-commons/nifi-expression-language/src/test/java/org/apache/nifi/attribute/expression/language/TestQuery.java +++ b/nifi-commons/nifi-expression-language/src/test/java/org/apache/nifi/attribute/expression/language/TestQuery.java @@ -821,6 +821,7 @@ public class TestQuery { // The expected resulted is calculated instead of a set number due to the inaccuracy of double arithmetic verifyEquals("${literal(5):toNumber():multiply(${two:plus(1)})}", attributes, 5*3.2); + verifyEquals("${literal(5.5E-1):toDecimal():plus(${literal(.5E1)}):multiply(${two:plus(1)})}", attributes, (0.55+5)*3.2); } @Test diff --git a/nifi-docs/src/main/asciidoc/expression-language-guide.adoc b/nifi-docs/src/main/asciidoc/expression-language-guide.adoc index 75290f60a1..1f296f6802 100644 --- a/nifi-docs/src/main/asciidoc/expression-language-guide.adoc +++ b/nifi-docs/src/main/asciidoc/expression-language-guide.adoc @@ -194,15 +194,20 @@ Language supports four different data types: - *Decimal*: A Decimal is a numeric value that can support decimals and larger values with minimal loss of precision. More precisely it is a double-precision 64-bit IEEE 754 floating point. Due to this minimal loss of precision this data type should not be used for very precise values, such as currency. For more documentation on the range of values stored in this data type - refer to this https://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.2.3[link]. Decimals cannot be expressed as un-quoted characters - when inputting a literal Decimal to an Expression Language function. They must be input as Strings using quotes, like so: "1.1". + refer to this https://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.2.3[link]. The following are some examples of the forms of + literal decimals that are supported in expression language (the "E" can also be lower-case): + + * 1.1 + * .1E1 + * 1.11E-12 + - *Date*: A Date is an object that holds a Date and Time. Utilizing the <> and <> functions this data type can be converted to/from Strings and numbers. If the whole Expression Language expression is evaluated to be a date then it will be converted to a String with the format: " ::