PageRenderTime 23ms CodeModel.GetById 7ms app.highlight 10ms RepoModel.GetById 2ms app.codeStats 0ms

/tags/release-0.1-rc2/hive/external/serde/src/java/org/apache/hadoop/hive/serde2/dynamic_type/DynamicSerDeStructBase.java

#
Java | 106 lines | 55 code | 18 blank | 33 comment | 4 complexity | 1b5470c0fc2f1e6d7b41c78f4785f1c0 MD5 | raw file
  1/**
  2 * Licensed to the Apache Software Foundation (ASF) under one
  3 * or more contributor license agreements.  See the NOTICE file
  4 * distributed with this work for additional information
  5 * regarding copyright ownership.  The ASF licenses this file
  6 * to you under the Apache License, Version 2.0 (the
  7 * "License"); you may not use this file except in compliance
  8 * with the License.  You may obtain a copy of the License at
  9 *
 10 *     http://www.apache.org/licenses/LICENSE-2.0
 11 *
 12 * Unless required by applicable law or agreed to in writing, software
 13 * distributed under the License is distributed on an "AS IS" BASIS,
 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15 * See the License for the specific language governing permissions and
 16 * limitations under the License.
 17 */
 18
 19package org.apache.hadoop.hive.serde2.dynamic_type;
 20
 21import java.io.Serializable;
 22import java.util.List;
 23
 24import org.apache.hadoop.hive.serde2.SerDeException;
 25import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
 26import org.apache.thrift.TException;
 27import org.apache.thrift.protocol.TProtocol;
 28import org.apache.thrift.protocol.TStruct;
 29
 30/**
 31 * DynamicSerDeStructBase.
 32 *
 33 */
 34public abstract class DynamicSerDeStructBase extends DynamicSerDeTypeBase
 35    implements Serializable {
 36
 37  DynamicSerDeFieldList fieldList;
 38
 39  public DynamicSerDeStructBase(int i) {
 40    super(i);
 41  }
 42
 43  public DynamicSerDeStructBase(thrift_grammar p, int i) {
 44    super(p, i);
 45  }
 46
 47  public abstract DynamicSerDeFieldList getFieldList();
 48
 49  @Override
 50  public void initialize() {
 51    fieldList = getFieldList();
 52    fieldList.initialize();
 53  }
 54
 55  @Override
 56  public boolean isPrimitive() {
 57    return false;
 58  }
 59
 60  @Override
 61  public Class getRealType() {
 62    return List.class;
 63  }
 64
 65  @Override
 66  public Object deserialize(Object reuse, TProtocol iprot)
 67      throws SerDeException, TException, IllegalAccessException {
 68    if (thrift_mode) {
 69      iprot.readStructBegin();
 70    }
 71
 72    Object o = fieldList.deserialize(reuse, iprot);
 73
 74    if (thrift_mode) {
 75      iprot.readStructEnd();
 76    }
 77    return o;
 78  }
 79
 80  /**
 81   * serialize
 82   * 
 83   * The way to serialize a Thrift "table" which in thrift land is really a
 84   * function and thus this class's name.
 85   * 
 86   * @param o
 87   *          - this list should be in the order of the function's params for
 88   *          now. If we wanted to remove this requirement, we'd need to make it
 89   *          a List<Pair<String, Object>> with the String being the field name.
 90   * 
 91   */
 92  @Override
 93  public void serialize(Object o, ObjectInspector oi, TProtocol oprot)
 94      throws TException, SerDeException, NoSuchFieldException, IllegalAccessException {
 95    if (thrift_mode) {
 96      oprot.writeStructBegin(new TStruct(name));
 97    }
 98
 99    fieldList.serialize(o, oi, oprot);
100
101    if (thrift_mode) {
102      oprot.writeStructEnd();
103    }
104  }
105
106}