Search in sources :

Example 1 with FileMetadata

use of org.apache.drill.exec.store.parquet.metadata.Metadata_V4.FileMetadata in project drill by apache.

the class Metadata method writeFile.

/**
 * Serialize parquet metadata to json and write to a file.
 *
 * @param parquetMetadata parquet table or directory metadata
 * @param p file path
 * @param fs Drill file system
 * @throws IOException if metadata can't be serialized
 */
private void writeFile(Object parquetMetadata, Path p, FileSystem fs) throws IOException {
    JsonFactory jsonFactory = new JsonFactory();
    jsonFactory.configure(Feature.AUTO_CLOSE_TARGET, false);
    jsonFactory.configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, false);
    ObjectMapper mapper = new ObjectMapper(jsonFactory);
    SimpleModule module = new SimpleModule();
    module.addSerializer(Path.class, new PathSerDe.Se());
    if (parquetMetadata instanceof Metadata_V4.FileMetadata) {
        module.addSerializer(ColumnMetadata_v4.class, new ColumnMetadata_v4.Serializer());
    }
    mapper.registerModule(module);
    OutputStream os = fs.create(p);
    mapper.writerWithDefaultPrettyPrinter().writeValue(os, parquetMetadata);
    os.flush();
    os.close();
}
Also used : ColumnMetadata_v4(org.apache.drill.exec.store.parquet.metadata.Metadata_V4.ColumnMetadata_v4) OutputStream(java.io.OutputStream) JsonFactory(com.fasterxml.jackson.core.JsonFactory) FileMetadata(org.apache.drill.exec.store.parquet.metadata.Metadata_V4.FileMetadata) ParquetFileMetadata(org.apache.drill.exec.store.parquet.metadata.MetadataBase.ParquetFileMetadata) PathSerDe(org.apache.drill.exec.serialization.PathSerDe) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule)

Aggregations

JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)1 OutputStream (java.io.OutputStream)1 PathSerDe (org.apache.drill.exec.serialization.PathSerDe)1 ParquetFileMetadata (org.apache.drill.exec.store.parquet.metadata.MetadataBase.ParquetFileMetadata)1 ColumnMetadata_v4 (org.apache.drill.exec.store.parquet.metadata.Metadata_V4.ColumnMetadata_v4)1 FileMetadata (org.apache.drill.exec.store.parquet.metadata.Metadata_V4.FileMetadata)1