带大写字母的cassandra键空间
cassandra keyspace with capital letter
使用框架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
有什么问题?
问题是对失败的 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)
);
你其实有好几种选择,可以用smart
、Smart
、"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;
使用框架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
有什么问题?
问题是对失败的 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)
);
你其实有好几种选择,可以用smart
、Smart
、"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;