-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add airlift compression codec based compressors and decompressors
- Loading branch information
1 parent
62ce7a4
commit b9a7dbe
Showing
12 changed files
with
236 additions
and
33 deletions.
There are no files selected for viewing
This file contains 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
58 changes: 58 additions & 0 deletions
58
parquet-hadoop/src/main/java/org/apache/parquet/hadoop/AirliftCompressor.java
This file contains 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,58 @@ | ||
/* | ||
* 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.parquet.hadoop; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import org.apache.hadoop.io.compress.CompressionCodec; | ||
import org.apache.hadoop.io.compress.CompressionOutputStream; | ||
import org.apache.hadoop.io.compress.Compressor; | ||
import org.apache.parquet.bytes.BytesInput; | ||
import org.apache.parquet.compression.CompressionCodecFactory; | ||
import org.apache.parquet.hadoop.metadata.CompressionCodecName; | ||
|
||
public class AirliftCompressor implements CompressionCodecFactory.BytesInputCompressor { | ||
private final Compressor compressor; | ||
private final ByteArrayOutputStream compressedOutBuffer; | ||
private final CompressionCodec codec; | ||
|
||
AirliftCompressor(CompressionCodec codec, int pageSize) { | ||
this.codec = codec; | ||
this.compressor = codec.createCompressor(); | ||
this.compressedOutBuffer = new ByteArrayOutputStream(pageSize); | ||
} | ||
|
||
@Override | ||
public BytesInput compress(BytesInput bytes) throws IOException { | ||
compressedOutBuffer.reset(); | ||
CompressionOutputStream cos = codec.createOutputStream(compressedOutBuffer, compressor); | ||
bytes.writeAllTo(cos); | ||
cos.finish(); | ||
cos.close(); | ||
return BytesInput.from(compressedOutBuffer); | ||
} | ||
|
||
@Override | ||
public CompressionCodecName getCodecName() { | ||
return CompressionCodecName.GZIP; | ||
} | ||
|
||
@Override | ||
public void release() {} | ||
} |
82 changes: 82 additions & 0 deletions
82
parquet-hadoop/src/main/java/org/apache/parquet/hadoop/AirliftCompressorCodecFactory.java
This file contains 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,82 @@ | ||
/* | ||
* 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.parquet.hadoop; | ||
|
||
import io.airlift.compress.gzip.JdkGzipCodec; | ||
import io.airlift.compress.lz4.Lz4Codec; | ||
import io.airlift.compress.lzo.LzoCodec; | ||
import org.apache.parquet.compression.CompressionCodecFactory; | ||
import org.apache.parquet.hadoop.codec.SnappyCodec; | ||
import org.apache.parquet.hadoop.metadata.CompressionCodecName; | ||
|
||
public class AirliftCompressorCodecFactory implements CompressionCodecFactory { | ||
|
||
private final int pageSize; | ||
|
||
AirliftCompressorCodecFactory(int pageSize) { | ||
this.pageSize = pageSize; | ||
} | ||
|
||
@Override | ||
public BytesInputCompressor getCompressor(CompressionCodecName codecName) { | ||
switch (codecName.getParquetCompressionCodec()) { | ||
case GZIP: | ||
return new AirliftCompressor(new JdkGzipCodec(), pageSize); | ||
case SNAPPY: | ||
return new AirliftCompressor(new SnappyCodec(), pageSize); | ||
case LZO: | ||
return new AirliftCompressor(new LzoCodec(), pageSize); | ||
case LZ4: | ||
return new AirliftCompressor(new Lz4Codec(), pageSize); | ||
default: | ||
throw new IllegalArgumentException("Codec not supported in AirliftCompressorCodecFactory: " + codecName); | ||
} | ||
} | ||
|
||
@Override | ||
public BytesInputDecompressor getDecompressor(CompressionCodecName codecName) { | ||
switch (codecName.getParquetCompressionCodec()) { | ||
case GZIP: | ||
return new AirliftDecompressor(new JdkGzipCodec()); | ||
case SNAPPY: | ||
return new AirliftDecompressor(new SnappyCodec()); | ||
case LZO: | ||
return new AirliftDecompressor(new LzoCodec()); | ||
case LZ4: | ||
return new AirliftDecompressor(new Lz4Codec()); | ||
default: | ||
throw new IllegalArgumentException("Codec not supported in AirliftCompressorCodecFactory: " + codecName); | ||
} | ||
} | ||
|
||
@Override | ||
public void release() {} | ||
|
||
static boolean isSupported(CompressionCodecName codecName) { | ||
switch (codecName.getParquetCompressionCodec()) { | ||
case GZIP: | ||
case SNAPPY: | ||
case LZO: | ||
case LZ4: | ||
return true; | ||
default: | ||
return false; | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
parquet-hadoop/src/main/java/org/apache/parquet/hadoop/AirliftDecompressor.java
This file contains 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,54 @@ | ||
/* | ||
* 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.parquet.hadoop; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.ByteBuffer; | ||
import org.apache.hadoop.io.compress.CompressionCodec; | ||
import org.apache.hadoop.io.compress.Decompressor; | ||
import org.apache.parquet.bytes.BytesInput; | ||
import org.apache.parquet.compression.CompressionCodecFactory; | ||
|
||
public class AirliftDecompressor implements CompressionCodecFactory.BytesInputDecompressor { | ||
private CompressionCodec codec; | ||
private final Decompressor decompressor; | ||
|
||
public AirliftDecompressor(CompressionCodec codec) { | ||
this.codec = codec; | ||
decompressor = codec.createDecompressor(); | ||
} | ||
|
||
@Override | ||
public BytesInput decompress(BytesInput bytes, int uncompressedSize) throws IOException { | ||
decompressor.reset(); | ||
InputStream is = codec.createInputStream(bytes.toInputStream(), decompressor); | ||
return BytesInput.from(is, uncompressedSize); | ||
} | ||
|
||
@Override | ||
public void decompress(ByteBuffer input, int compressedSize, ByteBuffer output, int uncompressedSize) | ||
throws IOException { | ||
ByteBuffer decompressed = decompress(BytesInput.from(input), uncompressedSize).toByteBuffer(); | ||
output.put(decompressed); | ||
} | ||
|
||
public void release() {} | ||
} | ||
|
This file contains 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 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 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 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
Oops, something went wrong.