PageRenderTime 40ms CodeModel.GetById 22ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Java | 78 lines | 45 code | 11 blank | 22 comment | 4 complexity | 5082987b8af50aa3ac7af2a72acba438 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 org.apache.hadoop.hive.serde2.SerDeException;
22import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
23import org.apache.hadoop.hive.serde2.objectinspector.primitive.ByteObjectInspector;
24import org.apache.thrift.TException;
25import org.apache.thrift.protocol.TProtocol;
26import org.apache.thrift.protocol.TType;
27
28/**
29 * DynamicSerDeTypeByte.
30 *
31 */
32public class DynamicSerDeTypeByte extends DynamicSerDeTypeBase {
33
34  // production is: byte
35
36  public DynamicSerDeTypeByte(int i) {
37    super(i);
38  }
39
40  public DynamicSerDeTypeByte(thrift_grammar p, int i) {
41    super(p, i);
42  }
43
44  @Override
45  public String toString() {
46    return "byte";
47  }
48
49  public Byte deserialize(TProtocol iprot) throws SerDeException, TException,
50      IllegalAccessException {
51    byte val = iprot.readByte();
52    if (val == 0
53        && iprot instanceof org.apache.hadoop.hive.serde2.thrift.WriteNullsProtocol
54        && ((org.apache.hadoop.hive.serde2.thrift.WriteNullsProtocol) iprot)
55        .lastPrimitiveWasNull()) {
56      return null;
57    }
58    return Byte.valueOf(val);
59  }
60
61  @Override
62  public Object deserialize(Object reuse, TProtocol iprot)
63      throws SerDeException, TException, IllegalAccessException {
64    return deserialize(iprot);
65  }
66
67  @Override
68  public void serialize(Object o, ObjectInspector oi, TProtocol oprot)
69      throws TException, SerDeException, NoSuchFieldException, IllegalAccessException {
70    ByteObjectInspector poi = (ByteObjectInspector) oi;
71    oprot.writeByte(poi.get(o));
72  }
73
74  @Override
75  public byte getType() {
76    return TType.BYTE;
77  }
78}