简体   繁体   English

如何在 Cassandra 中获取键空间中的表数?

[英]How to obtain number of tables in a keyspace in Cassandra?

For example, we can use例如,我们可以使用

select count(*) from student_database;

to calculate the number of rows in a table.计算表中的行数。 But how do we calculate the number of tables in a keyspace?但是我们如何计算键空间中表的数量呢?

DESCRIBE TABLES;

gives you the list of all tables in that keyspace.为您提供该键空间中所有表的列表。

And for a Cassandra 2.x (and lower) answer:对于 Cassandra 2.x(及更低版本)的答案:

SELECT COUNT(*) FROM system.schema_columnfamilies 
    WHERE keyspace_name='your keyspace';

SELECT count(*) FROM system_schema.tables WHERE keyspace_name='your keyspace'

The above query will work in cassandra 3.0 and above以上查询适用于 cassandra 3.0 及以上版本

rows = session.execute("SELECT count(*) FROM system_schema.tables WHERE keyspace_name = 'your_keyspace_name'")

print(list(rows))

Result:结果:

[Row(count=2)]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM