PageRenderTime 32ms CodeModel.GetById 18ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

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

#
Java | 66 lines | 35 code | 9 blank | 22 comment | 5 complexity | 45b544fc83e39f0fdf279d3d2bbcd657 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 */
18package org.apache.hadoop.hive.serde2.lazybinary.objectinspector;
19
20import java.util.List;
21
22import org.apache.hadoop.hive.serde2.lazybinary.LazyBinaryStruct;
23import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
24import org.apache.hadoop.hive.serde2.objectinspector.StandardStructObjectInspector;
25import org.apache.hadoop.hive.serde2.objectinspector.StructField;
26
27/**
28 * ObjectInspector for LazyBinaryStruct.
29 * 
30 * @see LazyBinaryStruct
31 */
32public class LazyBinaryStructObjectInspector extends
33    StandardStructObjectInspector {
34
35  protected LazyBinaryStructObjectInspector(List<String> structFieldNames,
36      List<ObjectInspector> structFieldObjectInspectors) {
37    super(structFieldNames, structFieldObjectInspectors);
38  }
39
40  protected LazyBinaryStructObjectInspector(List<StructField> fields) {
41    super(fields);
42  }
43
44  @Override
45  public Object getStructFieldData(Object data, StructField fieldRef) {
46    if (data == null) {
47      return null;
48    }
49    LazyBinaryStruct struct = (LazyBinaryStruct) data;
50    MyField f = (MyField) fieldRef;
51
52    int fieldID = f.getFieldID();
53    assert (fieldID >= 0 && fieldID < fields.size());
54
55    return struct.getField(fieldID);
56  }
57
58  @Override
59  public List<Object> getStructFieldsDataAsList(Object data) {
60    if (data == null) {
61      return null;
62    }
63    LazyBinaryStruct struct = (LazyBinaryStruct) data;
64    return struct.getFieldsAsList();
65  }
66}