cql3

Cassandra cql: how to select the LAST n rows from a table

故事扮演 提交于 2019-11-28 03:02:56
问题 I want to verify that rows are getting added to the table. What cql statement would show the last n rows from the table below? Table description below: cqlsh:timeseries> describe table option_data; CREATE TABLE option_data ( ts bigint, id text, strike decimal, callask decimal, callbid decimal, maturity timestamp, putask decimal, putbid decimal, PRIMARY KEY ((ts), id, strike) ) WITH bloom_filter_fp_chance=0.010000 AND caching='KEYS_ONLY' AND comment='' AND dclocal_read_repair_chance=0.100000

SELECT Specific Value from map

纵饮孤独 提交于 2019-11-28 01:48:46
I am trying to create a WIDE Column Table, 20,000+ columns Initially I was thinking I would use: CREATE TABLE details ( key TEXT, detail map<TEXT, TEXT> PRIMARY KEY (KEY) ); Inserting into this table works fine UPDATE details SET detail = detail + { 'col1': '12'} where key='123' ; UPDATE details SET detail = detail + { 'col20000': 'ABCD'} where key='123' ; However, I would like to read an individual detail: select detail[col1] where key='123' when executing this query I get the following error: no viable alternative at input '[' Will this work, or do I need a different approach? jbellis

CQL3 Each row to have its own schema

只愿长相守 提交于 2019-11-27 22:27:42
I want to use Cassandra in a .Net application. My objective is to store some data in a column family, but each row of data will have varying schema. Example (A very simple one) I want to have a 'Toys' column family to store the following objects, (Notice how they have very different properties other than the ID property) Toy object 1 { "id":"1", "name":"Car", "number_of_doors":4, "likes":3} Toy object 2 { "id":"2", "type":"Plane", "flying_range":"100m"} Toy object 3 { "id":"3", "category":"Train", "number_of_carriages":10} From my initial understanding and using of Datastax CSharp driver I

Prepared Statement with collection in IN clause in Datastax Cassandra CQL driver

我的未来我决定 提交于 2019-11-27 16:03:47
问题 I am trying to run the following query SELECT edge_id, b_id FROM booking_by_edge WHERE edge_id IN ? I bind Java list of Long's as a parameter and I get an exception SyntaxError: line 0:-1 mismatched input '<EOF>' expecting ')' (ResultSetFuture.java:242) If I try to use (?) it expects single Long item to be bound, but I need a collection Is there an error in my syntax? 回答1: Tested in Cassandra 2.1.3, the following code snippet works: PreparedStatement prepared = session.prepare("SELECT edge_id

how to avoid secondary indexes in cassandra?

亡梦爱人 提交于 2019-11-27 13:08:51
问题 I have heard repeatedly that secondary indexes (in cassandra) is only for convenience but not for better performance. The only case where it is recommended to use secondary indexes when you have low cardinality (such as gender column which has two values male or female) consider this example: CREATE TABLE users ( userID uuid, firstname text, lastname text, state text, zip int, PRIMARY KEY (userID) ); right now I cannot do this query unless I create a secondary index on users on firstname

How do secondary indexes work in Cassandra?

血红的双手。 提交于 2019-11-27 10:52:37
Suppose I have a column family: CREATE TABLE update_audit ( scopeid bigint, formid bigint, time timestamp, record_link_id bigint, ipaddress text, user_zuid bigint, value text, PRIMARY KEY ((scopeid, formid), time) ) WITH CLUSTERING ORDER BY (time DESC) With two secondary indexes, where record_link_id is a high-cardinality column: CREATE INDEX update_audit_id_idx ON update_audit (record_link_id); CREATE INDEX update_audit_user_zuid_idx ON update_audit (user_zuid); According to my knowledge Cassandra will create two hidden column families like so: CREATE TABLE update_audit_id_idx( record_link_id

MAX(), DISTINCT and group by in Cassandra

拈花ヽ惹草 提交于 2019-11-27 08:39:18
I am trying to remodel a SQL database Cassandra such that, I can find the Cassandra equivalent for the SQL queries. I use CQL 3 and Cassandra v1.2. I modeled the db design in cassandra so that it supports the order by clauses and denormalized tables to support the join operation. However I am at sea when it comes to DISTINCT, SUM() and GROUPBY equvalents SELECT a1,MAX(b1) FROM demo1 group by a1. SELECT DISTINCT (a2) FROM demo2 where b2='sea' SELECT sum(a3), sum(b3) from demo3 where c3='water' and d3='ocean' This is like a showstopper to my work for past couple of days. Is there a way in

How to copy data from a Cassandra table to another structure for better performance

点点圈 提交于 2019-11-27 06:40:46
问题 In several places it's advised to design our Cassandra tables according to the queries we are going to perform on them. In this article by DataScale they state this: The truth is that having many similar tables with similar data is a good thing in Cassandra. Limit the primary key to exactly what you’ll be searching with. If you plan on searching the data with a similar, but different criteria, then make it a separate table. There is no drawback for having the same data stored differently.

Cassandra UUID vs TimeUUID benefits and disadvantages

陌路散爱 提交于 2019-11-27 04:18:13
问题 Given that TimeUUID handily allows you to use now() in CQL, are there any reasons you wouldn't just go ahead and always use TimeUUID instead of plain old UUID? 回答1: UUID and TIMEUUID are stored the same way in Cassandra, and they only really represent two different sorting implementations. TIMEUUID columns are sorted by their time components first, and then by their raw bytes, whereas UUID columns are sorted by their version first, then if both are version 1 by their time component, and

Cassandra batch statement - Execution order

强颜欢笑 提交于 2019-11-27 03:34:31
问题 I have a batch statement of Cassandra that contains a delete and an insert statement of same partition key, where delete is the first statement and insert is the second. How the batch statement executes these statements ? Is in the same order in which,we added the statements? 回答1: No, it does not execute them in the order specified. To force a particular execution order, you can add the USING TIMESTAMP clause. Check the docs for more information: http://docs.datastax.com/en/cql/3.1/cql/cql