Java driver : how to get table/column/index info with v3 of driver?

175 views
Skip to first unread message

.

unread,
May 21, 2016, 2:56:10 AM5/21/16
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi,

I have some code using v2.1 of the Datastax driver that used CQL, getting info about columns in a table, the type of the column, and index (if any)
SELECT column_name, index_name, validator FROM system.schema_columns WHERE keyspace_name=? AND columnfamily_name=?

In v3 of the driver this CQL doesn't seem to be an option (some error message, can't remember off the top of my head), and I have seen through other posts that I could use
KeyspaceMetadata ks = session.getCluster().getMetadata().getKeyspace(schemaName);
TableMetadata table = ks.getTable(tableName);
List<ColumnMetadata> colmds = table.getColumns();
Collection<IndexMetadata> indexmds = table.getIndexes();

This works fine for columns, getting the name and "type", but I'm struggling to get info about how an index relates to a column or columns.

What am I missing to get the equivalent of the v2.1 CQL?


Second question would be, is using the XXXMetadata the most efficient, recommended way to get this info? (it's only used as a one-off up front checker of structure).

Thanks!

.

unread,
May 21, 2016, 4:03:23 AM5/21/16
to DataStax Java Driver for Apache Cassandra User Mailing List
In v2.1 and v2.2 of the java driver ColumnMetaData had a getIndex() which presumably would have given the info needed (whether the column is used in an index). Now it is removed :-S

Alexandre Dutra

unread,
May 21, 2016, 5:21:21 AM5/21/16
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi,

The lack of a simple way to tell whether a column is indexed or not is the consequence of one of the most difficult decisions we had to make when we added support for Cassandra 3.0.

As our Upgrade guide states[1], Cassandra 3.0 has opened the door for custom index implementations, so the good old secondary index is no longer the only kind of index. In that perspective, an index can now target virtually any object: a column, a group of columns, a function, an entire row... it depends on the implementation. That's why indexes are now associated with a table on which they operate, and not on a specific column anymore.

May others have complained about this[2]. That said, there are workarounds. See this StackOverflow question[3] for two possible workarounds:

1) Name your indexes according to a pattern such as <table_name>_<column_name>_idx, and extract the column name from the index name;
2) Inspect the "target" field of the IndexMetadata object[4] : for simple secondary indexes, this field contains the column name the index operates on. 

I hope that helps,

Alexandre


On Sat, May 21, 2016 at 10:03 AM '.' via DataStax Java Driver for Apache Cassandra User Mailing List <java-dri...@lists.datastax.com> wrote:
In v2.1 and v2.2 of the java driver ColumnMetaData had a getIndex() which presumably would have given the info needed (whether the column is used in an index). Now it is removed :-S

--
You received this message because you are subscribed to the Google Groups "DataStax Java Driver for Apache Cassandra User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.
--
Alexandre Dutra
Driver & Tools Engineer @ DataStax

.

unread,
May 21, 2016, 5:42:18 AM5/21/16
to DataStax Java Driver for Apache Cassandra User Mailing List
Thanks Alexandre for your thorough answer. Sorry I didn't find the links in previous searches. Will workaround it
Reply all
Reply to author
Forward
0 new messages