Cassandra Tips

BigDecimal, double, or float?

The difference between double and float is obviously the length of precision in the floating point value. Both double and float use binary representation of decimal numbers with a radix which is in many cases an approximation, not an absolute value. double is a 64-bit value while float is an even shorter 32-bit value. Therefore, we can say that double is more precise than float. However, in both cases, there is still a possibility of loss of precision which can be very noticeable when working with either very big numbers or very small numbers.

On the contrary, BigDecimal is devised to overcome this loss of precision discrepancy. It is an exact way of representing numbers. Its disadvantage is slower runtime performance.

Whenever you are dealing with money or precision is a must, BigDecimal is the best choice (or decimal in CQL native data types), otherwise double or float should be good enough.

Timestamp

The value of the  timestampfield is encoded as a 64-bit signed integer representing a number of milliseconds since the standard base time known as the epoch: January 1, 1970, at 00:00:00 GMT. A  timestamp data type can be entered as an integer for CQL input, or as a string literal in ISO 8601 formats

Timestamp or Timeuuid?

Timestamp is suitable for storing date and time values. TimeUUID, however, is more suitable in those cases where a conflict free, unique timestamp is needed.

Type 1 or type 4 UUID?

Type 1 uses the MAC address of the computer that is generating the UUID data type and the number of 100-nanosecond intervals since the adoption of the Gregorian calendar, to generate UUIDs. Its uniqueness across computers is guaranteed if MAC addresses are not duplicated; however, given the speed of modern processors, successive invocations on the same machine of a naive implementation of a type 1 generator might produce the same UUID, negating the property of uniqueness. Type 4 uses random or pseudorandom numbers. Therefore, it is the recommended type of UUID to be used.

Advertisements