You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by ma...@apache.org on 2016/10/24 14:34:10 UTC

[4/4] nifi git commit: NIFI-1662 Adding proper UI regex support for decimals in EL

NIFI-1662 Adding proper UI regex support for decimals in EL

This closes #1018


Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/e4a3e096
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/e4a3e096
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/e4a3e096

Branch: refs/heads/master
Commit: e4a3e096432f43087c499d69bcbb4f2a013269a7
Parents: 557e0b9
Author: jpercivall <jo...@yahoo.com>
Authored: Wed Oct 19 14:29:28 2016 -0400
Committer: Matt Burgess <ma...@apache.org>
Committed: Mon Oct 24 10:31:16 2016 -0400

----------------------------------------------------------------------
 .../language/antlr/AttributeExpressionLexer.g    |  3 +--
 .../attribute/expression/language/TestQuery.java |  1 +
 .../main/asciidoc/expression-language-guide.adoc | 11 ++++++++---
 .../webapp/js/jquery/nfeditor/languages/nfel.js  | 19 ++++++++++++++++++-
 4 files changed, 28 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/e4a3e096/nifi-commons/nifi-expression-language/src/main/antlr3/org/apache/nifi/attribute/expression/language/antlr/AttributeExpressionLexer.g
----------------------------------------------------------------------
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 34ef48b..12704dd 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')+ ;
 

http://git-wip-us.apache.org/repos/asf/nifi/blob/e4a3e096/nifi-commons/nifi-expression-language/src/test/java/org/apache/nifi/attribute/expression/language/TestQuery.java
----------------------------------------------------------------------
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 01183ec..eee88f7 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

http://git-wip-us.apache.org/repos/asf/nifi/blob/e4a3e096/nifi-docs/src/main/asciidoc/expression-language-guide.adoc
----------------------------------------------------------------------
diff --git a/nifi-docs/src/main/asciidoc/expression-language-guide.adoc b/nifi-docs/src/main/asciidoc/expression-language-guide.adoc
index 75290f6..1f296f6 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 <<dates>> and <<type_cast>> 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: "<Day of Week> <Month> <Day of Month> <Hour>:<Minute>:<Second> <Time Zone> <Year>".
 	Also expressed as "E MMM dd HH:mm:ss z yyyy" in Java SimpleDateFormat format. For example: "Wed Dec 31 12:00:04 UTC 2016".
 - *Boolean*: A Boolean is one of either `true` or `false`.
 
-After evaluating expression language functions, all attributes are stored as of type String.
+After evaluating expression language functions, all attributes are stored as type String.
 
 The Expression Language is generally able to automatically coerce a value of one data type to the appropriate
 data type for a function. However, functions do exist to manually coerce a value into a specific data type.

http://git-wip-us.apache.org/repos/asf/nifi/blob/e4a3e096/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/jquery/nfeditor/languages/nfel.js
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/jquery/nfeditor/languages/nfel.js b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/jquery/nfeditor/languages/nfel.js
index a73003f..dc4cc68 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/jquery/nfeditor/languages/nfel.js
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/jquery/nfeditor/languages/nfel.js
@@ -658,7 +658,24 @@ nf.nfel = (function() {
                             }
 
                             return argumentStringResult;
-                        } else if (stream.match(/^[0-9]+/)) {
+                        } else if (stream.match(/^(([0-9]+\.[0-9]*)([eE][+-]?([0-9])+)?)|((\.[0-9]+)([eE][+-]?([0-9])+)?)|(([0-9]+)([eE][+-]?([0-9])+))/)) {
+                            // -------------
+                            // Decimal value
+                            // -------------
+                            // This matches the following ANTLR spec for deciamls
+                            //
+                            // DECIMAL :    ('0'..'9')+ '.' ('0'..'9')* EXP?    ^([0-9]+\.[0-9]*)([eE][+-]?([0-9])+)?
+                            //             | '.' ('0'..'9')+ EXP?
+                            //             | ('0'..'9')+ EXP;
+                            //
+                            // fragment EXP : ('e'|'E') ('+'|'-')? ('0'..'9')+ ;
+
+                            // change context back to arguments
+                            state.context = ARGUMENTS;
+
+                            // style for decimal (use same as number)
+                            return 'number';
+                        } else if (stream.match(/^-?[0-9]+/)) {
                             // -------------
                             // integer value
                             // -------------