mirror of https://github.com/apache/cassandra
Merge branch 'cassandra-3.0' into trunk
Conflicts: CHANGES.txt
This commit is contained in:
commit
8644338fc8
|
|
@ -3,7 +3,8 @@
|
|||
* Add transparent data encryption core classes (CASSANDRA-9945)
|
||||
|
||||
|
||||
3.0
|
||||
3.0-rc2
|
||||
* Fix NPE in MVs on update (CASSANDRA-10503)
|
||||
* Only include modified cell data in indexing deltas (CASSANDRA-10438)
|
||||
* Do not load keyspace when creating sstable writer (CASSANDRA-10443)
|
||||
* If node is not yet gossiping write all MV updates to batchlog only (CASSANDRA-10413)
|
||||
|
|
|
|||
|
|
@ -192,6 +192,10 @@ public class View
|
|||
public boolean updateAffectsView(AbstractBTreePartition partition)
|
||||
{
|
||||
ReadQuery selectQuery = getReadQuery();
|
||||
|
||||
if (!partition.metadata().cfId.equals(definition.baseTableId))
|
||||
return false;
|
||||
|
||||
if (!selectQuery.selectsKey(partition.partitionKey()))
|
||||
return false;
|
||||
|
||||
|
|
@ -582,7 +586,7 @@ public class View
|
|||
public TemporalRow.Set getTemporalRowSet(AbstractBTreePartition partition, TemporalRow.Set existing, boolean isBuilding)
|
||||
{
|
||||
if (!updateAffectsView(partition))
|
||||
return null;
|
||||
return existing;
|
||||
|
||||
Set<ColumnIdentifier> columns = new HashSet<>(this.columns.primaryKeyDefs.size());
|
||||
for (ColumnDefinition def : this.columns.primaryKeyDefs)
|
||||
|
|
|
|||
|
|
@ -125,14 +125,19 @@ public class ViewManager
|
|||
TemporalRow.Set temporalRows = null;
|
||||
for (Map.Entry<String, View> view : viewsByName.entrySet())
|
||||
{
|
||||
temporalRows = view.getValue().getTemporalRowSet(update, temporalRows, false);
|
||||
|
||||
Collection<Mutation> viewMutations = view.getValue().createMutations(update, temporalRows, false);
|
||||
if (viewMutations != null && !viewMutations.isEmpty())
|
||||
// Make sure that we only get mutations from views which are affected since the set includes all views for a
|
||||
// keyspace. This will prevent calling getTemporalRowSet for the wrong base table.
|
||||
if (view.getValue().updateAffectsView(update))
|
||||
{
|
||||
if (mutations == null)
|
||||
mutations = Lists.newLinkedList();
|
||||
mutations.addAll(viewMutations);
|
||||
temporalRows = view.getValue().getTemporalRowSet(update, temporalRows, false);
|
||||
|
||||
Collection<Mutation> viewMutations = view.getValue().createMutations(update, temporalRows, false);
|
||||
if (viewMutations != null && !viewMutations.isEmpty())
|
||||
{
|
||||
if (mutations == null)
|
||||
mutations = Lists.newLinkedList();
|
||||
mutations.addAll(viewMutations);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -156,9 +161,6 @@ public class ViewManager
|
|||
|
||||
for (View view : allViews())
|
||||
{
|
||||
if (!cf.metadata().cfId.equals(view.getDefinition().baseTableId))
|
||||
continue;
|
||||
|
||||
if (view.updateAffectsView(cf))
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -810,6 +810,41 @@ public class ViewTest extends CQLTester
|
|||
assertRows(execute("SELECT k, intval from mv WHERE intval = ?", 1), row(0, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTwoTablesOneView() throws Throwable
|
||||
{
|
||||
execute("USE " + keyspace());
|
||||
executeNet(protocolVersion, "USE " + keyspace());
|
||||
|
||||
createTable("CREATE TABLE " + keyspace() + ".dummy_table (" +
|
||||
"j int, " +
|
||||
"intval int, " +
|
||||
"PRIMARY KEY (j))");
|
||||
|
||||
createTable("CREATE TABLE " + keyspace() + ".real_base (" +
|
||||
"k int, " +
|
||||
"intval int, " +
|
||||
"PRIMARY KEY (k))");
|
||||
|
||||
createView("mv", "CREATE MATERIALIZED VIEW %s AS SELECT * FROM " + keyspace() + ".real_base WHERE k IS NOT NULL AND intval IS NOT NULL PRIMARY KEY (intval, k)");
|
||||
createView("mv2", "CREATE MATERIALIZED VIEW %s AS SELECT * FROM " + keyspace() + ".dummy_table WHERE j IS NOT NULL AND intval IS NOT NULL PRIMARY KEY (intval, j)");
|
||||
|
||||
updateView("INSERT INTO " + keyspace() + ".real_base (k, intval) VALUES (?, ?)", 0, 0);
|
||||
assertRows(execute("SELECT k, intval FROM " + keyspace() + ".real_base WHERE k = ?", 0), row(0, 0));
|
||||
assertRows(execute("SELECT k, intval from mv WHERE intval = ?", 0), row(0, 0));
|
||||
|
||||
updateView("INSERT INTO " + keyspace() + ".real_base (k, intval) VALUES (?, ?)", 0, 1);
|
||||
assertRows(execute("SELECT k, intval FROM " + keyspace() + ".real_base WHERE k = ?", 0), row(0, 1));
|
||||
assertRows(execute("SELECT k, intval from mv WHERE intval = ?", 1), row(0, 1));
|
||||
|
||||
assertRows(execute("SELECT k, intval FROM " + keyspace() + ".real_base WHERE k = ?", 0), row(0, 1));
|
||||
assertRows(execute("SELECT k, intval from mv WHERE intval = ?", 1), row(0, 1));
|
||||
|
||||
updateView("INSERT INTO " + keyspace() +".dummy_table (j, intval) VALUES(?, ?)", 0, 1);
|
||||
assertRows(execute("SELECT j, intval FROM " + keyspace() + ".dummy_table WHERE j = ?", 0), row(0, 1));
|
||||
assertRows(execute("SELECT k, intval from mv WHERE intval = ?", 1), row(0, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecimalUpdate() throws Throwable
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue