在cassandra中创建表的键空间名称问题 [英] Key space name issue with creating table in cassandra

查看:132
本文介绍了在cassandra中创建表的键空间名称问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的密钥空间 emsSdk。我需要通过java在上述键空间中创建一个表。所以我遵循了使用spark-cassandra-connector的代码。下面提供了代码

I have an existing key space 'emsSdk'. I need to create a table in the mentioned key space through java. So i followed the code using spark-cassandra-connector. Code is provided below

ession.execute("CREATE TABLE emsSdk.activity (project_party_id TEXT, error_count TEXT,"
            + " lock_version TEXT, record_status_id TEXT, error_type TEXT, error_message TEXT, file TEXT, release_stage_id TEXT, "
            + "line_no TEXT, uid TEXT PRIMARY KEY, activity_type_id TEXT, created_at TEXT,"
            + "project_name TEXT, project_api_key TEXT, project_type_name TEXT, stage_name TEXT)");

但是它给了我一个错误,

But its giving me an error,

emssdk keyspace does not exists

我该如何解决?

推荐答案

我假设您使用CQL3创建表。 CQL3将键空间,表等的名称区分大小写。除非您将双引号引起来,否则CQL3语句中的名称将转换为小写。

I assume you use CQL3 to create the table. CQL3 treats names of keyspaces, tables etc. as case insensitive. Names in CQL3 statements are converted to lower case, unless you enclose them in double quotes.

如果在切换到CQL3之前创建了键空间,则键空间的名称仍为以混合大小写存储,即与emssdk不匹配的 emsSdk,CQL3之后的名称将其转换为小写。

If you created the keyspace before switching to CQL3, the name of the keyspace is still stored in mixed case, i.e. "emsSdk", which does not match emssdk, the name after CQL3 converts it to lower case.

所以解决方法是在语句:创建表 emsSdk.activity ...
当然,您必须对Java字符串中的引号进行转义:

So the fix is to quote the name in the statement: CREATE TABLE "emsSdk.activity" ... Of course you have to escape the quotes in the Java String:

"CREATE TABLE \"emsSdk.activity\" ..."

同样也可以: http://www.datastax.com/documentation/cql/3.0/cql/cql_reference/ucase-lcase_r.html

这篇关于在cassandra中创建表的键空间名称问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