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.
This commit is contained in:
@@ -51,7 +51,7 @@ public class CreateIndexCqlGenerator extends IndexNameCqlGenerator<CreateIndexSp
|
||||
cql.append(" ").append(spec().getName().asCql(true));
|
||||
}
|
||||
|
||||
cql.append(" ON ").append(spec().getTableName()).append(" (");
|
||||
cql.append(" ON ").append(spec().getTableName().asCql(true)).append(" (");
|
||||
|
||||
if (spec().getColumnFunction() != ColumnFunction.NONE) {
|
||||
cql.append(spec().getColumnFunction().name()).append("(").append(spec().getColumnName().asCql(true)).append(")");
|
||||
|
||||
@@ -18,8 +18,11 @@ package org.springframework.data.cassandra.core.cql.generator;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.cassandra.core.cql.keyspace.CreateIndexSpecification;
|
||||
|
||||
import com.datastax.oss.driver.api.core.CqlIdentifier;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link CreateIndexCqlGenerator}.
|
||||
*
|
||||
@@ -75,4 +78,14 @@ class CreateIndexCqlGeneratorUnitTests {
|
||||
assertThat(CreateIndexCqlGenerator.toCql(spec))
|
||||
.isEqualTo("CREATE INDEX ON mytable (column) WITH OPTIONS = {'foo': 'b''a''r', 'type': 'PREFIX'};");
|
||||
}
|
||||
|
||||
@Test // GH-1281
|
||||
void createIndexWithQuotation() {
|
||||
|
||||
CreateIndexSpecification spec = CreateIndexSpecification.createIndex("order_dob").columnName("\"order\"")
|
||||
.tableName(CqlIdentifier.fromInternal("order"));
|
||||
|
||||
assertThat(CreateIndexCqlGenerator.toCql(spec)).isEqualTo("CREATE INDEX order_dob ON \"order\" (\"order\");");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user