Skip to content

Conversation

@wgtmac
Copy link
Member

@wgtmac wgtmac commented Dec 8, 2022

This patch adds a parquet file generated by parquet-mr with following attributes:

  • a single column with fixed_length_byte_array type of size 4.
  • values are ordered in the descending order.
  • in total 1000 values written into 10 pages, with some random null values.
  • page index is generated.

After this file has been committed, I can go ahead to finish test cases required for page index in the apache/arrow#14803

Below is the complete java code to generate the file:

package org.apache.parquet.cli.commands;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.parquet.column.ParquetProperties;
import org.apache.parquet.example.data.Group;
import org.apache.parquet.example.data.simple.SimpleGroupFactory;
import org.apache.parquet.hadoop.ParquetWriter;
import org.apache.parquet.hadoop.example.GroupWriteSupport;
import org.apache.parquet.hadoop.metadata.CompressionCodecName;
import org.apache.parquet.io.api.Binary;
import org.apache.parquet.schema.MessageType;
import org.apache.parquet.schema.PrimitiveType;
import org.apache.parquet.schema.Types;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Random;

public class GenerateTestFile {

  public static void main(String[] args) {
    Path path = new Path("/tmp/fixed_length_byte_array.parquet");
    Configuration conf = new Configuration();

    MessageType schema = Types.buildMessage()
      .required(PrimitiveType.PrimitiveTypeName.FIXED_LEN_BYTE_ARRAY).length(4)
      .named("flba_field")
      .named("schema");
    SimpleGroupFactory fact = new SimpleGroupFactory(schema);
    GroupWriteSupport.setSchema(schema, conf);

    try (
      ParquetWriter<Group> writer = new ParquetWriter<>(
        path,
        new GroupWriteSupport(),
        CompressionCodecName.UNCOMPRESSED,
        /*blockSize=*/1024 * 1024,
        /*pageSize=*/128,
        /*dictionaryPageSize=*/128,
        /*enableDictionary=*/false,
        /*validating=*/false,
        ParquetProperties.WriterVersion.PARQUET_1_0,
        conf)) {

      Random rnd = new Random();
      for (int i = 1000; i > 0; --i) {
        if (rnd.nextInt(10) == 5) {
          writer.write(fact.newGroup());
        } else {
          ByteBuffer buffer = ByteBuffer.allocate(Integer.BYTES);
          writer.write(fact.newGroup()
            .append("flba_field",
              Binary.fromConstantByteArray(buffer.putInt(0, i).array())));
        }
      }
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }

}

@wgtmac
Copy link
Member Author

wgtmac commented Dec 8, 2022

@pitrou @emkornfield Can you please take a look? Thanks!

@pitrou pitrou changed the title ARROW-18420: Add fixed_length_byte_array.parquet for page index test ARROW-18420: [Parquet] Add fixed_length_byte_array.parquet for page index test Dec 8, 2022
Copy link
Member

@pitrou pitrou left a comment

Choose a reason for hiding this comment

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

Nice, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants