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