Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
0.5.0
-----
* AbstractSchemaBuilder.build() drops the cdc flag, silently disabling CDC on all tables (CASSANALYTICS-186)
* Fix total timeout calculation for getAllNodeSettings (CASSANALYTICS-179)
* Support vector data type (CASSANALYTICS-26)
* CDC batch-write mixing a CDC-enabled and CDC-disabled table drops the CDC table's mutation (CASSANALYTICS-182)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.apache.cassandra.spark.reader;

import java.util.Collections;
import java.util.HashMap;

import org.junit.jupiter.api.Test;
Expand All @@ -32,7 +33,9 @@
import org.apache.cassandra.schema.Schema;
import org.apache.cassandra.schema.TableMetadata;
import org.apache.cassandra.schema.Types;
import org.apache.cassandra.spark.data.CqlTable;
import org.apache.cassandra.spark.data.ReplicationFactor;
import org.apache.cassandra.spark.data.partitioner.Partitioner;
import org.apache.cassandra.utils.FBUtilities;

import static org.apache.cassandra.spark.reader.SchemaBuilder.rfToMap;
Expand Down Expand Up @@ -114,4 +117,51 @@ public void testSchemaBuilderWithPartiallyInitializedMetadata()

new SchemaBuilder(createTableStatement, keyspaceName, replicationFactor);
}

@Test
public void testBuildPreservesCdcFlag()
{
CassandraBridgeImplementation.setup();
String keyspaceName = "cdc" + getClass().getSimpleName();
ReplicationFactor replicationFactor = new ReplicationFactor(ReplicationFactor.ReplicationStrategy.LocalStrategy, new HashMap<>());
KeyspaceMetadata keyspaceMetadata = KeyspaceMetadata.create(keyspaceName, KeyspaceParams.create(true, rfToMap(replicationFactor)));
Schema.instance.load(keyspaceMetadata);
Keyspace.openWithoutSSTables(keyspaceName);

String createTableStatement = "CREATE TABLE " + keyspaceName + ".bar (a int PRIMARY KEY) WITH cdc = true";
TableMetadata tableMetadata = CQLFragmentParser
.parseAny(CqlParser::createTableStatement, createTableStatement, "CREATE TABLE")
.keyspace(keyspaceName)
.prepare(null)
.builder(Types.none())
.build();
KeyspaceMetadata keyspace = Schema.instance.getKeyspaceMetadata(keyspaceName);
Schema.instance.load(keyspace.withSwapped(keyspace.tables.with(tableMetadata)));

SchemaBuilder cdcEnabledBuilder = new SchemaBuilder(createTableStatement,
keyspaceName,
replicationFactor,
Partitioner.Murmur3Partitioner,
bridge -> Collections.emptySet(),
null,
0,
true);
CqlTable cdcEnabledTable = cdcEnabledBuilder.build();
assertThat(cdcEnabledTable.cdc())
.as("build() must preserve enableCdc=true through to the returned CqlTable")
.isTrue();

SchemaBuilder cdcDisabledBuilder = new SchemaBuilder(createTableStatement,
keyspaceName,
replicationFactor,
Partitioner.Murmur3Partitioner,
bridge -> Collections.emptySet(),
null,
0,
false);
CqlTable cdcDisabledTable = cdcDisabledBuilder.build();
assertThat(cdcDisabledTable.cdc())
.as("build() must preserve enableCdc=false through to the returned CqlTable")
.isFalse();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,8 @@ public CqlTable build()
replicationFactor,
fields,
new HashSet<>(udts.values()),
indexCount);
indexCount,
enableCdc);
Comment on lines +482 to +483

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not an action item for this patch – we should consider applying the builder pattern to CqlTable. The constructor overloads are error prone.

}

private Map<String, CqlField.CqlUdt> buildsUdts(KeyspaceMetadata keyspaceMetadata)
Expand Down
Loading