Cassandra UDT:错误:unpack需要长度为4的字符串参数

时间:2015-06-29 11:31:18

标签: c# cassandra cassandra-2.0

使用[cqlsh 5.0.1 |卡桑德拉2.1.5.469 | DSE 4.7.0 | CQL规范3.2.0 |原生协议v3] 和C#2.5驱动程序,我正在尝试将用户设置表示为UDT

以下是在* .cql脚本中定义的:

CREATE TYPE GeneralSettings (
    last_changed        timestamp,
    last_tokaned        timestamp,
    tokan               text,
    emails              list<text>,
);

CREATE TABLE users (
    id                  timeuuid,
    name                text,
    general_settings    frozen<GeneralSettings>,

    PRIMARY KEY (id)
);

以下内容在我的C#代码中定义:

public class UserGeneralSettings
{
    public DateTimeOffset? LastChanged { get; set; }
    public DateTimeOffset? LastTokened { get; set; }
    public string Token { get; set; }
    public IEnumerable<string> Emails { get; set; }
}
session.UserDefinedTypes.Define(
            UdtMap.For<UserGeneralSettings>().Map(s => s.LastChanged, "last_changed")
                                             .Map(s => s.LastTokened, "last_tokaned")
                                             .Map(s => s.Token, "tokan")
                                             .Map(s => s.Emails, "emails")
        );
For<User>()
        .TableName("users")
        .PartitionKey(e => e.Id)
        .Column(e => e.Id, cm => cm.WithName("id"))
        .Column(e => e.Name, cm => cm.WithName("name"))
        .Column(e => e.GeneralSettings, cm => cm.WithName("general_settings"));

我正在尝试使用IMapper界面将以下数据作为新用户记录插入:

newUser.GeneralSettings = new UserGeneralSettings
        {
            Emails = new [] { "test@provider.com" },
            LastChanged = DateTimeOffset.UtcNow,
            LastTokened = DateTimeOffset.UtcNow,
            Token = "abcd-efg-hijk-lmnop-qrst-uvw-xyz",
        };

但即使插入顺利,看起来它正在破坏我的用户表,因为我无法使用cqlsh从该表中选择任何内容。 我得到的错误是:

跟踪(最近一次呼叫最后一次):

文件“/ usr / share / dse / resources / cassandra / bin / cqlsh”,第1056行,在perform_simple_statement rows = self.session.execute(statement,trace = self.tracing_enabled) < / p>

文件“/usr/share/dse/resources/cassandra/bin/../lib/cassandra-driver-internal-only-2.5.1.zip/cassandra-driver-2.5.1/cassandra/ cluster.py“,第1405行,执行结果= future.result(超时)

文件“/usr/share/dse/resources/cassandra/bin/../lib/cassandra-driver-internal-only-2.5.1.zip/cassandra-driver-2.5.1/cassandra/ cluster.py“,第2976行,结果引发self._final_exception

错误:解包需要长度为4的字符串参数

有谁知道导致此错误的原因是什么? 这是一个错误吗?

1 个答案:

答案 0 :(得分:2)

这听起来很像CASSANDRA-7656。虽然,应该已经在后来的2.1版本候选版本中修复了。您插入的任何值是否为null?

我对这里发生的事情的理论是,Cassandra将timestamp与C#DateTimeOffset匹配。这是 DateTimeOffset?(可空)相同。

UserGeneralSettings类更改为使用DateTimeOffset作为时间戳,而不是可空类型(DateTimeOffset?)。然后截断你的表并再次尝试插入。