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
Related
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.
I have the following table:
CREATE TABLE dove.backend_events (
log_time_local timeuuid,
username text,
log_type text,
log_time timestamp,
device_category text,
log text,
device_details frozen<map<text, text>>,
PRIMARY KEY (log_time_local, username, device_details)
);
I am running this query: SELECT * FROM dove.backend_events WHERE device_details['category'] = 'mobile' ALLOW FILTERING;
I am getting this error: InvalidRequest: code=2200 [Invalid query] message="Map-entry equality predicates on frozen map column device_details are not supported"
What is causing it and how do I fix it? This error is not occurring when device_details is not part of the primary key and is not frozen.
You could add an index for device_details instead of setting it as primary key (and without freezing it):
CREATE TABLE dove.backend_events (
log_time_local timeuuid,
username text,
log_type text,
log_time timestamp,
device_category text,
log text,
device_details map<text, text>,
PRIMARY KEY (log_time_local, username)
);
CREATE INDEX dove.device_details_index ON dove.backend_events (ENTRIES(device_details));
This way you could run your query efficiently and without having to use ALLOW FILTERING:
SELECT * FROM dove.backend_events WHERE device_details['category'] = 'mobile';
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.
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().
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.