From 3249155080aa4a205fff2a141d9e5f9ab018d9f1 Mon Sep 17 00:00:00 2001 From: tedyu Date: Mon, 27 Feb 2017 14:41:07 -0800 Subject: [PATCH] HBASE-17689 Add support for table.existsAll in thrift2 THBaseservice (Yechao Chen) --- .../thrift2/ThriftHBaseServiceHandler.java | 18 + .../thrift2/generated/THBaseService.java | 1148 +++++++++++++++++ .../apache/hadoop/hbase/thrift2/hbase.thrift | 15 + .../TestThriftHBaseServiceHandler.java | 28 + 4 files changed, 1209 insertions(+) diff --git a/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftHBaseServiceHandler.java b/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftHBaseServiceHandler.java index 0165e79d379..b508a1f4b63 100644 --- a/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftHBaseServiceHandler.java +++ b/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftHBaseServiceHandler.java @@ -39,6 +39,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.nio.ByteBuffer; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; @@ -250,6 +251,23 @@ public class ThriftHBaseServiceHandler implements THBaseService.Iface { } } + @Override + public List existsAll(ByteBuffer table, List gets) throws TIOError, TException { + Table htable = getTable(table); + try { + boolean[] exists = htable.existsAll(getsFromThrift(gets)); + List result = new ArrayList<>(exists.length); + for (boolean exist : exists) { + result.add(exist); + } + return result; + } catch (IOException e) { + throw getTIOError(e); + } finally { + closeTable(htable); + } + } + @Override public TResult get(ByteBuffer table, TGet get) throws TIOError, TException { Table htable = getTable(table); diff --git a/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/generated/THBaseService.java b/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/generated/THBaseService.java index 2dc7fc75030..75ca93d68c2 100644 --- a/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/generated/THBaseService.java +++ b/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/generated/THBaseService.java @@ -50,6 +50,18 @@ public class THBaseService { */ public boolean exists(ByteBuffer table, TGet tget) throws TIOError, org.apache.thrift.TException; + /** + * Test for the existence of columns in the table, as specified by the TGets. + * + * This will return an array of booleans. Each value will be true if the related Get matches + * one or more keys, false if not. + * + * @param table the table to check on + * + * @param tgets a list of TGets to check for + */ + public List existsAll(ByteBuffer table, List tgets) throws TIOError, org.apache.thrift.TException; + /** * Method for getting data from a row. * @@ -276,6 +288,8 @@ public class THBaseService { public void exists(ByteBuffer table, TGet tget, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; + public void existsAll(ByteBuffer table, List tgets, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; + public void get(ByteBuffer table, TGet tget, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; public void getMultiple(ByteBuffer table, List tgets, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; @@ -361,6 +375,33 @@ public class THBaseService { throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "exists failed: unknown result"); } + public List existsAll(ByteBuffer table, List tgets) throws TIOError, org.apache.thrift.TException + { + send_existsAll(table, tgets); + return recv_existsAll(); + } + + public void send_existsAll(ByteBuffer table, List tgets) throws org.apache.thrift.TException + { + existsAll_args args = new existsAll_args(); + args.setTable(table); + args.setTgets(tgets); + sendBase("existsAll", args); + } + + public List recv_existsAll() throws TIOError, org.apache.thrift.TException + { + existsAll_result result = new existsAll_result(); + receiveBase(result, "existsAll"); + if (result.isSetSuccess()) { + return result.success; + } + if (result.io != null) { + throw result.io; + } + throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "existsAll failed: unknown result"); + } + public TResult get(ByteBuffer table, TGet tget) throws TIOError, org.apache.thrift.TException { send_get(table, tget); @@ -904,6 +945,41 @@ public class THBaseService { } } + public void existsAll(ByteBuffer table, List tgets, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + checkReady(); + existsAll_call method_call = new existsAll_call(table, tgets, resultHandler, this, ___protocolFactory, ___transport); + this.___currentMethod = method_call; + ___manager.call(method_call); + } + + public static class existsAll_call extends org.apache.thrift.async.TAsyncMethodCall { + private ByteBuffer table; + private List tgets; + public existsAll_call(ByteBuffer table, List tgets, org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { + super(client, protocolFactory, transport, resultHandler, false); + this.table = table; + this.tgets = tgets; + } + + public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { + prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("existsAll", org.apache.thrift.protocol.TMessageType.CALL, 0)); + existsAll_args args = new existsAll_args(); + args.setTable(table); + args.setTgets(tgets); + args.write(prot); + prot.writeMessageEnd(); + } + + public List getResult() throws TIOError, org.apache.thrift.TException { + if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) { + throw new IllegalStateException("Method call not finished!"); + } + org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array()); + org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); + return (new Client(prot)).recv_existsAll(); + } + } + public void get(ByteBuffer table, TGet tget, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { checkReady(); get_call method_call = new get_call(table, tget, resultHandler, this, ___protocolFactory, ___transport); @@ -1587,6 +1663,7 @@ public class THBaseService { private static Map> getProcessMap(Map> processMap) { processMap.put("exists", new exists()); + processMap.put("existsAll", new existsAll()); processMap.put("get", new get()); processMap.put("getMultiple", new getMultiple()); processMap.put("put", new put()); @@ -1633,6 +1710,29 @@ public class THBaseService { } } + public static class existsAll extends org.apache.thrift.ProcessFunction { + public existsAll() { + super("existsAll"); + } + + public existsAll_args getEmptyArgsInstance() { + return new existsAll_args(); + } + + protected boolean isOneway() { + return false; + } + + public existsAll_result getResult(I iface, existsAll_args args) throws org.apache.thrift.TException { + existsAll_result result = new existsAll_result(); + try { + result.success = iface.existsAll(args.table, args.tgets); + } catch (TIOError io) { + result.io = io; + } + return result; + } + } public static class get extends org.apache.thrift.ProcessFunction { public get() { super("get"); @@ -4165,6 +4265,1054 @@ public class THBaseService { } + public static class existsAll_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("existsAll_args"); + + private static final org.apache.thrift.protocol.TField TABLE_FIELD_DESC = new org.apache.thrift.protocol.TField("table", org.apache.thrift.protocol.TType.STRING, (short) 1); + private static final org.apache.thrift.protocol.TField TGETS_FIELD_DESC = new org.apache.thrift.protocol.TField("tgets", org.apache.thrift.protocol.TType.LIST, (short) 2); + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + + static { + schemes.put(StandardScheme.class, new existsAll_argsStandardSchemeFactory()); + schemes.put(TupleScheme.class, new existsAll_argsTupleSchemeFactory()); + } + + /** + * the table to check on + */ + public ByteBuffer table; // required + /** + * a list of TGets to check for + */ + public List tgets; // required + + /** + * The set of fields this struct contains, along with convenience methods for finding and manipulating them. + */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + /** + * the table to check on + */ + TABLE((short) 1, "table"), + /** + * a list of TGets to check for + */ + TGETS((short) 2, "tgets"); + + private static final Map byName = new HashMap(); + + 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: // TABLE + return TABLE; + case 2: // TGETS + return TGETS; + 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 + 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.TABLE, new org.apache.thrift.meta_data.FieldMetaData("table", org.apache.thrift.TFieldRequirementType.REQUIRED, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING, true))); + tmpMap.put(_Fields.TGETS, new org.apache.thrift.meta_data.FieldMetaData("tgets", org.apache.thrift.TFieldRequirementType.REQUIRED, + new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, TGet.class)))); + metaDataMap = Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(existsAll_args.class, metaDataMap); + } + + public existsAll_args() { + } + + public existsAll_args( + ByteBuffer table, + List tgets) { + this(); + this.table = table; + this.tgets = tgets; + } + + /** + * Performs a deep copy on other. + */ + public existsAll_args(existsAll_args other) { + if (other.isSetTable()) { + this.table = org.apache.thrift.TBaseHelper.copyBinary(other.table); + ; + } + if (other.isSetTgets()) { + List __this__tgets = new ArrayList(); + for (TGet other_element : other.tgets) { + __this__tgets.add(new TGet(other_element)); + } + this.tgets = __this__tgets; + } + } + + public existsAll_args deepCopy() { + return new existsAll_args(this); + } + + @Override + public void clear() { + this.table = null; + this.tgets = null; + } + + /** + * the table to check on + */ + public byte[] getTable() { + setTable(org.apache.thrift.TBaseHelper.rightSize(table)); + return table == null ? null : table.array(); + } + + public ByteBuffer bufferForTable() { + return table; + } + + /** + * the table to check on + */ + public existsAll_args setTable(byte[] table) { + setTable(table == null ? (ByteBuffer) null : ByteBuffer.wrap(table)); + return this; + } + + public existsAll_args setTable(ByteBuffer table) { + this.table = table; + return this; + } + + public void unsetTable() { + this.table = null; + } + + /** + * Returns true if field table is set (has been assigned a value) and false otherwise + */ + public boolean isSetTable() { + return this.table != null; + } + + public void setTableIsSet(boolean value) { + if (!value) { + this.table = null; + } + } + + public int getTgetsSize() { + return (this.tgets == null) ? 0 : this.tgets.size(); + } + + public java.util.Iterator getTgetsIterator() { + return (this.tgets == null) ? null : this.tgets.iterator(); + } + + public void addToTgets(TGet elem) { + if (this.tgets == null) { + this.tgets = new ArrayList(); + } + this.tgets.add(elem); + } + + /** + * a list of TGets to check for + */ + public List getTgets() { + return this.tgets; + } + + /** + * a list of TGets to check for + */ + public existsAll_args setTgets(List tgets) { + this.tgets = tgets; + return this; + } + + public void unsetTgets() { + this.tgets = null; + } + + /** + * Returns true if field tgets is set (has been assigned a value) and false otherwise + */ + public boolean isSetTgets() { + return this.tgets != null; + } + + public void setTgetsIsSet(boolean value) { + if (!value) { + this.tgets = null; + } + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case TABLE: + if (value == null) { + unsetTable(); + } else { + setTable((ByteBuffer) value); + } + break; + + case TGETS: + if (value == null) { + unsetTgets(); + } else { + setTgets((List) value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case TABLE: + return getTable(); + + case TGETS: + return getTgets(); + + } + 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 TABLE: + return isSetTable(); + case TGETS: + return isSetTgets(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof existsAll_args) + return this.equals((existsAll_args) that); + return false; + } + + public boolean equals(existsAll_args that) { + if (that == null) + return false; + + boolean this_present_table = true && this.isSetTable(); + boolean that_present_table = true && that.isSetTable(); + if (this_present_table || that_present_table) { + if (!(this_present_table && that_present_table)) + return false; + if (!this.table.equals(that.table)) + return false; + } + + boolean this_present_tgets = true && this.isSetTgets(); + boolean that_present_tgets = true && that.isSetTgets(); + if (this_present_tgets || that_present_tgets) { + if (!(this_present_tgets && that_present_tgets)) + return false; + if (!this.tgets.equals(that.tgets)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + return 0; + } + + public int compareTo(existsAll_args other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + existsAll_args typedOther = (existsAll_args) other; + + lastComparison = Boolean.valueOf(isSetTable()).compareTo(typedOther.isSetTable()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetTable()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.table, typedOther.table); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.valueOf(isSetTgets()).compareTo(typedOther.isSetTgets()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetTgets()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.tgets, typedOther.tgets); + 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("existsAll_args("); + boolean first = true; + + sb.append("table:"); + if (this.table == null) { + sb.append("null"); + } else { + org.apache.thrift.TBaseHelper.toString(this.table, sb); + } + first = false; + if (!first) sb.append(", "); + sb.append("tgets:"); + if (this.tgets == null) { + sb.append("null"); + } else { + sb.append(this.tgets); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + if (table == null) { + throw new org.apache.thrift.protocol.TProtocolException("Required field 'table' was not present! Struct: " + toString()); + } + if (tgets == null) { + throw new org.apache.thrift.protocol.TProtocolException("Required field 'tgets' was not present! Struct: " + toString()); + } + // 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 existsAll_argsStandardSchemeFactory implements SchemeFactory { + public existsAll_argsStandardScheme getScheme() { + return new existsAll_argsStandardScheme(); + } + } + + private static class existsAll_argsStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, existsAll_args 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: // TABLE + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.table = iprot.readBinary(); + struct.setTableIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // TGETS + if (schemeField.type == org.apache.thrift.protocol.TType.LIST) { + { + org.apache.thrift.protocol.TList _list132 = iprot.readListBegin(); + struct.tgets = new ArrayList(_list132.size); + for (int _i133 = 0; _i133 < _list132.size; ++_i133) { + TGet _elem134; // required + _elem134 = new TGet(); + _elem134.read(iprot); + struct.tgets.add(_elem134); + } + iprot.readListEnd(); + } + struct.setTgetsIsSet(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, existsAll_args struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.table != null) { + oprot.writeFieldBegin(TABLE_FIELD_DESC); + oprot.writeBinary(struct.table); + oprot.writeFieldEnd(); + } + if (struct.tgets != null) { + oprot.writeFieldBegin(TGETS_FIELD_DESC); + { + oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, struct.tgets.size())); + for (TGet _iter135 : struct.tgets) { + _iter135.write(oprot); + } + oprot.writeListEnd(); + } + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class existsAll_argsTupleSchemeFactory implements SchemeFactory { + public existsAll_argsTupleScheme getScheme() { + return new existsAll_argsTupleScheme(); + } + } + + private static class existsAll_argsTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, existsAll_args struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + oprot.writeBinary(struct.table); + { + oprot.writeI32(struct.tgets.size()); + for (TGet _iter136 : struct.tgets) { + _iter136.write(oprot); + } + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, existsAll_args struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + struct.table = iprot.readBinary(); + struct.setTableIsSet(true); + { + org.apache.thrift.protocol.TList _list137 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32()); + struct.tgets = new ArrayList(_list137.size); + for (int _i138 = 0; _i138 < _list137.size; ++_i138) { + TGet _elem139; // required + _elem139 = new TGet(); + _elem139.read(iprot); + struct.tgets.add(_elem139); + } + } + struct.setTgetsIsSet(true); + } + } + + } + + public static class existsAll_result implements org.apache.thrift.TBase, java.io.Serializable, Cloneable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("existsAll_result"); + + private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.LIST, (short) 0); + private static final org.apache.thrift.protocol.TField IO_FIELD_DESC = new org.apache.thrift.protocol.TField("io", org.apache.thrift.protocol.TType.STRUCT, (short) 1); + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + + static { + schemes.put(StandardScheme.class, new existsAll_resultStandardSchemeFactory()); + schemes.put(TupleScheme.class, new existsAll_resultTupleSchemeFactory()); + } + + public List success; // required + public TIOError io; // required + + /** + * The set of fields this struct contains, along with convenience methods for finding and manipulating them. + */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + SUCCESS((short) 0, "success"), + IO((short) 1, "io"); + + private static final Map byName = new HashMap(); + + 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 0: // SUCCESS + return SUCCESS; + case 1: // IO + return IO; + 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 + 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.SUCCESS, new org.apache.thrift.meta_data.FieldMetaData("success", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.BOOL)))); + tmpMap.put(_Fields.IO, new org.apache.thrift.meta_data.FieldMetaData("io", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRUCT))); + metaDataMap = Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(existsAll_result.class, metaDataMap); + } + + public existsAll_result() { + } + + public existsAll_result( + List success, + TIOError io) { + this(); + this.success = success; + this.io = io; + } + + /** + * Performs a deep copy on other. + */ + public existsAll_result(existsAll_result other) { + if (other.isSetSuccess()) { + List __this__success = new ArrayList(); + for (Boolean other_element : other.success) { + __this__success.add(other_element); + } + this.success = __this__success; + } + if (other.isSetIo()) { + this.io = new TIOError(other.io); + } + } + + public existsAll_result deepCopy() { + return new existsAll_result(this); + } + + @Override + public void clear() { + this.success = null; + this.io = null; + } + + public int getSuccessSize() { + return (this.success == null) ? 0 : this.success.size(); + } + + public java.util.Iterator getSuccessIterator() { + return (this.success == null) ? null : this.success.iterator(); + } + + public void addToSuccess(boolean elem) { + if (this.success == null) { + this.success = new ArrayList(); + } + this.success.add(elem); + } + + public List getSuccess() { + return this.success; + } + + public existsAll_result setSuccess(List success) { + this.success = success; + return this; + } + + public void unsetSuccess() { + this.success = null; + } + + /** + * Returns true if field success is set (has been assigned a value) and false otherwise + */ + public boolean isSetSuccess() { + return this.success != null; + } + + public void setSuccessIsSet(boolean value) { + if (!value) { + this.success = null; + } + } + + public TIOError getIo() { + return this.io; + } + + public existsAll_result setIo(TIOError io) { + this.io = io; + return this; + } + + public void unsetIo() { + this.io = null; + } + + /** + * Returns true if field io is set (has been assigned a value) and false otherwise + */ + public boolean isSetIo() { + return this.io != null; + } + + public void setIoIsSet(boolean value) { + if (!value) { + this.io = null; + } + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case SUCCESS: + if (value == null) { + unsetSuccess(); + } else { + setSuccess((List) value); + } + break; + + case IO: + if (value == null) { + unsetIo(); + } else { + setIo((TIOError) value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case SUCCESS: + return getSuccess(); + + case IO: + return getIo(); + + } + 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 SUCCESS: + return isSetSuccess(); + case IO: + return isSetIo(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof existsAll_result) + return this.equals((existsAll_result) that); + return false; + } + + public boolean equals(existsAll_result that) { + if (that == null) + return false; + + boolean this_present_success = true && this.isSetSuccess(); + boolean that_present_success = true && that.isSetSuccess(); + if (this_present_success || that_present_success) { + if (!(this_present_success && that_present_success)) + return false; + if (!this.success.equals(that.success)) + return false; + } + + boolean this_present_io = true && this.isSetIo(); + boolean that_present_io = true && that.isSetIo(); + if (this_present_io || that_present_io) { + if (!(this_present_io && that_present_io)) + return false; + if (!this.io.equals(that.io)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + return 0; + } + + public int compareTo(existsAll_result other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + existsAll_result typedOther = (existsAll_result) other; + + lastComparison = Boolean.valueOf(isSetSuccess()).compareTo(typedOther.isSetSuccess()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetSuccess()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.success, typedOther.success); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.valueOf(isSetIo()).compareTo(typedOther.isSetIo()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetIo()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.io, typedOther.io); + 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("existsAll_result("); + boolean first = true; + + sb.append("success:"); + if (this.success == null) { + sb.append("null"); + } else { + sb.append(this.success); + } + first = false; + if (!first) sb.append(", "); + sb.append("io:"); + if (this.io == null) { + sb.append("null"); + } else { + sb.append(this.io); + } + 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 existsAll_resultStandardSchemeFactory implements SchemeFactory { + public existsAll_resultStandardScheme getScheme() { + return new existsAll_resultStandardScheme(); + } + } + + private static class existsAll_resultStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, existsAll_result 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 0: // SUCCESS + if (schemeField.type == org.apache.thrift.protocol.TType.LIST) { + { + org.apache.thrift.protocol.TList _list140 = iprot.readListBegin(); + struct.success = new ArrayList(_list140.size); + for (int _i141 = 0; _i141 < _list140.size; ++_i141) { + boolean _elem142; // required + _elem142 = iprot.readBool(); + struct.success.add(_elem142); + } + iprot.readListEnd(); + } + struct.setSuccessIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 1: // IO + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.io = new TIOError(); + struct.io.read(iprot); + struct.setIoIsSet(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, existsAll_result struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.success != null) { + oprot.writeFieldBegin(SUCCESS_FIELD_DESC); + { + oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.BOOL, struct.success.size())); + for (boolean _iter143 : struct.success) { + oprot.writeBool(_iter143); + } + oprot.writeListEnd(); + } + oprot.writeFieldEnd(); + } + if (struct.io != null) { + oprot.writeFieldBegin(IO_FIELD_DESC); + struct.io.write(oprot); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class existsAll_resultTupleSchemeFactory implements SchemeFactory { + public existsAll_resultTupleScheme getScheme() { + return new existsAll_resultTupleScheme(); + } + } + + private static class existsAll_resultTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, existsAll_result struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + BitSet optionals = new BitSet(); + if (struct.isSetSuccess()) { + optionals.set(0); + } + if (struct.isSetIo()) { + optionals.set(1); + } + oprot.writeBitSet(optionals, 2); + if (struct.isSetSuccess()) { + { + oprot.writeI32(struct.success.size()); + for (boolean _iter144 : struct.success) { + oprot.writeBool(_iter144); + } + } + } + if (struct.isSetIo()) { + struct.io.write(oprot); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, existsAll_result struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + BitSet incoming = iprot.readBitSet(2); + if (incoming.get(0)) { + { + org.apache.thrift.protocol.TList _list145 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.BOOL, iprot.readI32()); + struct.success = new ArrayList(_list145.size); + for (int _i146 = 0; _i146 < _list145.size; ++_i146) { + boolean _elem147; // required + _elem147 = iprot.readBool(); + struct.success.add(_elem147); + } + } + struct.setSuccessIsSet(true); + } + if (incoming.get(1)) { + struct.io = new TIOError(); + struct.io.read(iprot); + struct.setIoIsSet(true); + } + } + } + + } + public static class get_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("get_args"); diff --git a/hbase-thrift/src/main/resources/org/apache/hadoop/hbase/thrift2/hbase.thrift b/hbase-thrift/src/main/resources/org/apache/hadoop/hbase/thrift2/hbase.thrift index 00f02032945..96fe4f7b645 100644 --- a/hbase-thrift/src/main/resources/org/apache/hadoop/hbase/thrift2/hbase.thrift +++ b/hbase-thrift/src/main/resources/org/apache/hadoop/hbase/thrift2/hbase.thrift @@ -315,6 +315,21 @@ service THBaseService { 2: required TGet tget ) throws (1:TIOError io) + + /** + * Test for the existence of columns in the table, as specified by the TGets. + * + * This will return an array of booleans. Each value will be true if the related Get matches + * one or more keys, false if not. + */ + list existsAll( + /** the table to check on */ + 1: required binary table, + + /** a list of TGets to check for */ + 2: required list tgets + ) throws (1:TIOError io) + /** * Method for getting data from a row. * diff --git a/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift2/TestThriftHBaseServiceHandler.java b/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift2/TestThriftHBaseServiceHandler.java index 4591c786e79..3b0a3f1ed4a 100644 --- a/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift2/TestThriftHBaseServiceHandler.java +++ b/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift2/TestThriftHBaseServiceHandler.java @@ -200,6 +200,34 @@ public class TestThriftHBaseServiceHandler { assertTrue(handler.exists(table, get)); } + @Test + public void testExistsAll() throws TIOError, TException { + ThriftHBaseServiceHandler handler = createHandler(); + byte[] rowName1 = "testExistsAll1".getBytes(); + byte[] rowName2 = "testExistsAll2".getBytes(); + ByteBuffer table = wrap(tableAname); + + List gets = new ArrayList<>(); + gets.add(new TGet(wrap(rowName2))); + gets.add(new TGet(wrap(rowName2))); + List existsResult1 = handler.existsAll(table, gets); + assertFalse(existsResult1.get(0)); + assertFalse(existsResult1.get(1)); + + List columnValues = new ArrayList(); + columnValues.add(new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname))); + columnValues.add(new TColumnValue(wrap(familyBname), wrap(qualifierBname), wrap(valueBname))); + List puts = new ArrayList(); + puts.add(new TPut(wrap(rowName1), columnValues)); + puts.add(new TPut(wrap(rowName2), columnValues)); + + handler.putMultiple(table, puts); + List existsResult2 = handler.existsAll(table,gets ); + + assertTrue(existsResult2.get(0)); + assertTrue(existsResult2.get(1)); + } + @Test public void testPutGet() throws Exception { ThriftHBaseServiceHandler handler = createHandler();