Skip to content

Commit 4c0eaeb

Browse files
feeblefakieKodaiD
andauthored
Backport to branch(3.14) : Fix Cassandra case insensitive issue (#2905)
Co-authored-by: Kodai Doki <[email protected]>
1 parent a424da7 commit 4c0eaeb

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

core/src/main/java/com/scalar/db/storage/cassandra/CassandraAdmin.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,9 @@ private TableMetadata createTableMetadata(com.datastax.driver.core.TableMetadata
211211
ClusteringOrder clusteringOrder = metadata.getClusteringOrder().get(i);
212212
builder.addClusteringKey(clusteringColumnName, convertOrder(clusteringOrder));
213213
}
214-
metadata.getIndexes().forEach(i -> builder.addSecondaryIndex(i.getTarget()));
214+
metadata
215+
.getIndexes()
216+
.forEach(i -> builder.addSecondaryIndex(unquoteIfNecessary(i.getTarget())));
215217
return builder.build();
216218
}
217219

@@ -302,8 +304,8 @@ public void addNewColumnToTable(
302304
throws ExecutionException {
303305
try {
304306
String alterTableQuery =
305-
SchemaBuilder.alterTable(namespace, table)
306-
.addColumn(columnName)
307+
SchemaBuilder.alterTable(quoteIfNecessary(namespace), quoteIfNecessary(table))
308+
.addColumn(quoteIfNecessary(columnName))
307309
.type(toCassandraDataType(columnType))
308310
.getQueryString();
309311

@@ -496,4 +498,14 @@ public String toString() {
496498
return strategyName;
497499
}
498500
}
501+
502+
private String unquoteIfNecessary(String identifier) {
503+
if (identifier == null) {
504+
return null;
505+
}
506+
if (identifier.length() >= 2 && identifier.startsWith("\"") && identifier.endsWith("\"")) {
507+
return identifier.substring(1, identifier.length() - 1).replace("\"\"", "\"");
508+
}
509+
return identifier;
510+
}
499511
}

0 commit comments

Comments
 (0)