Cassandra查询

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 啦:

SELECT * FROM system.schema_keyspaces;

下面就是所有的信息:

keyspace_name      | durable_writes | replication
--------------------+----------------+-------------------------------------------------------------------------------------
            cycling |           True | {'class': 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '1'}
               test |           True | {'Cassandra': '1', 'class': 'org.apache.cassandra.locator.NetworkTopologyStrategy'}
        system_auth |           True | {'class': 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '1'}
      system_schema |           True |                             {'class': 'org.apache.cassandra.locator.LocalStrategy'}
   dse_system_local |           True |                             {'class': 'org.apache.cassandra.locator.LocalStrategy'}
         dse_system |           True |                        {'class': 'org.apache.cassandra.locator.EverywhereStrategy'}
         dse_leases |           True | {'class': 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '1'}
          keyspace1 |           True | {'class': 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '2'}
         solr_admin |           True |                        {'class': 'org.apache.cassandra.locator.EverywhereStrategy'}
          dse_audit |           True | {'Cassandra': '2', 'class': 'org.apache.cassandra.locator.NetworkTopologyStrategy'}
 system_distributed |           True | {'class': 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '3'}
             system |           True |                             {'class': 'org.apache.cassandra.locator.LocalStrategy'}
           dse_perf |           True | {'class': 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '1'}
      system_traces |           True | {'class': 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '2'}
       dse_security |           True | {'class': 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '1'}

(15 rows)

 

你可能感兴趣的:(Cassandra,cql,Cassandra,Java,cql)