开发者

Is there build-in support for 'as of' a.k.a. 'date effective' data retrieval in Cassandra

开发者 https://www.devze.com 2023-03-21 02:19 出处:网络
I want to defin开发者_如何转开发e some data in a row, which is master/detail in nature. For illustration purposes let\'s say its a football league \'league-A\' with a collection of teams. Teams can be

I want to defin开发者_如何转开发e some data in a row, which is master/detail in nature. For illustration purposes let's say its a football league 'league-A' with a collection of teams. Teams can be added or removed over time, or their attributes may change, or the league's attributes may change.

In HBase I can define a table structure like this:

Column Family: League
       Column: Name
       Column: Sponsor
Column Family: Team
       Column: team-A
       Column: team-B  etc

Now if I add the following data (sorry for the non-standard notation, and I've simplified the timestamps to show just the date part):

Key    Timestamp    League { Name      Sponsor }
LG-A   2011-01-01            League-A  Big-Co

Key    Timestamp      Team
LG-A   2011-01-01       "The Blues": blues-data
LG-A   2011-01-01       "The Greens": greens-data
LG-A   2011-03-01       "The Reds": reds-data
LG-A   2011-03-10       "The Greens": greens-data2

I want to query the data for LG-A specifying time 2011-03-10 and get the result:

Key    Timestamp      Team
LG-A   2011-01-01       "The Blues": blues-data
LG-A   2011-03-01       "The Reds": reds-data
LG-A   2011-03-10       "The Greens": greens-data2

Similarly when I query for LG-A specifying time 2011-02-01 I get the result:

Key    Timestamp      Team
LG-A   2011-01-01       "The Blues": blues-data
LG-A   2011-01-01       "The Greens": greens-data

This is done in HBase by setting the timestamp when putting the data, and then setting the time range for the Get operation.

Can this be done in Cassandra easily? So far I have only come across suggestions to write column names using timestamp values to store timeseries data, but this does not seem to give the features illustrated above (e.g. I only want one entry for "The Greens" in my result, the one that's effective at the timestamp specified.


This is done in HBase by setting the timestamp when putting the data, and then setting the time range for the Get operation.

I'm reasonably sure this results in a full sequential scan.

You can manually seq scan in Cassandra, or you can create a column with your timestamp in it and index that. See http://www.datastax.com/dev/blog/whats-new-cassandra-07-secondary-indexes for an example (with non-ts data but the principle is the same).

0

精彩评论

暂无评论...
验证码 换一张
取 消