python - 在 pycassa 中找不到 Cassandra 列族

标签 python cassandra pycassa

我正在尝试连接到 Cassandra 以进行批量插入。但是,当我尝试连接时,出现错误。

我使用的代码:

from pycassa import columnfamily
from pycassa import pool

cassandra_ips = ['<an ip addr>']
conpool = pool.ConnectionPool('my_keyspace', cassandra_ips)

colfam = columnfamily.ColumnFamily(conpool, 'my_table')

然而,这在最后一行失败了:

pycassa.cassandra.ttypes.NotFoundException: NotFoundException(_message=None, why='Column family my_table not found.')

列族肯定存在:

cqlsh> use my_keyspace
   ... ;
cqlsh:my_keyspace> desc tables;

my_table

cqlsh:my_keyspace>

而且我不认为这是一个简单的表名拼写错误,因为我已经检查了十几次,也因为这个:

In [3]: sys_mgr = pycassa.system_manager.SystemManager(cassandra_ips[0])

In [4]: sys_mgr.get_keyspace_column_families('my_keyspace')
Out[4]: {}

为什么是 {}

如果重要的话:

  • 表/列系列是使用 CQL 创建的。
  • 该表目前是空的。
  • 该表大致使用以下方法创建:

    CREATE TABLE my_table (
      user_id int,
      year_month int,
      t timestamp,
      <tons of other attributes>
      PRIMARY KEY ((user_id, year_month), t)
    ) WITH compaction =
        { 'class' : 'LeveledCompactionStrategy', 'sstable_size_in_mb' : 160 };
    

最佳答案

为了通过 thrift API(例如 pycassa)访问 CQL3 数据库,必须使用压缩存储创建表。

CREATE TABLE my_table (
...
) WITH COMPACT STORAGE;

关于主键,来自 docs :

Using the compact storage directive prevents you from defining more than one column that is not part of a compound primary key.

目前您正在使用 composite partition key但是启用压缩存储限制我们使用复合 分区键。因此,您不必必须将它限制为单个列,它只需要是复合键的一部分即可。一期决赛reference .

关于python - 在 pycassa 中找不到 Cassandra 列族,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22260284/

相关文章:

java - 使用 Cassandra Java 驱动程序玩 2.x - 错误 com.datastax.driver.core.Session - 创建 xxx.xx 池时出错,但返回响应

cassandra - 如何知道Cassandra集群中有多少个节点?

python - 如何使用 pycassa 和 uuid key 获取数据

Cassandra 1.2 : Is CQL preferred over Thrift Based Clients

c++ - 不同编程语言的getters和setters的使用

python 类的属性不在 __init__ 中

python - MatPlotlib:未显示补丁

Cassandra java.io.IOException : Map failed for COMMIT-LOG-ALLOCATOR

用于 apache cassandra 的 python ORM

python - 使用 HTML 中嵌入的 Python 代码对数字进行平均