【问题标题】:Cassandra UDT: error: unpack requires a string argument of length 4Cassandra UDT:错误:解包需要长度为 4 的字符串参数
【发布时间】:2015-09-15 20:24:49
【问题描述】:

使用 [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 从该表中选择任何内容。 我得到的错误是:

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(timeout)

文件“/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 的字符串参数

有谁知道是什么导致了这个错误? 这是一个错误吗?

【问题讨论】:

    标签: c# cassandra cassandra-2.0


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-15
      相关资源
      最近更新 更多