Cassandra CQL implementation - cql

INSERT INTO patient(patient_id, pt_name, pt_dob, pt_gender, pt_occupation, pt_address, pt_city_town_vill, pt_district, pt_state, pt_pin, pt_country, pt_email_id, pt_phone, ecp_name, ecp_relation, ecp_address, ecp_city_town_vill, ecp_district, ecp_state, ecp_pin, ecp_country, ecp_email_id, ecp_phone, history, blood_grp, allergy) VALUES (c37d661d-7e61-49ea-96a5-68c34, 'Rahul', {'2015-12-3 23:21'}, 'male', 'farmer', 'nadia', 'berhampore','murshidabad','west bengal', '700300', 'india', 'abc#hi.com', '990876541', 'Rohan', 'family-friend', 'abc', 'downtown', 'dinajpur', 'bengal', '788905', 'zgyuj', 'dd#gc.com', '990742568', {'2015-12-3 10:00' : 'has diabetes and high blood pressure'}, 'O positive', {'rashes appear on consumption of prawns' : 'is allergic to quinone medicine'});
someone please solve this error...
<ErrorMessage code=2000 [Syntax error in CQL query] message=line 1:367 mismatched character ',' expecting set null">

Check character 367 (per error message). Is patient_id a uuid? I don't think c37d661d-7e61-49ea-96a5-68c34 is valid

Related

SELECT comment FROM comments_by_video WHERE uuid = 'with id 357c33b4-9054-a5e1- 8da8-d9e38294fac1';

I create table with
CREATE TABLE comments_by_video (
videoid uuid,
userid uuid,
comment text,
PRIMARY KEY(videoid, commentid));
and copy the table.
I excuted this query below
SELECT comment FROM comments_by_video WHERE userid = 'with id 357c33b4-9054-a5e1- 8da8-d9e38294fac1';
and got this error.
InvalidRequest: Error from server: code=2200 [Invalid query] message="Invalid STRING constant (with id 357c33b4-9054-a5e1- 8da8-d9e38294fac1) for "userid" of type uuid"
PLEASE HELP!
First error - UUIDs are written as-is, without quotes: 357c33b4-9054-a5e1- 8da8-d9e38294fac1
Second error - you're having condition on the field that isn't a partition key - this will require full table scan and won't work at scale. In Cassandra table structure is modeled around queries, so you'll need to have a table with partition key for userid
I recommend to read first chapters of this free book to understand how Cassandra works.

DS201: How to get value of "type timeuuid" while inserting into cassandra using Python Driver?

This is my first query on the forum so please correct if my understanding are wrong.
I am executing exercise Application Driver Connection from DS201.
Table is as follows:
cqlsh:killrvideo> SELECT * FROM videos_by_tag ;
tag | added_date | video_id | title
-----------+---------------------------------+--------------------------------------+------------------------------
datastax | 2013-10-16 00:00:00.000000+0000 | 4845ed97-14bd-11e5-8a40-8338255b7e33 | DataStax Studio
Now I want to do one task "Python code to insert a new video into the database" as per lab.
I tried this code and getting error:
>>> session.execute(
... "INSERT INTO videos_by_tag (tag, added_date, video_id, title)" +
... "VALUES ('cassandra', '2013-01-10', uuid(), 'Cassandra Is My Friend')")
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
File "cassandra/cluster.py", line 2618, in cassandra.cluster.Session.execute
File "cassandra/cluster.py", line 4877, in cassandra.cluster.ResponseFuture.result
cassandra.InvalidRequest: Error from server: code=2200 [Invalid query] message="Type error: cannot assign result of function system.uuid (type uuid) to video_id (type timeuuid)"
>>>
I tried below but failed:
UUIDs.timeBased()
ERROR:
cassandra.InvalidRequest: Error from server: code=2200 [Invalid query] message="Unknown function uuids.timebased called"
cassandra.util.uuid_from_time
ERROR:
cassandra.protocol.SyntaxException: <Error from server: code=2000 [Syntax error in CQL query] message="line 1:109 no viable alternative at input '.' (...)VALUES ('cassandra', '2013-01-10', [cassandra].util...)">
For time being I have hardcoded the value.
session.execute(
... "INSERT INTO videos_by_tag (tag, added_date, video_id, title)" +
... "VALUES ('cassandra', '2013-01-10', 245e8024-14bd-11e5-9743-8238357b7e32, 'Cassandra Is My Friend')")
Success in DB:
cassandra | 2013-01-10 00:00:00.000000+0000 | 245e8024-14bd-11e5-9743-8238357b7e32 | Cassandra Is My Friend
But I want to know this ?
You are correct in that the call to the uuid() function is your problem:
INSERT INTO videos_by_tag (tag,added_date,video_id,title)
VALUES ('cassandra', '2013-01-10', uuid(), 'Cassandra Is My Friend');
The uuid() function generates a type-4 UUID, whereas the video_id column is defined as a type-1 UUID (aka a TIMEUUID).
Instead, invoke the now() function to get a TIMEUUID:
INSERT INTO videos_by_tag (tag,added_date,video_id,title)
VALUES ('cassandra', '2013-01-10', now(), 'Cassandra Is My Friend');

