PageRenderTime 48ms CodeModel.GetById 25ms RepoModel.GetById 0ms 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
Possible License(s): Apache-2.0, BSD-3-Clause, JSON, CPL-1.0
  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. package org.apache.hadoop.hive.serde2.dynamic_type;
  19. import org.apache.hadoop.hive.serde2.SerDeException;
  20. import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
  21. import org.apache.hadoop.hive.serde2.objectinspector.primitive.IntObjectInspector;
  22. import org.apache.thrift.TException;
  23. import org.apache.thrift.protocol.TProtocol;
  24. import org.apache.thrift.protocol.TType;
  25. /**
  26. * DynamicSerDeTypei32.
  27. *
  28. */
  29. public class DynamicSerDeTypei32 extends DynamicSerDeTypeBase {
  30. // production is: i32
  31. public DynamicSerDeTypei32(int i) {
  32. super(i);
  33. }
  34. public DynamicSerDeTypei32(thrift_grammar p, int i) {
  35. super(p, i);
  36. }
  37. @Override
  38. public String toString() {
  39. return "i32";
  40. }
  41. @Override
  42. public Object deserialize(Object reuse, TProtocol iprot)
  43. throws SerDeException, TException, IllegalAccessException {
  44. int val = iprot.readI32();
  45. if (val == 0
  46. && iprot instanceof org.apache.hadoop.hive.serde2.thrift.WriteNullsProtocol
  47. && ((org.apache.hadoop.hive.serde2.thrift.WriteNullsProtocol) iprot)
  48. .lastPrimitiveWasNull()) {
  49. return null;
  50. }
  51. return Integer.valueOf(val);
  52. }
  53. @Override
  54. public void serialize(Object o, ObjectInspector oi, TProtocol oprot)
  55. throws TException, SerDeException, NoSuchFieldException, IllegalAccessException {
  56. IntObjectInspector poi = (IntObjectInspector) oi;
  57. oprot.writeI32(poi.get(o));
  58. }
  59. @Override
  60. public Class getRealType() {
  61. return java.lang.Integer.class;
  62. }
  63. public Integer getRealTypeInstance() {
  64. return Integer.valueOf(0);
  65. }
  66. @Override
  67. public byte getType() {
  68. return TType.I32;
  69. }
  70. }