Wednesday, April 08, 2015

Cassandra - NotFoundException: Column family not found

When I try to use pycassa to connect to a newly created columnfamily in Cassandra, I got the following error:
pycassa.cassandra.ttypes.NotFoundException: NotFoundException(_message=None, why='Column family tweets not found.')

The code looks like
pool = ConnectionPool('tweetsentiment', ['127.0.0.1:9160'])
col_fam = ColumnFamily(pool, 'tweets')

The table definitely exists (created in CQL):

Approximate structure, for reference:
(this should not be used to reproduce this schema)

CREATE TABLE tweetsentiment.tweets (
    key uuid PRIMARY KEY,
    data text,
    prediction text,
    "timestamp" text
) WITH bloom_filter_fp_chance = 0.01
    AND caching = '{"keys":"ALL", "rows_per_partition":"NONE"}'
    AND comment = ''
    AND compaction = {'min_threshold': '4', 'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32'}
    AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99.0PERCENTILE';

Turns out in order to accewss CQL3 databases via a thrift API, the table must be created using compact storage. So

CREATE TABLE tweetsentiment.tweets (
    key uuid PRIMARY KEY,
    data text,
    prediction text,
    "timestamp" text
) WITH compact storage

solved my problem.

"COMPACT STORAGE" is mainly targeted towards backward compatibility for definitions created before CQL3. The option also provides a slightly more compact layout of data on disk but at the price of diminished flexibility and extensibility for the table. Most notably, COMPACT STORAGE tables cannot have collections nor static columns and a COMPACT STORAGE table with at least one clustering column supports exactly one (as in not 0 nor more than 1) column not part of the PRIMARY KEY definition (which imply in particular that you cannot add nor remove columns after creation). For those reasons, COMPACT STORAGE is not recommended outside of the backward compatibility reason evoked above.

No comments: