Search in sources :

Example 6 with KeyspaceMetadata

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

the class CassandraTokenSplitManager method checkSizeEstimatesTableExist.

private void checkSizeEstimatesTableExist() {
    KeyspaceMetadata ks = session.executeWithSession(session -> session.getCluster().getMetadata().getKeyspace(SYSTEM));
    checkState(ks != null, "system keyspace metadata must not be null");
    TableMetadata table = ks.getTable(SIZE_ESTIMATES);
    if (table == null) {
        throw new PrestoException(NOT_SUPPORTED, "Cassandra versions prior to 2.1.5 are not supported");
    }
}
Also used : TableMetadata(com.datastax.driver.core.TableMetadata) PrestoException(com.facebook.presto.spi.PrestoException) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata)

Example 7 with KeyspaceMetadata

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

the class NativeCassandraSession method getAllSchemas.

@Override
public List<String> getAllSchemas() {
    ImmutableList.Builder<String> builder = ImmutableList.builder();
    List<KeyspaceMetadata> keyspaces = executeWithSession(session -> session.getCluster().getMetadata().getKeyspaces());
    for (KeyspaceMetadata meta : keyspaces) {
        builder.add(meta.getName());
    }
    return builder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata)

Example 8 with KeyspaceMetadata

use of com.datastax.driver.core.KeyspaceMetadata in project metacat by Netflix.

the class CassandraConnectorTableService method exists.

/**
     * {@inheritDoc}
     */
@Override
public boolean exists(@Nonnull @NonNull final ConnectorContext context, @Nonnull @NonNull final QualifiedName name) {
    final String keyspace = name.getDatabaseName();
    final String table = name.getTableName();
    log.debug("Checking if Cassandra table {}.{} exists for request {}", keyspace, table, context);
    try {
        final KeyspaceMetadata keyspaceMetadata = this.getCluster().getMetadata().getKeyspace(keyspace);
        if (keyspaceMetadata == null) {
            return false;
        }
        final boolean exists = keyspaceMetadata.getTable(table) != null;
        log.debug("Cassandra table {}.{} {} for request {}", keyspace, table, exists ? "exists" : "doesn't exist", context);
        return exists;
    } catch (final DriverException de) {
        log.error(de.getMessage(), de);
        throw this.getExceptionMapper().toConnectorException(de, name);
    }
}
Also used : DriverException(com.datastax.driver.core.exceptions.DriverException) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata)

Example 9 with KeyspaceMetadata

use of com.datastax.driver.core.KeyspaceMetadata in project metacat by Netflix.

the class CassandraConnectorTableService method listNames.

/**
     * {@inheritDoc}
     */
@Override
public List<QualifiedName> listNames(@Nonnull @NonNull final ConnectorContext context, @Nonnull @NonNull final QualifiedName name, @Nullable final QualifiedName prefix, @Nullable final Sort sort, @Nullable final Pageable pageable) {
    final String catalog = name.getCatalogName();
    final String keyspace = name.getDatabaseName();
    log.debug("Attempting to list table names in Cassandra keyspace {} for request {}", keyspace, context);
    try {
        final KeyspaceMetadata keyspaceMetadata = this.getCluster().getMetadata().getKeyspace(keyspace);
        if (keyspaceMetadata == null) {
            throw new DatabaseNotFoundException(name);
        }
        // TODO: Should we include views?
        final List<QualifiedName> tableNames = Lists.newArrayList();
        for (final TableMetadata tableMetadata : keyspaceMetadata.getTables()) {
            final String tableName = tableMetadata.getName();
            if (prefix != null && !tableName.startsWith(prefix.getTableName())) {
                continue;
            }
            tableNames.add(QualifiedName.ofTable(catalog, keyspace, tableName));
        }
        // Sort
        if (sort != null) {
            final Comparator<QualifiedName> tableNameComparator = Comparator.comparing(QualifiedName::getTableName);
            ConnectorUtils.sort(tableNames, sort, tableNameComparator);
        }
        // Paging
        final List<QualifiedName> paged = ConnectorUtils.paginate(tableNames, pageable);
        log.debug("Listed {} table names in Cassandra keyspace {} for request {}", paged.size(), keyspace, context);
        return paged;
    } catch (final DriverException de) {
        log.error(de.getMessage(), de);
        throw this.getExceptionMapper().toConnectorException(de, name);
    }
}
Also used : TableMetadata(com.datastax.driver.core.TableMetadata) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) QualifiedName(com.netflix.metacat.common.QualifiedName) DriverException(com.datastax.driver.core.exceptions.DriverException) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata)

Example 10 with KeyspaceMetadata

use of com.datastax.driver.core.KeyspaceMetadata in project metacat by Netflix.

the class CassandraConnectorDatabaseService method listNames.

/**
     * {@inheritDoc}
     */
@Override
public List<QualifiedName> listNames(@Nonnull @NonNull final ConnectorContext context, @Nonnull @NonNull final QualifiedName name, @Nullable final QualifiedName prefix, @Nullable final Sort sort, @Nullable final Pageable pageable) {
    log.debug("Attempting to list keyspaces for request {}", context);
    try {
        final List<QualifiedName> names = Lists.newArrayList();
        for (final KeyspaceMetadata keyspace : this.getCluster().getMetadata().getKeyspaces()) {
            final String keyspaceName = keyspace.getName();
            if (prefix != null && !keyspaceName.startsWith(prefix.getDatabaseName())) {
                continue;
            }
            names.add(QualifiedName.ofDatabase(name.getCatalogName(), keyspaceName));
        }
        if (sort != null) {
            // We can only really sort by the database name at this level so ignore SortBy field
            final Comparator<QualifiedName> comparator = Comparator.comparing(QualifiedName::getDatabaseName);
            ConnectorUtils.sort(names, sort, comparator);
        }
        final List<QualifiedName> results = ConnectorUtils.paginate(names, pageable);
        log.debug("Finished listing keyspaces for request {}", context);
        return results;
    } catch (final DriverException de) {
        log.error(de.getMessage(), de);
        throw this.getExceptionMapper().toConnectorException(de, name);
    }
}
Also used : QualifiedName(com.netflix.metacat.common.QualifiedName) DriverException(com.datastax.driver.core.exceptions.DriverException) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata)

Aggregations

KeyspaceMetadata (com.datastax.driver.core.KeyspaceMetadata)26 TableMetadata (com.datastax.driver.core.TableMetadata)9 DriverException (com.datastax.driver.core.exceptions.DriverException)7 Cluster (com.datastax.driver.core.Cluster)5 DatabaseNotFoundException (com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException)5 Test (org.junit.Test)5 ImmutableList (com.google.common.collect.ImmutableList)3 QualifiedName (com.netflix.metacat.common.QualifiedName)3 RegularStatement (com.datastax.driver.core.RegularStatement)2 TableInfo (com.netflix.metacat.common.server.connectors.model.TableInfo)2 ArrayList (java.util.ArrayList)2 ColumnMetadata (com.datastax.driver.core.ColumnMetadata)1 MaterializedViewMetadata (com.datastax.driver.core.MaterializedViewMetadata)1 MappingManager (com.datastax.driver.mapping.MappingManager)1 EntityFieldMetaData (com.datastax.driver.mapping.meta.EntityFieldMetaData)1 EntityTypeMetadata (com.datastax.driver.mapping.meta.EntityTypeMetadata)1 PrestoException (com.facebook.presto.spi.PrestoException)1 TableNotFoundException (com.facebook.presto.spi.TableNotFoundException)1 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)1 AnnotationUDT (zipkin.storage.cassandra3.Schema.AnnotationUDT)1