Skip to content

Commit

Permalink
Fix assertion error when describing mv as table
Browse files Browse the repository at this point in the history
patch by Maciej Sokol; reviewed by Brandon Williams and Stefan Miklosovic for CASSANDRA-18596
  • Loading branch information
masokol authored and smiklosovic committed Jun 19, 2023
1 parent 49dba85 commit 92d0a40
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.txt
@@ -1,4 +1,5 @@
4.0.11
* Fix assertion error when describing mv as table (CASSANDRA-18596)
* Track the amount of read data per row (CASSANDRA-18513)
* Fix Down nodes counter in nodetool describecluster (CASSANDRA-18512)
* Remove unnecessary shuffling of GossipDigests in Gossiper#makeRandomGossipDigest (CASSANDRA-18546)
Expand Down
Expand Up @@ -472,7 +472,7 @@ public static DescribeStatement<SchemaElement> table(String keyspace, String nam
{
return new Element(keyspace, name, (ks, t) -> {

TableMetadata table = checkNotNull(ks.getTableOrViewNullable(t),
TableMetadata table = checkNotNull(ks.getTableNullable(t),
"Table '%s' not found in keyspace '%s'", t, ks.name);

return Stream.concat(Stream.of(table), table.indexes.stream()
Expand Down
6 changes: 6 additions & 0 deletions src/java/org/apache/cassandra/schema/KeyspaceMetadata.java
Expand Up @@ -153,6 +153,12 @@ public TableMetadata getTableOrViewNullable(String tableOrViewName)
: view.metadata;
}

@Nullable
public TableMetadata getTableNullable(String tableName)
{
return tables.getNullable(tableName);
}

public boolean hasTable(String tableName)
{
return tables.get(tableName).isPresent();
Expand Down
Expand Up @@ -598,6 +598,23 @@ public void testPrimaryKeyPositionWithAndWithoutInternals() throws Throwable
tableCreateStatementWithoutDroppedColumn));
}

@Test
public void testDescribeMaterializedViewAsTable() throws Throwable
{
String table = createTable(KEYSPACE_PER_TEST, "CREATE TABLE IF NOT EXISTS %s (pk1 int, pk2 int, ck1 int, ck2 int, reg1 int, reg2 list<int>, reg3 int, PRIMARY KEY ((pk1, pk2), ck1, ck2)) WITH CLUSTERING ORDER BY (ck1 ASC, ck2 DESC);");

execute("CREATE MATERIALIZED VIEW IF NOT EXISTS " + KEYSPACE_PER_TEST + ".mv AS SELECT * FROM " + KEYSPACE_PER_TEST + '.' + table
+ " WHERE pk2 IS NOT NULL AND pk1 IS NOT NULL AND ck2 IS NOT NULL AND ck1 IS NOT NULL PRIMARY KEY ((pk2, pk1), ck2, ck1)");
try
{
describeError(format("DESCRIBE TABLE %s.%s", KEYSPACE_PER_TEST, "mv"),
format("Table '%s' not found in keyspace '%s'", "mv", KEYSPACE_PER_TEST));
}
finally
{
execute("DROP MATERIALIZED VIEW " + KEYSPACE_PER_TEST + ".mv");
}
}

@Test
public void testDescribeMissingKeyspace() throws Throwable
Expand Down

0 comments on commit 92d0a40

Please sign in to comment.