mirror of https://github.com/apache/cassandra
Revert "Revert "add Thrift get_multi_slice call""
This reverts commit 3f0702509b.
This commit is contained in:
parent
3f0702509b
commit
f45e4a556a
|
|
@ -55,7 +55,7 @@ namespace rb CassandraThrift
|
|||
# An effort should be made not to break forward-client-compatibility either
|
||||
# (e.g. one should avoid removing obsolete fields from the IDL), but no
|
||||
# guarantees in this respect are made by the Cassandra project.
|
||||
const string VERSION = "20.0.0"
|
||||
const string VERSION = "20.1.0"
|
||||
|
||||
|
||||
#
|
||||
|
|
@ -571,6 +571,35 @@ struct CfSplit {
|
|||
3: required i64 row_count
|
||||
}
|
||||
|
||||
/** The ColumnSlice is used to select a set of columns from inside a row.
|
||||
* If start or finish are unspecified they will default to the start-of
|
||||
* end-of value.
|
||||
* @param start. The start of the ColumnSlice inclusive
|
||||
* @param finish. The end of the ColumnSlice inclusive
|
||||
*/
|
||||
struct ColumnSlice {
|
||||
1: optional binary start,
|
||||
2: optional binary finish
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to perform multiple slices on a single row key in one rpc operation
|
||||
* @param key. The row key to be multi sliced
|
||||
* @param column_parent. The column family (super columns are unsupported)
|
||||
* @param column_slices. 0 to many ColumnSlice objects each will be used to select columns
|
||||
* @param reversed. Direction of slice
|
||||
* @param count. Maximum number of columns
|
||||
* @param consistency_level. Level to perform the operation at
|
||||
*/
|
||||
struct MultiSliceRequest {
|
||||
1: optional binary key,
|
||||
2: optional ColumnParent column_parent,
|
||||
3: optional list<ColumnSlice> column_slices,
|
||||
4: optional bool reversed=false,
|
||||
5: optional i32 count=1000,
|
||||
6: optional ConsistencyLevel consistency_level=ConsistencyLevel.ONE
|
||||
}
|
||||
|
||||
service Cassandra {
|
||||
# auth methods
|
||||
void login(1: required AuthenticationRequest auth_request) throws (1:AuthenticationException authnx, 2:AuthorizationException authzx),
|
||||
|
|
@ -749,7 +778,11 @@ service Cassandra {
|
|||
void truncate(1:required string cfname)
|
||||
throws (1: InvalidRequestException ire, 2: UnavailableException ue, 3: TimedOutException te),
|
||||
|
||||
|
||||
/**
|
||||
* Select multiple slices of a key in a single RPC operation
|
||||
*/
|
||||
list<ColumnOrSuperColumn> get_multi_slice(1:required MultiSliceRequest request)
|
||||
throws (1:InvalidRequestException ire, 2:UnavailableException ue, 3:TimedOutException te),
|
||||
|
||||
// Meta-APIs -- APIs to get information about the node or cluster,
|
||||
// rather than user data. The nodeprobe program provides usage examples.
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,551 @@
|
|||
/**
|
||||
* Autogenerated by Thrift Compiler (0.9.1)
|
||||
*
|
||||
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
||||
* @generated
|
||||
*/
|
||||
package org.apache.cassandra.thrift;
|
||||
/*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
import org.apache.thrift.scheme.IScheme;
|
||||
import org.apache.thrift.scheme.SchemeFactory;
|
||||
import org.apache.thrift.scheme.StandardScheme;
|
||||
|
||||
import org.apache.thrift.scheme.TupleScheme;
|
||||
import org.apache.thrift.protocol.TTupleProtocol;
|
||||
import org.apache.thrift.protocol.TProtocolException;
|
||||
import org.apache.thrift.EncodingUtils;
|
||||
import org.apache.thrift.TException;
|
||||
import org.apache.thrift.async.AsyncMethodCallback;
|
||||
import org.apache.thrift.server.AbstractNonblockingServer.*;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Collections;
|
||||
import java.util.BitSet;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The ColumnSlice is used to select a set of columns from inside a row.
|
||||
* If start or finish are unspecified they will default to the start-of
|
||||
* end-of value.
|
||||
* @param start. The start of the ColumnSlice inclusive
|
||||
* @param finish. The end of the ColumnSlice inclusive
|
||||
*/
|
||||
public class ColumnSlice implements org.apache.thrift.TBase<ColumnSlice, ColumnSlice._Fields>, java.io.Serializable, Cloneable, Comparable<ColumnSlice> {
|
||||
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("ColumnSlice");
|
||||
|
||||
private static final org.apache.thrift.protocol.TField START_FIELD_DESC = new org.apache.thrift.protocol.TField("start", org.apache.thrift.protocol.TType.STRING, (short)1);
|
||||
private static final org.apache.thrift.protocol.TField FINISH_FIELD_DESC = new org.apache.thrift.protocol.TField("finish", org.apache.thrift.protocol.TType.STRING, (short)2);
|
||||
|
||||
private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
|
||||
static {
|
||||
schemes.put(StandardScheme.class, new ColumnSliceStandardSchemeFactory());
|
||||
schemes.put(TupleScheme.class, new ColumnSliceTupleSchemeFactory());
|
||||
}
|
||||
|
||||
public ByteBuffer start; // optional
|
||||
public ByteBuffer finish; // optional
|
||||
|
||||
/** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
|
||||
public enum _Fields implements org.apache.thrift.TFieldIdEnum {
|
||||
START((short)1, "start"),
|
||||
FINISH((short)2, "finish");
|
||||
|
||||
private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
|
||||
|
||||
static {
|
||||
for (_Fields field : EnumSet.allOf(_Fields.class)) {
|
||||
byName.put(field.getFieldName(), field);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the _Fields constant that matches fieldId, or null if its not found.
|
||||
*/
|
||||
public static _Fields findByThriftId(int fieldId) {
|
||||
switch(fieldId) {
|
||||
case 1: // START
|
||||
return START;
|
||||
case 2: // FINISH
|
||||
return FINISH;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the _Fields constant that matches fieldId, throwing an exception
|
||||
* if it is not found.
|
||||
*/
|
||||
public static _Fields findByThriftIdOrThrow(int fieldId) {
|
||||
_Fields fields = findByThriftId(fieldId);
|
||||
if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
|
||||
return fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the _Fields constant that matches name, or null if its not found.
|
||||
*/
|
||||
public static _Fields findByName(String name) {
|
||||
return byName.get(name);
|
||||
}
|
||||
|
||||
private final short _thriftId;
|
||||
private final String _fieldName;
|
||||
|
||||
_Fields(short thriftId, String fieldName) {
|
||||
_thriftId = thriftId;
|
||||
_fieldName = fieldName;
|
||||
}
|
||||
|
||||
public short getThriftFieldId() {
|
||||
return _thriftId;
|
||||
}
|
||||
|
||||
public String getFieldName() {
|
||||
return _fieldName;
|
||||
}
|
||||
}
|
||||
|
||||
// isset id assignments
|
||||
private _Fields optionals[] = {_Fields.START,_Fields.FINISH};
|
||||
public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
|
||||
static {
|
||||
Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
|
||||
tmpMap.put(_Fields.START, new org.apache.thrift.meta_data.FieldMetaData("start", org.apache.thrift.TFieldRequirementType.OPTIONAL,
|
||||
new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING , true)));
|
||||
tmpMap.put(_Fields.FINISH, new org.apache.thrift.meta_data.FieldMetaData("finish", org.apache.thrift.TFieldRequirementType.OPTIONAL,
|
||||
new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING , true)));
|
||||
metaDataMap = Collections.unmodifiableMap(tmpMap);
|
||||
org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(ColumnSlice.class, metaDataMap);
|
||||
}
|
||||
|
||||
public ColumnSlice() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a deep copy on <i>other</i>.
|
||||
*/
|
||||
public ColumnSlice(ColumnSlice other) {
|
||||
if (other.isSetStart()) {
|
||||
this.start = org.apache.thrift.TBaseHelper.copyBinary(other.start);
|
||||
;
|
||||
}
|
||||
if (other.isSetFinish()) {
|
||||
this.finish = org.apache.thrift.TBaseHelper.copyBinary(other.finish);
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
public ColumnSlice deepCopy() {
|
||||
return new ColumnSlice(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
this.start = null;
|
||||
this.finish = null;
|
||||
}
|
||||
|
||||
public byte[] getStart() {
|
||||
setStart(org.apache.thrift.TBaseHelper.rightSize(start));
|
||||
return start == null ? null : start.array();
|
||||
}
|
||||
|
||||
public ByteBuffer bufferForStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
public ColumnSlice setStart(byte[] start) {
|
||||
setStart(start == null ? (ByteBuffer)null : ByteBuffer.wrap(start));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ColumnSlice setStart(ByteBuffer start) {
|
||||
this.start = start;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void unsetStart() {
|
||||
this.start = null;
|
||||
}
|
||||
|
||||
/** Returns true if field start is set (has been assigned a value) and false otherwise */
|
||||
public boolean isSetStart() {
|
||||
return this.start != null;
|
||||
}
|
||||
|
||||
public void setStartIsSet(boolean value) {
|
||||
if (!value) {
|
||||
this.start = null;
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] getFinish() {
|
||||
setFinish(org.apache.thrift.TBaseHelper.rightSize(finish));
|
||||
return finish == null ? null : finish.array();
|
||||
}
|
||||
|
||||
public ByteBuffer bufferForFinish() {
|
||||
return finish;
|
||||
}
|
||||
|
||||
public ColumnSlice setFinish(byte[] finish) {
|
||||
setFinish(finish == null ? (ByteBuffer)null : ByteBuffer.wrap(finish));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ColumnSlice setFinish(ByteBuffer finish) {
|
||||
this.finish = finish;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void unsetFinish() {
|
||||
this.finish = null;
|
||||
}
|
||||
|
||||
/** Returns true if field finish is set (has been assigned a value) and false otherwise */
|
||||
public boolean isSetFinish() {
|
||||
return this.finish != null;
|
||||
}
|
||||
|
||||
public void setFinishIsSet(boolean value) {
|
||||
if (!value) {
|
||||
this.finish = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setFieldValue(_Fields field, Object value) {
|
||||
switch (field) {
|
||||
case START:
|
||||
if (value == null) {
|
||||
unsetStart();
|
||||
} else {
|
||||
setStart((ByteBuffer)value);
|
||||
}
|
||||
break;
|
||||
|
||||
case FINISH:
|
||||
if (value == null) {
|
||||
unsetFinish();
|
||||
} else {
|
||||
setFinish((ByteBuffer)value);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public Object getFieldValue(_Fields field) {
|
||||
switch (field) {
|
||||
case START:
|
||||
return getStart();
|
||||
|
||||
case FINISH:
|
||||
return getFinish();
|
||||
|
||||
}
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
/** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
|
||||
public boolean isSet(_Fields field) {
|
||||
if (field == null) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
switch (field) {
|
||||
case START:
|
||||
return isSetStart();
|
||||
case FINISH:
|
||||
return isSetFinish();
|
||||
}
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object that) {
|
||||
if (that == null)
|
||||
return false;
|
||||
if (that instanceof ColumnSlice)
|
||||
return this.equals((ColumnSlice)that);
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean equals(ColumnSlice that) {
|
||||
if (that == null)
|
||||
return false;
|
||||
|
||||
boolean this_present_start = true && this.isSetStart();
|
||||
boolean that_present_start = true && that.isSetStart();
|
||||
if (this_present_start || that_present_start) {
|
||||
if (!(this_present_start && that_present_start))
|
||||
return false;
|
||||
if (!this.start.equals(that.start))
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean this_present_finish = true && this.isSetFinish();
|
||||
boolean that_present_finish = true && that.isSetFinish();
|
||||
if (this_present_finish || that_present_finish) {
|
||||
if (!(this_present_finish && that_present_finish))
|
||||
return false;
|
||||
if (!this.finish.equals(that.finish))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
HashCodeBuilder builder = new HashCodeBuilder();
|
||||
|
||||
boolean present_start = true && (isSetStart());
|
||||
builder.append(present_start);
|
||||
if (present_start)
|
||||
builder.append(start);
|
||||
|
||||
boolean present_finish = true && (isSetFinish());
|
||||
builder.append(present_finish);
|
||||
if (present_finish)
|
||||
builder.append(finish);
|
||||
|
||||
return builder.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ColumnSlice other) {
|
||||
if (!getClass().equals(other.getClass())) {
|
||||
return getClass().getName().compareTo(other.getClass().getName());
|
||||
}
|
||||
|
||||
int lastComparison = 0;
|
||||
|
||||
lastComparison = Boolean.valueOf(isSetStart()).compareTo(other.isSetStart());
|
||||
if (lastComparison != 0) {
|
||||
return lastComparison;
|
||||
}
|
||||
if (isSetStart()) {
|
||||
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.start, other.start);
|
||||
if (lastComparison != 0) {
|
||||
return lastComparison;
|
||||
}
|
||||
}
|
||||
lastComparison = Boolean.valueOf(isSetFinish()).compareTo(other.isSetFinish());
|
||||
if (lastComparison != 0) {
|
||||
return lastComparison;
|
||||
}
|
||||
if (isSetFinish()) {
|
||||
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.finish, other.finish);
|
||||
if (lastComparison != 0) {
|
||||
return lastComparison;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public _Fields fieldForId(int fieldId) {
|
||||
return _Fields.findByThriftId(fieldId);
|
||||
}
|
||||
|
||||
public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
|
||||
schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
|
||||
}
|
||||
|
||||
public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
|
||||
schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("ColumnSlice(");
|
||||
boolean first = true;
|
||||
|
||||
if (isSetStart()) {
|
||||
sb.append("start:");
|
||||
if (this.start == null) {
|
||||
sb.append("null");
|
||||
} else {
|
||||
org.apache.thrift.TBaseHelper.toString(this.start, sb);
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
if (isSetFinish()) {
|
||||
if (!first) sb.append(", ");
|
||||
sb.append("finish:");
|
||||
if (this.finish == null) {
|
||||
sb.append("null");
|
||||
} else {
|
||||
org.apache.thrift.TBaseHelper.toString(this.finish, sb);
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public void validate() throws org.apache.thrift.TException {
|
||||
// check for required fields
|
||||
// check for sub-struct validity
|
||||
}
|
||||
|
||||
private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
|
||||
try {
|
||||
write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
|
||||
} catch (org.apache.thrift.TException te) {
|
||||
throw new java.io.IOException(te);
|
||||
}
|
||||
}
|
||||
|
||||
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
|
||||
try {
|
||||
read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
|
||||
} catch (org.apache.thrift.TException te) {
|
||||
throw new java.io.IOException(te);
|
||||
}
|
||||
}
|
||||
|
||||
private static class ColumnSliceStandardSchemeFactory implements SchemeFactory {
|
||||
public ColumnSliceStandardScheme getScheme() {
|
||||
return new ColumnSliceStandardScheme();
|
||||
}
|
||||
}
|
||||
|
||||
private static class ColumnSliceStandardScheme extends StandardScheme<ColumnSlice> {
|
||||
|
||||
public void read(org.apache.thrift.protocol.TProtocol iprot, ColumnSlice struct) throws org.apache.thrift.TException {
|
||||
org.apache.thrift.protocol.TField schemeField;
|
||||
iprot.readStructBegin();
|
||||
while (true)
|
||||
{
|
||||
schemeField = iprot.readFieldBegin();
|
||||
if (schemeField.type == org.apache.thrift.protocol.TType.STOP) {
|
||||
break;
|
||||
}
|
||||
switch (schemeField.id) {
|
||||
case 1: // START
|
||||
if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
|
||||
struct.start = iprot.readBinary();
|
||||
struct.setStartIsSet(true);
|
||||
} else {
|
||||
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
|
||||
}
|
||||
break;
|
||||
case 2: // FINISH
|
||||
if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
|
||||
struct.finish = iprot.readBinary();
|
||||
struct.setFinishIsSet(true);
|
||||
} else {
|
||||
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
|
||||
}
|
||||
iprot.readFieldEnd();
|
||||
}
|
||||
iprot.readStructEnd();
|
||||
|
||||
// check for required fields of primitive type, which can't be checked in the validate method
|
||||
struct.validate();
|
||||
}
|
||||
|
||||
public void write(org.apache.thrift.protocol.TProtocol oprot, ColumnSlice struct) throws org.apache.thrift.TException {
|
||||
struct.validate();
|
||||
|
||||
oprot.writeStructBegin(STRUCT_DESC);
|
||||
if (struct.start != null) {
|
||||
if (struct.isSetStart()) {
|
||||
oprot.writeFieldBegin(START_FIELD_DESC);
|
||||
oprot.writeBinary(struct.start);
|
||||
oprot.writeFieldEnd();
|
||||
}
|
||||
}
|
||||
if (struct.finish != null) {
|
||||
if (struct.isSetFinish()) {
|
||||
oprot.writeFieldBegin(FINISH_FIELD_DESC);
|
||||
oprot.writeBinary(struct.finish);
|
||||
oprot.writeFieldEnd();
|
||||
}
|
||||
}
|
||||
oprot.writeFieldStop();
|
||||
oprot.writeStructEnd();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class ColumnSliceTupleSchemeFactory implements SchemeFactory {
|
||||
public ColumnSliceTupleScheme getScheme() {
|
||||
return new ColumnSliceTupleScheme();
|
||||
}
|
||||
}
|
||||
|
||||
private static class ColumnSliceTupleScheme extends TupleScheme<ColumnSlice> {
|
||||
|
||||
@Override
|
||||
public void write(org.apache.thrift.protocol.TProtocol prot, ColumnSlice struct) throws org.apache.thrift.TException {
|
||||
TTupleProtocol oprot = (TTupleProtocol) prot;
|
||||
BitSet optionals = new BitSet();
|
||||
if (struct.isSetStart()) {
|
||||
optionals.set(0);
|
||||
}
|
||||
if (struct.isSetFinish()) {
|
||||
optionals.set(1);
|
||||
}
|
||||
oprot.writeBitSet(optionals, 2);
|
||||
if (struct.isSetStart()) {
|
||||
oprot.writeBinary(struct.start);
|
||||
}
|
||||
if (struct.isSetFinish()) {
|
||||
oprot.writeBinary(struct.finish);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(org.apache.thrift.protocol.TProtocol prot, ColumnSlice struct) throws org.apache.thrift.TException {
|
||||
TTupleProtocol iprot = (TTupleProtocol) prot;
|
||||
BitSet incoming = iprot.readBitSet(2);
|
||||
if (incoming.get(0)) {
|
||||
struct.start = iprot.readBinary();
|
||||
struct.setStartIsSet(true);
|
||||
}
|
||||
if (incoming.get(1)) {
|
||||
struct.finish = iprot.readBinary();
|
||||
struct.setFinishIsSet(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -56,6 +56,6 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
public class cassandraConstants {
|
||||
|
||||
public static final String VERSION = "20.0.0";
|
||||
public static final String VERSION = "20.1.0";
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1980,6 +1980,78 @@ public class CassandraServer implements Cassandra.Iface
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ColumnOrSuperColumn> get_multi_slice(MultiSliceRequest request)
|
||||
throws InvalidRequestException, UnavailableException, TimedOutException
|
||||
{
|
||||
if (startSessionIfRequested())
|
||||
{
|
||||
Map<String, String> traceParameters = ImmutableMap.of("key", ByteBufferUtil.bytesToHex(request.key),
|
||||
"column_parent", request.column_parent.toString(),
|
||||
"consistency_level", request.consistency_level.name(),
|
||||
"count", String.valueOf(request.count),
|
||||
"column_slices", request.column_slices.toString());
|
||||
Tracing.instance.begin("get_multi_slice", traceParameters);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.debug("get_multi_slice");
|
||||
}
|
||||
try
|
||||
{
|
||||
ClientState cState = state();
|
||||
String keyspace = cState.getKeyspace();
|
||||
state().hasColumnFamilyAccess(keyspace, request.getColumn_parent().column_family, Permission.SELECT);
|
||||
CFMetaData metadata = ThriftValidation.validateColumnFamily(keyspace, request.getColumn_parent().column_family);
|
||||
if (metadata.cfType == ColumnFamilyType.Super)
|
||||
throw new org.apache.cassandra.exceptions.InvalidRequestException("get_multi_slice does not support super columns");
|
||||
ThriftValidation.validateColumnParent(metadata, request.getColumn_parent());
|
||||
org.apache.cassandra.db.ConsistencyLevel consistencyLevel = ThriftConversion.fromThrift(request.getConsistency_level());
|
||||
consistencyLevel.validateForRead(keyspace);
|
||||
List<ReadCommand> commands = new ArrayList<>(1);
|
||||
ColumnSlice[] slices = new ColumnSlice[request.getColumn_slices().size()];
|
||||
for (int i = 0 ; i < request.getColumn_slices().size() ; i++)
|
||||
{
|
||||
fixOptionalSliceParameters(request.getColumn_slices().get(i));
|
||||
Composite start = metadata.comparator.fromByteBuffer(request.getColumn_slices().get(i).start);
|
||||
Composite finish = metadata.comparator.fromByteBuffer(request.getColumn_slices().get(i).finish);
|
||||
if (!start.isEmpty() && !finish.isEmpty())
|
||||
{
|
||||
int compare = metadata.comparator.compare(start, finish);
|
||||
if (!request.reversed && compare > 0)
|
||||
throw new InvalidRequestException(String.format("Column slice at index %d had start greater than finish", i));
|
||||
else if (request.reversed && compare < 0)
|
||||
throw new InvalidRequestException(String.format("Reversed column slice at index %d had start less than finish", i));
|
||||
}
|
||||
slices[i] = new ColumnSlice(start, finish);
|
||||
}
|
||||
ColumnSlice[] deoverlapped = ColumnSlice.deoverlapSlices(slices, request.reversed ? metadata.comparator.reverseComparator() : metadata.comparator);
|
||||
SliceQueryFilter filter = new SliceQueryFilter(deoverlapped, request.reversed, request.count);
|
||||
ThriftValidation.validateKey(metadata, request.key);
|
||||
commands.add(ReadCommand.create(keyspace, request.key, request.column_parent.getColumn_family(), System.currentTimeMillis(), filter));
|
||||
return getSlice(commands, request.column_parent.isSetSuper_column(), consistencyLevel, cState).entrySet().iterator().next().getValue();
|
||||
}
|
||||
catch (RequestValidationException e)
|
||||
{
|
||||
throw ThriftConversion.toThrift(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Tracing.instance.stopSession();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the to start-of end-of value of "" for start and finish.
|
||||
* @param columnSlice
|
||||
*/
|
||||
private static void fixOptionalSliceParameters(org.apache.cassandra.thrift.ColumnSlice columnSlice) {
|
||||
if (!columnSlice.isSetStart())
|
||||
columnSlice.setStart(new byte[0]);
|
||||
if (!columnSlice.isSetFinish())
|
||||
columnSlice.setFinish(new byte[0]);
|
||||
}
|
||||
|
||||
/*
|
||||
* No-op since 3.0.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -43,6 +43,11 @@ import java.util.concurrent.TimeUnit;
|
|||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import org.apache.cassandra.db.index.PerRowSecondaryIndexTest;
|
||||
import org.apache.cassandra.io.sstable.*;
|
||||
import org.apache.cassandra.io.sstable.format.SSTableReader;
|
||||
import org.apache.cassandra.io.sstable.format.SSTableWriter;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.BeforeClass;
|
||||
|
|
@ -52,12 +57,7 @@ import org.junit.runner.RunWith;
|
|||
import org.apache.cassandra.OrderedJUnit4ClassRunner;
|
||||
import org.apache.cassandra.SchemaLoader;
|
||||
import org.apache.cassandra.Util;
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.ColumnDefinition;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.IndexType;
|
||||
import org.apache.cassandra.config.KSMetaData;
|
||||
import org.apache.cassandra.config.Schema;
|
||||
import org.apache.cassandra.config.*;
|
||||
import org.apache.cassandra.cql3.Operator;
|
||||
import org.apache.cassandra.db.columniterator.IdentityQueryFilter;
|
||||
import org.apache.cassandra.db.composites.CellName;
|
||||
|
|
@ -69,7 +69,6 @@ import org.apache.cassandra.db.filter.IDiskAtomFilter;
|
|||
import org.apache.cassandra.db.filter.NamesQueryFilter;
|
||||
import org.apache.cassandra.db.filter.QueryFilter;
|
||||
import org.apache.cassandra.db.filter.SliceQueryFilter;
|
||||
import org.apache.cassandra.db.index.PerRowSecondaryIndexTest;
|
||||
import org.apache.cassandra.db.index.SecondaryIndex;
|
||||
import org.apache.cassandra.db.marshal.IntegerType;
|
||||
import org.apache.cassandra.db.marshal.LexicalUUIDType;
|
||||
|
|
@ -81,12 +80,6 @@ import org.apache.cassandra.dht.IPartitioner;
|
|||
import org.apache.cassandra.dht.IncludingExcludingBounds;
|
||||
import org.apache.cassandra.dht.Range;
|
||||
import org.apache.cassandra.exceptions.ConfigurationException;
|
||||
import org.apache.cassandra.io.sstable.Component;
|
||||
import org.apache.cassandra.io.sstable.Descriptor;
|
||||
import org.apache.cassandra.io.sstable.SSTableDeletingTask;
|
||||
import org.apache.cassandra.io.sstable.SSTableSimpleWriter;
|
||||
import org.apache.cassandra.io.sstable.format.SSTableReader;
|
||||
import org.apache.cassandra.io.sstable.format.SSTableWriter;
|
||||
import org.apache.cassandra.io.sstable.metadata.MetadataCollector;
|
||||
import org.apache.cassandra.io.util.FileUtils;
|
||||
import org.apache.cassandra.locator.SimpleStrategy;
|
||||
|
|
@ -100,6 +93,7 @@ import org.apache.cassandra.utils.ByteBufferUtil;
|
|||
import org.apache.cassandra.utils.FBUtilities;
|
||||
import org.apache.cassandra.utils.Pair;
|
||||
import org.apache.cassandra.utils.WrappedRunnable;
|
||||
import org.apache.thrift.TException;
|
||||
|
||||
import static org.apache.cassandra.Util.cellname;
|
||||
import static org.apache.cassandra.Util.column;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,186 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.cassandra.thrift;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.apache.cassandra.SchemaLoader;
|
||||
import org.apache.cassandra.config.KSMetaData;
|
||||
import org.apache.cassandra.exceptions.ConfigurationException;
|
||||
import org.apache.cassandra.locator.SimpleStrategy;
|
||||
import org.apache.cassandra.service.EmbeddedCassandraService;
|
||||
import org.apache.cassandra.utils.ByteBufferUtil;
|
||||
import org.apache.thrift.TException;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MultiSliceTest
|
||||
{
|
||||
private static CassandraServer server;
|
||||
public static final String KEYSPACE1 = "MultiSliceTest";
|
||||
public static final String CF_STANDARD = "Standard1";
|
||||
|
||||
@BeforeClass
|
||||
public static void defineSchema() throws ConfigurationException, IOException, TException
|
||||
{
|
||||
SchemaLoader.prepareServer();
|
||||
new EmbeddedCassandraService().start();
|
||||
ThriftSessionManager.instance.setCurrentSocket(new InetSocketAddress(9160));
|
||||
SchemaLoader.createKeyspace(KEYSPACE1,
|
||||
SimpleStrategy.class,
|
||||
KSMetaData.optsWithRF(1),
|
||||
SchemaLoader.standardCFMD(KEYSPACE1, CF_STANDARD));
|
||||
server = new CassandraServer();
|
||||
server.set_keyspace(KEYSPACE1);
|
||||
}
|
||||
|
||||
private static MultiSliceRequest makeMultiSliceRequest(ByteBuffer key)
|
||||
{
|
||||
ColumnParent cp = new ColumnParent("Standard1");
|
||||
MultiSliceRequest req = new MultiSliceRequest();
|
||||
req.setKey(key);
|
||||
req.setCount(1000);
|
||||
req.reversed = false;
|
||||
req.setColumn_parent(cp);
|
||||
return req;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_multi_slice_optional_column_slice() throws TException
|
||||
{
|
||||
ColumnParent cp = new ColumnParent("Standard1");
|
||||
ByteBuffer key = ByteBuffer.wrap("multi_slice".getBytes());
|
||||
List<String> expected = new ArrayList<String>();
|
||||
for (char a = 'a'; a <= 'z'; a++)
|
||||
expected.add(a + "");
|
||||
|
||||
addTheAlphabetToRow(key, cp);
|
||||
MultiSliceRequest req = makeMultiSliceRequest(key);
|
||||
req.setColumn_slices(new ArrayList<ColumnSlice>());
|
||||
req.getColumn_slices().add(new ColumnSlice());
|
||||
List<ColumnOrSuperColumn> list = server.get_multi_slice(req);
|
||||
assertColumnNameMatches(expected, list);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_multi_slice() throws TException
|
||||
{
|
||||
ColumnParent cp = new ColumnParent("Standard1");
|
||||
ByteBuffer key = ByteBuffer.wrap("multi_slice_two_slice".getBytes());
|
||||
addTheAlphabetToRow(key, cp);
|
||||
MultiSliceRequest req = makeMultiSliceRequest(key);
|
||||
req.setColumn_slices(Arrays.asList(columnSliceFrom("a", "e"), columnSliceFrom("i", "n")));
|
||||
assertColumnNameMatches(Arrays.asList("a", "b", "c", "d", "e", "i", "j", "k" , "l", "m" , "n"), server.get_multi_slice(req));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_with_overlap() throws TException
|
||||
{
|
||||
ColumnParent cp = new ColumnParent("Standard1");
|
||||
ByteBuffer key = ByteBuffer.wrap("overlap".getBytes());
|
||||
addTheAlphabetToRow(key, cp);
|
||||
MultiSliceRequest req = makeMultiSliceRequest(key);
|
||||
req.setColumn_slices(Arrays.asList(columnSliceFrom("a", "e"), columnSliceFrom("d", "g")));
|
||||
assertColumnNameMatches(Arrays.asList("a", "b", "c", "d", "e", "f", "g"), server.get_multi_slice(req));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_with_overlap_reversed() throws TException
|
||||
{
|
||||
ColumnParent cp = new ColumnParent("Standard1");
|
||||
ByteBuffer key = ByteBuffer.wrap("overlap_reversed".getBytes());
|
||||
addTheAlphabetToRow(key, cp);
|
||||
MultiSliceRequest req = makeMultiSliceRequest(key);
|
||||
req.reversed = true;
|
||||
req.setColumn_slices(Arrays.asList(columnSliceFrom("e", "a"), columnSliceFrom("g", "d")));
|
||||
assertColumnNameMatches(Arrays.asList("g", "f", "e", "d", "c", "b", "a"), server.get_multi_slice(req));
|
||||
}
|
||||
|
||||
@Test(expected=InvalidRequestException.class)
|
||||
public void test_that_column_slice_is_proper() throws TException
|
||||
{
|
||||
ByteBuffer key = ByteBuffer.wrap("overlap".getBytes());
|
||||
MultiSliceRequest req = makeMultiSliceRequest(key);
|
||||
req.reversed = true;
|
||||
req.setColumn_slices(Arrays.asList(columnSliceFrom("a", "e"), columnSliceFrom("g", "d")));
|
||||
assertColumnNameMatches(Arrays.asList("a", "b", "c", "d", "e", "f", "g"), server.get_multi_slice(req));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_with_overlap_reversed_with_count() throws TException
|
||||
{
|
||||
ColumnParent cp = new ColumnParent("Standard1");
|
||||
ByteBuffer key = ByteBuffer.wrap("overlap_reversed_count".getBytes());
|
||||
addTheAlphabetToRow(key, cp);
|
||||
MultiSliceRequest req = makeMultiSliceRequest(key);
|
||||
req.setCount(6);
|
||||
req.reversed = true;
|
||||
req.setColumn_slices(Arrays.asList(columnSliceFrom("e", "a"), columnSliceFrom("g", "d")));
|
||||
assertColumnNameMatches(Arrays.asList("g", "f", "e", "d", "c", "b"), server.get_multi_slice(req));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_with_overlap_with_count() throws TException
|
||||
{
|
||||
ColumnParent cp = new ColumnParent("Standard1");
|
||||
ByteBuffer key = ByteBuffer.wrap("overlap_reversed_count".getBytes());
|
||||
addTheAlphabetToRow(key, cp);
|
||||
MultiSliceRequest req = makeMultiSliceRequest(key);
|
||||
req.setCount(6);
|
||||
req.setColumn_slices(Arrays.asList(columnSliceFrom("a", "e"), columnSliceFrom("d", "g"), columnSliceFrom("d", "g")));
|
||||
assertColumnNameMatches(Arrays.asList("a", "b", "c", "d", "e", "f"), server.get_multi_slice(req));
|
||||
}
|
||||
|
||||
private static void addTheAlphabetToRow(ByteBuffer key, ColumnParent parent)
|
||||
throws InvalidRequestException, UnavailableException, TimedOutException
|
||||
{
|
||||
for (char a = 'a'; a <= 'z'; a++) {
|
||||
Column c1 = new Column();
|
||||
c1.setName(ByteBufferUtil.bytes(String.valueOf(a)));
|
||||
c1.setValue(new byte [0]);
|
||||
c1.setTimestamp(System.nanoTime());
|
||||
server.insert(key, parent, c1, ConsistencyLevel.ONE);
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertColumnNameMatches(List<String> expected , List<ColumnOrSuperColumn> actual)
|
||||
{
|
||||
Assert.assertEquals(actual+" "+expected +" did not have same number of elements", actual.size(), expected.size());
|
||||
for (int i = 0 ; i< expected.size() ; i++)
|
||||
{
|
||||
Assert.assertEquals(actual.get(i) +" did not equal "+ expected.get(i),
|
||||
expected.get(i), new String(actual.get(i).getColumn().getName()));
|
||||
}
|
||||
}
|
||||
|
||||
private ColumnSlice columnSliceFrom(String startInclusive, String endInclusive)
|
||||
{
|
||||
ColumnSlice cs = new ColumnSlice();
|
||||
cs.setStart(ByteBufferUtil.bytes(startInclusive));
|
||||
cs.setFinish(ByteBufferUtil.bytes(endInclusive));
|
||||
return cs;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue