cassandra错误“批处理过大”使用python

qmb5sa22  于 2021-06-14  发布在  Cassandra
关注(0)|答案(1)|浏览(372)

我正在尝试将json文件插入到cassandra表中,方法是使用json模块从json中检索列,然后使用prepared语句将其插入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"
b4wnujal

b4wnujal1#

没有理由在这里使用批处理,它只会使事情变得更慢,并施加大小限制。把它改成:


# only prepare this once

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

相关问题