【问题标题】:cassandra keyspace with capital letter带有大写字母的 cassandra 键空间
【发布时间】:2016-12-27 18:42:51
【问题描述】:

使用框架Cassandra Achilles,它会生成下面的CQL,但它仅在键空间名称为小写时才有效

Session session = cluster.connect();
session.execute("DROP KEYSPACE IF EXISTS Smart;");
session.execute("CREATE KEYSPACE Smart WITH replication = { "                  
                  + " 'class': 'SimpleStrategy',  'replication_factor': '3' }; ");
session.execute("CREATE TYPE IF NOT EXISTS smart.bio_udt("+
                "birthplace text,"+
                "diplomas list<text>,"+
                "description text);");
session.execute("CREATE TABLE IF NOT EXISTS Smart.users("+
                "id bigint,"+
                "age_in_year int,"+
                "bio frozen<\"Smart\".bio_udt>,"+
                "favoritetags set<text>,"+
                "firstname text,"+
                "lastname text,"+
                "preferences map<int, text>,"+
                "PRIMARY KEY(id))");

出现错误:

com.datastax.driver.core.exceptions.InvalidQueryException: 
Statement on keyspace smart cannot refer to a user type in keyspace Smart; 
user types can only be used in the keyspace they are defined in

有什么问题?

【问题讨论】:

    标签: cassandra datastax


    【解决方案1】:

    问题在于,对失败的 UDT 创建查询的检查是区分大小写的,而所有其他查询都不区分大小写。因为您没有提供“Smart”语法,Cassandra 认为您的真正意思是“Smart”全小写。

    因此,如果您编写最终查询以使其正常工作,您所要做的就是这样编写:

    CREATE TABLE IF NOT EXISTS Smart.users(
      id bigint,
      age_in_year int,
      bio frozen<"smart".bio_udt>,
      favoritetags set<text>,
      firstname text,lastname text,
      preferences map<int, text>,
      PRIMARY KEY(id)
    );
    

    实际上你有几个选项,你可以使用smartSmart"smart",但不能使用"Smart",因为前三个指的是同一个东西,即smart,但是最后一个变体告诉 Cassandra “我正在寻找一个具有这种精确大小写的键空间,以大写 S 开头。

    如果没有引号,Cassandra 认为您的意思是不区分大小写的键空间,默认情况下它会全部小写。

    作为证据,在 cqlsh 中试试这个:

    cqlsh> CREATE KEYSPACE THISISUPPER WITH replication = { 'class': 'SimpleStrategy',  'replication_factor': '3' };
    cqlsh> DESCRIBE KEYSPACE thisisupper ;
    
    CREATE KEYSPACE thisisupper WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '3'}  AND durable_writes = true;
    

    如果您真的希望它全部区分大小写,请使用引号,然后您将无法访问它,除非您输入键空间的确切名称。

    cqlsh> CREATE KEYSPACE "HEYAQUOTES" WITH replication = { 'class': 'SimpleStrategy',  'replication_factor': '3' };
    cqlsh> DESCRIBE KEYSPACE heyquotes;
    
    Keyspace 'heyquotes' not found.
    cqlsh> DESCRIBE KEYSPACE "heyaquotes";
    
    Keyspace 'heyaquotes' not found.
    cqlsh> DESCRIBE KEYSPACE HEYAQUOTES;
    
    Keyspace 'heyaquotes' not found.
    cqlsh> DESCRIBE KEYSPACE "HEYAQUOTES";
    
    CREATE KEYSPACE "HEYAQUOTES" WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '3'}  AND durable_writes = true;
    

    【讨论】:

      猜你喜欢
      • 2017-08-11
      • 2015-06-16
      • 2017-07-17
      • 2016-02-13
      • 2011-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-18
      相关资源
      最近更新 更多