Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cassandra: text vs varchar

Does anyone know the difference between the two CQL data types text and varchar in Cassandra? The Cassandra documentation describes both types as "UTF-8 encoded string" and nothing more.

like image 275
darcyy Avatar asked Jul 08 '13 15:07

darcyy


People also ask

What is the difference between text and varchar in Cassandra?

it's the same for Cassandra. Both text and varchar are UTF8 encoded strings so they are exactly the same thing.

What is CQL in Java?

CQL-Java is a Free Software project that provides: A set of classes for representing a CQL parse tree (a base CQLNode class, CQLBooleanNode and its subclasses, CQLTermNode, etc.) A CQLCompiler class (and its lexer) which builds a parse tree given a CQL query as input.


2 Answers

text is just an alias for varchar!

The documentation:

  • Using cql3 - Datastax
  • CQL commands - Datastax
  • Documentation on Datatypes in CQL - Datastax
  • CQL3 Documentation - Apache

EDIT
Here's the link to the C* 1.2 docs. The text vs varchar info is still the same, however this document contains some extra datatypes.

EDIT v2 Documentation links have been updated to the docs for C* 3. I couldn't find a good alternative for the C* 1.2 docs.

like image 87
Lyuben Todorov Avatar answered Sep 29 '22 21:09

Lyuben Todorov


Probably you meant the CQL storage types, if not, disregard my answer.

In CQL there has been a ongoing trend to try to distance from the internals of cassandra. Whether that is a good thing, or a bad thing, is open to interpretation. What is relevant, however, is in latest versions of CQL developers have been trying to come up with syntax that is more familiar to people who are not that in depth into cassandra's internals.

If you were to take a look into this SO question, you will get a nice illustration of the situation: Creating column family or table in Cassandra while working Datastax API(which uses new Binary protocol)

In recent CQL versions, some aliases, alien to cassandra, but very well known to DBA's have started to appear. For example, the native to cassandra ColumnFamily has been aliased with Table, and text is just an alias for varchar and vice versa. Again, it is a matter of opinion if that is a good thing or not.

So, in conclusion, you can use varchar and text interchangeably.

like image 24
Nikola Yovchev Avatar answered Sep 29 '22 19:09

Nikola Yovchev