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