Which is better way to store boolean in cassandra, text column vs boolean column?

Viewed 140

Want to know the better way to store boolean in Cassandra between these two approaches:

  1. Store it as a text column with a single character. e.g: 'Y' or 'N'.

  2. Use the boolean column. e.g: true or false

2 Answers

It's OK to use either.

Using the CQL boolean type means that you can easily map it to the boolean type in whatever language your app is written in.

On the other hand, if your source is not boolean then it's easier to store it in CQL text type so you don't need to implement the logic that would convert Y to true and N to false in your app.

It really comes down to preference. Cheers!

Cassandra stores all data as hex byte arrays, so Erick is right in that it's really ok to use either.

I will say that I would strongly recommend using the boolean type, for two reasons:

  • Overall size. boolean takes 1 bit, versus a string of "true" which takes 4 bytes. That difference might not be too concerning today, but it's worth pointing out.
  • Data quality. Using a string leaves your app open to having to interpret different values like "true", "True", "Y", "y", "yes"...etc. Which all mean the same thing. Using a boolean removes any chance of ambiguity or invalid data.
Related