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:
Mark Paluch
2022-07-04 08:59:50 +02:00
parent 0f57ea68dc
commit 0dca3e6aaa
2 changed files with 14 additions and 1 deletions

View File

@@ -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(")");

View File

@@ -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\");");
}
}