如何使用parquet-avro在镶木地板文件中创建日期类型列

时间:2017-09-22 11:46:46

标签: parquet

我使用基于Java(1.8)的应用程序来创建使用库的镶木地板文件  org.apache.avro.Schema和org.apache.parquet.hadoop.ParquetWriter等..

这是我的示例代码

final String schemaLocation = ParquerWriterImpl.class.getClassLoader()。getResource(" parquet-schema /" + ParquetTypes.RISKINFO.getFileType())。getPath();

        Schema avroSchema = new Schema.Parser().parse(new File(schemaLocation));

        final MessageType parquetSchema = new AvroSchemaConverter().convert(avroSchema);
        final WriteSupport<Mapper> writeSupport = new AvroWriteSupport(parquetSchema, avroSchema);
        final String parquetPath = PropertyLoader.getPropertyLoader().getProperty(Constants.PROPERTY_MACHINE_FOLDERPATH) + "/" +
                parquetFileName;
        final Path path = new Path(parquetPath);
        ParquetWriter<GenericRecord> parquetWriter = new ParquetWriter(path, writeSupport, CompressionCodecName.SNAPPY, BLOCK_SIZE, 1024);
        final GenericRecord record = new GenericData.Record(avroSchema);
        parquetWriter.write(function.apply(new RiskInfoGen(record)));
        parquetWriter.close();  

创建此文件我使用的Avro架构如下所示。

},
  {
     "name": "additional",
    "type": {"type": "map", "values": "string","default" : null}

  },

  {
     "name": "mydate",
     "type": {"type": "int", "logicalType" : "date"}

  }

在POJO I级&#39; m映射&#34; mydate&#34;到Java int类型。

问题1 虽然我在这里获得了镶木地板文件,但在用spark开启该文件之后,&#34; mydate&#34;列显示为int类型而非预期日期类型。

请让我知道如何制作这个&#34; mydate&#34;作为镶木地板图案中的日期列。

例如mydate date(nullable true)

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题。我正在使用Parquet-Avro 1.8.1

切换到1.9.0为我修复了它:

{"name": "birth_date", "type": [{"type": "int", "logicalType" : "date"}, "null"]}"

我将值设置为:

record.put("birth_date", 1);

它在apache spark数据框中显示为 1970-01-02