Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用python逐个迭代cassandra行?_Python_Cassandra - Fatal编程技术网

如何使用python逐个迭代cassandra行?

如何使用python逐个迭代cassandra行?,python,cassandra,Python,Cassandra,假设我在cassandra中有一个表,比如现在有一百万行,我想用python一行一行地扫描所有行,或者50行一批地扫描,因为我必须迁移到其他数据库,比如sql。如何扫描每一行 CREATE TABLE emp( emp_id int PRIMARY KEY, emp_name text, emp_city text, emp_sal varint, emp_phone varint ); from cassandra.cluster imp

假设我在cassandra中有一个表,比如现在有一百万行,我想用python一行一行地扫描所有行,或者50行一批地扫描,因为我必须迁移到其他数据库,比如sql。如何扫描每一行

  CREATE TABLE emp(
     emp_id int PRIMARY KEY,
     emp_name text,
     emp_city text,
     emp_sal varint,
     emp_phone varint
);

from cassandra.cluster import Cluster

cluster = Cluster()
session = cluster.connect()
session.set_keyspace('users')
Row=  session.exexute(   select * from emp)
for row in Row:
     //Do something
上面的示例从Cassandra数据库获取所有行。
由于行数可能很大,因此在执行select语句时可能会导致内存问题。是否有任何方法逐个迭代行

您需要使用查询分页。Datastax针对Cassandra的Python驱动程序具有此功能。更多细节