ParquetWriter在java独立程序中输出空的镶木地板文件

时间:2016-06-20 01:44:49

标签: hadoop avro parquet

我尝试将现有的avro文件转换为镶木地板。但输出镶木地板文件是空的。我不确定我做错了什么......

我的代码段:

    FileReader<GenericRecord> fileReader = DataFileReader.openReader(
            new File("output/users.avro"), new GenericDatumReader<GenericRecord>());

    Schema avroSchema = fileReader.getSchema();

    // generate the corresponding Parquet schema
    MessageType parquetSchema = new AvroSchemaConverter().convert(avroSchema);

    // choose compression scheme
    CompressionCodecName compressionCodecName = CompressionCodecName.UNCOMPRESSED;

    // set Parquet file block size and page size values
    int pageSize = 64 * 1024;

    Path outputPath = new Path("output/users.parquet");

    // create a parquet writer using builder
    ParquetWriter parquetWriter = (ParquetWriter) AvroParquetWriter.builder(outputPath)
            .withSchema(avroSchema)
            .withCompressionCodec(compressionCodecName)
            .withPageSize(pageSize)
            .build();

    // read avro, write parquet
    while (fileReader.hasNext()) {
        GenericRecord record = fileReader.next();

        System.out.println(record);

        parquetWriter.write(record);
    }

1 个答案:

答案 0 :(得分:2)

我遇到了同样的问题,发现我需要在将数据提交到文件之前关闭parquetWriter。它只需要你添加

parquetWriter.close();
在while循环之后