【问题标题】:Non frozen collections and user defined types on Cassandra 2.1.8Cassandra 2.1.8 上的非冻结集合和用户定义类型
【发布时间】:2015-11-04 09:23:17
【问题描述】:

我正在尝试从here 运行以下示例

  CREATE TYPE address (
          street text,
          city text,
          zip int
      );

 CREATE TABLE user_profiles (
      login text PRIMARY KEY,
      first_name text,
      last_name text,
      email text,
      addresses map<text, address>
  );

但是,当我尝试创建 user_profiles 表时,我收到以下错误:

InvalidRequest: code=2200 [Invalid query] message="Non-frozen collections are not
allowed inside collections: map<text, address>

对为什么会发生这种情况有什么想法吗?

【问题讨论】:

    标签: cassandra cql cql3


    【解决方案1】:

    我正在运行 2.1.8 并且收到相同的错误消息。要解决此问题,您需要 frozen 关键字:

     CREATE TABLE user_profiles (
          login text PRIMARY KEY,
          first_name text,
          last_name text,
          email text,
          addresses map<text, frozen <address>>
      );
    

    Frozen 对于 UDT(目前)是必需的,因为它将它们序列化为单个值。 User Defined Type documentation 中的一个类似的更好的示例可能是您可以遵循的。试试看吧。

    【讨论】:

      【解决方案2】:

      当我在 cassandra 映射中错误地使用“字符串”而不是“文本”时收到此消息,例如:

      mymap map<bigint, string> 
      

      我关注了谷歌的这个 stackoverflow 线程,我认为这些信息可以为某人节省几分钟的时间。

      【讨论】:

      • 就这样。谢谢。
      【解决方案3】:

      尚不支持非冻结的 UDT。要求用户为每个 UDT 显式指定此关键字的原因是能够在 3.x 中引入 mutable UDTs 而不会破坏现有代码。

      【讨论】:

      • 感谢 Stefan 澄清这一点!我认为这是特定于收藏的;所以我也修正了我的答案。
      猜你喜欢
      • 2018-01-11
      • 2018-07-17
      • 1970-01-01
      • 2016-09-19
      • 2014-12-31
      • 2018-01-04
      • 2020-08-19
      • 1970-01-01
      • 2018-05-09
      相关资源
      最近更新 更多