Changeset: 6bfbf16160a6 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=6bfbf16160a6
Modified Files:
sql/common/sql_types.c
sql/test/BugTracker-2014/Tests/round-properties.Bug-3515.stable.out
sql/test/BugTracker-2014/Tests/round.Bug-3542.stable.out.int128
sql/test/Tests/round.stable.out
sql/test/pg_regress/Tests/numeric.stable.err
sql/test/pg_regress/Tests/numeric.stable.out.int128
Branch: Jul2017
Log Message:
Implement special case for round(): result has type of first argument.
diffs (264 lines):
diff --git a/sql/common/sql_types.c b/sql/common/sql_types.c
--- a/sql/common/sql_types.c
+++ b/sql/common/sql_types.c
@@ -643,14 +643,25 @@ sql_dup_subfunc(sql_allocator *sa, sql_f
} else if (IS_FUNC(f) || IS_UNION(f) || IS_ANALYTIC(f)) { /* not needed
for PROC */
unsigned int mscale = 0, mdigits = 0;
- if (ops) for (tn = ops->h; tn; tn = tn->next) {
- sql_subtype *a = tn->data;
+ if (ops) {
+ if (ops->h && ops->h->data && f->imp &&
+ strcmp(f->imp, "round") == 0) {
+ /* special case for round(): result is
+ * same type as first argument */
+ sql_subtype *a = ops->h->data;
+ mscale = a->scale;
+ mdigits = a->digits;
+ } else {
+ for (tn = ops->h; tn; tn = tn->next) {
+ sql_subtype *a = tn->data;
- /* same scale as the input */
- if (a && a->scale > mscale)
- mscale = a->scale;
- if (a && f->fix_scale == INOUT)
- mdigits = a->digits;
+ /* same scale as the input */
+ if (a && a->scale > mscale)
+ mscale = a->scale;
+ if (a && f->fix_scale == INOUT)
+ mdigits = a->digits;
+ }
+ }
}
if (!member) {
diff --git
a/sql/test/BugTracker-2014/Tests/round-properties.Bug-3515.stable.out
b/sql/test/BugTracker-2014/Tests/round-properties.Bug-3515.stable.out
--- a/sql/test/BugTracker-2014/Tests/round-properties.Bug-3515.stable.out
+++ b/sql/test/BugTracker-2014/Tests/round-properties.Bug-3515.stable.out
@@ -63,7 +63,7 @@ Ready.
% sys.ceil_floor_round, sys.L3 # table_name
% a, L3 # name
% decimal, decimal # type
-% 20, 10 # length
+% 20, 20 # length
[ -5.500, -6.000 ]
[ -5.499, -5.000 ]
[ 0.000, 0.000 ]
diff --git a/sql/test/BugTracker-2014/Tests/round.Bug-3542.stable.out.int128
b/sql/test/BugTracker-2014/Tests/round.Bug-3542.stable.out.int128
--- a/sql/test/BugTracker-2014/Tests/round.Bug-3542.stable.out.int128
+++ b/sql/test/BugTracker-2014/Tests/round.Bug-3542.stable.out.int128
@@ -50,7 +50,7 @@ Ready.
% sys.t1, sys.t2, sys.L4 # table_name
% id, id, L4 # name
% int, int, decimal # type
-% 1, 1, 7 # length
+% 1, 1, 38 # length
[ 1, 1, 0.00000000000000000000 ]
[ 1, 2, 0.00000000000000000000 ]
[ 2, 1, 0.00000000000000000000 ]
diff --git a/sql/test/Tests/round.stable.out b/sql/test/Tests/round.stable.out
--- a/sql/test/Tests/round.stable.out
+++ b/sql/test/Tests/round.stable.out
@@ -28,31 +28,31 @@ Ready.
% .L2, .L4, .L6, .L10 # table_name
% L2, L4, L6, L10 # name
% decimal, decimal, decimal, decimal # type
-% 3, 4, 4, 5 # length
+% 7, 7, 7, 7 # length
[ 750.00, 700.00, 1000.00, 0.00 ]
#SELECT ROUND(123.9994, 3),ROUND(123.9995, 3);
% .L2, .L4 # table_name
% L2, L4 # name
% decimal, decimal # type
-% 4, 4 # length
+% 9, 9 # length
[ 123.9990, 124.0000 ]
#SELECT ROUND(123.4545, 2);
% .L2 # table_name
% L2 # name
% decimal # type
-% 4 # length
+% 9 # length
[ 123.4500 ]
#SELECT ROUND(123.45, -2);
% .L2 # table_name
% L2 # name
% decimal # type
-% 4 # length
+% 7 # length
[ 100.00 ]
#SELECT ROUND(150.75, 0);
% .L2 # table_name
% L2 # name
% decimal # type
-% 10 # length
+% 7 # length
[ 151.00 ]
# 15:17:10 >
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
@@ -108,31 +108,7 @@ ERROR = !decimal (NaN) doesn't have form
MAPI = (monetdb) /var/tmp/mtest-31608/.s.monetdb.31061
QUERY = INSERT INTO num_exp_power_10_ln VALUES (1,'NaN');
ERROR = !decimal (NaN) doesn't have format (38.19)
-MAPI = (monetdb) /var/tmp/mtest-31608/.s.monetdb.31061
-QUERY = SELECT t1.id1, t1.id2, t1.result, round(t2.expected, 20) as expected
- FROM num_result t1, num_exp_add t2
- WHERE t1.id1 = t2.id1 AND t1.id2 = t2.id2
- AND t1.result <> round(t2.expected, 20);
-ERROR = !value (-343384922153970470000000000) exceeds limits of type int
-MAPI = (monetdb) /var/tmp/mtest-31608/.s.monetdb.31061
-QUERY = SELECT t1.id1, t1.id2, t1.result, round(t2.expected, 40) as expected
- FROM num_result t1, num_exp_sub t2
- WHERE t1.id1 = t2.id1 AND t1.id2 = t2.id2
- AND t1.result <> round(t2.expected, 40);
-ERROR = !value (343384922153970470000000000) exceeds limits of type int
-MAPI = (monetdb) /var/tmp/mtest-31769/.s.monetdb.32802
-QUERY = SELECT t1.id1, t1.id2, t1.result, round(t2.expected, 30) as expected
- FROM num_result t1, num_exp_mul t2
- WHERE t1.id1 = t2.id1 AND t1.id2 = t2.id2
- AND t1.result <> round(t2.expected, 30);
-ERROR = !value (11791320476268835968621358563202090) exceeds limits of type int
-MAPI = (monetdb) /var/tmp/mtest-31769/.s.monetdb.32802
-QUERY = SELECT t1.id1, t1.id2, t1.result, round(t2.expected, 80) as expected
- FROM num_result t1, num_exp_div t2
- WHERE t1.id1 = t2.id1 AND t1.id2 = t2.id2
- AND t1.result <> round(t2.expected, 80);
-ERROR = !value (10000000000000000000) exceeds limits of type int
-MAPI = (monetdb) /var/tmp/mtest-31769/.s.monetdb.32802
+MAPI = (monetdb) /var/tmp/mtest-30227/.s.monetdb.36405
QUERY = SELECT STDDEV(val) FROM num_data;
ERROR = !SELECT: no such unary operator 'stddev(decimal)'
MAPI = (monetdb) /var/tmp/mtest-27483/.s.monetdb.35395
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
@@ -909,6 +909,14 @@ Ready.
#INSERT INTO num_result SELECT t1.id, t2.id, round(t1.val + t2.val, 20)
# FROM num_data t1, num_data t2;
[ 100 ]
+#SELECT t1.id1, t1.id2, t1.result, round(t2.expected, 20) as expected
+# FROM num_result t1, num_exp_add t2
+# WHERE t1.id1 = t2.id1 AND t1.id2 = t2.id2
+# AND t1.result <> round(t2.expected, 20);
+% sys.t1, sys.t1, sys.t1, sys.L5 # table_name
+% id1, id2, result, expected # name
+% int, int, decimal, decimal # type
+% 1, 1, 40, 40 # length
#DELETE FROM num_result;
[ 100 ]
#INSERT INTO num_result SELECT t1.id, t2.id, t1.val - t2.val
@@ -927,6 +935,14 @@ Ready.
#INSERT INTO num_result SELECT t1.id, t2.id, round(t1.val - t2.val, 40)
# FROM num_data t1, num_data t2;
[ 100 ]
+#SELECT t1.id1, t1.id2, t1.result, round(t2.expected, 40) as expected
+# FROM num_result t1, num_exp_sub t2
+# WHERE t1.id1 = t2.id1 AND t1.id2 = t2.id2
+# AND t1.result <> round(t2.expected, 40);
+% sys.t1, sys.t1, sys.t1, sys.L5 # table_name
+% id1, id2, result, expected # name
+% int, int, decimal, decimal # type
+% 1, 1, 40, 40 # length
#DELETE FROM num_result;
[ 100 ]
#INSERT INTO num_result SELECT t1.id, t2.id, t1.val * t2.val
@@ -945,6 +961,14 @@ Ready.
#INSERT INTO num_result SELECT t1.id, t2.id, round(t1.val * t2.val, 30)
# FROM num_data t1, num_data t2 ORDER BY 1, 2;
[ 100 ]
+#SELECT t1.id1, t1.id2, t1.result, round(t2.expected, 30) as expected
+# FROM num_result t1, num_exp_mul t2
+# WHERE t1.id1 = t2.id1 AND t1.id2 = t2.id2
+# AND t1.result <> round(t2.expected, 30);
+% sys.t1, sys.t1, sys.t1, sys.L5 # table_name
+% id1, id2, result, expected # name
+% int, int, decimal, decimal # type
+% 1, 1, 40, 40 # length
#DELETE FROM num_result;
[ 100 ]
#INSERT INTO num_result SELECT t1.id, t2.id, t1.val / t2.val
@@ -1022,6 +1046,70 @@ Ready.
# FROM num_data t1, num_data t2
# WHERE t2.val <> '0.0';
[ 80 ]
+#SELECT t1.id1, t1.id2, t1.result, round(t2.expected, 80) as expected
+# FROM num_result t1, num_exp_div t2
+# WHERE t1.id1 = t2.id1 AND t1.id2 = t2.id2
+# AND t1.result <> round(t2.expected, 80);
+% sys.t1, sys.t1, sys.t1, sys.L5 # table_name
+% id1, id2, result, expected # name
+% int, int, decimal, decimal # type
+% 1, 1, 40, 40 # length
+[ 2, 3, -7967167.5673775050000000000, -7967167.5673775051044083527
]
+[ 2, 4, -4.4026748000000000000, -4.4026748004683011669 ]
+[ 2, 5, -2094.1886691450000000000, -2094.1886691456353549643
]
+[ 2, 6, -365.6859989140000000000, -365.6859989147976644094
]
+[ 2, 7, 0.4135748370000000000, 0.4135748377848523552 ]
+[ 2, 8, -458.5741672170000000000, -458.5741672172787088848
]
+[ 2, 9, 1.3775729990000000000, 1.3775729994643893181 ]
+[ 3, 2, -0.0000001250000000000, -0.0000001255151208435 ]
+[ 3, 4, 0.0000005520000000000, 0.0000005526022596155 ]
+[ 3, 5, 0.0002628520000000000, 0.0002628523438769550 ]
+[ 3, 6, 0.0000458990000000000, 0.0000458991223445760 ]
+[ 3, 7, -0.0000000510000000000, -0.0000000519098957424 ]
+[ 3, 8, 0.0000575570000000000, 0.0000575579920139955 ]
+[ 3, 9, -0.0000001720000000000, -0.0000001729062414985 ]
+[ 4, 2, -0.2271346500000000000, -0.2271346500299392039 ]
+[ 4, 3, 1809619.8171461710000000000, 1809619.8171461716937354988
]
+[ 4, 5, 475.6628104630000000000, 475.6628104630580268606 ]
+[ 4, 6, 83.0599613840000000000, 83.0599613843612949961 ]
+[ 4, 7, -0.0939371760000000000, -0.0939371760414513164 ]
+[ 4, 8, 104.1580829830000000000, 104.1580829836674189714 ]
+[ 4, 9, -0.3128945610000000000, -0.3128945611240376941 ]
+[ 5, 2, -0.0004775110000000000, -0.0004775118950519245 ]
+[ 5, 3, 3804.4172832940000000000, 3804.4172832946635730858
]
+[ 5, 4, 0.0021023290000000000, 0.0021023295872689719 ]
+[ 5, 6, 0.1746194140000000000, 0.1746194143357610269 ]
+[ 5, 7, -0.0001974860000000000, -0.0001974869045364371 ]
+[ 5, 8, 0.2189746190000000000, 0.2189746196097808523 ]
+[ 5, 9, -0.0006578070000000000, -0.0006578074935466043 ]
+[ 6, 2, -0.0027345860000000000, -0.0027345865112899582 ]
+[ 6, 3, 21786.9089629370000000000, 21786.9089629373549883991
]
+[ 6, 4, 0.0120394950000000000, 0.0120394951229568247 ]
+[ 6, 5, 5.7267400860000000000, 5.7267400867419235968 ]
+[ 6, 7, -0.0011309560000000000, -0.0011309561728153898 ]
+[ 6, 8, 1.2540107320000000000, 1.2540107320983961218 ]
+[ 6, 9, -0.0037670920000000000, -0.0037670925426525679 ]
+[ 7, 2, 2.4179420710000000000, 2.4179420715150338570 ]
+[ 7, 3, -19264149.6519721570000000000, -19264149.6519721577726218097
]
+[ 7, 4, -10.6454126270000000000, -10.6454126272513624769 ]
+[ 7, 5, -5063.6268888170000000000, -5063.6268888173094183657
]
+[ 7, 6, -884.2075617400000000000, -884.2075617400902877029
]
+[ 7, 8, -1108.8057718240000000000, -1108.8057718246284104112
]
+[ 7, 9, 3.3308917110000000000, 3.3308917119881041338 ]
+[ 8, 2, -0.0021806720000000000, -0.0021806723350078862 ]
+[ 8, 3, 17373.7819025520000000000, 17373.7819025522041763341
]
+[ 8, 4, 0.0096007910000000000, 0.0096007911374175896 ]
+[ 8, 5, 4.5667392950000000000, 4.5667392950928701946 ]
+[ 8, 6, 0.7974413410000000000, 0.7974413411332231442 ]
+[ 8, 7, -0.0009018710000000000, -0.0009018712072128017 ]
+[ 8, 9, -0.0030040350000000000, -0.0030040353293858274 ]
+[ 9, 2, 0.7259143430000000000, 0.7259143438415296153 ]
+[ 9, 3, -5783481.2169483570000000000, -5783481.2169483573085846868
]
+[ 9, 4, -3.1959647880000000000, -3.1959647889295841648 ]
+[ 9, 5, -1520.2015936430000000000, -1520.2015936432200450581
]
+[ 9, 6, -265.4567119540000000000, -265.4567119542696575128
]
+[ 9, 7, 0.3002199060000000000, 0.3002199069999581469 ]
+[ 9, 8, -332.8855656980000000000, -332.8855656982067547175
]
#DELETE FROM num_result;
[ 80 ]
#INSERT INTO num_result SELECT id, 0, SQRT(ABS(val))
@@ -1171,7 +1259,7 @@ Ready.
% sys.ceil_floor_round, sys.L3 # table_name
% a, L3 # name
% decimal, decimal # type
-% 20, 10 # length
+% 20, 20 # length
[ -5.500, -6.000 ]
[ -5.500, -6.000 ]
[ 9.500, 10.000 ]
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list