Updated Branches: refs/heads/trunk af3ad31c3 -> 4260736e1
Fix creating cellnameType for super columns Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/4260736e Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/4260736e Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/4260736e Branch: refs/heads/trunk Commit: 4260736e1eed08b49a31a9328d6823ae3fc86d0d Parents: af3ad31 Author: Sylvain Lebresne <[email protected]> Authored: Fri Jan 3 16:23:52 2014 +0100 Committer: Sylvain Lebresne <[email protected]> Committed: Fri Jan 3 16:24:02 2014 +0100 ---------------------------------------------------------------------- .../cassandra/db/composites/CellNames.java | 5 ++-- .../composites/CompoundSparseCellNameType.java | 27 ++++++++++++-------- 2 files changed, 20 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/4260736e/src/java/org/apache/cassandra/db/composites/CellNames.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/db/composites/CellNames.java b/src/java/org/apache/cassandra/db/composites/CellNames.java index 7c8cbbd..dc7d0e2 100644 --- a/src/java/org/apache/cassandra/db/composites/CellNames.java +++ b/src/java/org/apache/cassandra/db/composites/CellNames.java @@ -50,13 +50,14 @@ public abstract class CellNames List<AbstractType<?>> types = ((CompositeType)type).types; if (types.get(types.size() - 1) instanceof ColumnToCollectionType) { + // We don't allow collection for super columns, so the "name" type *must* be UTF8 assert types.get(types.size() - 2) instanceof UTF8Type; return new CompoundSparseCellNameType.WithCollection(types.subList(0, types.size() - 2), (ColumnToCollectionType)types.get(types.size() - 1)); } else { - assert types.get(types.size() - 1) instanceof UTF8Type; - return new CompoundSparseCellNameType(types.subList(0, types.size() - 1)); + AbstractType<?> nameType = types.get(types.size() - 1); + return new CompoundSparseCellNameType(types.subList(0, types.size() - 1), nameType); } } else http://git-wip-us.apache.org/repos/asf/cassandra/blob/4260736e/src/java/org/apache/cassandra/db/composites/CompoundSparseCellNameType.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/db/composites/CompoundSparseCellNameType.java b/src/java/org/apache/cassandra/db/composites/CompoundSparseCellNameType.java index a301665..d0e66f8 100644 --- a/src/java/org/apache/cassandra/db/composites/CompoundSparseCellNameType.java +++ b/src/java/org/apache/cassandra/db/composites/CompoundSparseCellNameType.java @@ -30,29 +30,36 @@ import org.apache.cassandra.utils.ByteBufferUtil; public class CompoundSparseCellNameType extends AbstractCompoundCellNameType { - private static final AbstractType<?> columnNameType = UTF8Type.instance; private static final ColumnIdentifier rowMarkerId = new ColumnIdentifier(ByteBufferUtil.EMPTY_BYTE_BUFFER, UTF8Type.instance); private static final CellName rowMarkerNoPrefix = new CompoundSparseCellName(rowMarkerId); + // For CQL3 columns, this is always UTF8Type. However, for compatibility with super columns, we need to allow it to be non-UTF8. + private final AbstractType<?> columnNameType; protected final Map<ByteBuffer, ColumnIdentifier> internedIds; public CompoundSparseCellNameType(List<AbstractType<?>> types) { - this(new CompoundCType(types)); + this(types, UTF8Type.instance); } - public CompoundSparseCellNameType(CompoundCType clusteringType) + public CompoundSparseCellNameType(List<AbstractType<?>> types, AbstractType<?> columnNameType) { - this(clusteringType, makeCType(clusteringType, null), new HashMap<ByteBuffer, ColumnIdentifier>()); + this(new CompoundCType(types), columnNameType); } - private CompoundSparseCellNameType(CompoundCType clusteringType, CompoundCType fullType, Map<ByteBuffer, ColumnIdentifier> internedIds) + private CompoundSparseCellNameType(CompoundCType clusteringType, AbstractType<?> columnNameType) + { + this(clusteringType, columnNameType, makeCType(clusteringType, columnNameType, null), new HashMap<ByteBuffer, ColumnIdentifier>()); + } + + private CompoundSparseCellNameType(CompoundCType clusteringType, AbstractType<?> columnNameType, CompoundCType fullType, Map<ByteBuffer, ColumnIdentifier> internedIds) { super(clusteringType, fullType); + this.columnNameType = columnNameType; this.internedIds = internedIds; } - protected static CompoundCType makeCType(CompoundCType clusteringType, ColumnToCollectionType collectionType) + protected static CompoundCType makeCType(CompoundCType clusteringType, AbstractType<?> columnNameType, ColumnToCollectionType collectionType) { List<AbstractType<?>> allSubtypes = new ArrayList<AbstractType<?>>(clusteringType.size() + (collectionType == null ? 1 : 2)); for (int i = 0; i < clusteringType.size(); i++) @@ -66,7 +73,7 @@ public class CompoundSparseCellNameType extends AbstractCompoundCellNameType public CellNameType setSubtype(int position, AbstractType<?> newType) { if (position < clusteringSize) - return new CompoundSparseCellNameType(clusteringType.setSubtype(position, newType), fullType.setSubtype(position, newType), internedIds); + return new CompoundSparseCellNameType(clusteringType.setSubtype(position, newType), columnNameType, fullType.setSubtype(position, newType), internedIds); if (position == clusteringSize) throw new IllegalArgumentException(); @@ -159,17 +166,17 @@ public class CompoundSparseCellNameType extends AbstractCompoundCellNameType WithCollection(CompoundCType clusteringType, ColumnToCollectionType collectionType) { - this(clusteringType, makeCType(clusteringType, collectionType), collectionType, new HashMap<ByteBuffer, ColumnIdentifier>()); + this(clusteringType, collectionType, new HashMap<ByteBuffer, ColumnIdentifier>()); } private WithCollection(CompoundCType clusteringType, ColumnToCollectionType collectionType, Map<ByteBuffer, ColumnIdentifier> internedIds) { - this(clusteringType, makeCType(clusteringType, collectionType), collectionType, internedIds); + this(clusteringType, makeCType(clusteringType, UTF8Type.instance, collectionType), collectionType, internedIds); } private WithCollection(CompoundCType clusteringType, CompoundCType fullCType, ColumnToCollectionType collectionType, Map<ByteBuffer, ColumnIdentifier> internedIds) { - super(clusteringType, fullCType, internedIds); + super(clusteringType, UTF8Type.instance, fullCType, internedIds); this.collectionType = collectionType; }
