繁体   English   中英

无法使用带有复合行键(UTF8Type,DateType)的Pycassa插入Cassandra列系列

[英]Can't insert into Cassandra column family using Pycassa with composite row keys (UTF8Type, DateType)

我有一个Cassandra列族(使用Pycassa创建),具有以下架构:

ColumnFamily: tracker
  Key Validation Class: org.apache.cassandra.db.marshal.CompositeType(org.apache.cassandra.db.marshal.UTF8Type,org.apache.cassandra.db.marshal.DateType)
  Default column value validator: org.apache.cassandra.db.marshal.BytesType
  Cells sorted by: org.apache.cassandra.db.marshal.UTF8Type
  GC grace seconds: 864000
  Compaction min/max thresholds: 4/32
  Read repair chance: 0.1
  DC Local Read repair chance: 0.0
  Populate IO Cache on flush: false
  Replicate on write: true
  Caching: KEYS_ONLY
  Bloom Filter FP chance: default
  Built indexes: []
  Compaction Strategy: org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy
  Compression Options:
    sstable_compression: org.apache.cassandra.io.compress.SnappyCompressor

我正在尝试使用以下行将其插入:

self.tracker_batcher.insert(tracker_key, dictionary_to_insert)

其中tracker_key为:

('cd7449e8-8f0d-4730-9ee4-ef60edfdd409', datetime.datetime(2013, 8, 14, 16, 47, 55, 856000))

我希望这行得通-我在其他表中使用日期类型作为行键,它们可以有效地对待。 另外-似乎我正在关注Pycassa网站( http://pycassa.github.io/pycassa/assorted/composite_types.html )上的教程。

有关更多信息,我正在使用Pycassa版本1.9.0和Cassandra 1.2.8

谢谢,

马特

编辑:

在一件怪异的事件中,我收到的第一条错误消息是:

TypeError: A str or unicode value was expected, but datetime was received instead (2013-08-14 16:45:15.376000)

我试图这样修改查询:

tracker_key = (str(dictionary_to_insert['session_id']), datetime.datetime.strftime(dictionary_to_insert['datestamp'], "%Y-%m-%d %H:%M:%S"))

即将日期时间更改为字符串

并收到以下错误消息:

    raise TypeError('DateType arguments must be a datetime or timestamp')
TypeError: DateType arguments must be a datetime or timestamp

莫名其妙。

因此看来问题出在实际上不是行列而是插入了值。

我已经指定我将使用UTF8Type作为值,但试图插入与列族相同的日期时间作为键的一部分。

创建跟踪器键,然后将dictionary_to_insert值转换为字符串即可修复它:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM