【问题标题】:Cassandra UDT nested set InvalidTypeExeceptionCassandra UDT 嵌套集 InvalidTypeException
【发布时间】:2015-04-18 21:01:55
【问题描述】:

我正在 Cassandra 2.1 中试验 UDT,并与 InvalidTypeExeception 作斗争。

我将表格设置为:

 session.execute("CREATE TYPE mykeyspace.address (" +
                    "  street text," +
                    "  city text," +
                    "  zip_code int," +
                    "  phones set<text>" +
                    ");"
    );
    session.execute("CREATE TYPE mykeyspace.fullname (" +
                    "  firstname text," +
                    "  lastname text" +
                    ");"
    );
    session.execute(
            "CREATE TABLE mykeyspace.users (" +
                    "  id uuid PRIMARY KEY," +
                    "  name frozen <fullname>," +
                    "  direct_reports set<frozen <fullname>>," +
                    "  addresses map<text, frozen <address>>" +
                    ");  ");

然后运行以下作为测试:

PreparedStatement statement = session.prepare("INSERT INTO mykeyspace.users (id, name, addresses) VALUES (?, ?, ?);");

UserType fullNameType = session.getCluster().getMetadata().getKeyspace("mykeyspace").getUserType("fullname");
UserType addresType = session.getCluster().getMetadata().getKeyspace("mykeyspace").getUserType("address");

BoundStatement boundStatement = new BoundStatement(statement);

UUID uuid = UUID.randomUUID();

UDTValue name = fullNameType.newValue().setString("firstname", "john").setString("lastname", "smith");


UDTValue address = addresType.newValue()
        .setString("street", "1 long st")
        .setString("city", "sydney")
        .setInt("zip_code", 2000)
        .setSet("phones",ImmutableSet.of("123", "456", "789")); // ERROR THROWN HERE

Map<String, UDTValue> addresses = new HashMap<String, UDTValue>();
addresses.put("home", address);
session.execute(boundStatement.bind(
        uuid,
        name,
        addresses
));

我收到以下针对 .setSet("phones"...) 行的错误:

Exception in thread "main" com.datastax.driver.core.exceptions.InvalidTypeException: 
Column phones is of type 'org.apache.cassandra.db.marshal.FrozenType(org.apache.cassandra.db.marshal.SetType(org.apache.cassandra.db.marshal.UTF8Type))', cannot set to a set

只是对我做错了什么以及我遗漏了什么感到困惑,我确信它很明显但无法弄清楚......

谢谢!

【问题讨论】:

  • 我也面临同样的错误

标签: java cassandra datastax user-defined-types


【解决方案1】:

那将是驱动程序中的错误。如果您确定您使用的是最新发布的驱动程序版本(以确保它尚未修复),请在java driver jira 上报告此问题。

【讨论】:

猜你喜欢
  • 2017-03-07
  • 2018-01-31
  • 2021-06-08
  • 2015-05-16
  • 2018-08-23
  • 1970-01-01
  • 2015-09-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多