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

Tri avatar image
Tri asked ·

Is there a CQL data type equivalent to Enum?

Is there an ENUM datatype in Cassandra? For example, using a pseudo-CQL language:

CREATE ENUM MovieGenre (Comedy, Romance, Fantasy, SciFi)

Then use it as:

INSERT INTO myMovie (movieid, name, genre)
VALUES (124-abcd, 'The Enum Story', MovieGenre.SciFi);

The idea is to use a more compact encoding of the values and avoid unintended creation of new values because of typos or case sensitivity.

cassandracql
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.

1 Answer

smadhavan avatar image
smadhavan answered ·

@Tri, CQL does not have an enum data type. It would have to be done from the application writing into the database. For example, one could write their own custom codec implementation using DataStax Java Driver 4.7 which was implemented as part of JAVA-846.

Alternatively, if you're looking for User Defined Type (UDT), refer to this documentation for working with them.

[EDIT] UDTs are not equivalent to enums.

I hope that helps!

4 comments 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.

@smadhavan Can you please show an example how to use UDT to fit a use-case of "Must-be-one-among-these" like enum?

BTW what is the syntax to write the inline code like the enum in red in your reply above? I used markdown (surround by backticks) but it seems not compatible in this board.

0 Likes 0 · ·

@Tri, I had updated my response above to clarify that UDTs are not equivalent to enums.

For using markdown style responses, please refer to this post explaining how to set it in your community profile.

1 Like 1 · ·

The DataStax Java Driver 4.7 you indicated is closer to what I was looking for. Thanks. Does that work with open source Cassandra? If yes, does it require a license?

0 Likes 0 · ·
Show more comments