PageRenderTime 55ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/release-0.0.0-rc0/hive/external/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StructObjectInspector.java

#
Java | 65 lines | 23 code | 7 blank | 35 comment | 2 complexity | 9e848f312c7ef5f39d0913318baee86a 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.objectinspector;
  19. import java.util.List;
  20. /**
  21. * StructObjectInspector.
  22. *
  23. */
  24. public abstract class StructObjectInspector implements ObjectInspector {
  25. // ** Methods that does not need a data object **
  26. /**
  27. * Returns all the fields.
  28. */
  29. public abstract List<? extends StructField> getAllStructFieldRefs();
  30. /**
  31. * Look up a field.
  32. */
  33. public abstract StructField getStructFieldRef(String fieldName);
  34. // ** Methods that need a data object **
  35. /**
  36. * returns null for data = null.
  37. */
  38. public abstract Object getStructFieldData(Object data, StructField fieldRef);
  39. /**
  40. * returns null for data = null.
  41. */
  42. public abstract List<Object> getStructFieldsDataAsList(Object data);
  43. @Override
  44. public String toString() {
  45. StringBuilder sb = new StringBuilder();
  46. List<? extends StructField> fields = getAllStructFieldRefs();
  47. sb.append(getClass().getName());
  48. sb.append("<");
  49. for (int i = 0; i < fields.size(); i++) {
  50. if (i > 0) {
  51. sb.append(",");
  52. }
  53. sb.append(fields.get(i).getFieldObjectInspector().toString());
  54. }
  55. sb.append(">");
  56. return sb.toString();
  57. }
  58. }