PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

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