Skip to content

Commit

Permalink
Fix DescribeStatementTest
Browse files Browse the repository at this point in the history
  • Loading branch information
pkolaczk committed Jan 20, 2025
1 parent 9c03401 commit cc3605e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
2 changes: 0 additions & 2 deletions src/java/org/apache/cassandra/schema/CompressionParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ public final class CompressionParams

public static final CompressionParams DEFAULT = DatabaseDescriptor.shouldUseAdaptiveCompressionByDefault() ? ADAPTIVE : FAST;

public static final CompressionParams INDEX_DEFAULT = DEFAULT.withChunkLength(DEFAULT_INDEX_CHUNK_LENGTH);

public static final CompressionParams NOOP = new CompressionParams(NoopCompressor.create(Collections.emptyMap()),
// 4 KiB is often the underlying disk block size
1024 * 4,
Expand Down
20 changes: 16 additions & 4 deletions src/java/org/apache/cassandra/schema/IndexMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,22 @@ public void appendCqlTo(CqlBuilder builder, TableMetadata table, boolean ifNotEx
.append(") USING ")
.appendWithSingleQuotes(copyOptions.remove(IndexTarget.CUSTOM_INDEX_OPTION_NAME));

builder.append(" WITH compression = ")
.append(compression.asMap())
.append(" AND options = ")
.append(copyOptions);
if (compression.isEnabled())
{
builder.append(" WITH compression = ")
.append(compression.asMap());

if (!copyOptions.isEmpty())
{
builder.append(" AND options = ")
.append(copyOptions);
}
}
else if (!copyOptions.isEmpty())
{
builder.append(" WITH options = ")
.append(copyOptions);
}
}
else
{
Expand Down
17 changes: 12 additions & 5 deletions src/java/org/apache/cassandra/schema/TableParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,12 @@ public void appendCqlTo(CqlBuilder builder, boolean isView)
.newLine()
.append("AND compression = ").append(compression.asMap())
.newLine()
.append("AND index_compression = ").append(indexCompression.asMap())
.newLine()
.append("AND memtable = ").append(memtable.asMap())
.newLine()
.append("AND crc_check_chance = ").append(crcCheckChance)
.newLine();


if (!isView)
{
builder.append("AND default_time_to_live = ").append(defaultTimeToLive)
Expand All @@ -309,8 +308,16 @@ public void appendCqlTo(CqlBuilder builder, boolean isView)
false)
.newLine()
.append("AND gc_grace_seconds = ").append(gcGraceSeconds)
.newLine()
.append("AND max_index_interval = ").append(maxIndexInterval)
.newLine();


if (indexCompression.isEnabled())
{
builder.append("AND index_compression = ").append(indexCompression.asMap())
.newLine();
}

builder.append("AND max_index_interval = ").append(maxIndexInterval)
.newLine()
.append("AND memtable_flush_period_in_ms = ").append(memtableFlushPeriodInMs)
.newLine()
Expand All @@ -336,7 +343,7 @@ public static final class Builder
private CachingParams caching = CachingParams.DEFAULT;
private CompactionParams compaction = CompactionParams.DEFAULT;
private CompressionParams compression = CompressionParams.DEFAULT;
private CompressionParams indexCompression = CompressionParams.INDEX_DEFAULT;
private CompressionParams indexCompression = CompressionParams.noCompression();
private MemtableParams memtable = MemtableParams.DEFAULT;
private ImmutableMap<String, ByteBuffer> extensions = ImmutableMap.of();
private boolean cdc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ public void testDescribeWithCustomIndex() throws Throwable
{
String table = createTable(KEYSPACE_PER_TEST, "CREATE TABLE %s (id int PRIMARY KEY, value text);");
String indexWithoutOptions = createIndex(KEYSPACE_PER_TEST, "CREATE CUSTOM INDEX ON %s(value) USING 'org.apache.cassandra.index.sasi.SASIIndex';");
String indexWithOptions = createIndex(KEYSPACE_PER_TEST, "CREATE CUSTOM INDEX ON %s(value) USING 'org.apache.cassandra.index.sasi.SASIIndex' WITH OPTIONS = {'is_literal': 'false'};");
String indexWithOptions = createIndex(KEYSPACE_PER_TEST, "CREATE CUSTOM INDEX ON %s(value) USING 'org.apache.cassandra.index.sasi.SASIIndex' WITH options = {'is_literal': 'false'};");

String expectedKeyspaceStmt = "CREATE KEYSPACE " + KEYSPACE_PER_TEST +
" WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}" +
Expand All @@ -821,7 +821,7 @@ public void testDescribeWithCustomIndex() throws Throwable
") WITH " + tableParametersCql();

String expectedIndexStmtWithoutOptions = "CREATE CUSTOM INDEX " + indexWithoutOptions + " ON " + KEYSPACE_PER_TEST + "." + table + " (value) USING 'org.apache.cassandra.index.sasi.SASIIndex';";
String expectedIndexStmtWithOptions = "CREATE CUSTOM INDEX " + indexWithOptions + " ON " + KEYSPACE_PER_TEST + "." + table + " (value) USING 'org.apache.cassandra.index.sasi.SASIIndex' WITH OPTIONS = {'is_literal': 'false'};";
String expectedIndexStmtWithOptions = "CREATE CUSTOM INDEX " + indexWithOptions + " ON " + KEYSPACE_PER_TEST + "." + table + " (value) USING 'org.apache.cassandra.index.sasi.SASIIndex' WITH options = {'is_literal': 'false'};";

assertRowsNet(executeDescribeNet("DESCRIBE KEYSPACE " + KEYSPACE_PER_TEST),
row(KEYSPACE_PER_TEST, "keyspace", KEYSPACE_PER_TEST, expectedKeyspaceStmt),
Expand Down

0 comments on commit cc3605e

Please sign in to comment.