首页 文章

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

提问于
浏览
1

使用[cqlsh 5.0.1 | Cassandra 2.1.5.469 | DSE 4.7.0 | CQL规范3.2.0 |本机协议v3]和C#2.5驱动程序, I'm trying to represent user settings as a 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从该表中选择任何内容 . 我得到的错误是:

Traceback(最近一次调用最后一次):

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

文件"/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

error: unpack requires a string argument of length 4

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

1 回答

  • 2

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

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

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

相关问题