Skip to content

Commit

Permalink
Improve messaging on indexing frozen collections
Browse files Browse the repository at this point in the history
Patch by Rocco Varela, reviewed by Bryn Cooke, Zhao Yang, and
brandonwilliams for CASSANDRA-15908
  • Loading branch information
rocco408 authored and driftx committed Jul 14, 2020
1 parent 9481e4e commit 9e74b67
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
@@ -1,4 +1,5 @@
4.0-alpha5
* Improve messaging on indexing frozen collections (CASSANDRA-15908)
* USING_G1 is incorrectly set in cassandra-env.sh if G1 is explicitly disabled with -UseG1GC (CASSANDRA-15931)
* Update compaction_throughput_mb_per_sec throttle default to 64 (CASSANDRA-14902)
* Add option to disable compaction at startup (CASSANDRA-15927)
Expand Down
Expand Up @@ -175,7 +175,8 @@ private void validateIndexTarget(TableMetadata table, IndexTarget target)
throw ire("Cannot create secondary index on the only partition key column %s", column);

if (column.type.isFrozenCollection() && target.type != Type.FULL)
throw ire("Cannot create %s() index on frozen column %s. Frozen collections only support full() indexes", target.type, column);
throw ire("Cannot create %s() index on frozen column %s. Frozen collections are immutable and must be fully " +
"indexed by using the 'full(%s)' modifier", target.type, column, column);

if (!column.type.isFrozenCollection() && target.type == Type.FULL)
throw ire("full() indexes can only be created on frozen collections");
Expand Down
Expand Up @@ -557,7 +557,7 @@ public void testSecondaryIndex() throws Throwable
assertInvalidIndexCreationWithMessage("CREATE INDEX ON %s (full(a))", "Cannot create secondary index on the only partition key column");
assertInvalidIndexCreationWithMessage("CREATE INDEX ON %s (keys(a))", "Cannot create secondary index on the only partition key column");
assertInvalidIndexCreationWithMessage("CREATE INDEX ON %s (keys(b))", "Cannot create keys() index on frozen column b. " +
"Frozen collections only support full() indexes");
"Frozen collections only support indexes on the entire data structure");

createTable("CREATE TABLE %s (a int, b frozen<list<int>>, c frozen<set<int>>, d frozen<map<int, text>>, PRIMARY KEY (a, b))");

Expand Down
Expand Up @@ -1483,8 +1483,8 @@ public void testIndexOnFrozenCollectionOfUDT() throws Throwable
Object udt2 = userType("a", 2);

execute("INSERT INTO %s (k, v) VALUES (?, ?)", 1, set(udt1, udt2));
assertInvalidMessage("Frozen collections only support full()", "CREATE INDEX idx ON %s (keys(v))");
assertInvalidMessage("Frozen collections only support full()", "CREATE INDEX idx ON %s (values(v))");
assertInvalidMessage("Frozen collections are immutable and must be fully indexed", "CREATE INDEX idx ON %s (keys(v))");
assertInvalidMessage("Frozen collections are immutable and must be fully indexed", "CREATE INDEX idx ON %s (values(v))");
String indexName = createIndex("CREATE INDEX ON %s (full(v))");

execute("INSERT INTO %s (k, v) VALUES (?, ?)", 2, set(udt2));
Expand Down
18 changes: 9 additions & 9 deletions test/unit/org/apache/cassandra/index/CustomIndexTest.java
Expand Up @@ -186,39 +186,39 @@ public void requireFullQualifierForFrozenCollectionTargets() throws Throwable
" PRIMARY KEY(k,c))");

assertInvalidMessage("Cannot create keys() index on frozen column fmap. " +
"Frozen collections only support full() indexes",
"Frozen collections are immutable and must be fully indexed",
String.format("CREATE CUSTOM INDEX ON %%s(c, keys(fmap)) USING'%s'",
StubIndex.class.getName()));
assertInvalidMessage("Cannot create entries() index on frozen column fmap. " +
"Frozen collections only support full() indexes",
"Frozen collections are immutable and must be fully indexed",
String.format("CREATE CUSTOM INDEX ON %%s(c, entries(fmap)) USING'%s'",
StubIndex.class.getName()));
assertInvalidMessage("Cannot create values() index on frozen column fmap. " +
"Frozen collections only support full() indexes",
"Frozen collections are immutable and must be fully indexed",
String.format("CREATE CUSTOM INDEX ON %%s(c, fmap) USING'%s'", StubIndex.class.getName()));

assertInvalidMessage("Cannot create keys() index on frozen column flist. " +
"Frozen collections only support full() indexes",
"Frozen collections are immutable and must be fully indexed",
String.format("CREATE CUSTOM INDEX ON %%s(c, keys(flist)) USING'%s'",
StubIndex.class.getName()));
assertInvalidMessage("Cannot create entries() index on frozen column flist. " +
"Frozen collections only support full() indexes",
"Frozen collections are immutable and must be fully indexed",
String.format("CREATE CUSTOM INDEX ON %%s(c, entries(flist)) USING'%s'",
StubIndex.class.getName()));
assertInvalidMessage("Cannot create values() index on frozen column flist. " +
"Frozen collections only support full() indexes",
"Frozen collections are immutable and must be fully indexed",
String.format("CREATE CUSTOM INDEX ON %%s(c, flist) USING'%s'", StubIndex.class.getName()));

assertInvalidMessage("Cannot create keys() index on frozen column fset. " +
"Frozen collections only support full() indexes",
"Frozen collections are immutable and must be fully indexed",
String.format("CREATE CUSTOM INDEX ON %%s(c, keys(fset)) USING'%s'",
StubIndex.class.getName()));
assertInvalidMessage("Cannot create entries() index on frozen column fset. " +
"Frozen collections only support full() indexes",
"Frozen collections are immutable and must be fully indexed",
String.format("CREATE CUSTOM INDEX ON %%s(c, entries(fset)) USING'%s'",
StubIndex.class.getName()));
assertInvalidMessage("Cannot create values() index on frozen column fset. " +
"Frozen collections only support full() indexes",
"Frozen collections are immutable and must be fully indexed",
String.format("CREATE CUSTOM INDEX ON %%s(c, fset) USING'%s'", StubIndex.class.getName()));

createIndex(String.format("CREATE CUSTOM INDEX ON %%s(c, full(fmap)) USING'%s'", StubIndex.class.getName()));
Expand Down

0 comments on commit 9e74b67

Please sign in to comment.