Search in sources :

Example 26 with ColumnMetadata

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);
}
Also used : ColumnMetadata(com.datastax.driver.core.ColumnMetadata) Test(org.testng.annotations.Test) CassandraVersion(com.datastax.driver.core.utils.CassandraVersion)

Example 27 with ColumnMetadata

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));
}
Also used : ColumnMetadata(com.datastax.driver.core.ColumnMetadata) ByteBuffer(java.nio.ByteBuffer) Test(org.testng.annotations.Test)

Example 28 with ColumnMetadata

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);
}
Also used : ColumnMetadata(com.datastax.driver.core.ColumnMetadata) Test(org.testng.annotations.Test) CassandraVersion(com.datastax.driver.core.utils.CassandraVersion)

Example 29 with ColumnMetadata

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);
}
Also used : ColumnMetadata(com.datastax.driver.core.ColumnMetadata) Test(org.testng.annotations.Test)

Example 30 with ColumnMetadata

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);
}
Also used : TableMetadata(com.datastax.driver.core.TableMetadata) ColumnMetadata(com.datastax.driver.core.ColumnMetadata) EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata) Test(org.junit.Test)

Aggregations

ColumnMetadata (com.datastax.driver.core.ColumnMetadata)37 Test (org.testng.annotations.Test)11 TableMetadata (com.datastax.driver.core.TableMetadata)8 CassandraVersion (com.datastax.driver.core.utils.CassandraVersion)8 EntityTypeMetadata (com.datastax.driver.mapping.meta.EntityTypeMetadata)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 AbstractTableMetadata (com.datastax.driver.core.AbstractTableMetadata)2 KeyspaceMetadata (com.datastax.driver.core.KeyspaceMetadata)2 ImmutableList (com.google.common.collect.ImmutableList)2 ByteBuffer (java.nio.ByteBuffer)2 BoundStatementMapper (org.simpleflatmapper.datastax.BoundStatementMapper)2 Cluster (com.datastax.driver.core.Cluster)1 DataType (com.datastax.driver.core.DataType)1 MaterializedViewMetadata (com.datastax.driver.core.MaterializedViewMetadata)1 RegularStatement (com.datastax.driver.core.RegularStatement)1 EntityWithCompositeKey (com.datastax.driver.mapping.entity.EntityWithCompositeKey)1 EntityWithIndexes (com.datastax.driver.mapping.entity.EntityWithIndexes)1 EntityWithTimeUUID (com.datastax.driver.mapping.entity.EntityWithTimeUUID)1 EntityFieldMetaData (com.datastax.driver.mapping.meta.EntityFieldMetaData)1