PageRenderTime 36ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 133 lines | 85 code | 21 blank | 27 comment | 6 complexity | bcb5e1474967221372283d6afe8bd44f 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.Map;
  20. import org.apache.commons.logging.Log;
  21. import org.apache.commons.logging.LogFactory;
  22. import org.apache.hadoop.hive.serde2.lazy.LazyMap;
  23. import org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector;
  24. import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
  25. import org.apache.hadoop.io.Text;
  26. /**
  27. * LazyMapObjectInspector works on struct data that is stored in LazyStruct.
  28. *
  29. * Always use the ObjectInspectorFactory to create new ObjectInspector objects,
  30. * instead of directly creating an instance of this class.
  31. */
  32. public class LazyMapObjectInspector implements MapObjectInspector {
  33. public static final Log LOG = LogFactory.getLog(LazyMapObjectInspector.class
  34. .getName());
  35. ObjectInspector mapKeyObjectInspector;
  36. ObjectInspector mapValueObjectInspector;
  37. byte itemSeparator;
  38. byte keyValueSeparator;
  39. Text nullSequence;
  40. boolean escaped;
  41. byte escapeChar;
  42. /**
  43. * Call ObjectInspectorFactory.getStandardListObjectInspector instead.
  44. */
  45. protected LazyMapObjectInspector(ObjectInspector mapKeyObjectInspector,
  46. ObjectInspector mapValueObjectInspector, byte itemSeparator,
  47. byte keyValueSeparator, Text nullSequence, boolean escaped,
  48. byte escapeChar) {
  49. this.mapKeyObjectInspector = mapKeyObjectInspector;
  50. this.mapValueObjectInspector = mapValueObjectInspector;
  51. this.itemSeparator = itemSeparator;
  52. this.keyValueSeparator = keyValueSeparator;
  53. this.nullSequence = nullSequence;
  54. this.escaped = escaped;
  55. this.escapeChar = escapeChar;
  56. }
  57. @Override
  58. public final Category getCategory() {
  59. return Category.MAP;
  60. }
  61. @Override
  62. public String getTypeName() {
  63. return org.apache.hadoop.hive.serde.Constants.MAP_TYPE_NAME + "<"
  64. + mapKeyObjectInspector.getTypeName() + ","
  65. + mapValueObjectInspector.getTypeName() + ">";
  66. }
  67. @Override
  68. public ObjectInspector getMapKeyObjectInspector() {
  69. return mapKeyObjectInspector;
  70. }
  71. @Override
  72. public ObjectInspector getMapValueObjectInspector() {
  73. return mapValueObjectInspector;
  74. }
  75. @Override
  76. public Object getMapValueElement(Object data, Object key) {
  77. if (data == null) {
  78. return null;
  79. }
  80. return ((LazyMap) data).getMapValueElement(key);
  81. }
  82. @Override
  83. public Map<?, ?> getMap(Object data) {
  84. if (data == null) {
  85. return null;
  86. }
  87. return ((LazyMap) data).getMap();
  88. }
  89. @Override
  90. public int getMapSize(Object data) {
  91. if (data == null) {
  92. return -1;
  93. }
  94. return ((LazyMap) data).getMapSize();
  95. }
  96. // Called by LazyMap
  97. public byte getItemSeparator() {
  98. return itemSeparator;
  99. }
  100. public byte getKeyValueSeparator() {
  101. return keyValueSeparator;
  102. }
  103. public Text getNullSequence() {
  104. return nullSequence;
  105. }
  106. public boolean isEscaped() {
  107. return escaped;
  108. }
  109. public byte getEscapeChar() {
  110. return escapeChar;
  111. }
  112. }