Changeset: 3724c13593dd for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=3724c13593dd
Modified Files:
        sql/backends/monet5/sql_result.c
        sql/server/sql_decimal.c
        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/pg_regress/Tests/numeric.stable.err
        sql/test/pg_regress/Tests/numeric.stable.out.int128
Branch: Oct2020-merged-Jun2020
Log Message:

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


diffs (200 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
@@ -1888,6 +1888,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
@@ -47,7 +47,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;
        }
 
@@ -57,10 +56,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-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/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