Cassandra 2.1.0-beta2: Invalid set literal for ColumnDefinition - cassandra

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.

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.

nested map in cassandra data modelling

I have following requirement of my dataset, need to unserstand what datatype should I use and how to save my data accordingly :-
CREATE TABLE events (
id text,
evntoverlap map<text, map<timestamp,int>>,
PRIMARY KEY (id)
)
evntoverlap = {
'Dig1': {{'2017-10-09 04:10:05', 0}},
'Dig2': {{'2017-10-09 04:11:05', 0},{'2017-10-09 04:15:05', 0}},
'Dig3': {{'2017-10-09 04:11:05', 0},{'2017-10-09 04:15:05', 0},{'2017-10-09 04:11:05', 0}}
}
This gives an error :-
Error from server: code=2200 [Invalid query] message="Non-frozen collections are not allowed inside collections: map<text, map<timestamp, int>>"
How should I store this type of data in single column . Please suggest datatype and insert command for the same.
Thanks,
There is limitation of Cassandra - you can't nest collection (or UDT) inside collection without making it frozen. So you need to "froze" one of the collections - either nested:
CREATE TABLE events (
id text,
evntoverlap map<text, frozen<map<timestamp,int>>>,
PRIMARY KEY (id)
);
or top-level:
CREATE TABLE events (
id text,
evntoverlap frozen<map<text, map<timestamp,int>>>,
PRIMARY KEY (id)
);
See documentation for more details.
CQL collections limited to 64kb, if putting things like maps in maps you might push that limit. Especially with frozen maps you are deserializing the entire map, modifying it, and re inserting. Might be better off with a
CREATE TABLE events (
id text,
evnt_key, text
value map<timestamp, int>,
PRIMARY KEY ((id), evnt_key)
)
Or even a
CREATE TABLE events (
id text,
evnt_key, text
evnt_time timestamp
value int,
PRIMARY KEY ((id), evnt_key, evnt_time)
)
It would be more efficient and safer while giving additional benefits like being able to order the event_time's in ascending or descending order.

CQL: Invalid set literal for values of type map

I have this table
create table constants_values
(
key_name_1 text,
key_name_2 text,
values map<text, frozen<nav_tag_values>>,
PRIMARY KEY(key_name_1, key_name_2)
);
UDT:
CREATE TYPE ks_mobApp.nav_tag_values (
values set<text>
);
Here i am inserting values:
cqlsh:ks_mobapp> insert into constants_values(key_name_1,key_name_2,values)
values('Sell', 'Electronics', {{'Mobile', {values:{'Laptop'}}}});
and here is error:
InvalidRequest: code=2200 [Invalid query]
message="Invalid set literal for values of type map<text, nav_tag_values>"
What i am missing ?
Try this with cqlsh:
INSERT INTO constants_values(key_name_1,key_name_2,values)
VALUES('Sell', 'Electronics', {'Mobile': {value : ['Laptop']});
INSERT INTO constants_values(key_name_1,key_name_2,values) values('Sell', 'Electronics', {'Mobile': {values:{'Laptop'}}});
the key point is the : vs the , in your original statement.

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 : missing EOF at ')' when trying to create simple table

I am trying to create a simple table on Cassandra using cqlsh. The syntax is:
CREATE TABLE TEST(
timestamp timestamp,
system_id text,
hostname text,
cpu_pct float,
memory_used bigint,
PRIMARY_KEY(system_id, timestamp)
);
When I run this I get this error however. How to fix?
ErrorMessage code=2000 [Syntax error in CQL query] message="line 8:0 missing EOF at ')' (...,PRIMARY_KEY(system_id, timestamp)[)];)"
CREATE TABLE TEST(
timestamp timestamp,
system_id text,
hostname text,
cpu_pct float,
memory_used bigint,
PRIMARY KEY(system_id, timestamp)
);
See CQL CREATE TABLE Doc
You accidentally put an underscore between "PRIMARY KEY" instead of a space.
Also you might not want a field called "timestamp" since that is also a Cassandra type, so maybe call that "ts" or something.
PRIMARY_KEY() should be PRIMARY KEY().

Resources