Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Decimal edge case failure #3949

Open
acquamarin opened this issue Jul 26, 2024 · 3 comments · May be fixed by #3952
Open

Bug: Decimal edge case failure #3949

acquamarin opened this issue Jul 26, 2024 · 3 comments · May be fixed by #3952
Labels
bug Something isn't working

Comments

@acquamarin
Copy link
Collaborator

acquamarin commented Jul 26, 2024

Kùzu version

master

What operating system are you using?

macOS M1

What happened?

bug1.

kuzu> create node table person (id int64, a decimal (38,0), primary key(id));
kuzu> create (p:person {id: 2, a: 100000000000000000000000000000000000000.000000000000000000000000000000});
(0 tuples)
(0 columns)
Time: 0.21ms (compiling), 0.62ms (executing)
kuzu> match (p:person) return p.*;
┌───────┬────────────────────────────────────────┐
│ p.id  │ p.a                                    │
│ INT64 │ DECIMAL(38, 0)                         │
├───────┼────────────────────────────────────────┤
│ 5     │ 99999999999999999999999999999999999999 │
│ 2     │ 99999999999999997748809823456034029568 │
└───────┴────────────────────────────────────────┘

Should throw an exception since 100000000000000000000000000000000000000.000000000000000000000000000000 is out of range.

bug2.

kuzu> create (p:person {id: 22, a: -99999999999999999999999999999999999999.999999999999999999999999999999});
(0 tuples)
(0 columns)
Time: 0.34ms (compiling), 0.60ms (executing)
kuzu> match (p:person) return p.*;
┌───────┬─────────────────────────────────────────┐
│ p.id  │ p.a                                     │
│ INT64 │ DECIMAL(38, 0)                          │
├───────┼─────────────────────────────────────────┤
│ 5     │ 99999999999999999999999999999999999999  │
│ 2     │ 99999999999999997748809823456034029568  │
│ 22    │ -99999999999999997748809823456034029568 │
└───────┴─────────────────────────────────────────┘

should throw an exception as well

bug3.
incorrect result when adding decimal with double:
kuzu:

kuzu> return  cast(1 as decimal (32, 1)) + 9007199254740992.0000;
┌──────────────────────────────────────────────────────────────────┐
│ +(CAST(CAST(1, DECIMAL(32, 1)), DOUBLE),9007199254740992.000000) │
│ DOUBLE                                                           │
├──────────────────────────────────────────────────────────────────┤
│ 9007199254740992.000000                                          │
└──────────────────────────────────────────────────────────────────┘
(1 tuple)
(1 column)
Time: 0.07ms (compiling), 0.12ms (executing)

duckdb:

D select cast(1 as decimal (32, 1)) + 9007199254740992.0000;
┌────────────────────────────────────────────────────┐
│ (CAST(1 AS DECIMAL(32,1)) + 9007199254740992.0000) │
│                   decimal(36,4)                    │
├────────────────────────────────────────────────────┤
│                              9007199254740993.0000 │
└────────────────────────────────────────────────────┘

Are there known steps to reproduce?

No response

@acquamarin acquamarin added the bug Something isn't working label Jul 26, 2024
@mxwli
Copy link
Contributor

mxwli commented Jul 26, 2024

The crux of the problem here is that literals are still interpreted as DOUBLE, whereas in DuckDB, they're interpreted as DECIMAL.

In bug 1 and 2, the issue is that there is then floating point imprecision when you attempt to cast the doubles to decimals.

In bug 3, the only reason DuckDB gives the correct result is because the arithmetic is DECIMAL arithmetic.

select cast(1 as decimal (32, 1)) + 9007199254740992.0000::double;

Gives the same result we give.

@acquamarin
Copy link
Collaborator Author

The crux of the problem here is that literals are still interpreted as DOUBLE, whereas in DuckDB, they're interpreted as DECIMAL.
I think we should be smart about how we interpret those numbers.

@mxwli
Copy link
Contributor

mxwli commented Jul 29, 2024

Changing the default interpretation to decimal breaks a lot of things. I'm not sure where to interpret the number as a decimal in this case. Perhaps when it comes to inserting into something with a known schema, we should interpret literals as a string and then apply casting.

Edit: Xiyang told me this solution is really slow. We may have to delay this fix until after the release.

@ray6080 ray6080 mentioned this issue Jan 16, 2025
73 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants