You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Will Zhang <we...@gmail.com> on 2015/12/16 00:30:56 UTC

Materialized View: can the view's partition key change due to changes to the underlying table?

Hi all,

I originally raised this on SO, but not really getting any answer there, thought I give it a try here.


Just thinking about this so please correct my understanding if any of this isn't right. 

Environment: Apache Cassandra v3.0.0

Say you have a table and a materialized view created on it:

create table source(
id text, field text, stamp timestamp, data text, 
primary key(id, field))

create materialized view myview as
select * from source
where data is not null and id is not null and field is not null
primary key (data, field, id)
My understanding is that myview.data would essentially be the partition key for the view here (and data in source is automatically replicated by the server into myview?). 

If that is true, what happens internally when a table update is performed on source table and the source.data column is updated?


SO: http://stackoverflow.com/questions/33943960/apache-cassandra-3-0-0-materialized-view-can-the-views-partition-key-change-du

Thanks,

Will




Re: Materialized View: can the view's partition key change due to changes to the underlying table?

Posted by Jack Krupansky <ja...@gmail.com>.
It should all just work as expected, as if by magic. That's the whole point
of having MV, so that Cassandra does all the bookkeeping for you. Yes, the
partition key can change, so an update to the base table can cause one (or
more) MV rows to be deleted and one (or more) new MV rows to be created. It
does not change the partition key per se, but it is as if it were changed
and the row moved. This can in fact result in the row moving from one node
to another if the column(s) used in the MV partition key change in the base
table row.

-- Jack Krupansky

On Tue, Dec 15, 2015 at 6:30 PM, Will Zhang <we...@gmail.com>
wrote:

> Hi all,
>
> I originally raised this on SO, but not really getting any answer there,
> thought I give it a try here.
>
>
> Just thinking about this so please correct my understanding if any of this
> isn't right.
>
> Environment: Apache Cassandra v3.0.0
>
> Say you have a table and a materialized view created on it:
>
> create table source(
> id text, field text, stamp timestamp, data text,
> primary key(id, field))
>
> create materialized view myview as
> select * from source
> where data is not null and id is not null and field is not null
> primary key (data, field, id)
>
> My understanding is that myview.data would essentially be the partition
> key for the view here (and data in source is automatically replicated by
> the server into myview?).
>
> *If that is true, what happens internally when a table update is performed
> on source table and the source.data column is updated?*
>
> SO:
> http://stackoverflow.com/questions/33943960/apache-cassandra-3-0-0-materialized-view-can-the-views-partition-key-change-du
>
> Thanks,
>
> Will
>
>
>
>

Re: Materialized View: can the view's partition key change due to changes to the underlying table?

Posted by Will Zhang <we...@gmail.com>.
Thanks Carl & Jack, that explains it well. The servers does get busy when such an update happens. Very helpful!

Will

Sent from my iPhone

> On 16 Dec 2015, at 00:05, Carl Yeksigian <ca...@yeksigian.com> wrote:
> 
> In the case of an update to the source table where data is changed, a tombstone will be generated for the old value and an insert will be generated for the new value. This happens serially for the source partition, so if there are multiple updates to the same partition, a tombstone will be generated for each intermediate value.
> 
> This blog post has more details: http://www.datastax.com/dev/blog/new-in-cassandra-3-0-materialized-views
> 
> -Carl
> 
>> On Dec 15, 2015 18:49, "Will Zhang" <we...@gmail.com> wrote:
>> Haven't had a chance to yet but I will. However, trying might not fully explain what happens behind the scenes, ie, you'd see the effect but not everything that happens. 
>> 
>> Thanks. 
>> 
>> Sent from my iPhone
>> 
>>> On 15 Dec 2015, at 23:41, Laing, Michael <mi...@nytimes.com> wrote:
>>> 
>>> why don't you just try it?
>>> 
>>>> On Tue, Dec 15, 2015 at 6:30 PM, Will Zhang <we...@gmail.com> wrote:
>>>> Hi all,
>>>> 
>>>> I originally raised this on SO, but not really getting any answer there, thought I give it a try here.
>>>> 
>>>> 
>>>> Just thinking about this so please correct my understanding if any of this isn't right. 
>>>> 
>>>> Environment: Apache Cassandra v3.0.0
>>>> 
>>>> Say you have a table and a materialized view created on it:
>>>> 
>>>> create table source(
>>>> id text, field text, stamp timestamp, data text, 
>>>> primary key(id, field))
>>>> 
>>>> create materialized view myview as
>>>> select * from source
>>>> where data is not null and id is not null and field is not null
>>>> primary key (data, field, id)
>>>> My understanding is that myview.data would essentially be the partition key for the view here (and data in source is automatically replicated by the server into myview?). 
>>>> 
>>>> If that is true, what happens internally when a table update is performed on source table and the source.data column is updated?
>>>> 
>>>> 
>>>> SO: http://stackoverflow.com/questions/33943960/apache-cassandra-3-0-0-materialized-view-can-the-views-partition-key-change-du
>>>> 
>>>> Thanks,
>>>> 
>>>> Will

