-
Notifications
You must be signed in to change notification settings - Fork 9.1k
WIP. HADOOP-17124. Support LZO Codec using aircompressor #3612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
viirya
wants to merge
5
commits into
apache:trunk
Choose a base branch
from
viirya:lzo
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+910
−0
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
186 changes: 186 additions & 0 deletions
186
...p-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/compress/LzoCodec2.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.hadoop.io.compress; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
import org.apache.hadoop.conf.Configurable; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.fs.CommonConfigurationKeys; | ||
import org.apache.hadoop.io.compress.lzo.LzoCompressor; | ||
import org.apache.hadoop.io.compress.lzo.LzoDecompressor; | ||
|
||
/** | ||
* This class creates lzo compressors/decompressors. | ||
*/ | ||
public class LzoCodec2 implements Configurable, CompressionCodec { | ||
Configuration conf; | ||
|
||
/** | ||
* Set the configuration to be used by this object. | ||
* | ||
* @param conf the configuration object. | ||
*/ | ||
@Override | ||
public void setConf(Configuration conf) { | ||
this.conf = conf; | ||
} | ||
|
||
/** | ||
* Return the configuration used by this object. | ||
* | ||
* @return the configuration object used by this object. | ||
*/ | ||
@Override | ||
public Configuration getConf() { | ||
return conf; | ||
} | ||
|
||
/** | ||
* Create a {@link CompressionOutputStream} that will write to the given | ||
* {@link OutputStream}. | ||
* | ||
* @param out the location for the final output stream | ||
* @return a stream the user can write uncompressed data to have it compressed | ||
* @throws IOException | ||
*/ | ||
@Override | ||
public CompressionOutputStream createOutputStream(OutputStream out) | ||
throws IOException { | ||
return CompressionCodec.Util. | ||
createOutputStreamWithCodecPool(this, conf, out); | ||
} | ||
|
||
/** | ||
* Create a {@link CompressionOutputStream} that will write to the given | ||
* {@link OutputStream} with the given {@link Compressor}. | ||
* | ||
* @param out the location for the final output stream | ||
* @param compressor compressor to use | ||
* @return a stream the user can write uncompressed data to have it compressed | ||
* @throws IOException | ||
*/ | ||
@Override | ||
public CompressionOutputStream createOutputStream(OutputStream out, | ||
Compressor compressor) throws IOException { | ||
int bufferSize = conf.getInt( | ||
CommonConfigurationKeys.IO_COMPRESSION_CODEC_LZO_BUFFERSIZE_KEY, | ||
CommonConfigurationKeys.IO_COMPRESSION_CODEC_LZO_BUFFERSIZE_DEFAULT); | ||
io.airlift.compress.lzo.LzoCodec codec = new io.airlift.compress.lzo.LzoCodec(); | ||
Configuration lzoConf = new Configuration(this.conf); | ||
lzoConf.setInt(CommonConfigurationKeys.IO_COMPRESSION_CODEC_LZO_BUFFERSIZE_KEY, bufferSize); | ||
codec.setConf(lzoConf); | ||
return codec.createOutputStream(out); | ||
} | ||
|
||
/** | ||
* Get the type of {@link Compressor} needed by this {@link CompressionCodec}. | ||
* | ||
* @return the type of compressor needed by this codec. | ||
*/ | ||
@Override | ||
public Class<? extends Compressor> getCompressorType() { | ||
return LzoCompressor.class; | ||
} | ||
|
||
/** | ||
* Create a new {@link Compressor} for use by this {@link CompressionCodec}. | ||
* | ||
* @return a new compressor for use by this codec | ||
*/ | ||
@Override | ||
public Compressor createCompressor() { | ||
int bufferSize = conf.getInt( | ||
CommonConfigurationKeys.IO_COMPRESSION_CODEC_LZO_BUFFERSIZE_KEY, | ||
CommonConfigurationKeys.IO_COMPRESSION_CODEC_LZO_BUFFERSIZE_DEFAULT); | ||
return new LzoCompressor(bufferSize); | ||
} | ||
|
||
/** | ||
* Create a {@link CompressionInputStream} that will read from the given | ||
* input stream. | ||
* | ||
* @param in the stream to read compressed bytes from | ||
* @return a stream to read uncompressed bytes from | ||
* @throws IOException | ||
*/ | ||
@Override | ||
public CompressionInputStream createInputStream(InputStream in) | ||
throws IOException { | ||
return CompressionCodec.Util. | ||
createInputStreamWithCodecPool(this, conf, in); | ||
} | ||
|
||
/** | ||
* Create a {@link CompressionInputStream} that will read from the given | ||
* {@link InputStream} with the given {@link Decompressor}. | ||
* | ||
* @param in the stream to read compressed bytes from | ||
* @param decompressor decompressor to use | ||
* @return a stream to read uncompressed bytes from | ||
* @throws IOException | ||
*/ | ||
@Override | ||
public CompressionInputStream createInputStream(InputStream in, | ||
Decompressor decompressor) throws IOException { | ||
int bufferSize = conf.getInt( | ||
CommonConfigurationKeys.IO_COMPRESSION_CODEC_LZO_BUFFERSIZE_KEY, | ||
CommonConfigurationKeys.IO_COMPRESSION_CODEC_LZO_BUFFERSIZE_DEFAULT); | ||
io.airlift.compress.lzo.LzoCodec codec = new io.airlift.compress.lzo.LzoCodec(); | ||
Configuration lzoConf = new Configuration(this.conf); | ||
lzoConf.setInt(CommonConfigurationKeys.IO_COMPRESSION_CODEC_LZO_BUFFERSIZE_KEY, bufferSize); | ||
codec.setConf(lzoConf); | ||
return codec.createInputStream(in); | ||
} | ||
|
||
/** | ||
* Get the type of {@link Decompressor} needed by this {@link CompressionCodec}. | ||
* | ||
* @return the type of decompressor needed by this codec. | ||
*/ | ||
@Override | ||
public Class<? extends Decompressor> getDecompressorType() { | ||
return LzoDecompressor.class; | ||
} | ||
|
||
/** | ||
* Create a new {@link Decompressor} for use by this {@link CompressionCodec}. | ||
* | ||
* @return a new decompressor for use by this codec | ||
*/ | ||
@Override | ||
public Decompressor createDecompressor() { | ||
int bufferSize = conf.getInt( | ||
CommonConfigurationKeys.IO_COMPRESSION_CODEC_LZO_BUFFERSIZE_KEY, | ||
CommonConfigurationKeys.IO_COMPRESSION_CODEC_LZO_BUFFERSIZE_DEFAULT); | ||
return new LzoDecompressor(bufferSize); | ||
} | ||
|
||
/** | ||
* Get the default filename extension for this kind of compression. | ||
* | ||
* @return <code>.lzo_deflate</code>. | ||
*/ | ||
@Override | ||
public String getDefaultExtension() { | ||
return CodecConstants.LZO_CODEC_EXTENSION; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will rename to
LzoCodec
before merging.