PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/release-0.0.0-rc0/hive/external/ql/src/java/org/apache/hadoop/hive/ql/io/CombineHiveRecordReader.java

#
Java | 100 lines | 62 code | 14 blank | 24 comment | 1 complexity | 6833efa91322ad354a299a43cc589dce 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.io;
  19. import java.io.IOException;
  20. import org.apache.hadoop.conf.Configuration;
  21. import org.apache.hadoop.hive.ql.exec.ExecMapper;
  22. import org.apache.hadoop.hive.ql.io.CombineHiveInputFormat.CombineHiveInputSplit;
  23. import org.apache.hadoop.hive.shims.HadoopShims.InputSplitShim;
  24. import org.apache.hadoop.io.Writable;
  25. import org.apache.hadoop.io.WritableComparable;
  26. import org.apache.hadoop.mapred.FileSplit;
  27. import org.apache.hadoop.mapred.InputFormat;
  28. import org.apache.hadoop.mapred.InputSplit;
  29. import org.apache.hadoop.mapred.JobConf;
  30. import org.apache.hadoop.mapred.RecordReader;
  31. import org.apache.hadoop.mapred.Reporter;
  32. /**
  33. * CombineHiveRecordReader.
  34. *
  35. * @param <K>
  36. * @param <V>
  37. */
  38. public class CombineHiveRecordReader<K extends WritableComparable, V extends Writable>
  39. extends HiveContextAwareRecordReader<K, V> {
  40. private final RecordReader recordReader;
  41. public CombineHiveRecordReader(InputSplit split, Configuration conf,
  42. Reporter reporter, Integer partition) throws IOException {
  43. JobConf job = (JobConf) conf;
  44. CombineHiveInputSplit hsplit = new CombineHiveInputSplit(job,
  45. (InputSplitShim) split);
  46. String inputFormatClassName = hsplit.inputFormatClassName();
  47. Class inputFormatClass = null;
  48. try {
  49. inputFormatClass = Class.forName(inputFormatClassName);
  50. } catch (ClassNotFoundException e) {
  51. throw new IOException("CombineHiveRecordReader: class not found "
  52. + inputFormatClassName);
  53. }
  54. InputFormat inputFormat = HiveInputFormat.getInputFormatFromCache(
  55. inputFormatClass, job);
  56. // create a split for the given partition
  57. FileSplit fsplit = new FileSplit(hsplit.getPaths()[partition], hsplit
  58. .getStartOffsets()[partition], hsplit.getLengths()[partition], hsplit
  59. .getLocations());
  60. this.recordReader = inputFormat.getRecordReader(fsplit, job, reporter);
  61. this.initIOContext(fsplit, job, inputFormatClass, this.recordReader);
  62. }
  63. @Override
  64. public void doClose() throws IOException {
  65. recordReader.close();
  66. }
  67. public K createKey() {
  68. return (K) recordReader.createKey();
  69. }
  70. public V createValue() {
  71. return (V) recordReader.createValue();
  72. }
  73. public long getPos() throws IOException {
  74. return recordReader.getPos();
  75. }
  76. public float getProgress() throws IOException {
  77. return recordReader.getProgress();
  78. }
  79. @Override
  80. public boolean doNext(K key, V value) throws IOException {
  81. if (ExecMapper.getDone()) {
  82. return false;
  83. }
  84. return recordReader.next(key, value);
  85. }
  86. }