Re: Materialized View: can the view's partition key change due to changes to the underlying table?

Posted by Carl Yeksigian <ca...@yeksigian.com>.
In the case of an update to the source table where data is changed, a
tombstone will be generated for the old value and an insert will be
generated for the new value. This happens serially for the source
partition, so if there are multiple updates to the same partition, a
tombstone will be generated for each intermediate value.

This blog post has more details:
http://www.datastax.com/dev/blog/new-in-cassandra-3-0-materialized-views

-Carl
On Dec 15, 2015 18:49, "Will Zhang" <we...@gmail.com> wrote:

> Haven't had a chance to yet but I will. However, trying might not fully
> explain what happens behind the scenes, ie, you'd see the effect but not
> everything that happens.
>
> Thanks.
>
> Sent from my iPhone
>
> On 15 Dec 2015, at 23:41, Laing, Michael <mi...@nytimes.com>
> wrote:
>
> why don't you just try it?
>
> On Tue, Dec 15, 2015 at 6:30 PM, Will Zhang <we...@gmail.com>
> wrote:
>
>> Hi all,
>>
>> I originally raised this on SO, but not really getting any answer there,
>> thought I give it a try here.
>>
>>
>> Just thinking about this so please correct my understanding if any of
>> this isn't right.
>>
>> Environment: Apache Cassandra v3.0.0
>>
>> Say you have a table and a materialized view created on it:
>>
>> create table source(
>> id text, field text, stamp timestamp, data text,
>> primary key(id, field))
>>
>> create materialized view myview as
>> select * from source
>> where data is not null and id is not null and field is not null
>> primary key (data, field, id)
>>
>> My understanding is that myview.data would essentially be the partition
>> key for the view here (and data in source is automatically replicated by
>> the server into myview?).
>>
>> *If that is true, what happens internally when a table update is
>> performed on source table and the source.data column is updated?*
>>
>> SO:
>> http://stackoverflow.com/questions/33943960/apache-cassandra-3-0-0-materialized-view-can-the-views-partition-key-change-du
>>
>> Thanks,
>>
>> Will
>>
>>
>>
>>
>

Re: Materialized View: can the view's partition key change due to changes to the underlying table?

Posted by Will Zhang <we...@gmail.com>.
Haven't had a chance to yet but I will. However, trying might not fully explain what happens behind the scenes, ie, you'd see the effect but not everything that happens. 

Thanks. 

Sent from my iPhone

> On 15 Dec 2015, at 23:41, Laing, Michael <mi...@nytimes.com> wrote:
> 
> why don't you just try it?
> 
>> On Tue, Dec 15, 2015 at 6:30 PM, Will Zhang <we...@gmail.com> wrote:
>> Hi all,
>> 
>> I originally raised this on SO, but not really getting any answer there, thought I give it a try here.
>> 
>> 
>> Just thinking about this so please correct my understanding if any of this isn't right. 
>> 
>> Environment: Apache Cassandra v3.0.0
>> 
>> Say you have a table and a materialized view created on it:
>> 
>> create table source(
>> id text, field text, stamp timestamp, data text, 
>> primary key(id, field))
>> 
>> create materialized view myview as
>> select * from source
>> where data is not null and id is not null and field is not null
>> primary key (data, field, id)
>> My understanding is that myview.data would essentially be the partition key for the view here (and data in source is automatically replicated by the server into myview?). 
>> 
>> If that is true, what happens internally when a table update is performed on source table and the source.data column is updated?
>> 
>> 
>> SO: http://stackoverflow.com/questions/33943960/apache-cassandra-3-0-0-materialized-view-can-the-views-partition-key-change-du
>> 
>> Thanks,
>> 
>> Will
>> 
>> 
>> 
> 

Re: Materialized View: can the view's partition key change due to changes to the underlying table?

Posted by "Laing, Michael" <mi...@nytimes.com>.
why don't you just try it?

On Tue, Dec 15, 2015 at 6:30 PM, Will Zhang <we...@gmail.com>
wrote:

> Hi all,
>
> I originally raised this on SO, but not really getting any answer there,
> thought I give it a try here.
>
>
> Just thinking about this so please correct my understanding if any of this
> isn't right.
>
> Environment: Apache Cassandra v3.0.0
>
> Say you have a table and a materialized view created on it:
>
> create table source(
> id text, field text, stamp timestamp, data text,
> primary key(id, field))
>
> create materialized view myview as
> select * from source
> where data is not null and id is not null and field is not null
> primary key (data, field, id)
>
> My understanding is that myview.data would essentially be the partition
> key for the view here (and data in source is automatically replicated by
> the server into myview?).
>
> *If that is true, what happens internally when a table update is performed
> on source table and the source.data column is updated?*
>
> SO:
> http://stackoverflow.com/questions/33943960/apache-cassandra-3-0-0-materialized-view-can-the-views-partition-key-change-du
>
> Thanks,
>
> Will
>
>
>
>