问题
Using Cassandra 1.2. I created a table using CQL 3 the following way:
CREATE TABLE foo (
user text PRIMARY KEY,
emails set<text>
);
Now I am trying to query the data through pycassa:
import pycassa
from pycassa.pool import ConnectionPool
pool = ConnectionPool('ks1', ['localhost:9160'])
foo = pycassa.ColumnFamily(pool, 'foo')
This gives me
Traceback (most recent call last):
File "test.py", line 5, in <module>
foo = pycassa.ColumnFamily(pool, 'foo')
File "/home/john/src/pycassa/lib/python2.7/site-packages/pycassa/columnfamily.py", line 284, in __init__
self.load_schema()
File "/home/john/src/pycassa/lib/python2.7/site-packages/pycassa/columnfamily.py", line 312, in load_schema
raise nfe
pycassa.cassandra.ttypes.NotFoundException: NotFoundException(_message=None, why='Column family foo not found.')
How can this be accomplished?
回答1:
If you have created your tables using CQL3 and you want to access them through a thrift based client; you will have to specify the Compact Storage property. e.g :
CREATE TABLE dummy_file_test
(
dtPtn INT,
pxID INT,
startTm INT,
endTm INT,
patID BIGINT,
efile BLOB,
PRIMARY KEY((dtPtn, pxID, startTm))
)with compact storage;
This is what i had to do while accessing CQL3 based column Families with Pycassa
回答2:
I am testing with Cassandra 1.2.8 and pycassa 1.9.0 and CQL3. I was able to verify that tables created in CQL3 using the "WITH COMPACT STORAGE" used during the CREATE table statement does make the table (column family) visible to pycassa. Unfortunately, I was not able to find how to alter the table to get the "WITH COMPACT STORAGE" to show up in the DESCRIBE TABLE command. THE ALTER TABLE WITH statement is supposed to allow you to change that setting but no luck.
To verify the results simply create two tables using CQL3 one using the WITH COMPACT STORAGE and one without it and the results are re-producable.
It looks like to accomplish the stated goal the table would need to be dropped and then re-created using the "WITH COMPACT STORAGE" option as part of the CREATE statement. If you don't want to loose any data then possibly rename the existing table, create the new empty table with the correct options, and then move the data back into the desired table. Unless, of course you can find how to alter the table correctly, which would be easier, if possible.
回答3:
Column families created with CQL3 cannot use the Thrift API which pycassa uses.
You can read this if you have more questions.
回答4:
It certainly appears that your column family (table) is not defined properly. Run cqlsh
and then describe keyspace ks1;
. My guess is you won't see your CF listed. Check to see that your keyspace name is correct.
回答5:
Pycassa doesn't support newer versions of cassandra - see Ival's answer and here for more info. See https://pypi.python.org/pypi/cql/1.0.4 for an alternative solution to pycassa.
来源:https://stackoverflow.com/questions/14185291/reading-cassandra-1-2-table-with-pycassa