From ca5f08fa7ab5e0e844c7d809d3778338958d160c Mon Sep 17 00:00:00 2001 From: Wade McEwen Date: Fri, 19 Feb 2016 11:45:00 -0600 Subject: [PATCH] API-3791 support exponent on decimals Something something scientific notation. --- lib/sparkql/token.rb | 2 +- test/unit/lexer_test.rb | 9 +++++++++ test/unit/parser_compatability_test.rb | 22 ++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/sparkql/token.rb b/lib/sparkql/token.rb index 7c9f94c..60df9fc 100644 --- a/lib/sparkql/token.rb +++ b/lib/sparkql/token.rb @@ -7,7 +7,7 @@ module Sparkql::Token STANDARD_FIELD = /[A-Z]+[A-Za-z0-9]*/ CUSTOM_FIELD = /^(\"([^$."][^."]+)\".\"([^$."][^."]*)\")/ INTEGER = /^\-?[0-9]+/ - DECIMAL = /^\-?[0-9]+\.[0-9]+/ + DECIMAL = /^\-?[0-9]+\.[0-9]+([Ee]-?[0-9]{1,2})?/ CHARACTER = /^'([^'\\]*(\\.[^'\\]*)*)'/ DATE = /^[0-9]{4}\-[0-9]{2}\-[0-9]{2}/ TIME = /^[0-9]{2}\:[0-9]{2}((\:[0-9]{2})(\.[0-9]{1,50})?)?/ diff --git a/test/unit/lexer_test.rb b/test/unit/lexer_test.rb index 0617341..a92a340 100644 --- a/test/unit/lexer_test.rb +++ b/test/unit/lexer_test.rb @@ -100,4 +100,13 @@ def test_utc_offsets assert_equal :DATETIME, token.first, op end end + + def test_decimal_matches + ['-15.42', '1.0', '0.22', '9.0E-6', '-9.0E-3'].each do |op| + @lexer = Lexer.new(op) + token = @lexer.shift + assert_equal :DECIMAL, token.first, op + end + end + end diff --git a/test/unit/parser_compatability_test.rb b/test/unit/parser_compatability_test.rb index bf06bb9..471c0ce 100644 --- a/test/unit/parser_compatability_test.rb +++ b/test/unit/parser_compatability_test.rb @@ -67,6 +67,21 @@ def setup :type => :decimal, :operator => "Eq" }, + { + :string => "FloatField Eq 9.1E-6", + :type => :decimal, + :operator => "Eq" + }, + { + :string => "FloatField Eq -9.1E-6", + :type => :decimal, + :operator => "Eq" + }, + { + :string => "FloatField Eq 1.0E8", + :type => :decimal, + :operator => "Eq" + }, { :string => "FloatField Eq -2001.120,-2002.0", :type => :decimal, @@ -468,6 +483,13 @@ def find_operator(string) assert_equal true, parser.escape_value(expressions.first) end + test "escape decimal values" do + parser = Parser.new + expressions = parser.tokenize( "DecimalField Eq 0.00005 And DecimalField Eq 5.0E-5" ) + assert_equal 5.0E-5, parser.escape_value(expressions.first) + assert_equal parser.escape_value(expressions.first), parser.escape_value(expressions.last) + end + test "Between" do ["BathsFull Bt 10,20", "DateField Bt 2012-12-31,2013-01-31"].each do |f| parser = Parser.new