大写字母

时间:2016-08-20 21:15:07

标签: cassandra datastax

使用框架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

问题是什么?

1 个答案:

答案 0 :(得分:3)

问题是检查失败的UDT创建查询是区分大小写的,而所有其他查询都不是。因为你还没有提供“智能”语法,所以Cassandra认为你的所有小写都意味着“聪明”。

因此,如果您将最终查询写入工作,那么您所要做的就是这样写:

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;