LucidDB / luciddb

DEFUNCT: See README
https://github.com/LucidDB/luciddb
Apache License 2.0
52 stars 24 forks source link

[FRG-44] Inserting a decimal that is has too many integral digits does not always give exception #826

Closed dynamobi-build closed 12 years ago

dynamobi-build commented 12 years ago

[reporter="schoi", created="Thu, 16 Feb 2006 11:29:09 -0500 (GMT-05:00)"] Repro:
----------
create schema s;
set schema 's';

-- this gives error, for all (P,S) < 19:

create table t1 (a decimal(1,1) primary key);
insert into t1 values(1);
-- > error. good.

-- this does not give error (only P=S=19):

create table t2 (a decimal(19,19) primary key);
insert into t2 values(1);

select * from t2;

--
-- +-------------------------+
-- | A |
-- +-------------------------+
-- | -0.8446744073709551616 |
-- +-------------------------+
--

dynamobi-build commented 12 years ago

[author="jpham", created="Thu, 16 Feb 2006 17:22:06 -0500 (GMT-05:00)"] I returned an error, though given the way the code is set up, it is hard
to return a localized error. 5489

dynamobi-build commented 12 years ago

[author="schoi", created="Fri, 17 Feb 2006 11:31:50 -0500 (GMT-05:00)"] With this change, i now get an error when i try to insert a decimal with 19 scale (but losing decimal digits should be okay)

CREATE TABLE FOO (x DECIMAL);
INSERT INTO FOO VALUES (0.1234567890123456789);
-- below used to return a row with x = 0, but now it gives error.
SELECT * FROM FOO;

Error: java.lang.UnsupportedOperationException: class java.lang.String: Could not rescale decimal to required scale (state=,code=0)


Also, not sure why the error message above is returned for the original description's decimal(19,19) table, but not for any of the others.

Here are the different exceptions:
-------------------------------------------------------------------------------------
create table t1 (a decimal(1,1) primary key);
insert into t1 values(1);

Error: could not calculate results for the following row:
[ 0 ]
Messages:
[0]:PC=6 Code=22003 (state=,code=0)


create table t2 (a decimal(19,19) primary key);
insert into t2 values(1);

Error: java.lang.UnsupportedOperationException: class java.lang.String: Could not rescale decimal to required scale (state=,code=0)

dynamobi-build commented 12 years ago

[author="jpham", created="Mon, 1 May 2006 11:58:23 -0500 (GMT-05:00)"] decimal(19,19) can now be inserted as of 6465
and should round the value to the nearest integer

the errors are different between inserting into
decimal(1,1) and decimal(19,19) because
conversion occurs in two steps:
  (1) rescale the value
  (2) check for overflow

we cant rescale decimal(1,0) to decimal(19,19)
because that would require multiplying by 10^19,
which we do not support. but you would be able
to rescale decimal(2,1) to decimal(19,19).

we can scale decimal(1,0) to decimal(1,1) but
we don't catch the error this causes until we
perform an overflow check. we should really
throw a validation error for this, since it causes
an overflow 100% of the time. but maybe we
can file another bug for that.