PageRenderTime 50ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/release-0.1-rc2/hive/external/serde/src/java/org/apache/hadoop/hive/serde2/lazy/objectinspector/LazyUnionObjectInspector.java

#
Java | 130 lines | 86 code | 20 blank | 24 comment | 4 complexity | 250697487d926bccdabdb34d53080c6c 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.lazy.objectinspector;
  19. import java.util.ArrayList;
  20. import java.util.List;
  21. import org.apache.commons.logging.Log;
  22. import org.apache.commons.logging.LogFactory;
  23. import org.apache.hadoop.hive.serde2.lazy.LazyUnion;
  24. import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
  25. import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils;
  26. import org.apache.hadoop.hive.serde2.objectinspector.UnionObjectInspector;
  27. import org.apache.hadoop.io.Text;
  28. /**
  29. * LazyUnionObjectInspector works on union data that is stored in LazyUnion.
  30. *
  31. * Always use the {@link LazyObjectInspectorFactory} to create new
  32. * ObjectInspector objects, instead of directly creating an instance of this
  33. * class.
  34. */
  35. public class LazyUnionObjectInspector implements UnionObjectInspector {
  36. public static final Log LOG = LogFactory
  37. .getLog(LazyUnionObjectInspector.class.getName());
  38. protected List<ObjectInspector> ois;
  39. @Override
  40. public String getTypeName() {
  41. return ObjectInspectorUtils.getStandardUnionTypeName(this);
  42. }
  43. byte separator;
  44. Text nullSequence;
  45. boolean escaped;
  46. byte escapeChar;
  47. protected LazyUnionObjectInspector(
  48. List<ObjectInspector> ois, byte separator,
  49. Text nullSequence, boolean escaped,
  50. byte escapeChar) {
  51. init(ois, separator,
  52. nullSequence, escaped, escapeChar);
  53. }
  54. protected void init(
  55. List<ObjectInspector> ois, byte separator,
  56. Text nullSequence, boolean escaped,
  57. byte escapeChar) {
  58. this.separator = separator;
  59. this.nullSequence = nullSequence;
  60. this.escaped = escaped;
  61. this.escapeChar = escapeChar;
  62. this.ois = new ArrayList<ObjectInspector>();
  63. this.ois.addAll(ois);
  64. }
  65. protected LazyUnionObjectInspector(List<ObjectInspector> ois,
  66. byte separator, Text nullSequence) {
  67. init(ois, separator, nullSequence);
  68. }
  69. protected void init(List<ObjectInspector> ois, byte separator,
  70. Text nullSequence) {
  71. this.separator = separator;
  72. this.nullSequence = nullSequence;
  73. this.ois = new ArrayList<ObjectInspector>();
  74. this.ois.addAll(ois);
  75. }
  76. @Override
  77. public final Category getCategory() {
  78. return Category.UNION;
  79. }
  80. public byte getSeparator() {
  81. return separator;
  82. }
  83. public Text getNullSequence() {
  84. return nullSequence;
  85. }
  86. public boolean isEscaped() {
  87. return escaped;
  88. }
  89. public byte getEscapeChar() {
  90. return escapeChar;
  91. }
  92. @Override
  93. public Object getField(Object data) {
  94. if (data == null) {
  95. return null;
  96. }
  97. return ((LazyUnion) data).getField();
  98. }
  99. @Override
  100. public List<ObjectInspector> getObjectInspectors() {
  101. return ois;
  102. }
  103. @Override
  104. public byte getTag(Object data) {
  105. if (data == null) {
  106. return -1;
  107. }
  108. return ((LazyUnion) data).getTag();
  109. }
  110. }