shangxinli commented on a change in pull request #793: URL: https://github.com/apache/parquet-mr/pull/793#discussion_r432142474
########## File path: parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestZstandardCodec.java ########## @@ -0,0 +1,146 @@ +/* + * 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 org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.io.LongWritable; +import org.apache.hadoop.io.Text; +import org.apache.hadoop.io.compress.CompressionOutputStream; +import org.apache.hadoop.mapred.JobClient; +import org.apache.hadoop.mapred.JobConf; +import org.apache.hadoop.mapred.OutputCollector; +import org.apache.hadoop.mapred.Reporter; +import org.apache.hadoop.mapred.RunningJob; +import org.apache.hadoop.mapred.TextInputFormat; +import org.apache.parquet.bytes.BytesInput; +import org.apache.parquet.example.data.Group; +import org.apache.parquet.example.data.simple.SimpleGroupFactory; +import org.apache.parquet.hadoop.codec.ZstandardCodec; +import org.apache.parquet.hadoop.example.GroupWriteSupport; +import org.apache.parquet.hadoop.mapred.DeprecatedParquetOutputFormat; +import org.apache.parquet.hadoop.metadata.CompressionCodecName; +import org.apache.parquet.schema.MessageTypeParser; +import org.junit.Assert; +import org.junit.Test; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.util.Random; + +public class TestZstandardCodec { + + private final Path inputPath = new Path("src/test/java/org/apache/parquet/hadoop/example/TestInputOutputFormat.java"); + + @Test + public void testZstdCodec() throws IOException { + ZstandardCodec codec = new ZstandardCodec(); + Configuration conf = new Configuration(); + int[] levels = {1, 4, 7, 10, 13, 16, 19, 22}; + int[] dataSizes = {0, 1, 10, 1024, 1024 * 1024}; + + for (int i = 0; i < levels.length; i++) { + conf.setInt(ZstandardCodec.PARQUET_COMPRESS_ZSTD_LEVEL, levels[i]); + codec.setConf(conf); + for (int j = 0; j < dataSizes.length; j++) { + testZstd(codec, dataSizes[j]); + } + } + } + + private void testZstd(ZstandardCodec codec, int dataSize) throws IOException { + byte[] data = new byte[dataSize]; + (new Random()).nextBytes(data); + BytesInput compressedData = compress(codec, BytesInput.from(data)); + BytesInput decompressedData = decompress(codec, compressedData, data.length); + Assert.assertArrayEquals(data, decompressedData.toByteArray()); + } + + private BytesInput compress(ZstandardCodec codec, BytesInput bytes) throws IOException { + ByteArrayOutputStream compressedOutBuffer = new ByteArrayOutputStream((int)bytes.size()); + CompressionOutputStream cos = codec.createOutputStream(compressedOutBuffer, null); + bytes.writeAllTo(cos); + cos.close(); + return BytesInput.from(compressedOutBuffer); + } + + private BytesInput decompress(ZstandardCodec codec, BytesInput bytes, int uncompressedSize) throws IOException { + BytesInput decompressed; + InputStream is = codec.createInputStream(bytes.toInputStream(), null); + decompressed = BytesInput.from(is, uncompressedSize); + is.close(); + return decompressed; + } + + @Test + public void testZstdConfWithMr() throws Exception { + JobConf jobConf = new JobConf(); + Configuration conf = new Configuration(); + jobConf.setInt(ZstandardCodec.PARQUET_COMPRESS_ZSTD_LEVEL, 18); + jobConf.setInt(ZstandardCodec.PARQUET_COMPRESS_ZSTD_LEVEL, 4); + RunningJob mapRedJob = runMapReduceJob(CompressionCodecName.ZSTD, jobConf, conf); + assert(mapRedJob.isSuccessful()); + } + + private RunningJob runMapReduceJob(CompressionCodecName codec, JobConf jobConf, Configuration conf) throws IOException, ClassNotFoundException, InterruptedException { Review comment: I set breakpoint and checked it. But I don't know how to get back the level/workers at the MR job. Any ideal how to do that? I also verified it in the standalone Spark application. Do you think that is sufficient? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
