E.g. like get_count(key) in pycassa.
Or, when will this be implemented in CQL?
Thanks,
Charlie | DBA
E.g. like get_count(key) in pycassa.
Or, when will this be implemented in CQL?
Thanks,
Charlie | DBA
http://www.datastax.com/docs/1.0/references/cql/SELECT
You should be able to do:
SELECT count(*) FROM <keyspace>.<columnfamily> WHERE KEY = <key>
That's correct, but to elaborate, you would need to define a composite PK on that columnfamily and then use the *partition key* in the WHERE clause. See http://www.datastax.com/dev/blog/schema-in-cassandra-1-1 for an explanation.
Composite PK is only supported in Cassandra 1.1.
Hi Jonathan Ellis and Nickmbailey,
Thanks for the reply. I'll try composite PK on Cassandra 1.1 later.
FYI,
It doesn't work on Cassandra 1.0.7. ;)
/home/cassandra>cqlsh
Connected to Test Cluster at localhost:9160.
[cqlsh 2.0.0 | Cassandra 1.0.7 | CQL spec 2.0.0 | Thrift protocol 19.20.0]
Use HELP for help.
cqlsh>
cqlsh> CREATE KEYSPACE demo with strategy_class = 'SimpleStrategy' and strategy_options:replication_factor=1;
cqlsh> use demo;
cqlsh:demo> CREATE COLUMNFAMILY c1 (id int PRIMARY KEY)
... WITH comparator=varchar AND default_validation=int;
cqlsh:demo> update c1 set a01 =1 where id = 1;
cqlsh:demo> update c1 set a02 =1 where id = 1;
cqlsh:demo> update c1 set a03 =1 where id = 1;
cqlsh:demo> update c1 set a04 =1 where id = 1;
cqlsh:demo> update c1 set a05 =1 where id = 1;
cqlsh:demo> update c1 set a06 =1 where id = 1;
cqlsh:demo> update c1 set a07 =1 where id = 1;
cqlsh:demo> update c1 set a08 =1 where id = 1;
cqlsh:demo> update c1 set a09 =1 where id = 1;
...
cqlsh:demo> update c1 set a25 =1 where id = 1;
cqlsh:demo>
cqlsh:demo>
cqlsh:demo> SELECT count(*) FROM demo.c1 where id=1;
count |
1 |
Thanks,
Charlie | DBA
Like I said, you need to declare a composite PK for this, which is only supported in 1.1.
Sure. I'll test it after CQL3.0 is released.
It didn't work on my local CQL 3.0.
FYI,
$>cqlsh --cql3
Connected to MyCluster at xxx:9160.
[cqlsh 2.2.0 | Cassandra 1.1.0 | CQL spec 3.0.0 | Thrift protocol 19.30.0]
Use HELP for help.
cqlsh> use demo;
cqlsh:demo> SELECT count(*) FROM demo.c1 where id=1;
Bad Request: Only COUNT(*) and COUNT(1) operations are currently supported.
cqlsh:demo> SELECT count(1) FROM demo.c1 where id=1;
count
-------
1
Thanks,
Charlie | DBA
[cqlsh 2.2.0 | Cassandra 1.1.0 | CQL spec 3.0.0 | Thrift protocol 19.30.0]
Use HELP for help.
cqlsh> use demo;
drop COLUMNFAMILY isbn_price_v3k3;
CREATE COLUMNFAMILY isbn_price_v3k3
(isbn varchar,
price float,
listing_id int,
qty int,
obj varchar,
PRIMARY KEY (isbn, price, listing_id)
);
insert into isbn_price_v3k3(isbn, price, listing_id, obj) values ('111222333444',1.2,1001,'axxxxxxxxx');
insert into isbn_price_v3k3(isbn, price, listing_id, obj) values ('111222333444',1.2,1002,'axxxxxxxxx');
insert into isbn_price_v3k3(isbn, price, listing_id, obj) values ('111222333444',1.2,1003,'axxxxxxxxx');
insert into isbn_price_v3k3(isbn, price, listing_id, obj) values ('111222333444',5.5,1004,'axxxxxxxxx');
insert into isbn_price_v3k3(isbn, price, listing_id, obj) values ('111222333444',5.5,1005,'axxxxxxxxx');
insert into isbn_price_v3k3(isbn, price, listing_id, obj) values ('111222333444',1.2, 995,'axxxxxxxxx');
insert into isbn_price_v3k3(isbn, price, listing_id, obj) values ('111222333444',5.5, 978,'bxxxxxxxxx');
cqlsh:demo> SELECT isbn, price FROM isbn_price_v3 where isbn='111222333444';
isbn | price
--------------+-------
111222333444 | 2.2
111222333444 | 3.4
111222333444 | 5.5
111222333444 | 7.1
111222333444 | 7.2
111222333444 | 7.3
111222333444 | 9.8
cqlsh:demo> SELECT count(*) FROM isbn_price_v3 where isbn='111222333444';
Bad Request: Only COUNT(*) and COUNT(1) operations are currently supported.
cqlsh:demo> SELECT count(1) FROM isbn_price_v3 where isbn='111222333444';
count
-------
1
It still didn't work.
Thanks,
Charlie|DBA
Confirmed, there's a bug here in the CQL3 parser- it doesn't treat the * right. Use "count(1)" instead for now; it is precisely equivalent. This is fixed in https://issues.apache.org/jira/browse/CASSANDRA-4185 .
clearance polo shirts are also referred to as "polos" in addition to grew to become so famous about world of golf training; men and women started out getting in touch with them world of golf shirts. However the thoughts "polo ralph lauren outlet online " in addition to "golf shirt" are used interchangeably, the word "polo shirt" is actually more popular. Embroidered hollister outlet online tend to be used with regard to organization, casual in addition to recreational activitieshttp://www.clearance-polo-shirts.com.
You must log in to post.