PageRenderTime 24ms CodeModel.GetById 15ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/tags/release-0.1-rc2/hive/external/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDTF.java

#
Java | 84 lines | 18 code | 10 blank | 56 comment | 0 complexity | dd77e5cdc727458ca2e61b53a357fc32 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.ql.udf.generic;
20
21import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
22import org.apache.hadoop.hive.ql.metadata.HiveException;
23import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
24import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector;
25
26/**
27 * A Generic User-defined Table Generating Function (UDTF)
28 *
29 * Generates a variable number of output rows for a single input row. Useful for
30 * explode(array)...
31 */
32
33public abstract class GenericUDTF {
34  Collector collector = null;
35
36  /**
37   * Initialize this GenericUDTF. This will be called only once per instance.
38   *
39   * @param args
40   *          An array of ObjectInspectors for the arguments
41   * @return A StructObjectInspector for output. The output struct represents a
42   *         row of the table where the fields of the stuct are the columns. The
43   *         field names are unimportant as they will be overridden by user
44   *         supplied column aliases.
45   */
46  public abstract StructObjectInspector initialize(ObjectInspector[] argOIs)
47      throws UDFArgumentException;
48
49  /**
50   * Give a set of arguments for the UDTF to process.
51   *
52   * @param o
53   *          object array of arguments
54   */
55  public abstract void process(Object[] args) throws HiveException;
56
57  /**
58   * Called to notify the UDTF that there are no more rows to process.
59   * Clean up code or additional forward() calls can be made here.
60   */
61  public abstract void close() throws HiveException;
62
63  /**
64   * Associates a collector with this UDTF. Can't be specified in the
65   * constructor as the UDTF may be initialized before the collector has been
66   * constructed.
67   *
68   * @param collector
69   */
70  public final void setCollector(Collector collector) {
71    this.collector = collector;
72  }
73
74  /**
75   * Passes an output row to the collector.
76   *
77   * @param o
78   * @throws HiveException
79   */
80  protected final void forward(Object o) throws HiveException {
81    collector.collect(o);
82  }
83
84}