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
Add get_decimal() #177
Add get_decimal() #177
Conversation
Get cassadra decimal value as BigDecimal (https://docs.rs/bigdecimal/latest/bigdecimal/) Signed-off-by: Marian Marencik <github@marianm.net>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Signed-off-by: Marian Marencik github@marianm.net
af329cc
to
ad5484b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @M5135213521asd3 , this looks good. Just a couple of things:
- Please can you ensure you return the actual error, rather than a fixed one.
- I think this must be missing the code to supply a decimal value to Cassandra (i.e., bind). Please can you add that?
- Please can you add a decimal test in all the relevant places, to
tests/basic.rs
? Use a value that requires multiple bytes and a non-zero scale, so that the code is properly exercised. - Please can you also add a specific test for endianness (to the same file), which uses a literal CQL statement to write a decimal value (e.g.,
INSERT INTO blah ... VALUES (99999.1234)
), and then uses get_decimal to retrieve it and checks it gets the right value?
Thanks!
44be3a7
to
ad5484b
Compare
Signed-off-by: Marian Marencik github@marianm.net
Signed-off-by: Marian Marencik github@marianm.net
Signed-off-by: Marian Marencik github@marianm.net
I have include it to this request, but from my side there is one todo:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much! This is looking great! I have a suggestion for how to deal with your remaining TODO; otherwise this is fine!
src/cassandra/statement.rs
Outdated
let varint = dec_parts.0.to_signed_bytes_be(); | ||
let scale = dec_parts.1; | ||
|
||
//@TODO: cpp scale = i32, BigInt scale = i64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I think it's highly unlikely anyone will be using 4GB BigInts, but just in case, you should convert scale using try_into() and then if it fails return an error. I think it's OK to reuse one of the CASS_ERROR_LIB
errors here, even though that's not strictly accurate: probably CASS_ERROR_LIB_INVALID_DATA
.
src/cassandra/statement.rs
Outdated
let varint = dec_parts.0.to_signed_bytes_be(); | ||
let scale = dec_parts.1; | ||
|
||
//@TODO: cpp scale = i32, BigInt scale = i64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above.
Signed-off-by: Marian Marencik github@marianm.net
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks!
Get cassadra decimal value as BigDecimal (https://docs.rs/bigdecimal/latest/bigdecimal/)
Signed-off-by: Marian Marencik github@marianm.net