Search in sources :

Example 46 with TableMetadata

use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.

the class DropIndexStatement method checkAccess.

public void checkAccess(ClientState state) throws UnauthorizedException, InvalidRequestException {
    TableMetadata metadata = lookupIndexedTable();
    if (metadata == null)
        return;
    state.hasColumnFamilyAccess(metadata.keyspace, metadata.name, Permission.ALTER);
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata)

Example 47 with TableMetadata

use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.

the class DropTableStatement method announceMigration.

public Event.SchemaChange announceMigration(QueryState queryState, boolean isLocalOnly) throws ConfigurationException {
    try {
        KeyspaceMetadata ksm = Schema.instance.getKeyspaceMetadata(keyspace());
        if (ksm == null)
            throw new ConfigurationException(String.format("Cannot drop table in unknown keyspace '%s'", keyspace()));
        TableMetadata metadata = ksm.getTableOrViewNullable(columnFamily());
        if (metadata != null) {
            if (metadata.isView())
                throw new InvalidRequestException("Cannot use DROP TABLE on Materialized View");
            boolean rejectDrop = false;
            StringBuilder messageBuilder = new StringBuilder();
            for (ViewMetadata def : ksm.views) {
                if (def.baseTableId.equals(metadata.id)) {
                    if (rejectDrop)
                        messageBuilder.append(',');
                    rejectDrop = true;
                    messageBuilder.append(def.name);
                }
            }
            if (rejectDrop) {
                throw new InvalidRequestException(String.format("Cannot drop table when materialized views still depend on it (%s.{%s})", keyspace(), messageBuilder.toString()));
            }
        }
        MigrationManager.announceTableDrop(keyspace(), columnFamily(), isLocalOnly);
        return new Event.SchemaChange(Event.SchemaChange.Change.DROPPED, Event.SchemaChange.Target.TABLE, keyspace(), columnFamily());
    } catch (ConfigurationException e) {
        if (ifExists)
            return null;
        throw e;
    }
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException) KeyspaceMetadata(org.apache.cassandra.schema.KeyspaceMetadata) ViewMetadata(org.apache.cassandra.schema.ViewMetadata)

Example 48 with TableMetadata

use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.

the class AbstractBTreePartition method build.

// Note that when building with a RowIterator, deletion will generally be LIVE, but we allow to pass it nonetheless because PartitionUpdate
// passes a MutableDeletionInfo that it mutates later.
protected static Holder build(RowIterator rows, DeletionInfo deletion, boolean buildEncodingStats, int initialRowCapacity) {
    TableMetadata metadata = rows.metadata();
    RegularAndStaticColumns columns = rows.columns();
    boolean reversed = rows.isReverseOrder();
    BTree.Builder<Row> builder = BTree.builder(metadata.comparator, initialRowCapacity);
    builder.auto(false);
    while (rows.hasNext()) builder.add(rows.next());
    if (reversed)
        builder.reverse();
    Row staticRow = rows.staticRow();
    Object[] tree = builder.build();
    EncodingStats stats = buildEncodingStats ? EncodingStats.Collector.collect(staticRow, BTree.iterator(tree), deletion) : EncodingStats.NO_STATS;
    return new Holder(columns, tree, deletion, staticRow, stats);
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) BTree(org.apache.cassandra.utils.btree.BTree)

Example 49 with TableMetadata

use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.

the class UnfilteredPartitionIterators method merge.

