PageRenderTime 19ms CodeModel.GetById 12ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

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

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