Search in sources :

Example 1 with IndexMetadata

use of com.datastax.driver.core.IndexMetadata in project presto by prestodb.

the class NativeCassandraSession method buildColumnHandle.

private CassandraColumnHandle buildColumnHandle(TableMetadata tableMetadata, ColumnMetadata columnMeta, boolean partitionKey, boolean clusteringKey, int ordinalPosition, boolean hidden) {
    CassandraType cassandraType = CassandraType.getCassandraType(columnMeta.getType().getName());
    List<CassandraType> typeArguments = null;
    if (cassandraType != null && cassandraType.getTypeArgumentSize() > 0) {
        List<DataType> typeArgs = columnMeta.getType().getTypeArguments();
        switch(cassandraType.getTypeArgumentSize()) {
            case 1:
                typeArguments = ImmutableList.of(CassandraType.getCassandraType(typeArgs.get(0).getName()));
                break;
            case 2:
                typeArguments = ImmutableList.of(CassandraType.getCassandraType(typeArgs.get(0).getName()), CassandraType.getCassandraType(typeArgs.get(1).getName()));
                break;
            default:
                throw new IllegalArgumentException("Invalid type arguments: " + typeArgs);
        }
    }
    boolean indexed = false;
    for (IndexMetadata idx : tableMetadata.getIndexes()) {
        if (idx.getTarget().equals(columnMeta.getName())) {
            indexed = true;
            break;
        }
    }
    return new CassandraColumnHandle(connectorId, columnMeta.getName(), ordinalPosition, cassandraType, typeArguments, partitionKey, clusteringKey, indexed, hidden);
}
Also used : DataType(com.datastax.driver.core.DataType) IndexMetadata(com.datastax.driver.core.IndexMetadata)

Aggregations

DataType (com.datastax.driver.core.DataType)1 IndexMetadata (com.datastax.driver.core.IndexMetadata)1