I'm trying to create a simple table in cassandra, this is the command I run,
create table app_instance(app_id int, app_name varchar, proc_id varchar, os_priority int, cpu_time int, num_io_ops int, primary_key (host_id, proc_id)) with clustering order by (proc_id DESC) ;
I get the following error,
SyntaxException: line 1:132 no viable alternative at input '(' (...int, num_io_ops int, primary_key [(]...)
What am I doing wrong here?
It should be primary key, with a space, not primary_key, as ernest_k already noted in a comment.
The way you wrote it,
...cpu_time int, num_io_ops int, primary_key (host_id, proc_id)
the CQL parser thinks that "primary_key" is the name of yet another column, just as num_io_ops was, and now expects to see the name of the type - and doesn't expect an open parenthesis after the "primary_key", and this is exactly what the error message told you (albeit vaguely).
Related
tried to create the following table:
CREATE TABLE customTableSchema(
id UUID PRIMARY KEY,
table_id UUID,
schema text,
created_at timestamp,
last_modified_at timestamp,
);
came up with this error:
SyntaxException: line 4:8 missing ')' at '<missing '
The schema is reserved keyword in the Cassandra Query Language, so you can't use it (see this table in the docs).
Since "schema" is a reserverd keyword, you cannot use your query in current form. If you intend to use it then you can do it as below
CREATE TABLE customTableSchema(
id UUID PRIMARY KEY,
table_id UUID,
"schema" text,
created_at timestamp,
last_modified_at timestamp,
);
You can refer this page for reserved cql keywords.
Through postgresql, postgis, pgrouting and nodejs I am working on a project which basically finds a path between shops.
There are three tables in my database
1.CREATE TABLE public."edges" (id int, name varchar(100), highway varchar(100), oneway varchar(100), surface varchar(100), the_geom geometry, source int, target int);
2.CREATE TABLE public."edges_noded" (id bigint, old_id int, sub_id int, source bigint, target bigint, the_geom geometry, name varchar(100), type varchar(100), distance double precision);
3.CREATE TABLE public."edges_noded_vertices_pgr" (id bigint, cnt int, chk int, ein int, eout int, the_geom geometry); –
And the query by which I am finding path
client.query( "WITH dijkstra AS (SELECT * FROM pgr_dijkstra('SELECT id,source,target,distance AS cost FROM
edges_noded',"+source+","+target+",FALSE)) SELECT seq, CASE WHEN
dijkstra.node = edges_noded.source THEN
ST_AsGeoJSON(edges_noded.the_geom) ELSE
ST_AsGeoJSON(ST_Reverse(edges_noded.the_geom)) END AS
route_geom_x,CASE WHEN dijkstra.node = edges_noded.source THEN
ST_AsGeoJSON(edges_noded.the_geom) ELSE
ST_AsGeoJSON(ST_Reverse(edges_noded.the_geom)) END AS route_geom_y
FROM dijkstra JOIN edges_noded ON(edge = id) ORDER BY
seq",(err,res)=>{ })
This query works for me but taking too much time for example, If I want to find a path between 30 shops then it is taking almost 25 to 30 sec which is too much.
After searching about this problem I found this link
https://gis.stackexchange.com/questions/16886/how-can-i-optimize-pgrouting-for-speed/16888
In this link Délawenis is saying that use a st_buffer so it doesn't get all ways, but just the "nearby" ways:
So I tried to apply st_buffer in above query but not got any success.
If someone has any idea plz help me with this problem.
If this approach is wrong please also tell me the right way.
create table seller(
seller_id int primary key,
seller_name text,
seller_email set<text>,
seller_address map<text>,
seller_phone list<text>,
product_id int,
product_title_text,
product_description text,
product_trackno int,
product_bidoption text,
bid_startdate date,
bid_closedate date,
bid_startprice int,
bid_withdrawdate date);
SyntaxException: line 1:110 mismatched input '>' expecting ',' (...<text>,
seller_address map<text[>],...)
What changes should be made in order to execute?
Of course you can, with some adjustments:
1) It helps if the type of a column isn't linked to the column name by an underscore. Instead of:
product_title_text,
This will work:
product_title text,
2) You'll also need to provide both types for the map collection. Instead of:
seller_address map<TEXT>,
This will work:
seller_address map<TEXT,TEXT>,
Full CQL:
create table seller(
seller_id int primary key,
seller_name text,
seller_email set<TEXT>,
seller_address map<TEXT,TEXT>,
seller_phone list<TEXT>,
product_id int,
product_title text,
product_description text,
product_trackno int,
product_bidoption text,
bid_startdate date,
bid_closedate date,
bid_startprice int,
bid_withdrawdate date);
Also, are you really only ever going to query this table by seller_id? If not, you may want to rethink the primary key definition.
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 am having troubles with using now() function with timestamp type.
Please take a look at the following code:
Table creation:
CREATE TABLE "Test" (
video_id UUID,
upload_timestamp TIMESTAMP,
title VARCHAR,
views INT,
PRIMARY KEY (video_id, upload_timestamp)
) WITH CLUSTERING ORDER BY (upload_timestamp DESC);
The problematic INSERT query:
INSERT INTO "Test" (video_id, upload_timestamp, title, views)
VALUES (uuid(), now(), 'Test', 0);
The INSERT query seems looking fine to me. However, when I execute it, I see the following error:
Unable to execute CQL script on 'XXX': cannot assign result of function now (type timeuuid) to upload_timestamp (type timestamp)
What I am doing wrong here?
I use DataStax Enterprise 4.5.2
now() returns a timeuuid, not a timestamp. You clould try dateOf(now()). Have a read of this from the docs:
dateOf and unixTimestampOf
The dateOf and unixTimestampOf functions take a timeuuid argument and
extract the embedded timestamp. However, while the dateof function
return it with the timestamp type (that most client, including cqlsh,
interpret as a date), the unixTimestampOf function returns it as a
bigint raw value.