Search in sources :

Example 51 with KeyspaceMetadata

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

the class NativeCassandraSession method getAllTables.

@Override
public List<String> getAllTables(String schema) throws SchemaNotFoundException {
    KeyspaceMetadata meta = getCheckedKeyspaceMetadata(schema);
    ImmutableList.Builder<String> builder = ImmutableList.builder();
    for (TableMetadata tableMeta : meta.getTables()) {
        builder.add(tableMeta.getName());
    }
    return builder.build();
}
Also used : TableMetadata(com.datastax.driver.core.TableMetadata) ImmutableList(com.google.common.collect.ImmutableList) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata)

Example 52 with KeyspaceMetadata

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

the class NativeCassandraSession method getTableMetadata.

private TableMetadata getTableMetadata(SchemaTableName schemaTableName) {
    String schemaName = schemaTableName.getSchemaName();
    String tableName = schemaTableName.getTableName();
    KeyspaceMetadata keyspaceMetadata = getCheckedKeyspaceMetadata(schemaName);
    TableMetadata tableMetadata = keyspaceMetadata.getTable(tableName);
    if (tableMetadata != null) {
        return tableMetadata;
    }
    for (TableMetadata table : keyspaceMetadata.getTables()) {
        if (table.getName().equalsIgnoreCase(tableName)) {
            return table;
        }
    }
    throw new TableNotFoundException(schemaTableName);
}
Also used : TableMetadata(com.datastax.driver.core.TableMetadata) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata)

Example 53 with KeyspaceMetadata

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

the class CassandraConnectorTableService method get.

/**
     * {@inheritDoc}
     */
@Override
public TableInfo get(@Nonnull @NonNull final ConnectorContext context, @Nonnull @NonNull final QualifiedName name) {
    final String keyspace = name.getDatabaseName();
    final String table = name.getTableName();
    log.debug("Attempting to get metadata for Cassandra table {}.{} for request {}", keyspace, table, context);
    try {
        final KeyspaceMetadata keyspaceMetadata = this.getCluster().getMetadata().getKeyspace(keyspace);
        if (keyspaceMetadata == null) {
            throw new DatabaseNotFoundException(name);
        }
        final TableMetadata tableMetadata = keyspaceMetadata.getTable(table);
        if (tableMetadata == null) {
            throw new TableNotFoundException(name);
        }
        final TableInfo tableInfo = this.getTableInfo(name, tableMetadata);
        log.debug("Successfully got metadata for Cassandra table {}.{} for request {}", keyspace, table, context);
        return tableInfo;
    } catch (final DriverException de) {
        log.error(de.getMessage(), de);
        throw this.getExceptionMapper().toConnectorException(de, name);
    }
}
Also used : TableMetadata(com.datastax.driver.core.TableMetadata) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) TableInfo(com.netflix.metacat.common.server.connectors.model.TableInfo) DriverException(com.datastax.driver.core.exceptions.DriverException) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata)

Example 54 with KeyspaceMetadata

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

the class CassandraConnectorDatabaseService method listViewNames.

/**
     * {@inheritDoc}
     */
@Override
public List<QualifiedName> listViewNames(@Nonnull @NonNull final ConnectorContext context, @Nonnull @NonNull final QualifiedName databaseName) {
    final String catalogName = databaseName.getCatalogName();
    final String keyspace = databaseName.getDatabaseName();
    log.debug("Attempting to get materialized view names for keyspace {} due to request {}", keyspace, context);
    try {
        final KeyspaceMetadata keyspaceMetadata = this.getCluster().getMetadata().getKeyspace(keyspace);
        if (keyspaceMetadata == null) {
            throw new DatabaseNotFoundException(databaseName);
        }
        final ImmutableList.Builder<QualifiedName> viewsBuilder = ImmutableList.builder();
        for (final MaterializedViewMetadata view : keyspaceMetadata.getMaterializedViews()) {
            viewsBuilder.add(QualifiedName.ofView(catalogName, keyspace, view.getBaseTable().getName(), view.getName()));
        }
        final List<QualifiedName> views = viewsBuilder.build();
        log.debug("Successfully found {} views for keyspace {} due to request {}", views.size(), keyspace, context);
        return views;
    } catch (final DriverException de) {
        log.error(de.getMessage(), de);
        throw this.getExceptionMapper().toConnectorException(de, databaseName);
    }
}
Also used : MaterializedViewMetadata(com.datastax.driver.core.MaterializedViewMetadata) ImmutableList(com.google.common.collect.ImmutableList) 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 55 with KeyspaceMetadata

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

the class CassandraConnectorTableService method list.

/**
     * {@inheritDoc}
     */
@Override
public List<TableInfo> list(@Nonnull @NonNull final ConnectorContext context, @Nonnull @NonNull final QualifiedName name, @Nullable final QualifiedName prefix, @Nullable final Sort sort, @Nullable final Pageable pageable) {
    final String keyspace = name.getDatabaseName();
    log.debug("Attempting to list tables 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<TableInfo> tables = Lists.newArrayList();
        for (final TableMetadata tableMetadata : keyspaceMetadata.getTables()) {
            if (prefix != null && !tableMetadata.getName().startsWith(prefix.getTableName())) {
                continue;
            }
            tables.add(this.getTableInfo(name, tableMetadata));
        }
        // Sort
        if (sort != null) {
            final Comparator<TableInfo> tableComparator = Comparator.comparing((t) -> t.getName().getTableName());
            ConnectorUtils.sort(tables, sort, tableComparator);
        }
        // Paging
        final List<TableInfo> pagedTables = ConnectorUtils.paginate(tables, pageable);
        log.debug("Listed {} tables in Cassandra keyspace {} for request {}", pagedTables.size(), keyspace, context);
        return pagedTables;
    } 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) TableInfo(com.netflix.metacat.common.server.connectors.model.TableInfo) DriverException(com.datastax.driver.core.exceptions.DriverException) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata)

Aggregations

KeyspaceMetadata (com.datastax.driver.core.KeyspaceMetadata)83 TableMetadata (com.datastax.driver.core.TableMetadata)40 ImmutableList (com.google.common.collect.ImmutableList)20 DriverException (com.datastax.driver.core.exceptions.DriverException)15 Cluster (com.datastax.driver.core.Cluster)14 AbstractTableMetadata (com.datastax.driver.core.AbstractTableMetadata)13 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)12 Map (java.util.Map)12 ArrayList (java.util.ArrayList)11 DatabaseNotFoundException (com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException)10 HashMap (java.util.HashMap)10 List (java.util.List)10 ColumnMetadata (com.datastax.driver.core.ColumnMetadata)9 MaterializedViewMetadata (com.datastax.driver.core.MaterializedViewMetadata)9 Metadata (com.datastax.driver.core.Metadata)9 Session (com.datastax.driver.core.Session)9 Set (java.util.Set)9 PrestoException (com.facebook.presto.spi.PrestoException)7 PreparedStatement (com.datastax.driver.core.PreparedStatement)6 Statement (com.datastax.driver.core.Statement)6