Changeset: 4191e53d4a25 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=4191e53d4a25
Modified Files:
        sql/backends/monet5/sql_result.c
        sql/server/sql_decimal.c
        sql/test/BugTracker-2009/Tests/prepare_decimal_bug.SF-2831994.stable.out
        sql/test/BugTracker-2013/Tests/copy-into-decimal.Bug-3265.stable.out
        sql/test/BugTracker-2014/Tests/number_4_4.Bug-3543.stable.out
        sql/test/Tests/decimal2.stable.out
        sql/test/mapi/Tests/sql_dec38.stable.out.int128
        sql/test/mergetables/Tests/mergequery.stable.out
        sql/test/pg_regress/Tests/numeric.stable.err
        sql/test/pg_regress/Tests/numeric.stable.out.int128
Branch: Jun2020-decimals
Log Message:

Fixing decimals:
- Length must be based on output instead of input length.
- Fix test results.


diffs (255 lines):

diff --git a/sql/backends/monet5/sql_result.c b/sql/backends/monet5/sql_result.c
--- a/sql/backends/monet5/sql_result.c
+++ b/sql/backends/monet5/sql_result.c
@@ -2031,6 +2031,8 @@ get_print_width(int mtype, sql_class ecl
                count = 1 + digits;
                if (scale > 0)
                        count += 1;
+               if (scale == digits) // for preceding 0, e.g. 0.
+                       count += 1;
                return count;
        } else if (eclass == EC_DATE) {
                return 10;
diff --git a/sql/server/sql_decimal.c b/sql/server/sql_decimal.c
--- a/sql/server/sql_decimal.c
+++ b/sql/server/sql_decimal.c
@@ -61,7 +61,6 @@ decimal_from_str(char *dec, int* digits,
        if (*dec == '.') {  // case: (+|-).456
 fractional_sep_first_opp:
                dec++;
-               _digits++; // add one to digits for single implicit preceding 
0, e.g. (+|-)0.456
                goto trailing_digits;
        }
 
@@ -71,10 +70,17 @@ fractional_sep_first_opp:
                goto end_state;
        }
        while (*dec == '0'){
-               // skip leading zeros in preceding digits.
+               // skip leading zeros in preceding digits, e.g. '0004563.1234' 
=> '4563.1234'
                dec++;
-               if (*dec == '.')
+               if (*dec == '.') {
+                       if (dec[1] == 0) { // special case: '(0...0)0.'. We 
give this expression precision (1,0).
+                               _digits = 1;
+                               dec++;
+                               goto end_state;
+                       }
+
                        goto fractional_sep_first_opp;
+               }
        }
        for (; *dec && (isdigit((unsigned char) *dec)); dec++) {
                if (res > max0 || (res == max0 && *dec - '0' > max1))
diff --git 
a/sql/test/BugTracker-2009/Tests/prepare_decimal_bug.SF-2831994.stable.out 
b/sql/test/BugTracker-2009/Tests/prepare_decimal_bug.SF-2831994.stable.out
--- a/sql/test/BugTracker-2009/Tests/prepare_decimal_bug.SF-2831994.stable.out
+++ b/sql/test/BugTracker-2009/Tests/prepare_decimal_bug.SF-2831994.stable.out
@@ -38,7 +38,7 @@ stdout of test 'prepare_decimal_bug.SF-2
 % sys.test2831994,     sys.test2831994,        sys.test2831994 # table_name
 % id,  value,  value2 # name
 % bigint,      decimal,        decimal # type
-% 1,   7,      7 # length
+% 1,   8,      8 # length
 [ 3,   0.00000,        2.34000 ]
 
 # 19:40:00 >  
diff --git 
a/sql/test/BugTracker-2013/Tests/copy-into-decimal.Bug-3265.stable.out 
b/sql/test/BugTracker-2013/Tests/copy-into-decimal.Bug-3265.stable.out
--- a/sql/test/BugTracker-2013/Tests/copy-into-decimal.Bug-3265.stable.out
+++ b/sql/test/BugTracker-2013/Tests/copy-into-decimal.Bug-3265.stable.out
@@ -59,7 +59,7 @@ stdout of test 'copy-into-decimal.Bug-32
 % sys.test3265 # table_name
 % x # name
 % decimal # type
-% 11 # length
+% 12 # length
 [ 0.123456789  ]
 [ 0.123456789  ]
 #rollback;
diff --git a/sql/test/BugTracker-2014/Tests/number_4_4.Bug-3543.stable.out 
b/sql/test/BugTracker-2014/Tests/number_4_4.Bug-3543.stable.out
--- a/sql/test/BugTracker-2014/Tests/number_4_4.Bug-3543.stable.out
+++ b/sql/test/BugTracker-2014/Tests/number_4_4.Bug-3543.stable.out
@@ -35,7 +35,7 @@ stdout of test 'number_4_4.Bug-3543` in 
 % sys.fract_only,      sys.fract_only # table_name
 % id,  val # name
 % int, decimal # type
-% 1,   6 # length
+% 1,   7 # length
 [ 1,   -0.9999 ]
 [ 2,   0.9999  ]
 [ 3,   0.9999  ]
@@ -43,7 +43,7 @@ stdout of test 'number_4_4.Bug-3543` in 
 % sys.fract_only,      sys.fract_only # table_name
 % id,  val # name
 % int, decimal # type
-% 1,   6 # length
+% 1,   7 # length
 [ 1,   -0.9999 ]
 [ 2,   0.9999  ]
 [ 3,   0.9999  ]
@@ -51,7 +51,7 @@ stdout of test 'number_4_4.Bug-3543` in 
 % sys.fract_only,      sys.fract_only # table_name
 % id,  val # name
 % int, decimal # type
-% 1,   6 # length
+% 1,   7 # length
 [ 1,   -0.9999 ]
 [ 2,   0.9999  ]
 [ 3,   0.9999  ]
@@ -59,7 +59,7 @@ stdout of test 'number_4_4.Bug-3543` in 
 % sys.fract_only,      sys.fract_only # table_name
 % id,  val # name
 % int, decimal # type
-% 1,   6 # length
+% 1,   7 # length
 [ 1,   -0.9999 ]
 [ 2,   0.9999  ]
 [ 3,   0.9999  ]
diff --git a/sql/test/Tests/decimal2.stable.out 
b/sql/test/Tests/decimal2.stable.out
--- a/sql/test/Tests/decimal2.stable.out
+++ b/sql/test/Tests/decimal2.stable.out
@@ -33,25 +33,25 @@ stdout of test 'decimal2` in directory '
 % .%2 # table_name
 % %2 # name
 % decimal # type
-% 4 # length
+% 5 # length
 [ 0.01 ]
 #select .1;
 % .%2 # table_name
 % %2 # name
 % decimal # type
-% 3 # length
+% 4 # length
 [ 0.1  ]
 #select .10;
 % .%2 # table_name
 % %2 # name
 % decimal # type
-% 4 # length
+% 5 # length
 [ 0.10 ]
 #select 01.0;
 % .%2 # table_name
 % %2 # name
 % decimal # type
-% 5 # length
+% 4 # length
 [ 1.0  ]
 #select 10.0;
 % .%2 # table_name
diff --git a/sql/test/mapi/Tests/sql_dec38.stable.out.int128 
b/sql/test/mapi/Tests/sql_dec38.stable.out.int128
--- a/sql/test/mapi/Tests/sql_dec38.stable.out.int128
+++ b/sql/test/mapi/Tests/sql_dec38.stable.out.int128
@@ -31,7 +31,7 @@ stdout of test 'sql_dec38` in directory 
 % sys.sql_dec38,       sys.sql_dec38,  sys.sql_dec38 # table_name
 % d38_0,       d38_19, d38_38 # name
 % decimal,     decimal,        decimal # type
-% 39,  40,     40 # length
+% 39,  40,     41 # length
 [ 12345678901234567899876543210987654321,      
1234567890123456789.9876543210987654321,        
0.12345678901234567899876543210987654321        ]
 
 # 23:45:59 >  
diff --git a/sql/test/mergetables/Tests/mergequery.stable.out 
b/sql/test/mergetables/Tests/mergequery.stable.out
--- a/sql/test/mergetables/Tests/mergequery.stable.out
+++ b/sql/test/mergetables/Tests/mergequery.stable.out
@@ -88,7 +88,7 @@ stdout of test 'mergequery` in directory
 % mal # name
 % clob # type
 % 142 # length
-function user.s22_0():void;
+function user.s24_0():void;
     X_3:void := querylog.define("explain insert into answ\nselect * from 
complete where x>=1.0 and x <=2.0;":str, "default_pipe":str, 68:int);
 barrier X_247:bit := language.dataflow();
     X_81:bat[:dbl] := bat.new(nil:dbl);
@@ -169,7 +169,7 @@ exit X_247:bit;
     X_99:int := sql.append(X_96:int, "sys":str, "answ":str, "z":str, 
X_90:bat[:dbl]);
     X_101:lng := aggr.count(X_90:bat[:dbl]);
     sql.affectedRows(X_99:int, X_101:lng);
-end user.s22_0;
+end user.s24_0;
 #inline               actions= 0 time=1 usec 
 #remap                actions= 0 time=2 usec 
 #costmodel            actions= 1 time=1 usec 
@@ -207,7 +207,7 @@ end user.s22_0;
 % mal # name
 % clob # type
 % 164 # length
-function user.s24_0():void;
+function user.s26_0():void;
     X_5:void := querylog.define("explain insert into answ\nselect * from 
complete\nwhere x between 0 and 2 and y between 0 and 2;":str, 
"default_pipe":str, 78:int);
 barrier X_262:bit := language.dataflow();
     X_92:bat[:dbl] := bat.new(nil:dbl);
@@ -298,9 +298,9 @@ exit X_262:bit;
     X_110:int := sql.append(X_107:int, "sys":str, "answ":str, "z":str, 
X_101:bat[:dbl]);
     X_112:lng := aggr.count(X_101:bat[:dbl]);
     sql.affectedRows(X_110:int, X_112:lng);
-end user.s24_0;
-#inline               actions= 0 time=1 usec 
-#remap                actions= 0 time=2 usec 
+end user.s26_0;
+#inline               actions= 0 time=2 usec 
+#remap                actions= 0 time=3 usec 
 #costmodel            actions= 1 time=2 usec 
 #coercion             actions= 0 time=2 usec 
 #aliases              actions= 8 time=10 usec 
diff --git a/sql/test/pg_regress/Tests/numeric.stable.err 
b/sql/test/pg_regress/Tests/numeric.stable.err
--- a/sql/test/pg_regress/Tests/numeric.stable.err
+++ b/sql/test/pg_regress/Tests/numeric.stable.err
@@ -363,7 +363,11 @@ MAPI  = (monetdb) /var/tmp/mtest-30274/.
 QUERY = INSERT INTO num_input_test(n1) VALUES ('        nan');
 ERROR = !Decimal (        nan) doesn't have format (18.3)
 CODE  = 42000
-MAPI  = (monetdb) /var/tmp/mtest-30274/.s.monetdb.37685
+MAPI  = (monetdb) /var/tmp/mtest-12753/.s.monetdb.33817
+QUERY = INSERT INTO num_input_test(n1) VALUES ('     ');
+ERROR = !Decimal (     ) doesn't have format (18.3)
+CODE  = 42000
+MAPI  = (monetdb) /var/tmp/mtest-12753/.s.monetdb.33817
 QUERY = INSERT INTO num_input_test(n1) VALUES ('   1234   %');
 ERROR = !Decimal (   1234   %) doesn't have format (18.3)
 CODE  = 42000
@@ -383,7 +387,11 @@ MAPI  = (monetdb) /var/tmp/mtest-30274/.
 QUERY = INSERT INTO num_input_test(n1) VALUES ('5. 0   ');
 ERROR = !Decimal (5. 0   ) doesn't have format (18.3)
 CODE  = 42000
-MAPI  = (monetdb) /var/tmp/mtest-30274/.s.monetdb.37685
+MAPI  = (monetdb) /var/tmp/mtest-12753/.s.monetdb.33817
+QUERY = INSERT INTO num_input_test(n1) VALUES ('');
+ERROR = !Decimal () doesn't have format (18.3)
+CODE  = 42000
+MAPI  = (monetdb) /var/tmp/mtest-12753/.s.monetdb.33817
 QUERY = INSERT INTO num_input_test(n1) VALUES (' N aN ');
 ERROR = !Decimal ( N aN ) doesn't have format (18.3)
 CODE  = 42000
diff --git a/sql/test/pg_regress/Tests/numeric.stable.out.int128 
b/sql/test/pg_regress/Tests/numeric.stable.out.int128
--- a/sql/test/pg_regress/Tests/numeric.stable.out.int128
+++ b/sql/test/pg_regress/Tests/numeric.stable.out.int128
@@ -1219,7 +1219,7 @@ stdout of test 'numeric` in directory 's
 % sys.fract_only,      sys.fract_only # table_name
 % id,  val # name
 % int, decimal # type
-% 1,   6 # length
+% 1,   7 # length
 [ 1,   0.0000  ]
 [ 2,   0.1000  ]
 [ 4,   -0.9999 ]
@@ -1280,10 +1280,6 @@ stdout of test 'numeric` in directory 's
 [ 1    ]
 #INSERT INTO num_input_test(n1) VALUES ('-555.50');
 [ 1    ]
-#INSERT INTO num_input_test(n1) VALUES ('     ');
-[ 1    ]
-#INSERT INTO num_input_test(n1) VALUES ('');
-[ 1    ]
 #SELECT * FROM num_input_test;
 % sys.num_input_test # table_name
 % n1 # name
@@ -1294,8 +1290,6 @@ stdout of test 'numeric` in directory 's
 [ -93853.000   ]
 [ 555.500      ]
 [ -555.500     ]
-[ 0.000        ]
-[ 0.000        ]
 #DROP TABLE num_input_test;
 #DROP TABLE num_data;
 #DROP TABLE num_exp_add;
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to