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