Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private void upsertIntoNamespacesTable(String keyspace) {
String insertQuery =
QueryBuilder.insertInto(
quoteIfNecessary(metadataKeyspace), quoteIfNecessary(NAMESPACES_TABLE))
.value(NAMESPACES_NAME_COL, quoteIfNecessary(keyspace))
.value(NAMESPACES_NAME_COL, keyspace)
.toString();
clusterManager.getSession().execute(insertQuery);
}
Expand Down Expand Up @@ -180,7 +180,7 @@ private void deleteFromNamespacesTable(String keyspace) {
String deleteQuery =
QueryBuilder.delete()
.from(quoteIfNecessary(metadataKeyspace), quoteIfNecessary(NAMESPACES_TABLE))
.where(QueryBuilder.eq(NAMESPACES_NAME_COL, quoteIfNecessary(keyspace)))
.where(QueryBuilder.eq(NAMESPACES_NAME_COL, keyspace))
.toString();
clusterManager.getSession().execute(deleteQuery);
}
Expand Down Expand Up @@ -271,15 +271,21 @@ private TableMetadata createTableMetadata(com.datastax.driver.core.TableMetadata
throws ExecutionException {
TableMetadata.Builder builder = TableMetadata.newBuilder();
for (ColumnMetadata column : metadata.getColumns()) {
builder.addColumn(column.getName(), fromCassandraDataType(column.getType().getName()));
builder.addColumn(
unquoteIfNecessary(column.getName()), fromCassandraDataType(column.getType().getName()));
}
metadata.getPartitionKey().forEach(c -> builder.addPartitionKey(c.getName()));
metadata
.getPartitionKey()
.forEach(c -> builder.addPartitionKey(unquoteIfNecessary(c.getName())));
for (int i = 0; i < metadata.getClusteringColumns().size(); i++) {
String clusteringColumnName = metadata.getClusteringColumns().get(i).getName();
String clusteringColumnName =
unquoteIfNecessary(metadata.getClusteringColumns().get(i).getName());
ClusteringOrder clusteringOrder = metadata.getClusteringOrder().get(i);
builder.addClusteringKey(clusteringColumnName, convertOrder(clusteringOrder));
}
metadata.getIndexes().forEach(i -> builder.addSecondaryIndex(i.getTarget()));
metadata
.getIndexes()
.forEach(i -> builder.addSecondaryIndex(unquoteIfNecessary(i.getTarget())));
return builder.build();
}

Expand Down Expand Up @@ -349,7 +355,7 @@ public boolean namespaceExists(String namespace) throws ExecutionException {
String query =
QueryBuilder.select(NAMESPACES_NAME_COL)
.from(quoteIfNecessary(metadataKeyspace), quoteIfNecessary(NAMESPACES_TABLE))
.where(QueryBuilder.eq(NAMESPACES_NAME_COL, quoteIfNecessary(namespace)))
.where(QueryBuilder.eq(NAMESPACES_NAME_COL, namespace))
.toString();
ResultSet resultSet = clusterManager.getSession().execute(query);

Expand Down Expand Up @@ -396,8 +402,8 @@ public void addNewColumnToTable(
}
try {
String alterTableQuery =
SchemaBuilder.alterTable(namespace, table)
.addColumn(columnName)
SchemaBuilder.alterTable(quoteIfNecessary(namespace), quoteIfNecessary(table))
.addColumn(quoteIfNecessary(columnName))
.type(toCassandraDataType(columnType))
.getQueryString();

Expand Down Expand Up @@ -686,4 +692,14 @@ public String toString() {
return strategyName;
}
}

private String unquoteIfNecessary(String identifier) {
if (identifier == null) {
return null;
}
if (identifier.length() >= 2 && identifier.startsWith("\"") && identifier.endsWith("\"")) {
return identifier.substring(1, identifier.length() - 1).replace("\"\"", "\"");
}
return identifier;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ private void verifyInsertIntoKeyspacesTableQuery(String keyspace) {
QueryBuilder.insertInto(
quoteIfNecessary(METADATA_KEYSPACE),
quoteIfNecessary(CassandraAdmin.NAMESPACES_TABLE))
.value(CassandraAdmin.NAMESPACES_NAME_COL, quoteIfNecessary(keyspace))
.value(CassandraAdmin.NAMESPACES_NAME_COL, keyspace)
.toString();
verify(cassandraSession).execute(query);
}
Expand Down Expand Up @@ -569,7 +569,7 @@ private void verifyDeleteFromKeyspacesTableQuery(String keyspace) {
.from(
quoteIfNecessary(METADATA_KEYSPACE),
quoteIfNecessary(CassandraAdmin.NAMESPACES_TABLE))
.where(QueryBuilder.eq(CassandraAdmin.NAMESPACES_NAME_COL, quoteIfNecessary(keyspace)))
.where(QueryBuilder.eq(CassandraAdmin.NAMESPACES_NAME_COL, keyspace))
.toString();
verify(cassandraSession).execute(query);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,28 @@ public abstract class DistributedStorageAdminIntegrationTestBase {
LoggerFactory.getLogger(DistributedStorageAdminIntegrationTestBase.class);

private static final String TEST_NAME = "storage_admin";
private static final String NAMESPACE1 = "int_test_" + TEST_NAME + "1";
private static final String NAMESPACE2 = "int_test_" + TEST_NAME + "2";
private static final String NAMESPACE3 = "int_test_" + TEST_NAME + "3";
private static final String TABLE1 = "test_table1";
private static final String TABLE2 = "test_table2";
private static final String TABLE3 = "test_table3";
private static final String TABLE4 = "test_table4";
private static final String COL_NAME1 = "c1";
private static final String COL_NAME2 = "c2";
private static final String COL_NAME3 = "c3";
private static final String COL_NAME4 = "c4";
private static final String COL_NAME5 = "c5";
private static final String COL_NAME6 = "c6";
private static final String COL_NAME7 = "c7";
private static final String COL_NAME8 = "c8";
private static final String COL_NAME9 = "c9";
private static final String COL_NAME10 = "c10";
private static final String COL_NAME11 = "c11";
private static final String COL_NAME12 = "c12";
private static final String COL_NAME13 = "c13";
private static final String COL_NAME14 = "c14";
private static final String COL_NAME15 = "c15";
private static final String NAMESPACE1 = "Int_test_" + TEST_NAME + "1";
private static final String NAMESPACE2 = "Int_test_" + TEST_NAME + "2";
private static final String NAMESPACE3 = "Int_test_" + TEST_NAME + "3";
private static final String TABLE1 = "Test_table1";
private static final String TABLE2 = "Test_table2";
private static final String TABLE3 = "Test_table3";
private static final String TABLE4 = "Test_table4";
private static final String COL_NAME1 = "Column1";
private static final String COL_NAME2 = "Column2";
private static final String COL_NAME3 = "Column3";
private static final String COL_NAME4 = "Column4";
private static final String COL_NAME5 = "Column5";
private static final String COL_NAME6 = "Column6";
private static final String COL_NAME7 = "Column7";
private static final String COL_NAME8 = "Column8";
private static final String COL_NAME9 = "Column9";
private static final String COL_NAME10 = "Column10";
private static final String COL_NAME11 = "Column11";
private static final String COL_NAME12 = "Column12";
private static final String COL_NAME13 = "Column13";
private static final String COL_NAME14 = "Column14";
private static final String COL_NAME15 = "Column15";

private static final TableMetadata TABLE_METADATA =
TableMetadata.newBuilder()
Expand Down