Range scans on columns using Astyanax - cassandra

My column family stores data in the column names and I want to perform range query on the columns using Astyanax. Can anyone suggest how to do that?

There are lots example on range query available here
Sample one
keyspace.prepareQuery(CF_TIME_UUID)
.getKey(rowKey)
.withColumnRange(
new RangeBuilder()
.setLimit(10)
.setStart(TimeUUIDUtils.getTimeUUID(0))
.setEnd(TimeUUIDUtils
.getTimeUUID(Long.MAX_VALUE >> 8))
.build()).execute();

I agree with abhi and this is exactly how Playorm has implemented it. You may see the code of columnSlice() API at https://github.com/deanhiller/playorm/blob/master/src/main/java/com/alvazan/orm/layer9z/spi/db/cassandra/CassandraSession.java
Also, if you are using Playorm for Cassandra you can just use its ColumnSlice API. The example is given at https://github.com/deanhiller/playorm/blob/master/src/test/java/com/alvazan/test/TestColumnSlice.java

Actually, you could just use PlayOrm Query language as well if you final goal is getting the entities out.

Related

Using Cassandra for time-series data storage

I'm a newbie to Cassandra and now evaluate it for our needs here - I need to handle a dynamic storage which holds a signal data from many sources. Each source provides, together with it's meta-data values, a continuous stream of signal data (time-value series).
What is the best data-model, even just as a starting-point, to handle this kind of data? Is it possible to insert the data as a vector (and not sample by sample) using CQL? Any link with concrete examples will be highly appreciated!
Thanks
Update:
Thanks a lot for the helpful comments! I looked at several examples and the method is clear. Still I have two issues:
I see on cqlsh the time stamp-value couples on a separate rows and not within a single row (for instance, if I insert 3 pairs of time stamp-values into the same key I expect to get it on query 1 row with 3 time stamp columns
Is it possible to INSERT a vector of values (and not repeated INSERTs)?
thanks
Is it possible to INSERT a vector of values (and not repeated INSERTs)?
I hope you are trying to use Batch execution. This is your good starting point.
http://docs.datastax.com/en/cql/3.1/cql/cql_reference/batch_r.html
Or you might be looking for Collection Type. Please note that they have their own limitations.
https://docs.datastax.com/en/cql/3.0/cql/cql_using/use_collections_c.html
As mentioned in other answers, article by Patrick McFadin should get you started.
Hope it helps!

Is it possible to insert/write data without defining columns in Cassandra?

I am trying to understand the fundamentals of Cassandra data model. I am using CQL. As per I know the schema must be defined before anyone can insert into new columns. If someone needs to add any column can use ALTER TABLE and can INSERT value to that new column.
But in cassandra definitive guide there is written that Cassandra is schema less.
In Cassandra, you don’t define the columns up front; you just define the column
families you want in the keyspace, and then you can start writing data without defining
the columns anywhere. That’s because in Cassandra, all of a column’s names are
supplied by the client.
I am getting confused and not finding any expected answer. Can someone please explain it to me or tell me if I am missing somthing?
Thanks in advance.
Theres two different APIs to interact with Cassandra for writing data. First there's the thrift API which always allowed to create columns dynamically, but also supports adding meta data for your columns.
Next theres the newer CQL based API. CQL was created to provide another abstraction layer that would make it more user friendly to work with Cassandra. With CQL you're required to define a schema upfront for your column names and datatypes. However, that doesn't mean its not possible to use dynamic columns using CQL.
See here for differences:
http://www.datastax.com/dev/blog/thrift-to-cql3
You are reading "Cassandra, the definitive guide": a 3/4 years old book that is telling you something that has changed long time ago. Now you have to define the tables structure before being able to write data.
Here you can find some reasons behind CQL introduction and the schema-less abandonment.
The official Datastax documentation should be your definitive guide.
HTH,
Carlo

Cassandra row key starts with [duplicate]

I have a cassandra column family which has a row key like
2012-09-30-05-42-00:30:5856869
I need to query some thing like
select * from cf where key like %5856869%
Currently I am using Astyanax , is same possible in astyanax. If not, which implementation would support it.
LIKE queries are not supported in Cassandra. If you want to query based on part of a key, you'll want to use composite keys. But in this specific case, the 5856869 portion of the key would have to be the first part for you to do what you want. Remember that with Cassandra, you must write your data the way you expect to read it.
None.... you need to write index manually - this is how you handle such things in Cassandra, or you might try full text search: Cassandra full text search like

Searching for data in Cassandra

I understand that with Cassandra, it is possible to search using secondary indexes, but the problem is I am trying to search on information from a super column. So I want to search on a value within a super column, but return everything within that row (not just that one super column).Is this possible to do?
My understanding is that Facebook and Twitter use Cassandra, and so it would seem quite pointless if they have search facilities but it is not possible to search using something built into Cassandra.
Please correct me if I have not understood the proper use of super columns within Cassandra.
Thanks.
You cannot search on a super column value, as secondary indexes are not supported for SCs. You should avoid using super columns for a variety of reasons, but mostly because they are effectively deprecated. Most super column use cases are supported through the use of composites--which will ultimately replace SCs. In the meantime, if you must search for a value in a SC, you will have to do so manually (i.e. in code) or using an external tool such as Hadoop or Solr.

secondary index on column store dbs

Is there any column store database that supports secondary index ?
I know HBase does, but it's not there yet.
Haggai.
By storing overlapping projections in different sort orders, column stores based on the C-Store architecture (so, as far as commericial implementations go, Vertica) natively support secondary indexes.
See http://db.csail.mit.edu/projects/cstore/vldb.pdf
Also check out MonetDb, which treats "create index" statements as hints for its self-organizing engine.
Take a look in this class IndexSpecification which is part of r0.19.3.
Here you can see how to use it (maybe they have a test for that as well)
I've never used that and don't if it performs well. please share with us your results.
good luck
-- Yonatan
Sybase IQ supports as many indexes as you might ever desire on every column and even within a column (e.g. the word index which lets you stay with defaults or specify your own delimiter)

Resources