Insert to cassandra from python using cql

旧巷老猫 提交于 2019-12-03 05:43:22
Oren

It looks like you are trying to follow the example in: http://pypi.python.org/pypi/cql/1.4.0

import cql
con = cql.connect(host, port, keyspace)
cursor = con.cursor()
cursor.execute("CQL QUERY", dict(kw='Foo', kw2='Bar', kwn='etc...'))

However, if you only need to insert one row (like in your question), just drop the empty dict() parameter.

Also, since you are using composite keys, make sure you use CQL3 http://www.datastax.com/dev/blog/whats-new-in-cql-3-0

connection = cql.connect('localhost:9160', cql_version='3.0.0')

The following code should work (just adapt it to localhost if needed):

import cql
con = cql.connect('172.24.24.24', 9160,  keyspace, cql_version='3.0.0')
print ("Connected!")
cursor = con.cursor()
CQLString = "INSERT INTO event_attend (event_id, event_type, event_user_id) VALUES (131, 'Party', 3156);"
cursor.execute(CQLString)

For python 2.7, 3.3, 3.4, 3.5, and 3.6 for installation you can use

     $ pip install cassandra-driver

And in python:

     import cassandra

Documentation can be found under https://datastax.github.io/python-driver/getting_started.html#passing-parameters-to-cql-queries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!