使用python驱动程序计算Cassandra列族中的“行” [英] Counting 'rows' in column family of Cassandra using python driver

查看:78
本文介绍了使用python驱动程序计算Cassandra列族中的“行”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用python驱动程序更有效地计算Cassandra列族中的行?
我使用以下代码:

How count "rows" in column family of Cassandra using python driver more effectively? I use following code:

from cassandra.cluster import Cluster
from sys import stdout

servers = ['server1', 'server2']
cluster = Cluster(servers)
session = cluster.connect()

result = session.execute('select * from ks1.t1')

count = 0

for i in result:
    count += 1

print count


推荐答案

要在Python中实现此目的,为什么不以下内容:

To achieve this in Python, why not the following:

from cassandra.cluster import Cluster

servers = ['server1', 'server2']
cluster = Cluster(servers)
session = cluster.connect()

result = session.execute('select count(*) from ks1.t1')

count = 0
for row in result: # will only be 1 row
    count += row.count

print(count)

这篇关于使用python驱动程序计算Cassandra列族中的“行”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