DataStax Academy FAQ

DataStax Academy migrated to a new learning management system (LMS) in July 2020. We are also moving to a new Cassandra Certification process so there are changes to exam bookings, voucher system and issuing of certificates.

Check out the Academy FAQ pages for answers to your questions:


question

george.ricketts_175787 avatar image
george.ricketts_175787 asked ·

c# driver and decimals with scale > 28

Hi All,

I'm getting the following issue when trying to read from a cassandra decimal column using the C# driver:

System.ArgumentOutOfRangeException: CLR Decimal structure can not represent numbers with a scale greater than 28


Is there a workaround for this? I can't see any way of passing a cast through the driver.


Thanks,
George

driver
1 comment
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

@george.ricketts_175787 just acknowledging your question and I'll look into it. Cheers!

0 Likes 0 · ·

1 Answer

joao.reis avatar image
joao.reis answered ·

Hi, you can create a custom type serializer that deserializes Cassandra's decimal to your custom type and serializes your type into Cassandra's decimal. You can look at this implementation for some pointers:

https://github.com/datastax/csharp-driver/blob/d14c6b4f90e6ccb4087c32a2444d6b7ce1487793/src/Cassandra.Tests/Extensions/Serializers/BigDecimalSerializer.cs#L28-L50

This specific BigDecimalSerializer is just a basic implementation that is used in our driver's test suite, we haven't tested it for production use. The BigDecimal.ToString() method has huge memory issues in case the value is ridiculously large for example.

To use a custom type serializer you can add it to the Builder like this:

var builder = Cluster.Builder()
                     .AddContactPoint(TestCluster.InitialContactPoint)
                     .WithTypeSerializers(new TypeSerializerDefinitions()
                         .Define(new BigDecimalSerializer()));
Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.