When you use cqlsh
with Cassandra you can make a describe
query to get the information of a table for example:
DESCRIBE TABLE emp;
And it will give you something like:
CREATE TABLE emp (
empid int PRIMARY KEY,
deptid int,
description text
) ...
....
So how can I query this using Astyanax support for CQL. I was able to query simple SELECT
statements with this:
OperationResult<CqlResult<String, String>> result
= keyspace.prepareQuery(empColumnFamily)
.withCql("Select * from emp;")
.execute();
But this isn't working for DESCRIBE
statements.
PD: I am really doing this to get the DATA TYPES
of the table, parsing it later and obtaining for example int, int, text
, so please if you have a different approach to get those, it could be awesome.
This query select column, validator from system.schema_columns;
doesn't work because it doesn't return the composite keys.
DESCRIBE
is not part of the CQL spec (neither CQL2 nor CQL3). If you'd like to completely reconstruct theDESCRIBE
you could take a look at cqlsh implementation (look forprint_recreate_columnfamily
).You could also get some more meta info from
system.schema_columnfamilies
:select keyspace_name, columnfamily_name, key_validator from schema_columnfamilies;