make scrubbing collection-aware

This commit is contained in:
Jonathan Ellis 2013-08-08 17:06:56 -05:00
parent 9e0efa3dbb
commit 73b0ffba82
2 changed files with 27 additions and 10 deletions

View File

@ -293,16 +293,9 @@ public class Column implements IColumn
// If this is a CQL table, we need to pull out the CQL column name to look up the correct column type.
// (Note that COMPACT composites are handled by validateName, above.)
ByteBuffer internalName;
if (cfdef.isComposite && !cfdef.isCompact)
{
AbstractCompositeType comparator = (AbstractCompositeType) metadata.comparator;
List<AbstractCompositeType.CompositeComponent> components = comparator.deconstruct(name);
internalName = components.get(components.size() - 1).value;
}
else
{
internalName = name;
}
internalName = (cfdef.isComposite && !cfdef.isCompact)
? ((CompositeType) metadata.comparator).extractLastComponent(name)
: name;
AbstractType<?> valueValidator = metadata.getValueValidator(internalName);
if (valueValidator != null)

View File

@ -124,6 +124,30 @@ public class CompositeType extends AbstractCompositeType
return build(serialized);
}
// Extract component idx from bb. Return null if there is not enough component.
public static ByteBuffer extractComponent(ByteBuffer bb, int idx)
{
bb = bb.duplicate();
int i = 0;
while (bb.remaining() > 0)
{
ByteBuffer c = getWithShortLength(bb);
if (i == idx)
return c;
bb.get(); // skip end-of-component
++i;
}
return null;
}
// Extract CQL3 column name from the full column name.
public ByteBuffer extractLastComponent(ByteBuffer bb)
{
int idx = types.get(types.size() - 1) instanceof ColumnToCollectionType ? types.size() - 2 : types.size() - 1;
return extractComponent(bb, idx);
}
@Override
public boolean isCompatibleWith(AbstractType<?> previous)
{