PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/release-0.1-rc2/hive/external/ql/src/java/org/apache/hadoop/hive/ql/io/HiveSequenceFileOutputFormat.java

#
Java | 79 lines | 34 code | 10 blank | 35 comment | 0 complexity | 493d9982b8210ec798e4924ad16f4227 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 java.util.Properties;
  21. import org.apache.hadoop.fs.FileSystem;
  22. import org.apache.hadoop.fs.Path;
  23. import org.apache.hadoop.hive.ql.exec.Utilities;
  24. import org.apache.hadoop.hive.ql.exec.FileSinkOperator.RecordWriter;
  25. import org.apache.hadoop.io.BytesWritable;
  26. import org.apache.hadoop.io.SequenceFile;
  27. import org.apache.hadoop.io.Writable;
  28. import org.apache.hadoop.io.WritableComparable;
  29. import org.apache.hadoop.mapred.JobConf;
  30. import org.apache.hadoop.mapred.SequenceFileOutputFormat;
  31. import org.apache.hadoop.util.Progressable;
  32. /** A {@link HiveOutputFormat} that writes {@link SequenceFile}s. */
  33. public class HiveSequenceFileOutputFormat extends SequenceFileOutputFormat
  34. implements HiveOutputFormat<WritableComparable, Writable> {
  35. BytesWritable EMPTY_KEY = new BytesWritable();
  36. /**
  37. * create the final out file, and output an empty key as the key.
  38. *
  39. * @param jc
  40. * the job configuration file
  41. * @param finalOutPath
  42. * the final output file to be created
  43. * @param valueClass
  44. * the value class used for create
  45. * @param isCompressed
  46. * whether the content is compressed or not
  47. * @param tableProperties
  48. * the tableInfo of this file's corresponding table
  49. * @param progress
  50. * progress used for status report
  51. * @return the RecordWriter for the output file
  52. */
  53. @Override
  54. public RecordWriter getHiveRecordWriter(JobConf jc, Path finalOutPath,
  55. Class<? extends Writable> valueClass, boolean isCompressed,
  56. Properties tableProperties, Progressable progress) throws IOException {
  57. FileSystem fs = finalOutPath.getFileSystem(jc);
  58. final SequenceFile.Writer outStream = Utilities.createSequenceWriter(jc,
  59. fs, finalOutPath, BytesWritable.class, valueClass, isCompressed);
  60. return new RecordWriter() {
  61. public void write(Writable r) throws IOException {
  62. outStream.append(EMPTY_KEY, r);
  63. }
  64. public void close(boolean abort) throws IOException {
  65. outStream.close();
  66. }
  67. };
  68. }
  69. }