PageRenderTime 23ms CodeModel.GetById 19ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Java | 64 lines | 34 code | 10 blank | 20 comment | 2 complexity | 231c65312656aab9bf59cbace9c1936f 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;
22
23import org.apache.hadoop.conf.Configuration;
24import org.apache.hadoop.hive.ql.metadata.HiveException;
25import org.apache.hadoop.hive.ql.plan.LimitDesc;
26import org.apache.hadoop.hive.ql.plan.api.OperatorType;
27
28/**
29 * Limit operator implementation Limits the number of rows to be passed on.
30 **/
31public class LimitOperator extends Operator<LimitDesc> implements Serializable {
32  private static final long serialVersionUID = 1L;
33
34  protected transient int limit;
35  protected transient int currCount;
36
37  @Override
38  protected void initializeOp(Configuration hconf) throws HiveException {
39    super.initializeOp(hconf);
40    limit = conf.getLimit();
41    currCount = 0;
42  }
43
44  @Override
45  public void processOp(Object row, int tag) throws HiveException {
46    if (currCount < limit) {
47      forward(row, inputObjInspectors[tag]);
48      currCount++;
49    } else {
50      setDone(true);
51    }
52  }
53
54  @Override
55  public String getName() {
56    return "LIM";
57  }
58
59  @Override
60  public OperatorType getType() {
61    return OperatorType.LIMIT;
62  }
63
64}