use of com.datastax.driver.core.ColumnMetadata in project java-driver by datastax.
the class IndexMetadataTest method should_create_metadata_for_full_index_on_map.
@Test(groups = "short")
@CassandraVersion("2.1.3")
public void should_create_metadata_for_full_index_on_map() {
String createFullIndex = String.format("CREATE INDEX map_full_index ON %s.indexing (full(map_full));", keyspace);
session().execute(createFullIndex);
ColumnMetadata column = getColumn("map_full");
IndexMetadata index = getIndex("map_full_index");
assertThat(index).hasName("map_full_index").hasParent((TableMetadata) column.getParent()).isNotCustomIndex().hasTarget("full(map_full)").hasKind(COMPOSITES).asCqlQuery(createFullIndex);
assertThat((TableMetadata) column.getParent()).hasIndex(index);
}
use of com.datastax.driver.core.ColumnMetadata in project java-driver by datastax.
the class IndexMetadataTest method should_parse_legacy_custom_index_options.
@Test(groups = "short", description = "This test case builds a ColumnMetadata object programmatically to test custom indices with pre-3.0 layout," + "otherwise, it would require deploying an actual custom index class into the C* test cluster")
public void should_parse_legacy_custom_index_options() {
TableMetadata table = getTable("indexing");
List<ByteBuffer> columnData = ImmutableList.of(// column name
wrap("text_column"), // component index
wrap(0), // column kind
wrap("regular"), // index name
wrap("custom_index"), // index type
wrap("CUSTOM"), // validator
wrap("org.apache.cassandra.db.marshal.UTF8Type"), // index options
wrap("{\"foo\" : \"bar\", \"class_name\" : \"dummy.DummyIndex\"}"));
Row columnRow = ArrayBackedRow.fromData(legacyColumnDefs, M3PToken.FACTORY, protocolVersion, columnData);
Raw columnRaw = Raw.fromRow(columnRow, VersionNumber.parse("2.1"));
ColumnMetadata column = ColumnMetadata.fromRaw(table, columnRaw, DataType.varchar());
IndexMetadata index = IndexMetadata.fromLegacy(column, columnRaw);
assertThat(index).isNotNull().hasName("custom_index").isCustomIndex().hasOption("foo", "bar").hasKind(CUSTOM).asCqlQuery(String.format("CREATE CUSTOM INDEX custom_index ON %s.indexing (text_column) " + "USING 'dummy.DummyIndex' WITH OPTIONS = {'foo' : 'bar'};", keyspace));
}
use of com.datastax.driver.core.ColumnMetadata in project java-driver by datastax.
the class IndexMetadataTest method should_allow_multiple_indexes_on_map_column.
@Test(groups = "short")
@CassandraVersion("3.0")
public void should_allow_multiple_indexes_on_map_column() {
String createEntriesIndex = String.format("CREATE INDEX map_all_entries_index ON %s.indexing (entries(map_all));", keyspace);
session().execute(createEntriesIndex);
String createKeysIndex = String.format("CREATE INDEX map_all_keys_index ON %s.indexing (keys(map_all));", keyspace);
session().execute(createKeysIndex);
String createValuesIndex = String.format("CREATE INDEX map_all_values_index ON %s.indexing (values(map_all));", keyspace);
session().execute(createValuesIndex);
ColumnMetadata column = getColumn("map_all");
TableMetadata table = (TableMetadata) column.getParent();
assertThat(getIndex("map_all_entries_index")).hasParent(table).asCqlQuery(createEntriesIndex);
assertThat(getIndex("map_all_keys_index")).hasParent(table).asCqlQuery(createKeysIndex);
assertThat(getIndex("map_all_values_index")).hasParent(table).asCqlQuery(createValuesIndex);
}
use of com.datastax.driver.core.ColumnMetadata in project java-driver by datastax.
the class IndexMetadataTest method should_create_metadata_for_simple_index.
@Test(groups = "short")
public void should_create_metadata_for_simple_index() {
String createValuesIndex = String.format("CREATE INDEX text_column_index ON %s.indexing (text_column);", keyspace);
session().execute(createValuesIndex);
ColumnMetadata column = getColumn("text_column");
IndexMetadata index = getIndex("text_column_index");
assertThat(index).hasName("text_column_index").hasParent((TableMetadata) column.getParent()).isNotCustomIndex().hasTarget("text_column").hasKind(COMPOSITES).asCqlQuery(createValuesIndex);
assertThat((TableMetadata) column.getParent()).hasIndex(index);
}
use of com.datastax.driver.core.ColumnMetadata in project cassandra-driver-mapping by valchkou.
the class SchemaSyncTest method testAlter.
@Test
public void testAlter() {
SchemaSync.drop(keyspace, session, EntityWithIndexes.class);
SchemaSync.sync(keyspace, session, EntityWithIndexes.class);
SchemaSync.sync(keyspace, session, EntityWithIndexesV2.class);
EntityTypeMetadata entityMetadata = EntityTypeParser.getEntityMetadata(EntityWithIndexes.class);
TableMetadata tableMetadata = cluster.getMetadata().getKeyspace(keyspace).getTable(entityMetadata.getTableName());
assertNotNull(tableMetadata);
assertEquals("test_entity_index", tableMetadata.getName());
assertEquals(6, tableMetadata.getColumns().size());
ColumnMetadata columnMetadata = tableMetadata.getColumn("uuid");
// assertNull(columnMetadata.getIndex());
columnMetadata = tableMetadata.getColumn("email");
// assertNotNull(columnMetadata.getIndex());
// assertEquals("test_entity_email_idx", columnMetadata.getIndex().getName());
columnMetadata = tableMetadata.getColumn("timestamp");
// assertNull(columnMetadata.getIndex());
columnMetadata = tableMetadata.getColumn("counter2");
// assertEquals("test_entity_counter_idx", columnMetadata.getIndex().getName());
columnMetadata = tableMetadata.getColumn("name");
assertNull(columnMetadata);
columnMetadata = tableMetadata.getColumn("ref");
assertNotNull(columnMetadata);
columnMetadata = tableMetadata.getColumn("pets");
assertNotNull(columnMetadata);
}
Aggregations