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