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);
}
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);
}
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);
}
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);
}
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());
}
Aggregations