Skip to content

Commit 8645713

Browse files
committed
Properly render table name as CQL during index creation.
We now use the proper CQL representation applying quoting if necessary when creating indexes. Previously, we just used the plain toString format of the CQL identifier that didn't quote the table name. Closes #1281.
1 parent 6c3add1 commit 8645713

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/generator/CreateIndexCqlGenerator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public StringBuilder toCql(StringBuilder cql) {
5151
cql.append(" ").append(spec().getName().asCql(true));
5252
}
5353

54-
cql.append(" ON ").append(spec().getTableName()).append(" (");
54+
cql.append(" ON ").append(spec().getTableName().asCql(true)).append(" (");
5555

5656
if (spec().getColumnFunction() != ColumnFunction.NONE) {
5757
cql.append(spec().getColumnFunction().name()).append("(").append(spec().getColumnName().asCql(true)).append(")");

spring-data-cassandra/src/test/java/org/springframework/data/cassandra/core/cql/generator/CreateIndexCqlGeneratorUnitTests.java

+13
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
import static org.assertj.core.api.Assertions.*;
1919

2020
import org.junit.jupiter.api.Test;
21+
2122
import org.springframework.data.cassandra.core.cql.keyspace.CreateIndexSpecification;
2223

24+
import com.datastax.oss.driver.api.core.CqlIdentifier;
25+
2326
/**
2427
* Unit tests for {@link CreateIndexCqlGenerator}.
2528
*
@@ -75,4 +78,14 @@ void createIndexWithOptions() {
7578
assertThat(CreateIndexCqlGenerator.toCql(spec))
7679
.isEqualTo("CREATE INDEX ON mytable (column) WITH OPTIONS = {'foo': 'b''a''r', 'type': 'PREFIX'};");
7780
}
81+
82+
@Test // GH-1281
83+
void createIndexWithQuotation() {
84+
85+
CreateIndexSpecification spec = CreateIndexSpecification.createIndex("order_dob").columnName("\"order\"")
86+
.tableName(CqlIdentifier.fromInternal("order"));
87+
88+
assertThat(CreateIndexCqlGenerator.toCql(spec)).isEqualTo("CREATE INDEX order_dob ON \"order\" (\"order\");");
89+
90+
}
7891
}

0 commit comments

Comments
 (0)