PageRenderTime 33ms CodeModel.GetById 28ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Java | 74 lines | 18 code | 9 blank | 47 comment | 0 complexity | 411d1e8a70ba72ea8893f3d4da680396 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.lazy;
19
20import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
21
22/**
23 * LazyObject stores an object in a range of bytes in a byte[].
24 * 
25 * A LazyObject can represent any primitive object or hierarchical object like
26 * array, map or struct.
27 */
28public abstract class LazyObject<OI extends ObjectInspector> {
29
30  OI oi;
31
32  /**
33   * Create a LazyObject.
34   * 
35   * @param oi
36   *          Derived classes can access meta information about this Lazy Object
37   *          (e.g, separator, nullSequence, escaper) from it.
38   */
39  protected LazyObject(OI oi) {
40    this.oi = oi;
41  }
42
43  /**
44   * Set the data for this LazyObject. We take ByteArrayRef instead of byte[] so
45   * that we will be able to drop the reference to byte[] by a single
46   * assignment. The ByteArrayRef object can be reused across multiple rows.
47   * 
48   * @param bytes
49   *          The wrapper of the byte[].
50   * @param start
51   *          The start position inside the bytes.
52   * @param length
53   *          The length of the data, starting from "start"
54   * @see ByteArrayRef
55   */
56  public abstract void init(ByteArrayRef bytes, int start, int length);
57
58  /**
59   * If the LazyObject is a primitive Object, then deserialize it and return the
60   * actual primitive Object. Otherwise (array, map, struct), return this.
61   */
62  public abstract Object getObject();
63
64  @Override
65  public abstract int hashCode();
66
67  protected OI getInspector() {
68    return oi;
69  }
70
71  protected void setInspector(OI oi) {
72    this.oi = oi;
73  }
74}