PageRenderTime 20ms CodeModel.GetById 9ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

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

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