Skip to content
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

PARQUET-2333: Support bzip2 and xz compression in the to-avro subcommand #1131

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions parquet-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@
<artifactId>avro</artifactId>
<version>${avro.version}</version>
</dependency>
<dependency>
<groupId>org.tukaani</groupId>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it have any license issue? And what about its dependency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it has no license issue, since its Java implementation is public domain, which is classified into Category A. It also doesn't seem to have any dependent libraries.

As other examples, Druid, HBase and Spark already include it.
https://github.com/apache/druid/blob/druid-27.0.0/pom.xml#L527-L531
https://github.com/apache/hbase/blob/rel/2.5.5/pom.xml#L1470-L1474
https://github.com/apache/spark/blob/v3.4.1/pom.xml#L1489-L1493

<artifactId>xz</artifactId>
<version>${tukaani.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.github.luben</groupId>
<artifactId>zstd-jni</artifactId>
Expand Down
32 changes: 19 additions & 13 deletions parquet-cli/src/main/java/org/apache/parquet/cli/util/Codecs.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.apache.parquet.cli.util;

import org.apache.avro.AvroRuntimeException;
import org.apache.avro.file.CodecFactory;
import org.apache.parquet.hadoop.metadata.CompressionCodecName;

Expand All @@ -34,19 +35,24 @@ public static CompressionCodecName parquetCodec(String codec) {
}

public static CodecFactory avroCodec(String codec) {
CompressionCodecName parquetCodec = parquetCodec(codec);
switch (parquetCodec) {
case UNCOMPRESSED:
return CodecFactory.nullCodec();
case SNAPPY:
return CodecFactory.snappyCodec();
case GZIP:
return CodecFactory.deflateCodec(9);
case ZSTD:
return CodecFactory.zstandardCodec(CodecFactory.DEFAULT_ZSTANDARD_LEVEL);
default:
throw new IllegalArgumentException(
"Codec incompatible with Avro: " + codec);
String avroCodec;
if (codec.equalsIgnoreCase(CompressionCodecName.GZIP.name())) {
avroCodec = "deflate";
} else if (codec.equalsIgnoreCase(CompressionCodecName.SNAPPY.name())) {
avroCodec = "snappy";
} else if (codec.equalsIgnoreCase(CompressionCodecName.UNCOMPRESSED.name())) {
avroCodec = "null";
} else if (codec.equalsIgnoreCase(CompressionCodecName.ZSTD.name())) {
avroCodec = "zstandard";
} else {
avroCodec = codec;
}
CodecFactory factory;
try {
factory = CodecFactory.fromString(avroCodec);
} catch (AvroRuntimeException e) {
throw new IllegalArgumentException("Codec incompatible with Avro: " + codec, e);
}
return factory;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ public void testToAvroCommandWithZstdCompression() throws IOException {
Assert.assertTrue(avroFile.exists());
}

@Test
public void testToAvroCommandWithBzip2Compression() throws IOException {
File avroFile = toAvro(parquetFile(), "bzip2");
Assert.assertTrue(avroFile.exists());
}

@Test
public void testToAvroCommandWithXzCompression() throws IOException {
File avroFile = toAvro(parquetFile(), "xz");
Assert.assertTrue(avroFile.exists());
}

@Test(expected = IllegalArgumentException.class)
public void testToAvroCommandWithInvalidCompression() throws IOException {
toAvro(parquetFile(), "FOO");
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
<!-- parquet-cli dependencies -->
<opencsv.version>2.3</opencsv.version>
<jcommander.version>1.82</jcommander.version>
<tukaani.version>1.9</tukaani.version>
<zstd-jni.version>1.5.0-1</zstd-jni.version>
<commons-text.version>1.8</commons-text.version>
<jsr305.version>3.0.2</jsr305.version>
Expand Down