PageRenderTime 21ms CodeModel.GetById 13ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Java | 65 lines | 23 code | 7 blank | 35 comment | 2 complexity | 9e848f312c7ef5f39d0913318baee86a 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.objectinspector;
19
20import java.util.List;
21
22/**
23 * StructObjectInspector.
24 *
25 */
26public abstract class StructObjectInspector implements ObjectInspector {
27
28  // ** Methods that does not need a data object **
29  /**
30   * Returns all the fields.
31   */
32  public abstract List<? extends StructField> getAllStructFieldRefs();
33
34  /**
35   * Look up a field.
36   */
37  public abstract StructField getStructFieldRef(String fieldName);
38
39  // ** Methods that need a data object **
40  /**
41   * returns null for data = null.
42   */
43  public abstract Object getStructFieldData(Object data, StructField fieldRef);
44
45  /**
46   * returns null for data = null.
47   */
48  public abstract List<Object> getStructFieldsDataAsList(Object data);
49
50  @Override
51  public String toString() {
52    StringBuilder sb = new StringBuilder();
53    List<? extends StructField> fields = getAllStructFieldRefs();
54    sb.append(getClass().getName());
55    sb.append("<");
56    for (int i = 0; i < fields.size(); i++) {
57      if (i > 0) {
58        sb.append(",");
59      }
60      sb.append(fields.get(i).getFieldObjectInspector().toString());
61    }
62    sb.append(">");
63    return sb.toString();
64  }
65}