0001
0002
0003
0004
0005
0006
0007 package org.apache.hive.service.cli.thrift;
0008
0009 import org.apache.commons.lang.builder.HashCodeBuilder;
0010 import org.apache.thrift.scheme.IScheme;
0011 import org.apache.thrift.scheme.SchemeFactory;
0012 import org.apache.thrift.scheme.StandardScheme;
0013
0014 import org.apache.thrift.scheme.TupleScheme;
0015 import org.apache.thrift.protocol.TTupleProtocol;
0016 import org.apache.thrift.protocol.TProtocolException;
0017 import org.apache.thrift.EncodingUtils;
0018 import org.apache.thrift.TException;
0019 import java.util.List;
0020 import java.util.ArrayList;
0021 import java.util.Map;
0022 import java.util.HashMap;
0023 import java.util.EnumMap;
0024 import java.util.Set;
0025 import java.util.HashSet;
0026 import java.util.EnumSet;
0027 import java.util.Collections;
0028 import java.util.BitSet;
0029 import java.nio.ByteBuffer;
0030 import java.util.Arrays;
0031 import org.slf4j.Logger;
0032 import org.slf4j.LoggerFactory;
0033
0034 public class TTableSchema implements org.apache.thrift.TBase<TTableSchema, TTableSchema._Fields>, java.io.Serializable, Cloneable {
0035 private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TTableSchema");
0036
0037 private static final org.apache.thrift.protocol.TField COLUMNS_FIELD_DESC = new org.apache.thrift.protocol.TField("columns", org.apache.thrift.protocol.TType.LIST, (short)1);
0038
0039 private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
0040 static {
0041 schemes.put(StandardScheme.class, new TTableSchemaStandardSchemeFactory());
0042 schemes.put(TupleScheme.class, new TTableSchemaTupleSchemeFactory());
0043 }
0044
0045 private List<TColumnDesc> columns;
0046
0047
0048 public enum _Fields implements org.apache.thrift.TFieldIdEnum {
0049 COLUMNS((short)1, "columns");
0050
0051 private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
0052
0053 static {
0054 for (_Fields field : EnumSet.allOf(_Fields.class)) {
0055 byName.put(field.getFieldName(), field);
0056 }
0057 }
0058
0059
0060
0061
0062 public static _Fields findByThriftId(int fieldId) {
0063 switch(fieldId) {
0064 case 1:
0065 return COLUMNS;
0066 default:
0067 return null;
0068 }
0069 }
0070
0071
0072
0073
0074
0075 public static _Fields findByThriftIdOrThrow(int fieldId) {
0076 _Fields fields = findByThriftId(fieldId);
0077 if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
0078 return fields;
0079 }
0080
0081
0082
0083
0084 public static _Fields findByName(String name) {
0085 return byName.get(name);
0086 }
0087
0088 private final short _thriftId;
0089 private final String _fieldName;
0090
0091 _Fields(short thriftId, String fieldName) {
0092 _thriftId = thriftId;
0093 _fieldName = fieldName;
0094 }
0095
0096 public short getThriftFieldId() {
0097 return _thriftId;
0098 }
0099
0100 public String getFieldName() {
0101 return _fieldName;
0102 }
0103 }
0104
0105
0106 public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
0107 static {
0108 Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
0109 tmpMap.put(_Fields.COLUMNS, new org.apache.thrift.meta_data.FieldMetaData("columns", org.apache.thrift.TFieldRequirementType.REQUIRED,
0110 new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST,
0111 new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, TColumnDesc.class))));
0112 metaDataMap = Collections.unmodifiableMap(tmpMap);
0113 org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(TTableSchema.class, metaDataMap);
0114 }
0115
0116 public TTableSchema() {
0117 }
0118
0119 public TTableSchema(
0120 List<TColumnDesc> columns)
0121 {
0122 this();
0123 this.columns = columns;
0124 }
0125
0126
0127
0128
0129 public TTableSchema(TTableSchema other) {
0130 if (other.isSetColumns()) {
0131 List<TColumnDesc> __this__columns = new ArrayList<TColumnDesc>();
0132 for (TColumnDesc other_element : other.columns) {
0133 __this__columns.add(new TColumnDesc(other_element));
0134 }
0135 this.columns = __this__columns;
0136 }
0137 }
0138
0139 public TTableSchema deepCopy() {
0140 return new TTableSchema(this);
0141 }
0142
0143 @Override
0144 public void clear() {
0145 this.columns = null;
0146 }
0147
0148 public int getColumnsSize() {
0149 return (this.columns == null) ? 0 : this.columns.size();
0150 }
0151
0152 public java.util.Iterator<TColumnDesc> getColumnsIterator() {
0153 return (this.columns == null) ? null : this.columns.iterator();
0154 }
0155
0156 public void addToColumns(TColumnDesc elem) {
0157 if (this.columns == null) {
0158 this.columns = new ArrayList<TColumnDesc>();
0159 }
0160 this.columns.add(elem);
0161 }
0162
0163 public List<TColumnDesc> getColumns() {
0164 return this.columns;
0165 }
0166
0167 public void setColumns(List<TColumnDesc> columns) {
0168 this.columns = columns;
0169 }
0170
0171 public void unsetColumns() {
0172 this.columns = null;
0173 }
0174
0175
0176 public boolean isSetColumns() {
0177 return this.columns != null;
0178 }
0179
0180 public void setColumnsIsSet(boolean value) {
0181 if (!value) {
0182 this.columns = null;
0183 }
0184 }
0185
0186 public void setFieldValue(_Fields field, Object value) {
0187 switch (field) {
0188 case COLUMNS:
0189 if (value == null) {
0190 unsetColumns();
0191 } else {
0192 setColumns((List<TColumnDesc>)value);
0193 }
0194 break;
0195
0196 }
0197 }
0198
0199 public Object getFieldValue(_Fields field) {
0200 switch (field) {
0201 case COLUMNS:
0202 return getColumns();
0203
0204 }
0205 throw new IllegalStateException();
0206 }
0207
0208
0209 public boolean isSet(_Fields field) {
0210 if (field == null) {
0211 throw new IllegalArgumentException();
0212 }
0213
0214 switch (field) {
0215 case COLUMNS:
0216 return isSetColumns();
0217 }
0218 throw new IllegalStateException();
0219 }
0220
0221 @Override
0222 public boolean equals(Object that) {
0223 if (that == null)
0224 return false;
0225 if (that instanceof TTableSchema)
0226 return this.equals((TTableSchema)that);
0227 return false;
0228 }
0229
0230 public boolean equals(TTableSchema that) {
0231 if (that == null)
0232 return false;
0233
0234 boolean this_present_columns = true && this.isSetColumns();
0235 boolean that_present_columns = true && that.isSetColumns();
0236 if (this_present_columns || that_present_columns) {
0237 if (!(this_present_columns && that_present_columns))
0238 return false;
0239 if (!this.columns.equals(that.columns))
0240 return false;
0241 }
0242
0243 return true;
0244 }
0245
0246 @Override
0247 public int hashCode() {
0248 HashCodeBuilder builder = new HashCodeBuilder();
0249
0250 boolean present_columns = true && (isSetColumns());
0251 builder.append(present_columns);
0252 if (present_columns)
0253 builder.append(columns);
0254
0255 return builder.toHashCode();
0256 }
0257
0258 public int compareTo(TTableSchema other) {
0259 if (!getClass().equals(other.getClass())) {
0260 return getClass().getName().compareTo(other.getClass().getName());
0261 }
0262
0263 int lastComparison = 0;
0264 TTableSchema typedOther = (TTableSchema)other;
0265
0266 lastComparison = Boolean.valueOf(isSetColumns()).compareTo(typedOther.isSetColumns());
0267 if (lastComparison != 0) {
0268 return lastComparison;
0269 }
0270 if (isSetColumns()) {
0271 lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.columns, typedOther.columns);
0272 if (lastComparison != 0) {
0273 return lastComparison;
0274 }
0275 }
0276 return 0;
0277 }
0278
0279 public _Fields fieldForId(int fieldId) {
0280 return _Fields.findByThriftId(fieldId);
0281 }
0282
0283 public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
0284 schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
0285 }
0286
0287 public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
0288 schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
0289 }
0290
0291 @Override
0292 public String toString() {
0293 StringBuilder sb = new StringBuilder("TTableSchema(");
0294 boolean first = true;
0295
0296 sb.append("columns:");
0297 if (this.columns == null) {
0298 sb.append("null");
0299 } else {
0300 sb.append(this.columns);
0301 }
0302 first = false;
0303 sb.append(")");
0304 return sb.toString();
0305 }
0306
0307 public void validate() throws org.apache.thrift.TException {
0308
0309 if (!isSetColumns()) {
0310 throw new org.apache.thrift.protocol.TProtocolException("Required field 'columns' is unset! Struct:" + toString());
0311 }
0312
0313
0314 }
0315
0316 private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
0317 try {
0318 write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
0319 } catch (org.apache.thrift.TException te) {
0320 throw new java.io.IOException(te);
0321 }
0322 }
0323
0324 private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
0325 try {
0326 read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
0327 } catch (org.apache.thrift.TException te) {
0328 throw new java.io.IOException(te);
0329 }
0330 }
0331
0332 private static class TTableSchemaStandardSchemeFactory implements SchemeFactory {
0333 public TTableSchemaStandardScheme getScheme() {
0334 return new TTableSchemaStandardScheme();
0335 }
0336 }
0337
0338 private static class TTableSchemaStandardScheme extends StandardScheme<TTableSchema> {
0339
0340 public void read(org.apache.thrift.protocol.TProtocol iprot, TTableSchema struct) throws org.apache.thrift.TException {
0341 org.apache.thrift.protocol.TField schemeField;
0342 iprot.readStructBegin();
0343 while (true)
0344 {
0345 schemeField = iprot.readFieldBegin();
0346 if (schemeField.type == org.apache.thrift.protocol.TType.STOP) {
0347 break;
0348 }
0349 switch (schemeField.id) {
0350 case 1:
0351 if (schemeField.type == org.apache.thrift.protocol.TType.LIST) {
0352 {
0353 org.apache.thrift.protocol.TList _list38 = iprot.readListBegin();
0354 struct.columns = new ArrayList<TColumnDesc>(_list38.size);
0355 for (int _i39 = 0; _i39 < _list38.size; ++_i39)
0356 {
0357 TColumnDesc _elem40;
0358 _elem40 = new TColumnDesc();
0359 _elem40.read(iprot);
0360 struct.columns.add(_elem40);
0361 }
0362 iprot.readListEnd();
0363 }
0364 struct.setColumnsIsSet(true);
0365 } else {
0366 org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
0367 }
0368 break;
0369 default:
0370 org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
0371 }
0372 iprot.readFieldEnd();
0373 }
0374 iprot.readStructEnd();
0375 struct.validate();
0376 }
0377
0378 public void write(org.apache.thrift.protocol.TProtocol oprot, TTableSchema struct) throws org.apache.thrift.TException {
0379 struct.validate();
0380
0381 oprot.writeStructBegin(STRUCT_DESC);
0382 if (struct.columns != null) {
0383 oprot.writeFieldBegin(COLUMNS_FIELD_DESC);
0384 {
0385 oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, struct.columns.size()));
0386 for (TColumnDesc _iter41 : struct.columns)
0387 {
0388 _iter41.write(oprot);
0389 }
0390 oprot.writeListEnd();
0391 }
0392 oprot.writeFieldEnd();
0393 }
0394 oprot.writeFieldStop();
0395 oprot.writeStructEnd();
0396 }
0397
0398 }
0399
0400 private static class TTableSchemaTupleSchemeFactory implements SchemeFactory {
0401 public TTableSchemaTupleScheme getScheme() {
0402 return new TTableSchemaTupleScheme();
0403 }
0404 }
0405
0406 private static class TTableSchemaTupleScheme extends TupleScheme<TTableSchema> {
0407
0408 @Override
0409 public void write(org.apache.thrift.protocol.TProtocol prot, TTableSchema struct) throws org.apache.thrift.TException {
0410 TTupleProtocol oprot = (TTupleProtocol) prot;
0411 {
0412 oprot.writeI32(struct.columns.size());
0413 for (TColumnDesc _iter42 : struct.columns)
0414 {
0415 _iter42.write(oprot);
0416 }
0417 }
0418 }
0419
0420 @Override
0421 public void read(org.apache.thrift.protocol.TProtocol prot, TTableSchema struct) throws org.apache.thrift.TException {
0422 TTupleProtocol iprot = (TTupleProtocol) prot;
0423 {
0424 org.apache.thrift.protocol.TList _list43 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32());
0425 struct.columns = new ArrayList<TColumnDesc>(_list43.size);
0426 for (int _i44 = 0; _i44 < _list43.size; ++_i44)
0427 {
0428 TColumnDesc _elem45;
0429 _elem45 = new TColumnDesc();
0430 _elem45.read(iprot);
0431 struct.columns.add(_elem45);
0432 }
0433 }
0434 struct.setColumnsIsSet(true);
0435 }
0436 }
0437
0438 }
0439