问题
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
How can i resolve this?
回答1:
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.
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.
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\" ..."
Soo also: http://www.datastax.com/documentation/cql/3.0/cql/cql_reference/ucase-lcase_r.html
回答2:
You will need to enclose emsSdk in quotes in your query. If you dont, then it is converted to lowercase. Any object that has been created with uppercase letters will need to be enclosed in quotes when referenced from the CQL query.
Session.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)");
来源:https://stackoverflow.com/questions/28447149/key-space-name-issue-with-creating-table-in-cassandra