Critical codec bugfix for Cassandra collections
Fixed a critical bug in codecs which treated empty Cassandra collections as an error since there is aggressive null checking. However, Cassandra does not actually have the concept of nullable collections like they do with their other datatypes. They store empty collections using null which is a bit confusing. So we changed the behavior of the codecs to account for this fact. So now you can do this:
Given a Cassandra table
CREATE TABLE example (
id INT PRIMARY KEY,
data set<ascii>
);
final case class Example(
@CqlColumn("id") id: Int,
@CqlColumn("data") data: Set[String]
)
val insert =
InsertBuilder("example")
.values(
"id" -> 2,
"data" -> Set.empty[String]
)
.build
.executeMutation
val select =
SelectBuilder
.from("example")
.allColumns
.build[Example]
.execute
.runCollect
This will correctly return empty Set values. The same is true when using the Cursor API.
🔴 Please keep in mind if you wrap Cassandra collections in Option
, you'll get the equivalent of having Option[NonEmptyCollection]
behavior in that you will either have a None
if you persist an empty collection or a populated collection would appear as Some(List(1))
as an example.