Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 @@ -164,9 +164,9 @@ public String asCql() {
builder.append(",");
}
if (entry.getValue().equals(NO_INDEX_TYPE)) {
builder.append(entry.getKey());
builder.append(entry.getKey().asCql(true));
} else {
builder.append(entry.getValue()).append("(").append(entry.getKey()).append(")");
builder.append(entry.getValue()).append("(").append(entry.getKey().asCql(true)).append(")");
}
}
builder.append(")");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static com.datastax.oss.driver.api.querybuilder.Assertions.assertThat;
import static com.datastax.oss.driver.api.querybuilder.SchemaBuilder.createIndex;

import com.datastax.oss.driver.api.core.CqlIdentifier;
import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap;
import org.junit.Test;

Expand Down Expand Up @@ -82,6 +83,17 @@ public void should_generate_create_index_with_name_if_not_exists() {
.hasCql("CREATE INDEX IF NOT EXISTS bar ON x (y)");
}

@Test
public void should_generate_create_index_with_correct_quoting() {
assertThat(createIndex("bAr").onTable("xY").andColumn("aB"))
.hasCql("CREATE INDEX bar ON xy (ab)");
assertThat(
createIndex(CqlIdentifier.fromInternal("bAr"))
.onTable(CqlIdentifier.fromInternal("xY"))
.andColumn(CqlIdentifier.fromInternal("aB")))
.hasCql("CREATE INDEX \"bAr\" ON \"xY\" (\"aB\")");
}

@Test
public void should_generate_create_index_values() {
assertThat(createIndex().onTable("x").andColumnValues("m"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static com.datastax.oss.driver.api.querybuilder.SchemaBuilder.createTable;
import static com.datastax.oss.driver.api.querybuilder.SchemaBuilder.udt;

import com.datastax.oss.driver.api.core.CqlIdentifier;
import com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder;
import com.datastax.oss.driver.api.core.type.DataTypes;
import com.datastax.oss.driver.api.querybuilder.SchemaBuilder;
Expand All @@ -44,6 +45,25 @@ public void should_generate_create_table_if_not_exists() {
.hasCql("CREATE TABLE IF NOT EXISTS bar (k int PRIMARY KEY)");
}

@Test
public void should_generate_create_table_with_correct_quoting() {
assertThat(
createTable("bAr")
.withPartitionKey("kY", DataTypes.INT)
.withClusteringColumn("xZ", DataTypes.INT)
.withStaticColumn("sT", DataTypes.TEXT)
.withColumn("cL", DataTypes.BLOB))
.hasCql("CREATE TABLE bar (ky int,xz int,st text STATIC,cl blob,PRIMARY KEY(ky,xz))");
assertThat(
createTable(CqlIdentifier.fromInternal("bAr"))
.withPartitionKey(CqlIdentifier.fromInternal("kY"), DataTypes.INT)
.withClusteringColumn(CqlIdentifier.fromInternal("xZ"), DataTypes.INT)
.withStaticColumn(CqlIdentifier.fromInternal("sT"), DataTypes.TEXT)
.withColumn(CqlIdentifier.fromInternal("cL"), DataTypes.BLOB))
.hasCql(
"CREATE TABLE \"bAr\" (\"kY\" int,\"xZ\" int,\"sT\" text STATIC,\"cL\" blob,PRIMARY KEY(\"kY\",\"xZ\"))");
}

@Test
public void should_generate_create_table_with_single_partition_key() {
assertThat(
Expand Down