python - 使用python时cassandra错误 "Batch too large"

标签 python json cassandra cqlsh

我正在尝试通过使用 json 模块从 json 中检索列,然后使用准备好的语句将其插入到 cassandra 中,将 json 文件插入到 cassandra 表中。该文件准确地说是 2778ko。我不知道如何插入它。请帮忙!!!

query = """
        INSERT INTO profile9 (id,profilelegacy,profilealternative,aboutlegacy,skills,recommendations,accomplishments,peoplealsoviewed,volunteerExperience,profile)
          VALUES (?,?,?,?,?,?,?,?,?,?);

          """

        insert_user = session.prepare(query)
        batch = BatchStatement(consistency_level=ConsistencyLevel.ONE)
        batch.add(insert_user, (idd, profileLegacy, profilealternative, aboutlegacy, skills,
                                recommendations, accomplishments, peopleAlsoviewed, volunteerExperience, profile,))
        log = logging.getLogger()
        log.info('Batch Insert Completed')
        session.execute(batch)

我收到此错误

line 64, in parsing
    session.execute(batch)
  File "C:\Python\Python37\lib\site-packages\cassandra\cluster.py", line 2240, in execute
    timeout, execution_profile, paging_state, host).result()
  File "C:\Python\Python37\lib\site-packages\cassandra\cluster.py", line 4198, in result
    raise self._final_exception
cassandra.InvalidRequest: Error from server: code=2200 [Invalid query] message="Batch too large"

最佳答案

这里没有理由使用批处理,它只会使事情变慢并施加大小限制。只需将其更改为:

# only prepare this once
prepared = session.prepare(query)
...
session.execute(prepared.bind((idd, profileLegacy, profilealternative, aboutlegacy, skills,
                        recommendations, accomplishments, peopleAlsoviewed, volunteerExperience, profile,)))

关于python - 使用python时cassandra错误 "Batch too large",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57497906/

相关文章:

javascript - 在 Flask 与 JS 中设置 cookie

java - 是否可以在 pycharm\intellij 中启动\调试应用程序之前将脚本设置为 'source'?

javascript - JSON.Parse 出现问题 - 控制台在 DOCTYPE 中显示错误

C# Cassandra Datastax 驱动程序 - 处理失败的连接

computer-science - 什么是 SSTable?

python - TypeError : exceptions must be old-style classes or derived from BaseException, 不是 NoneType

python - 逐行读取文件,有时读取同一循环中的下一行

php - 如何在用 php 收到 MySQL 结果后,但在编码为 json 之前,按类型对 MySQL 结果进行分组?

ios - 在 Swift 中解析 JSON 中的嵌套数组

Cassandra 1.1 或 1.2 用于生产用途?