首页 > 解决方案 > CQLSH COPY ERROR TypeError: 'int' object is not iterable

问题描述

我有下面的代码试图转储表数据,但出现错误 TypeError: 'int' object is not iterable。

import argparse
    import sys
    import itertools
    import codecs
    import uuid
    import os

    try:
        import cassandra
        import cassandra.concurrent
    except ImportError:
        sys.exit('Python Cassandra driver not installed. You might try \"pip install cassandra-driver\".')
    from cassandra.cluster import Cluster, ResultSet
    from cassandra.policies import DCAwareRoundRobinPolicy
    from cassandra.auth import PlainTextAuthProvider
    from cassandra.cluster import ConsistencyLevel

    datafile = "/Users/username/adf.csv"

    if os.path.exists(datafile):
        os.remove(datafile)
    def dumptableascsv():
        auth_provider = PlainTextAuthProvider(username='cassandra', password='cassandra')
        cluster = Cluster(['127.0.0.1'],
                          load_balancing_policy=DCAwareRoundRobinPolicy(local_dc='Cassandra'),
                          port=9042, auth_provider=auth_provider)
        session = cluster.connect('qualys_ioc')
        session.execute("COPY qualys_ioc.agent_delta_fragment(agent_id , delta_id , fragment_id, boolean ,created_on)  TO "
                        "'/Users/username/adf.csv' WITH HEADER = true ;", ConsistencyLevel.QUORUM)
    dumptableascsv()

标签: pythoncassandradatastaxcqlsh

解决方案


COPY是一个cqlsh推荐 - 它不是 的一部分CQL,并且不能通过本机协议客户端执行。您收到此特定错误而不是服务器请求错误,因为您parametersSession.execute.

您可以使用cqlsh脚本来执行此操作,或者查看DS Bulk 工具以实现高性能加载和卸载。


推荐阅读