no viable alternative at input '<' cassandra map

I created a type as such
create type (
street text,
city text,
state text,
zip int
);
then tried to create a table like this:
create table (
fName text PRIMARY KEY,
addressess map<text, frozen<address>>
);
but I keep getting this error though:
SyntaxException: <ErrorMessage code=2000 [Syntax error in CQL query] message="line 1:78 no viable alternative at input '<' (..., addresses <string, frozen [<]...)">
I followed this doc on datastax and I'm on version 2.1.8
http://docs.datastax.com/en/cql/3.1/cql/cql_using/cqlUseUDT.html

Cassandra 2.1.0-beta2: Invalid set literal for ColumnDefinition

I'm trying out Cassandra 2.1.0-beta2 for nested user defined types. These are the structures that has been created through cqlsh 5.0.0:
CREATE TYPE channelsource(id text, sources set<text>);
CREATE TYPE primaryfeed(name text, type text, multisource channelsource);
CREATE TABLE somedata (
source text PRIMARY KEY,
unitid text,
dayssincebirth text,
reporttime text,
somefeed primaryfeed
);
This sample insert fails:
INSERT INTO somedata (source, unitid, dayssincebirth, reporttime, somefeed)
VALUES('GFDS8-v1.2.3', 'xxxxxxxx-ABCD-1234-B8F9-11111177F4', '89', '13:02:39',
{'dha', 'foo', {'someid', {'aa', 'cc'}}});
With this error:
code=2200 [Invalid query] message="Invalid set literal for ColumnDefinition
{name=somefeed, type=org.apache.cassandra.db.marshal.UserType
(bispace,7072696d61727966656564,6e616d65:org.apache.cassandra.db.marshal.UTF8Type,
74797065:org.apache.cassandra.db.marshal.UTF8Type,6d756c7469736f75726365:
org.apache.cassandra.db.marshal.UserType(bispace,6368616e6e656c736f75726365,6964
:org.apache.cassandra.db.marshal.UTF8Type,736f7572636573:
org.apache.cassandra.db.marshal.SetType(org.apache.cassandra.db.marshal.UTF8Type))),
kind=REGULAR, componentIndex=0, indexName=null, indexType=null} of type primaryfeed"
Any pointers on what the correct syntax I should be using? I'm assuming that nested user defined types are supported in 2.1 onwards.
You basically need to pass also the name of the fields, i.e.
{name: 'dha', type: 'foo', ...}
More details are in this article http://www.datastax.com/dev/blog/cql-in-2-1
Note: the syntax you used ( {'val', 'val'}) is the syntax for sets and that explains the error you are seeing.

Insert query failing in cassandra when using now()

INSERT INTO testtable (id, user_name, gender, rank) VALUES (now(), 'test_user', 'MALE', 2) ;
Bad Request: line 1:60 no viable alternative at input 'now'
Can someone help on the above error message when trying to insert a timeuuid into a table in cassandra.
You need to upgrade Cassandra - the timeuuid functions were added in Cassandra 1.2.2.

Resources