public static UnfilteredPartitionIterator merge(final List<? extends UnfilteredPartitionIterator> iterators, final int nowInSec, final MergeListener listener) {
    assert listener != null;
    assert !iterators.isEmpty();
    final TableMetadata metadata = iterators.get(0).metadata();
    final MergeIterator<UnfilteredRowIterator, UnfilteredRowIterator> merged = MergeIterator.get(iterators, partitionComparator, new MergeIterator.Reducer<UnfilteredRowIterator, UnfilteredRowIterator>() {

        private final List<UnfilteredRowIterator> toMerge = new ArrayList<>(iterators.size());

        private DecoratedKey partitionKey;

        private boolean isReverseOrder;

        public void reduce(int idx, UnfilteredRowIterator current) {
            partitionKey = current.partitionKey();
            isReverseOrder = current.isReverseOrder();
            // Note that because the MergeListener cares about it, we want to preserve the index of the iterator.
            // Non-present iterator will thus be set to empty in getReduced.
            toMerge.set(idx, current);
        }

        protected UnfilteredRowIterator getReduced() {
            UnfilteredRowIterators.MergeListener rowListener = listener.getRowMergeListener(partitionKey, toMerge);
            // Replace nulls by empty iterators
            for (int i = 0; i < toMerge.size(); i++) if (toMerge.get(i) == null)
                toMerge.set(i, EmptyIterators.unfilteredRow(metadata, partitionKey, isReverseOrder));
            return UnfilteredRowIterators.merge(toMerge, nowInSec, rowListener);
        }

        protected void onKeyChange() {
            toMerge.clear();
            for (int i = 0; i < iterators.size(); i++) toMerge.add(null);
        }
    });
    return new AbstractUnfilteredPartitionIterator() {

        public TableMetadata metadata() {
            return metadata;
        }

        public boolean hasNext() {
            return merged.hasNext();
        }

        public UnfilteredRowIterator next() {
            return merged.next();
        }

        @Override
        public void close() {
            merged.close();
            listener.close();
        }
    };
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) MergeIterator(org.apache.cassandra.utils.MergeIterator)

Example 50 with TableMetadata

use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.

the class UnfilteredPartitionIterators method mergeLazily.

public static UnfilteredPartitionIterator mergeLazily(final List<? extends UnfilteredPartitionIterator> iterators, final int nowInSec) {
    assert !iterators.isEmpty();
    if (iterators.size() == 1)
        return iterators.get(0);
    final TableMetadata metadata = iterators.get(0).metadata();
    final MergeIterator<UnfilteredRowIterator, UnfilteredRowIterator> merged = MergeIterator.get(iterators, partitionComparator, new MergeIterator.Reducer<UnfilteredRowIterator, UnfilteredRowIterator>() {

        private final List<UnfilteredRowIterator> toMerge = new ArrayList<>(iterators.size());

        public void reduce(int idx, UnfilteredRowIterator current) {
            toMerge.add(current);
        }

        protected UnfilteredRowIterator getReduced() {
            return new LazilyInitializedUnfilteredRowIterator(toMerge.get(0).partitionKey()) {

                protected UnfilteredRowIterator initializeIterator() {
                    return UnfilteredRowIterators.merge(toMerge, nowInSec);
                }
            };
        }

        protected void onKeyChange() {
            toMerge.clear();
        }
    });
    return new AbstractUnfilteredPartitionIterator() {

        public TableMetadata metadata() {
            return metadata;
        }

        public boolean hasNext() {
            return merged.hasNext();
        }

        public UnfilteredRowIterator next() {
            return merged.next();
        }

        @Override
        public void close() {
            merged.close();
        }
    };
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) MergeIterator(org.apache.cassandra.utils.MergeIterator)

Aggregations

TableMetadata (org.apache.cassandra.schema.TableMetadata)129 Test (org.junit.Test)63 ByteBuffer (java.nio.ByteBuffer)29 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)17 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)13 File (java.io.File)10 PartitionUpdate (org.apache.cassandra.db.partitions.PartitionUpdate)10 Mutation (org.apache.cassandra.db.Mutation)8 InvalidRequestException (org.apache.cassandra.exceptions.InvalidRequestException)8 KeyspaceMetadata (org.apache.cassandra.schema.KeyspaceMetadata)8 Descriptor (org.apache.cassandra.io.sstable.Descriptor)7 IndexMetadata (org.apache.cassandra.schema.IndexMetadata)6 IOException (java.io.IOException)5 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)5 IndexTarget (org.apache.cassandra.cql3.statements.IndexTarget)5 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)5 ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)4 UntypedResultSet (org.apache.cassandra.cql3.UntypedResultSet)4 AbstractType (org.apache.cassandra.db.marshal.AbstractType)4 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)4