Creating keyspace on Cassandra - cassandra

I am new to Cassandra, I wrote a blog in French that narrate all the unpleasant experiences that I have because of him (like always having Unable to find java executable when launching it after rebooting or the 7199 always already in use...). I created a github repository to share my cassandra directory.
But until now I can manage them unti this new one that didn't appeared last time I tried to launch Cassandra.
I try to create a keyspace about Cassandra with the help of the tutorialspoint tutorial but there is a problem: When I make the command to create a Keyspace:
;CREATE KEYSPACE k1 WITH
strategy_class = 'SimpleStrategy'
AND trategy_otpions:replication_factor = '1';
...
Or even :
cqlsh> CREATE KEYSPACE k1 WITH
... replication = {'class': 'strategy_class = 'SimpleStrategy'
... AND trategy_otpions:replication_factor = '1';
...
It just won't compile even after a semicolon ...
Do you have an idea ?
Do you have a good tutorial on Cassandra ?
Edit 28/11
I don't know why but this command worked :
cqlsh> CREATE KEYSPACE IF NOT EXISTS k1 WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'} AND durable_writes = true;
My next question will be on how to import a very large csv file one can found on the open platform of French public data there is at least 150 column which can all have the vartext type but the first one which is numeric.

I think your syntax for cqlsh it's wrong, if the one that you pasted is the one that you used.
The correct syntax for cqlsh is CREATE KEYSPACE test WITH replication = {'class':'SimpleStrategy', 'replication_factor' : 3};.
For importing data from a csv file you should read on this https://docs.datastax.com/en/cql/3.3/cql/cql_using/useInsertCopyCSV.html

Related

Cassandra Datastax Node.js driver can't find keyspace

Just installed Cassandra (3.11.1) and Datastax node.js driver (3.3.0).
Created a simple structure:
CREATE KEYSPACE CaseBox
WITH REPLICATION={
'class': 'SimpleStrategy',
'replication_factor': 1};
USE CaseBox;
CREATE TABLE Regions (
regionId int,
name varchar,
PRIMARY KEY ((regionId))
);
Trying connect to the keyspace with no success:
const client = new cassandra.Client({
contactPoints: ['localhost'],
keyspace: 'CaseBox'
});
await client.connect();
Error: Keyspace 'CaseBox' does not exist.
If I change the desired kayspace to system it works.
What's wrong? Please assist.
You can find my full Cassandra config, CQL and js scripts here.
Keyspace names are forced lower case when unquoted in CQL.
Use CREATE KEYSPACE "CaseBox" in CQL or keyspace: 'casebox' in Node.
Generally just use snake_case names as you won't get trapped like this as often.

"Drop keyspace" command in cassandra

i created a key space named 'hello' in Cassandra and started using it(use command). so the commands were typed after cqlsh:hello> in the cql. i then dropped the key space hello, but still it is showing cqlsh:hello> at beginning of each command. why so ?
The keyspace is gone, but you need to reset your session context with the 'use' command.
cqlsh:test> create keyspace xyz with replication = {'class':'SimpleStrategy', 'replication_factor':1} ;
cqlsh:test> use xyz;
cqlsh:xyz> drop keyspace xyz;
cqlsh:xyz> describe keyspace
Keyspace 'xyz' not found.
cqlsh:xyz>

Cassandra NoHostAvailable: error in CQLSH

I just finished creating my table in cassandra. I attempted to insert data into the table and I was given this error:
cqlsh:test> INSERT into qw (id, user, pass, email, phoneNum) VALUES (1, 'scman', '123','sc#gmaail.com','123-456-7890');
NoHostAvailable:
I checked that my server was running. What could be causing this problem.
This is too late to answer. But I wanted to share my experience.
If you have a single node cluster and use NetworkTopologyStrategy, then it throws this error. Check your keyspace configuration.
Error during inserting data: NoHostAvailable:
My CQL command to update the replication
ALTER KEYSPACE my_keyspace WITH replication = {'class' : 'NetworkTopologyStrategy', 'DC1' : 1 ,'DC2' :2 };
was slightly different from the config files : conf/cassandra-rackdc.properties
# These properties are used with GossipingPropertyFileSnitch and will
# indicate the rack and dc for this node
dc=dc1
rack=rack1
resulting in a
cqlsh: my_keyspace> select * from world where message_id = 'hello_world';
NoHostAvailable:
the replication strategy is case sensitive and copy/paste from documentation may lead you to a mistake.
Fix : Changing the replication info so that it match the config files
ALTER KEYSPACE my_keyspace WITH replication = {'class' : 'NetworkTopologyStrategy', 'dc1' : 1 ,'dc2' :2 };
And execute on each node :
bin/nodetool repair --full my_keyspace
Got replication set on every node

export cassandra schema (all keyspaces and tables)

I am going through the code of apache cassandra 2.2 branch, and unable to find where we can backup entire schema (including all keyspaces and tables).
If you only need to backup scheme than you can use DESCRIBE KEYSPACE in cqlsh
cqlsh $(hostname) -e "DESCRIBE KEYSPACE <keyspace>;" > backup.cql
To restore scheme you can simply do
cat backup.cql | cqlsh $(hostname)
EDIT
To describe keyspace programmatically via thrift client. Compile client and then you can use describe_keyspaces/describe_keyspace
Cassandra.Client client = ...
for (KDef keyspaceDefinition : client.describe_keyspaces()) {
// process keyspace data
}

Altering keyspace to change strategy class is not working in cassandra-cli

I have tried to alter the keypace with strategy class and options using below command in cassandra-cli of version cassandra 1.1.6 but it says 'Syntax error at position 0: no viable alternative at input 'ALTER'.
ALTER KEYSPACE system_auth WITH REPLICATION =
{'class' : 'NetworkTopologyStrategy', 'dc1' : 3, 'dc2' : 2};
What is wrong here?
What is happening, is that you are using CQL syntax to update a keyspace from within the (deprecated) cassandra-cli tool. If you were using the cqlsh tool, your command would work just fine. But with cassandra-cli, that's not going to work. As Yasmeen indicated, the correct syntax that you will want to use is UPDATE KEYSPACE:
UPDATE KEYSPACE system_auth with placement_strategy = 'NetworkTopologyStrategy'
and strategy_options = {'dc1' : 3, 'dc2' : 2};
I do recommend that you use cqlsh in the future. The cassandra-cli is deprecated, and will not receive any further updates.
Also, you should also see about upgrading your cluster to a more recent version of Cassandra. While you are missing out on several new features, there have been many bugs fixed since 1.1.6 (bugs that you are probably running into).
UPDATE KEYSPACE demo
WITH placement_strategy = 'NetworkTopologyStrategy'
AND strategy_options = {'dc1' : 3, 'dc2' : 2};

Resources