Cassandra底层与hbase相似,但是 它可以用SQL进行查询 ,基本查询就不详细去说了,这里记录一下,关于索引、主键的一些查询语句。
查询索引:
String query = String.format("select options from system_schema.indexes where table_name = '%s' ALLOW FILTERING",tableName);
ResultSetFuture resultSet = getSession().executeAsync(query);
其中的system_schema.indexes储存着所有表的index
查询主键:
String query2 = String.format("select column_name from system_schema.columns where table_name='%s' and kind='partition_key' ALLOW FILTERING;",tableName);
ResultSetFuture resultSet2 = getSession().executeAsync(query2);
其中的system_schema.columns储存着所有的表的列信息,kind='partition_key'的就是主键啦~
看到这里,大家也就清楚了吧,system_schma 就是存着所有表元信息的keyspaces 啦: