use of org.apache.cassandra.db.marshal.AbstractType in project eiger by wlloyd.
the class AbstractThreadUnsafeSortedColumns method retainAll.
public void retainAll(ISortedColumns columns) {
Iterator<IColumn> iter = iterator();
Iterator<IColumn> toRetain = columns.iterator();
IColumn current = iter.hasNext() ? iter.next() : null;
IColumn retain = toRetain.hasNext() ? toRetain.next() : null;
AbstractType comparator = getComparator();
while (current != null && retain != null) {
int c = comparator.compare(current.name(), retain.name());
if (c == 0) {
if (current instanceof SuperColumn) {
assert retain instanceof SuperColumn;
((SuperColumn) current).retainAll((SuperColumn) retain);
}
current = iter.hasNext() ? iter.next() : null;
retain = toRetain.hasNext() ? toRetain.next() : null;
} else if (c < 0) {
iter.remove();
current = iter.hasNext() ? iter.next() : null;
} else // c > 0
{
retain = toRetain.hasNext() ? toRetain.next() : null;
}
}
while (current != null) {
iter.remove();
current = iter.hasNext() ? iter.next() : null;
}
}
use of org.apache.cassandra.db.marshal.AbstractType in project eiger by wlloyd.
the class Column method validateFields.
@Override
public void validateFields(CFMetaData metadata) throws MarshalException {
validateName(metadata);
AbstractType valueValidator = metadata.getValueValidator(name());
if (valueValidator != null)
valueValidator.validate(value());
}
use of org.apache.cassandra.db.marshal.AbstractType in project eiger by wlloyd.
the class IndexHelperTest method testIndexHelper.
@Test
public void testIndexHelper() {
List<IndexInfo> indexes = new ArrayList<IndexInfo>();
indexes.add(new IndexInfo(bytes(0L), bytes(5L), 0, 0));
indexes.add(new IndexInfo(bytes(10L), bytes(15L), 0, 0));
indexes.add(new IndexInfo(bytes(20L), bytes(25L), 0, 0));
AbstractType comp = IntegerType.instance;
assert 0 == IndexHelper.indexFor(bytes(-1L), indexes, comp, false);
assert 0 == IndexHelper.indexFor(bytes(5L), indexes, comp, false);
assert 1 == IndexHelper.indexFor(bytes(12L), indexes, comp, false);
assert 2 == IndexHelper.indexFor(bytes(17L), indexes, comp, false);
assert 3 == IndexHelper.indexFor(bytes(100L), indexes, comp, false);
assert -1 == IndexHelper.indexFor(bytes(-1L), indexes, comp, true);
assert 0 == IndexHelper.indexFor(bytes(5L), indexes, comp, true);
assert 1 == IndexHelper.indexFor(bytes(12L), indexes, comp, true);
assert 1 == IndexHelper.indexFor(bytes(17L), indexes, comp, true);
assert 2 == IndexHelper.indexFor(bytes(100L), indexes, comp, true);
}
use of org.apache.cassandra.db.marshal.AbstractType in project eiger by wlloyd.
the class ThriftValidation method validateCfDef.
public static void validateCfDef(CfDef cf_def, CFMetaData old) throws InvalidRequestException {
try {
if (cf_def.name.length() > 32)
throw new InvalidRequestException(String.format("Column family names shouldn't be more than 32 character long (got \"%s\")", cf_def.name));
if (cf_def.key_alias != null) {
if (!cf_def.key_alias.hasRemaining())
throw new InvalidRequestException("key_alias may not be empty");
try {
// it's hard to use a key in a select statement if we can't type it.
// for now let's keep it simple and require ascii.
AsciiType.instance.validate(cf_def.key_alias);
} catch (MarshalException e) {
throw new InvalidRequestException("Key aliases must be ascii");
}
}
ColumnFamilyType cfType = ColumnFamilyType.create(cf_def.column_type);
if (cfType == null)
throw new InvalidRequestException("invalid column type " + cf_def.column_type);
TypeParser.parse(cf_def.key_validation_class);
TypeParser.parse(cf_def.comparator_type);
TypeParser.parse(cf_def.subcomparator_type);
TypeParser.parse(cf_def.default_validation_class);
if (cfType != ColumnFamilyType.Super && cf_def.subcomparator_type != null)
throw new InvalidRequestException("subcomparator_type is invalid for standard columns");
if (cf_def.column_metadata == null)
return;
AbstractType comparator = cfType == ColumnFamilyType.Standard ? TypeParser.parse(cf_def.comparator_type) : TypeParser.parse(cf_def.subcomparator_type);
if (cf_def.key_alias != null) {
// check if any of the columns has name equal to the cf.key_alias
for (ColumnDef columnDef : cf_def.column_metadata) {
if (cf_def.key_alias.equals(columnDef.name))
throw new InvalidRequestException("Invalid column name: " + AsciiType.instance.compose(cf_def.key_alias) + ", because it equals the key_alias");
}
}
// initialize a set of names NOT in the CF under consideration
Set<String> indexNames = new HashSet<String>();
for (ColumnFamilyStore cfs : ColumnFamilyStore.all()) {
if (!cfs.getColumnFamilyName().equals(cf_def.name))
for (ColumnDefinition cd : cfs.metadata.getColumn_metadata().values()) indexNames.add(cd.getIndexName());
}
for (ColumnDef c : cf_def.column_metadata) {
TypeParser.parse(c.validation_class);
try {
comparator.validate(c.name);
} catch (MarshalException e) {
throw new InvalidRequestException(String.format("Column name %s is not valid for comparator %s", ByteBufferUtil.bytesToHex(c.name), cf_def.comparator_type));
}
if (c.index_type == null) {
if (c.index_name != null)
throw new ConfigurationException("index_name cannot be set without index_type");
} else {
if (cfType == ColumnFamilyType.Super)
throw new InvalidRequestException("Secondary indexes are not supported on supercolumns");
// should have a default set by now if none was provided
assert c.index_name != null;
if (!Migration.isLegalName(c.index_name))
throw new InvalidRequestException("Illegal index name " + c.index_name);
// check index names against this CF _and_ globally
if (indexNames.contains(c.index_name))
throw new InvalidRequestException("Duplicate index name " + c.index_name);
indexNames.add(c.index_name);
ColumnDefinition oldCd = old == null ? null : old.getColumnDefinition(c.name);
if (oldCd != null && oldCd.getIndexType() != null) {
assert oldCd.getIndexName() != null;
if (!oldCd.getIndexName().equals(c.index_name))
throw new InvalidRequestException("Cannot modify index name");
}
if (c.index_type == IndexType.CUSTOM) {
if (c.index_options == null || !c.index_options.containsKey(SecondaryIndex.CUSTOM_INDEX_OPTION_NAME))
throw new InvalidRequestException("Required index option missing: " + SecondaryIndex.CUSTOM_INDEX_OPTION_NAME);
}
// Create the index type and validate the options
ColumnDefinition cdef = ColumnDefinition.fromThrift(c);
// This method validates the column metadata but does not intialize the index
SecondaryIndex.createInstance(null, cdef);
}
}
validateMinMaxCompactionThresholds(cf_def);
// validates compression parameters
CompressionParameters.create(cf_def.compression_options);
} catch (ConfigurationException e) {
throw new InvalidRequestException(e.getMessage());
}
}
use of org.apache.cassandra.db.marshal.AbstractType in project eiger by wlloyd.
the class ThriftValidation method validateRange.
public static void validateRange(CFMetaData metadata, ColumnParent column_parent, SliceRange range) throws InvalidRequestException {
AbstractType comparator = metadata.getComparatorFor(column_parent.super_column);
try {
comparator.validate(range.start);
comparator.validate(range.finish);
} catch (MarshalException e) {
throw new InvalidRequestException(e.getMessage());
}
if (range.count < 0)
throw new InvalidRequestException("get_slice requires non-negative count");
Comparator<ByteBuffer> orderedComparator = range.isReversed() ? comparator.reverseComparator : comparator;
if (range.start.remaining() > 0 && range.finish.remaining() > 0 && orderedComparator.compare(range.start, range.finish) > 0) {
throw new InvalidRequestException("range finish must come after start in the order of traversal");
}
}
Aggregations