PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/release-0.0.0-rc0/hive/external/ql/src/java/org/apache/hadoop/hive/ql/exec/CollectOperator.java

#
Java | 85 lines | 52 code | 11 blank | 22 comment | 5 complexity | 99a1e5389faba719d6a954eebab216e7 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.exec;
  19. import java.io.Serializable;
  20. import java.util.ArrayList;
  21. import org.apache.hadoop.conf.Configuration;
  22. import org.apache.hadoop.hive.ql.metadata.HiveException;
  23. import org.apache.hadoop.hive.ql.plan.api.OperatorType;
  24. import org.apache.hadoop.hive.ql.plan.CollectDesc;
  25. import org.apache.hadoop.hive.serde2.objectinspector.InspectableObject;
  26. import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
  27. import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils;
  28. /**
  29. * Buffers rows emitted by other operators.
  30. **/
  31. public class CollectOperator extends Operator<CollectDesc> implements
  32. Serializable {
  33. private static final long serialVersionUID = 1L;
  34. protected transient ArrayList<Object> rowList;
  35. protected transient ObjectInspector standardRowInspector;
  36. transient int maxSize;
  37. @Override
  38. protected void initializeOp(Configuration hconf) throws HiveException {
  39. super.initializeOp(hconf);
  40. rowList = new ArrayList<Object>();
  41. maxSize = conf.getBufferSize().intValue();
  42. }
  43. boolean firstRow = true;
  44. @Override
  45. public void processOp(Object row, int tag) throws HiveException {
  46. ObjectInspector rowInspector = inputObjInspectors[tag];
  47. if (firstRow) {
  48. firstRow = false;
  49. // Get the standard ObjectInspector of the row
  50. standardRowInspector = ObjectInspectorUtils
  51. .getStandardObjectInspector(rowInspector);
  52. }
  53. if (rowList.size() < maxSize) {
  54. // Create a standard copy of the object.
  55. Object o = ObjectInspectorUtils.copyToStandardObject(row, rowInspector);
  56. rowList.add(o);
  57. }
  58. forward(row, rowInspector);
  59. }
  60. public void retrieve(InspectableObject result) {
  61. assert (result != null);
  62. if (rowList.isEmpty()) {
  63. result.o = null;
  64. result.oi = null;
  65. } else {
  66. result.o = rowList.remove(0);
  67. result.oi = standardRowInspector;
  68. }
  69. }
  70. @Override
  71. public OperatorType getType() {
  72. return null;
  73. }
  74. }