modifying cqlsh prompt to get unique identifier - cassandra

Currently when I start up cqlsh, I get:
ubuntu#ip-172-31-83-106:~$ cqlsh
Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.11.4 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
cqlsh>
I want to be able to change
cqlsh>
not something unique, like
ubuntu#ip-172-31-83-106>
and each time I run a query, the prompt will remain. How can I do that?

CQLSH has very limited support for customization of the prompt. The only custom thing that you can bring into prompt is the string that should be passed via CQLSH_PROMPT environment variable and that will be printed before cqlsh> string (see sources)
For example, if you start your CQLSH as
CQLSH_PROMPT="$(whoami)#$(hostname)" cqlsh
then you'll gets something like this:
ubuntu#ip-172-31-83-106
cqlsh>
but that's all what you can do.

Related

Failure to execute cql script using cqlsh with nested SOURCE on DSE 5.1.2

I have a script I used to execute queries and DDL in DSE 4.8.10.
The script include nested use of the SOURCE command.
E.g.
1.sql
USE test;
SOURCE '2.sql'
exit;
2.sql
SELECT count(1) FROM user;
SOURCE '3.sql';
3.sql
SELECT count(1) FROM user;
When executing this script with DSE 4.8.10 it runs correctly and output
cqlsh –f 1.sql
count
--------
0
(1 rows)
count
--------
0
(1 rows)
Running the same script in DSE 5.1.2.
cqlsh –f 1.sql
count
-------
0
(1 rows)
Warnings :
Aggregation query used without partition key
2.sql:3:DSEShell instance has no attribute 'execution_profiles'
The actual issue is that the script in 3.sql is not executed.
I failed to find any useful information on the error
"DSEShell instance has no attribute 'execution_profiles'"
I failed to figure out what are execution_profiles although they are mentioned int the python docs here
Note: I am using python 2.7.7
Update
I did some additional investigations
With DSE-5.1.2 I switch the off to authenticator: AllowAllAuthenticator
authorizer: AllowAllAuthorizer, but I am still experiencing the issue
With DSE-5.1.1 it also happens
With DSE-5.0.9 it works
I failed to reproduce this in Apache Cassandra 3.11.0
Update 2: following support ticket we posted for Datastaxs we got a patch for this issue, I guess we should be expecting this to be fixed in the near feature.
As from DSE 5.1.4 this issue was resolved as part of DSP-14494.
See the 5.1.4 release notes
DSP-14494:Always define execution_profiles in cqlsh.py.
I tested this with 5.1.4 and the issue was resolved.

How to get Cassandra database dump with data

I need to get a dump(with data) from remote Cassandra database. I was able to get database schema via following command.How can i get all data in the keyspace?
I'm using Cassandra 1.1.9
echo -e "connect localhost/9260;\r\n use PWC_Keyspace;\r\n show schema;\n" | bin/cassandra-cli -h localhost -port 9260 > dilshan.cdl
With Cassandra 1.1.9, I don't believe you have access to cqlsh with the copy-to command, so you'll be stuck with 2 options.
1) Export the data from the data files (sstables) on disk using sstable2json, or
2) Write a program to iterate over every row and copy/serialize it to a format you find easier to work with.
You MAY be able to use a more recent cqlsh (say, from 2.0, which still used thrift instead of the native interface), and point it at your 1.1.9 server and use 'COPY TO' to export each table to a csv. However, the COPY command in cqlsh for 2.0 doesn't use paging, and cassandra 1.1.19 doesn't support paging, so there's a very good chance it's simply going to time out and fail.

Create table using cqlsh does not return to prompt

I am trying to create a table using cqlsh with composite primary key but it doesn't return to the cqlsh prompt. The cqlsh and cassandra versions are cqlsh 3.1.7 | Cassandra 1.2.13.2. Can we not create composite primary key using cqlsh? Have tried Dbeaver but that also fails reporting mismatched input ',' expecting EOF. Are there any other clients that allow to create?
Any suggestions would be helpful.
I tried your CREATE TABLE command on the same version of Cassandra using cql 3 and it just worked. It failed using cql 2.
If you're still using cql 2, that's likely the source of your problem.

How does "DROP TABLE IF EXISTS" work in Cassandra?

I'm trying to understand the syntax of DROP TABLE IF EXISTS in Cassandra.
DROP TABLE IF EXISTS nonexistanttable; does not seem to work:
$ ./cqlsh
Connected to Test Cluster at localhost:9160.
[cqlsh 4.1.1 | Cassandra 2.0.5 | CQL spec 3.1.1 | Thrift protocol 19.39.0]
Use HELP for help.
cqlsh> USE Foo;
cqlsh:foo> DROP TABLE IF EXISTS bar;
Bad Request: unconfigured columnfamily bar
What am I doing wrong?
The idea of DROP TABLE IF EXISTS is that you avoid getting the InvalidRequestException "Bad Request: unconfigured columnfamily" by droping the table only if it is actually created so your query statement is valid.
You are getting the exception because this was a bug in 2.0.5. It has been fixed for C* 2.0.6 but if you want to see DROP TABLE IF EXISTS immediately, try downloading and building cassandra from source:
git clone -b cassandra-2.0 git://git.apache.org/cassandra.git cassandra
cd cassandra
ant build

Datastax Cassandra odbc driver and starting cql2 on cqlsh 3 gives error as cqlsh: error: no such option: -2

I have installed datastax ODBC driver for cassndra and also i have created keyspace and some tables using cql 3. But ODBC driver is not showing up those tables.
Also in odbc documentation i read that the driver does not currently support version 3.0 of the Cassandra Query Language (CQL3) and the driver will not recognize keyspaces and column families that are defined with CQL 3.
So in order to use cql 2 i am using following command which is suggested in driver documentation:
...\cqlsh” -2
But this is giving an error saying "cqlsh: error: no such option: -2"
Can anybody help me out with this?
cql2 is deprecated and was removed from cslqh in Cassandra 2.0. It will be removed from the server as well in 3.0.
I do not know when cql3 support will be added to the ODBC driver.
The documentation is not correct regarding how to start cqlsh using a previous spec/version...you need to use --cqlversion instead of -2 (see notes below). However, as mentioned in jbellis' answer cql2 support has been removed from later versions of cassandra.
CQL Shell for Apache Cassandra
Options:
--version show program's version number and exit
-h, --help show this help message and exit
-C, --color Always use color output
--no-color Never use color output
-u USERNAME, --username=USERNAME
Authenticate as user.
-p PASSWORD, --password=PASSWORD
Authenticate using password.
-k KEYSPACE, --keyspace=KEYSPACE
Authenticate to the given keyspace.
-f FILE, --file=FILE Execute commands from FILE, then exit
-t TRANSPORT_FACTORY, --transport-factory=TRANSPORT_FACTORY
Use the provided Thrift transport factory function.
--debug Show additional debugging information
--cqlversion=CQLVERSION
Specify a particular CQL version (default: 3.1.1).
Examples: "3.0.3", "3.1.0"
-e EXECUTE, --execute=EXECUTE
Execute the statement and quit.

Resources