PageRenderTime 76ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 2ms

/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
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 java.io.Serializable;
  20. import java.util.List;
  21. import org.apache.hadoop.hive.serde2.SerDeException;
  22. import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
  23. import org.apache.thrift.TException;
  24. import org.apache.thrift.protocol.TProtocol;
  25. import org.apache.thrift.protocol.TStruct;
  26. /**
  27. * DynamicSerDeStructBase.
  28. *
  29. */
  30. public abstract class DynamicSerDeStructBase extends DynamicSerDeTypeBase
  31. implements Serializable {
  32. DynamicSerDeFieldList fieldList;
  33. public DynamicSerDeStructBase(int i) {
  34. super(i);
  35. }
  36. public DynamicSerDeStructBase(thrift_grammar p, int i) {
  37. super(p, i);
  38. }
  39. public abstract DynamicSerDeFieldList getFieldList();
  40. @Override
  41. public void initialize() {
  42. fieldList = getFieldList();
  43. fieldList.initialize();
  44. }
  45. @Override
  46. public boolean isPrimitive() {
  47. return false;
  48. }
  49. @Override
  50. public Class getRealType() {
  51. return List.class;
  52. }
  53. @Override
  54. public Object deserialize(Object reuse, TProtocol iprot)
  55. throws SerDeException, TException, IllegalAccessException {
  56. if (thrift_mode) {
  57. iprot.readStructBegin();
  58. }
  59. Object o = fieldList.deserialize(reuse, iprot);
  60. if (thrift_mode) {
  61. iprot.readStructEnd();
  62. }
  63. return o;
  64. }
  65. /**
  66. * serialize
  67. *
  68. * The way to serialize a Thrift "table" which in thrift land is really a
  69. * function and thus this class's name.
  70. *
  71. * @param o
  72. * - this list should be in the order of the function's params for
  73. * now. If we wanted to remove this requirement, we'd need to make it
  74. * a List<Pair<String, Object>> with the String being the field name.
  75. *
  76. */
  77. @Override
  78. public void serialize(Object o, ObjectInspector oi, TProtocol oprot)
  79. throws TException, SerDeException, NoSuchFieldException, IllegalAccessException {
  80. if (thrift_mode) {
  81. oprot.writeStructBegin(new TStruct(name));
  82. }
  83. fieldList.serialize(o, oi, oprot);
  84. if (thrift_mode) {
  85. oprot.writeStructEnd();
  86. }
  87. }
  88. }