3

I'm trying to provide a service for user validation of table structures, one component of which is column data type, like uuid, text, and bigint in the `CREATE TABLE' statement below.

USE my_keyspace;
CREATE TABLE users (
    id uuid,
    name text,
    age bigint);

If I do

USE system;
SELECT validator FROM schema_columns
WHERE keyspace_name='my_keyspace' AND columnfamily_name='users';

I get

org.apache.cassandra.db.marshal.UUIDType
org.apache.cassandra.db.marshal.UTF8Type
org.apache.cassandra.db.marshal.LongType

Which seems informative, but on closer inspection, multiple distinct datatypes can map to the same validator value. Is there a way I can pull the data type info as entered in the `CREATE TABLE' statement, or at least find some distinction between the types?

Also, I'm curious as to why the validator data has the 'org.apache.cassandra...' prepended to it, and couldn't find an explanation, so if anybody knows why that is, I'd be very interested to know.

2 Answers 2

6

Which seems informative, but on closer inspection, multiple distinct datatypes can map to the same validator value.

If this is the case, as for example with varchar and text, I believe that the data types map on one another and are interchangeable. Anyone else correct me if I am wrong.

Is there a way I can pull the data type info as entered in the `CREATE TABLE' statement, or at least find some distinction between the types?

The only way I know would be:

DESC TABLE users;

Also, I'm curious as to why the validator data has the 'org.apache.cassandra...' prepended to it, and couldn't find an explanation, so if anybody knows why that is, I'd be very interested to know.

Cassandra is implemented in Java and this is the full path to the Class that implements the data type.

More info:

http://docs.datastax.com/en/cql/3.0/cql/cql_reference/cql_data_types_c.html

https://github.com/apache/cassandra/tree/trunk/src/java/org/apache/cassandra/db/marshal

2

Use following query:

select column_name,type from system_schema.columns where keyspace_name ='my_keyspace' AND table_name='users';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.