PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/release-0.2.0-rc0/src/java/org/apache/hcatalog/mapreduce/HCatRecordReader.java

#
Java | 103 lines | 45 code | 14 blank | 44 comment | 1 complexity | 40f458a1c073384ca33be85667658b25 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.hcatalog.mapreduce;
  19. import java.io.IOException;
  20. import org.apache.hadoop.io.Writable;
  21. import org.apache.hadoop.io.WritableComparable;
  22. import org.apache.hadoop.mapreduce.InputSplit;
  23. import org.apache.hadoop.mapreduce.RecordReader;
  24. import org.apache.hadoop.mapreduce.TaskAttemptContext;
  25. import org.apache.hcatalog.data.HCatRecord;
  26. /** The HCat wrapper for the underlying RecordReader, this ensures that the initialize on
  27. * the underlying record reader is done with the underlying split, not with HCatSplit.
  28. */
  29. class HCatRecordReader extends RecordReader<WritableComparable, HCatRecord> {
  30. /** The underlying record reader to delegate to. */
  31. private final RecordReader<? extends WritableComparable, ? extends Writable> baseRecordReader;
  32. /** The storage driver used */
  33. private final HCatInputStorageDriver storageDriver;
  34. /**
  35. * Instantiates a new hcat record reader.
  36. * @param baseRecordReader the base record reader
  37. */
  38. public HCatRecordReader(HCatInputStorageDriver storageDriver, RecordReader<? extends WritableComparable, ? extends Writable> baseRecordReader) {
  39. this.baseRecordReader = baseRecordReader;
  40. this.storageDriver = storageDriver;
  41. }
  42. /* (non-Javadoc)
  43. * @see org.apache.hadoop.mapreduce.RecordReader#initialize(org.apache.hadoop.mapreduce.InputSplit, org.apache.hadoop.mapreduce.TaskAttemptContext)
  44. */
  45. @Override
  46. public void initialize(InputSplit split, TaskAttemptContext taskContext)
  47. throws IOException, InterruptedException {
  48. InputSplit baseSplit = split;
  49. if( split instanceof HCatSplit ) {
  50. baseSplit = ((HCatSplit) split).getBaseSplit();
  51. }
  52. baseRecordReader.initialize(baseSplit, taskContext);
  53. }
  54. /* (non-Javadoc)
  55. * @see org.apache.hadoop.mapreduce.RecordReader#getCurrentKey()
  56. */
  57. @Override
  58. public WritableComparable getCurrentKey() throws IOException, InterruptedException {
  59. return baseRecordReader.getCurrentKey();
  60. }
  61. /* (non-Javadoc)
  62. * @see org.apache.hadoop.mapreduce.RecordReader#getCurrentValue()
  63. */
  64. @Override
  65. public HCatRecord getCurrentValue() throws IOException, InterruptedException {
  66. return storageDriver.convertToHCatRecord(baseRecordReader.getCurrentKey(),baseRecordReader.getCurrentValue());
  67. }
  68. /* (non-Javadoc)
  69. * @see org.apache.hadoop.mapreduce.RecordReader#getProgress()
  70. */
  71. @Override
  72. public float getProgress() throws IOException, InterruptedException {
  73. return baseRecordReader.getProgress();
  74. }
  75. /* (non-Javadoc)
  76. * @see org.apache.hadoop.mapreduce.RecordReader#nextKeyValue()
  77. */
  78. @Override
  79. public boolean nextKeyValue() throws IOException, InterruptedException {
  80. return baseRecordReader.nextKeyValue();
  81. }
  82. /* (non-Javadoc)
  83. * @see org.apache.hadoop.mapreduce.RecordReader#close()
  84. */
  85. @Override
  86. public void close() throws IOException {
  87. baseRecordReader.close();
  88. }
  89. }