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