通过python获取cassandra的信息
我通过以下方式连接到远程Cassandra DB:通过python获取cassandra的信息,python,cassandra,Python,Cassandra,我通过以下方式连接到远程Cassandra DB: from cassandra.cluster import Cluster from cassandra.auth import PlainTextAuthProvider from cassandra.query import dict_factory cluster = Cluster(contact_points=[CASSANDRA_HOST], username='1',password='123') session=cluster
from cassandra.cluster import Cluster
from cassandra.auth import PlainTextAuthProvider
from cassandra.query import dict_factory
cluster = Cluster(contact_points=[CASSANDRA_HOST], username='1',password='123')
session=cluster.connect()
然后,我想得到Cassandra中已有的键空间、表和列的列表。在cqlsh中,它与
描述键空间
一起使用。如何在Python中做到这一点?集群的实例有一个作为实例的元数据
字段-它有一个键空间
成员,该成员是现有键空间的列表,通过迭代可以得到所有表,然后是每个表的列,等等
descripe KEYSPACE
是cqlsh
命令,尽管它可能会作为普通的CQL命令得到支持(不记得了,它可能是4.0版本的一部分)除了集群元数据之外,系统架构
KEYSPACE是您的朋友!您可以像从下表中选择任何其他数据一样选择此数据:
system_schema.keyspaces
system_schema.tables
system_schema.columns
提取列元数据可能如下所示:
strCCQL = "SELECT column_name,type FROM system_schema.columns WHERE keyspace_name=? AND table_name=?"
pcStatement = session.prepare(strCCQL)
pcStatement.consistency_level=ConsistencyLevel.LOCAL_ONE
crows = session.execute(pcStatement,[keyspace,table])
for crow in crows:
column = crow.column_name
type = crow.type
print keyspace,table,column,type
这个例子把所有这些放在一起。但是,您可以通过以类似的方式查询键空间
和表
表,使用键空间和表名数据为其种子