mirror of https://github.com/apache/cassandra
fix MultiElementType pack/unpack accessor api
This commit is contained in:
parent
d3deef36d3
commit
94c2ec3c96
|
|
@ -33,6 +33,7 @@ import org.apache.cassandra.cql3.functions.Function;
|
|||
import org.apache.cassandra.cql3.terms.Term;
|
||||
import org.apache.cassandra.cql3.terms.Terms;
|
||||
import org.apache.cassandra.db.filter.RowFilter;
|
||||
import org.apache.cassandra.db.marshal.ByteBufferAccessor;
|
||||
import org.apache.cassandra.db.marshal.ListType;
|
||||
import org.apache.cassandra.index.Index;
|
||||
import org.apache.cassandra.index.IndexRegistry;
|
||||
|
|
@ -402,7 +403,7 @@ public final class SimpleRestriction implements SingleRestriction
|
|||
|
||||
private static ByteBuffer multiInputOperatorValues(ColumnMetadata column, List<ByteBuffer> values)
|
||||
{
|
||||
return ListType.getInstance(column.type, false).pack(values);
|
||||
return ListType.getInstance(column.type, false).pack(values, ByteBufferAccessor.instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import com.google.common.collect.BoundType;
|
|||
import com.google.common.collect.Range;
|
||||
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
import org.apache.cassandra.db.marshal.ByteBufferAccessor;
|
||||
import org.apache.cassandra.db.marshal.ListType;
|
||||
import org.apache.cassandra.db.marshal.LongType;
|
||||
import org.apache.cassandra.db.marshal.UserType;
|
||||
|
|
@ -384,7 +385,7 @@ abstract class ColumnTimestamps
|
|||
List<ByteBuffer> buffers = new ArrayList<>(timestamps.size());
|
||||
timestamps.forEach(timestamp -> buffers.add(type.toByteBuffer(timestamp)));
|
||||
|
||||
return LONG_LIST_TYPE.pack(buffers);
|
||||
return LONG_LIST_TYPE.pack(buffers, ByteBufferAccessor.instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import org.apache.cassandra.cql3.terms.Lists;
|
|||
import org.apache.cassandra.db.TypeSizes;
|
||||
import org.apache.cassandra.db.filter.ColumnFilter.Builder;
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
import org.apache.cassandra.db.marshal.ByteBufferAccessor;
|
||||
import org.apache.cassandra.db.marshal.ListType;
|
||||
import org.apache.cassandra.io.util.DataInputPlus;
|
||||
import org.apache.cassandra.io.util.DataOutputPlus;
|
||||
|
|
@ -101,7 +102,7 @@ final class ListSelector extends Selector
|
|||
{
|
||||
buffers.add(elements.get(i).getOutput(protocolVersion));
|
||||
}
|
||||
return type.pack(buffers);
|
||||
return type.pack(buffers, ByteBufferAccessor.instance);
|
||||
}
|
||||
|
||||
public void reset()
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import org.apache.cassandra.cql3.terms.Sets;
|
|||
import org.apache.cassandra.db.TypeSizes;
|
||||
import org.apache.cassandra.db.filter.ColumnFilter.Builder;
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
import org.apache.cassandra.db.marshal.ByteBufferAccessor;
|
||||
import org.apache.cassandra.db.marshal.SetType;
|
||||
import org.apache.cassandra.io.util.DataInputPlus;
|
||||
import org.apache.cassandra.io.util.DataOutputPlus;
|
||||
|
|
@ -103,7 +104,7 @@ final class SetSelector extends Selector
|
|||
{
|
||||
buffers.add(elements.get(i).getOutput(protocolVersion));
|
||||
}
|
||||
return type.pack(new ArrayList<>(buffers));
|
||||
return type.pack(new ArrayList<>(buffers), ByteBufferAccessor.instance);
|
||||
}
|
||||
|
||||
public void reset()
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import org.apache.cassandra.cql3.terms.Tuples;
|
|||
import org.apache.cassandra.db.TypeSizes;
|
||||
import org.apache.cassandra.db.filter.ColumnFilter.Builder;
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
import org.apache.cassandra.db.marshal.ByteBufferAccessor;
|
||||
import org.apache.cassandra.db.marshal.TupleType;
|
||||
import org.apache.cassandra.exceptions.InvalidRequestException;
|
||||
import org.apache.cassandra.io.util.DataInputPlus;
|
||||
|
|
@ -102,7 +103,7 @@ final class TupleSelector extends Selector
|
|||
{
|
||||
buffers.add(elements.get(i).getOutput(protocolVersion));
|
||||
}
|
||||
return type.pack(buffers);
|
||||
return type.pack(buffers, ByteBufferAccessor.instance);
|
||||
}
|
||||
|
||||
public void reset()
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import java.util.Map.Entry;
|
|||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
import org.apache.cassandra.db.marshal.ByteBufferAccessor;
|
||||
import org.apache.cassandra.schema.ColumnMetadata;
|
||||
import org.apache.cassandra.schema.TableMetadata;
|
||||
import org.apache.cassandra.cql3.ColumnSpecification;
|
||||
|
|
@ -197,7 +198,7 @@ final class UserTypeSelector extends Selector
|
|||
Selector selector = fields.get(userType.fieldName(i));
|
||||
buffers.add(selector == null ? null : selector.getOutput(protocolVersion));
|
||||
}
|
||||
return type.pack(buffers);
|
||||
return type.pack(buffers, ByteBufferAccessor.instance);
|
||||
}
|
||||
|
||||
public void reset()
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import org.apache.cassandra.cql3.terms.Lists;
|
|||
import org.apache.cassandra.cql3.QueryOptions;
|
||||
import org.apache.cassandra.db.filter.ColumnFilter;
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
import org.apache.cassandra.db.marshal.ByteBufferAccessor;
|
||||
import org.apache.cassandra.db.marshal.VectorType;
|
||||
import org.apache.cassandra.exceptions.InvalidRequestException;
|
||||
import org.apache.cassandra.io.util.DataInputPlus;
|
||||
|
|
@ -126,7 +127,7 @@ public class VectorSelector extends Selector
|
|||
for (int i = 0, m = elements.size(); i < m; i++)
|
||||
buffers.add(elements.get(i).getOutput(protocolVersion));
|
||||
|
||||
return type.pack(buffers);
|
||||
return type.pack(buffers, ByteBufferAccessor.instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ public class RowFilter implements Iterable<RowFilter.Expression>
|
|||
private static final Logger logger = LoggerFactory.getLogger(RowFilter.class);
|
||||
|
||||
public static final Serializer serializer = new Serializer();
|
||||
private static final RowFilter NONE = new RowFilter(Collections.emptyList(), false);
|
||||
public static final RowFilter NONE = new RowFilter(Collections.emptyList(), false);
|
||||
|
||||
protected final List<Expression> expressions;
|
||||
|
||||
|
|
|
|||
|
|
@ -350,15 +350,15 @@ public abstract class CollectionType<T> extends MultiElementType<T>
|
|||
}
|
||||
|
||||
@Override
|
||||
public ByteBuffer pack(List<ByteBuffer> elements)
|
||||
public <V> V pack(List<V> elements, ValueAccessor<V> accessor)
|
||||
{
|
||||
return getSerializer().pack(elements);
|
||||
return getSerializer().pack(elements, accessor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ByteBuffer> unpack(ByteBuffer input)
|
||||
public <V> List<V> unpack(V value, ValueAccessor<V> accessor)
|
||||
{
|
||||
return getSerializer().unpack(input);
|
||||
return getSerializer().unpack(value, accessor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -44,7 +44,28 @@ public abstract class MultiElementType<T> extends AbstractType<T>
|
|||
* @param elements the serialized values of the elements
|
||||
* @return the serialized representation of the value composed of the specified elements.
|
||||
*/
|
||||
public abstract ByteBuffer pack(List<ByteBuffer> elements);
|
||||
public abstract <V> V pack(List<V> elements, ValueAccessor<V> accessor);
|
||||
|
||||
/**
|
||||
* Returns the serialized representation of the value composed of the specified elements.
|
||||
*
|
||||
* @param elements the serialized values of the elements
|
||||
* @return the serialized representation of the value composed of the specified elements.
|
||||
*/
|
||||
public ByteBuffer pack(List<ByteBuffer> elements)
|
||||
{
|
||||
return pack(elements, ByteBufferAccessor.instance);
|
||||
}
|
||||
|
||||
public final ByteBuffer packBuffer(List<ByteBuffer> elements)
|
||||
{
|
||||
return pack(elements, ByteBufferAccessor.instance);
|
||||
}
|
||||
|
||||
public final byte[] packArray(List<byte[]> elements)
|
||||
{
|
||||
return pack(elements, ByteArrayAccessor.instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the serialized representation of the elements composing the specified value.
|
||||
|
|
@ -52,7 +73,23 @@ public abstract class MultiElementType<T> extends AbstractType<T>
|
|||
* @param value a serialized value of this type
|
||||
* @return the serialized representation of the elements composing the specified value.
|
||||
*/
|
||||
public abstract List<ByteBuffer> unpack(ByteBuffer value);
|
||||
/**
|
||||
* Returns the serialized representation of the elements composing the specified value.
|
||||
*
|
||||
* @param value a serialized value of this type
|
||||
* @return the serialized representation of the elements composing the specified value.
|
||||
*/
|
||||
public abstract <V> List<V> unpack(V value, ValueAccessor<V> accessor);
|
||||
|
||||
public final List<byte[]> unpack(byte[] value)
|
||||
{
|
||||
return unpack(value, ByteArrayAccessor.instance);
|
||||
}
|
||||
|
||||
public final List<ByteBuffer> unpack(ByteBuffer value)
|
||||
{
|
||||
return unpack(value, ByteBufferAccessor.instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this type supports bind markers for its elements when the type value is provided through a literal.
|
||||
|
|
|
|||
|
|
@ -295,11 +295,6 @@ public class TupleType extends MultiElementType<ByteBuffer>
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<ByteBuffer> unpack(ByteBuffer value)
|
||||
{
|
||||
return unpack(value, ByteBufferAccessor.instance);
|
||||
}
|
||||
|
||||
public <V> List<V> unpack(V value, ValueAccessor<V> accessor)
|
||||
{
|
||||
int numberOfElements = size();
|
||||
|
|
@ -381,14 +376,14 @@ public class TupleType extends MultiElementType<ByteBuffer>
|
|||
}
|
||||
|
||||
@Override
|
||||
public ByteBuffer pack(List<ByteBuffer> components)
|
||||
public <V> V pack(List<V> elements, ValueAccessor<V> accessor)
|
||||
{
|
||||
return pack(ByteBufferAccessor.instance, components);
|
||||
return pack(accessor, elements);
|
||||
}
|
||||
|
||||
public ByteBuffer pack(ByteBuffer... components)
|
||||
{
|
||||
return pack(Arrays.asList(components));
|
||||
return pack(Arrays.asList(components), ByteBufferAccessor.instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -472,7 +467,7 @@ public class TupleType extends MultiElementType<ByteBuffer>
|
|||
fields.add(type.fromString(fieldString));
|
||||
}
|
||||
}
|
||||
return pack(fields);
|
||||
return pack(fields, ByteBufferAccessor.instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -613,7 +608,7 @@ public class TupleType extends MultiElementType<ByteBuffer>
|
|||
for (AbstractType<?> type : types)
|
||||
buffers.add(type.getMaskedValue());
|
||||
|
||||
return serializer.serialize(pack(buffers));
|
||||
return serializer.serialize(pack(buffers, ByteBufferAccessor.instance));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -215,7 +215,7 @@ public class UserType extends TupleType implements SchemaElement
|
|||
while (components.size() < size())
|
||||
components.add(null);
|
||||
|
||||
return pack(components);
|
||||
return pack(components, ByteBufferAccessor.instance);
|
||||
}
|
||||
|
||||
public <V> void validateCell(Cell<V> cell) throws MarshalException
|
||||
|
|
|
|||
|
|
@ -137,12 +137,6 @@ public final class VectorType<T> extends MultiElementType<List<T>>
|
|||
return serializer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ByteBuffer> unpack(ByteBuffer buffer)
|
||||
{
|
||||
return unpack(buffer, ByteBufferAccessor.instance);
|
||||
}
|
||||
|
||||
public <V> List<V> unpack(V buffer, ValueAccessor<V> accessor)
|
||||
{
|
||||
return getSerializer().unpack(buffer, accessor);
|
||||
|
|
@ -193,11 +187,6 @@ public final class VectorType<T> extends MultiElementType<List<T>>
|
|||
return buffer;
|
||||
}
|
||||
|
||||
public ByteBuffer pack(List<ByteBuffer> elements)
|
||||
{
|
||||
return pack(elements, ByteBufferAccessor.instance);
|
||||
}
|
||||
|
||||
public <V> V pack(List<V> elements, ValueAccessor<V> accessor)
|
||||
{
|
||||
return getSerializer().pack(elements, accessor);
|
||||
|
|
|
|||
|
|
@ -859,12 +859,12 @@ public class AccordKeyspace
|
|||
|
||||
private static ByteBuffer serializeKey(PartitionKey key)
|
||||
{
|
||||
return TupleType.pack(ByteBufferAccessor.instance, Arrays.asList(UUIDSerializer.instance.serialize(key.table().asUUID()), key.partitionKey().getKey()));
|
||||
return KEY_TYPE.pack(UUIDSerializer.instance.serialize(key.table().asUUID()), key.partitionKey().getKey());
|
||||
}
|
||||
|
||||
private static ByteBuffer serializeTimestamp(Timestamp timestamp)
|
||||
{
|
||||
return TupleType.pack(ByteBufferAccessor.instance, Arrays.asList(bytes(timestamp.msb), bytes(timestamp.lsb), bytes(timestamp.node.id)));
|
||||
return TIMESTAMP_TYPE.pack(bytes(timestamp.msb), bytes(timestamp.lsb), bytes(timestamp.node.id));
|
||||
}
|
||||
|
||||
public interface TimestampFactory<T extends Timestamp>
|
||||
|
|
|
|||
Loading…
Reference in New Issue