Search in sources :

Example 6 with ColumnMetadata

use of com.datastax.driver.core.ColumnMetadata in project java-driver by datastax.

the class IndexMetadataTest method should_create_metadata_for_index_on_map_entries.

@Test(groups = "short")
@CassandraVersion("2.2.0")
public void should_create_metadata_for_index_on_map_entries() {
    String createEntriesIndex = String.format("CREATE INDEX map_entries_index ON %s.indexing (entries(map_entries));", keyspace);
    session().execute(createEntriesIndex);
    ColumnMetadata column = getColumn("map_entries");
    IndexMetadata index = getIndex("map_entries_index");
    assertThat(index).hasName("map_entries_index").hasParent((TableMetadata) column.getParent()).isNotCustomIndex().hasTarget("entries(map_entries)").hasKind(COMPOSITES).asCqlQuery(createEntriesIndex);
    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 7 with ColumnMetadata

use of com.datastax.driver.core.ColumnMetadata in project java-driver by datastax.

the class IndexMetadataTest method should_create_metadata_for_index_on_map_values.

@Test(groups = "short")
@CassandraVersion("2.1.0")
public void should_create_metadata_for_index_on_map_values() {
    // 3.0 assumes the 'values' keyword if index on a collection
    String createValuesIndex = ccm().getCassandraVersion().getMajor() > 2 ? String.format("CREATE INDEX map_values_index ON %s.indexing (values(map_values));", keyspace) : String.format("CREATE INDEX map_values_index ON %s.indexing (map_values);", keyspace);
    session().execute(createValuesIndex);
    ColumnMetadata column = getColumn("map_values");
    IndexMetadata index = getIndex("map_values_index");
    assertThat(index).hasName("map_values_index").hasParent((TableMetadata) column.getParent()).isNotCustomIndex().hasTarget(ccm().getCassandraVersion().getMajor() > 2 ? "values(map_values)" : "map_values").hasKind(COMPOSITES).asCqlQuery(createValuesIndex);
    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 8 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_list.

@Test(groups = "short")
@CassandraVersion("2.1.3")
public void should_create_metadata_for_full_index_on_list() {
    String createFullIndex = String.format("CREATE INDEX list_full_index ON %s.indexing (full(list_full));", keyspace);
    session().execute(createFullIndex);
    ColumnMetadata column = getColumn("list_full");
    IndexMetadata index = getIndex("list_full_index");
    assertThat(index).hasName("list_full_index").hasParent((TableMetadata) column.getParent()).isNotCustomIndex().hasTarget("full(list_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 9 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_set.

@Test(groups = "short")
@CassandraVersion("2.1.3")
public void should_create_metadata_for_full_index_on_set() {
    String createFullIndex = String.format("CREATE INDEX set_full_index ON %s.indexing (full(set_full));", keyspace);
    session().execute(createFullIndex);
    ColumnMetadata column = getColumn("set_full");
    IndexMetadata index = getIndex("set_full_index");
    assertThat(index).hasName("set_full_index").hasParent((TableMetadata) column.getParent()).isNotCustomIndex().hasTarget("full(set_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 10 with ColumnMetadata

use of com.datastax.driver.core.ColumnMetadata in project calcite by apache.

the class CassandraSchema method getRelDataType.

RelProtoDataType getRelDataType(String columnFamily, boolean view) {
    List<ColumnMetadata> columns;
    if (view) {
        columns = getKeyspace().getMaterializedView(columnFamily).getColumns();
    } else {
        columns = getKeyspace().getTable(columnFamily).getColumns();
    }
    // Temporary type factory, just for the duration of this method. Allowable
    // because we're creating a proto-type, not a type; before being used, the
    // proto-type will be copied into a real type factory.
    final RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
    final RelDataTypeFactory.Builder fieldInfo = typeFactory.builder();
    for (ColumnMetadata column : columns) {
        final String columnName = column.getName();
        final DataType type = column.getType();
        // TODO: This mapping of types can be done much better
        SqlTypeName typeName = SqlTypeName.ANY;
        if (type == DataType.uuid() || type == DataType.timeuuid()) {
            // We currently rely on this in CassandraFilter to detect UUID columns.
            // That is, these fixed length literals should be unquoted in CQL.
            typeName = SqlTypeName.CHAR;
        } else if (type == DataType.ascii() || type == DataType.text() || type == DataType.varchar()) {
            typeName = SqlTypeName.VARCHAR;
        } else if (type == DataType.cint() || type == DataType.varint()) {
            typeName = SqlTypeName.INTEGER;
        } else if (type == DataType.bigint()) {
            typeName = SqlTypeName.BIGINT;
        } else if (type == DataType.cdouble() || type == DataType.cfloat() || type == DataType.decimal()) {
            typeName = SqlTypeName.DOUBLE;
        }
        fieldInfo.add(columnName, typeFactory.createSqlType(typeName)).nullable(true);
    }
    return RelDataTypeImpl.proto(fieldInfo.build());
}
Also used : ColumnMetadata(com.datastax.driver.core.ColumnMetadata) SqlTypeFactoryImpl(org.apache.calcite.sql.type.SqlTypeFactoryImpl) SqlTypeName(org.apache.calcite.sql.type.SqlTypeName) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) RelProtoDataType(org.apache.calcite.rel.type.RelProtoDataType) DataType(com.datastax.driver.core.DataType)

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