parquet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject parquet-mr git commit: PARQUET-318: Remove unnecessary object mapper
Date Wed, 16 Dec 2015 19:41:53 GMT
Repository: parquet-mr
Updated Branches:
  refs/heads/master fa7588c4c -> 367fe13b4


PARQUET-318: Remove unnecessary object mapper

Author: Nezih Yigitbasi <nyigitbasi@netflix.com>

Closes #227 from nezihyigitbasi/318 and squashes the following commits:

b8e4ca9 [Nezih Yigitbasi] Remove unnecessary object mapper


Project: http://git-wip-us.apache.org/repos/asf/parquet-mr/repo
Commit: http://git-wip-us.apache.org/repos/asf/parquet-mr/commit/367fe13b
Tree: http://git-wip-us.apache.org/repos/asf/parquet-mr/tree/367fe13b
Diff: http://git-wip-us.apache.org/repos/asf/parquet-mr/diff/367fe13b

Branch: refs/heads/master
Commit: 367fe13b46a0b4dda56b7f12273d6c9afb1da23f
Parents: fa7588c
Author: Nezih Yigitbasi <nyigitbasi@netflix.com>
Authored: Wed Dec 16 11:41:46 2015 -0800
Committer: Ryan Blue <blue@apache.org>
Committed: Wed Dec 16 11:41:46 2015 -0800

----------------------------------------------------------------------
 .../parquet/hadoop/metadata/ParquetMetadata.java | 19 ++++++++++---------
 .../converter/TestParquetMetadataConverter.java  | 12 +++++++++++-
 2 files changed, 21 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/parquet-mr/blob/367fe13b/parquet-hadoop/src/main/java/org/apache/parquet/hadoop/metadata/ParquetMetadata.java
----------------------------------------------------------------------
diff --git a/parquet-hadoop/src/main/java/org/apache/parquet/hadoop/metadata/ParquetMetadata.java
b/parquet-hadoop/src/main/java/org/apache/parquet/hadoop/metadata/ParquetMetadata.java
index d35582a..a645117 100644
--- a/parquet-hadoop/src/main/java/org/apache/parquet/hadoop/metadata/ParquetMetadata.java
+++ b/parquet-hadoop/src/main/java/org/apache/parquet/hadoop/metadata/ParquetMetadata.java
@@ -27,6 +27,7 @@ import org.codehaus.jackson.JsonGenerationException;
 import org.codehaus.jackson.JsonParseException;
 import org.codehaus.jackson.map.JsonMappingException;
 import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.ObjectWriter;
 import org.codehaus.jackson.map.SerializationConfig.Feature;
 
 /**
@@ -38,11 +39,7 @@ import org.codehaus.jackson.map.SerializationConfig.Feature;
  */
 public class ParquetMetadata {
 
-  private static ObjectMapper objectMapper = new ObjectMapper();
-  private static ObjectMapper prettyObjectMapper = new ObjectMapper();
-  static {
-    prettyObjectMapper.configure(Feature.INDENT_OUTPUT, true);
-  }
+  private static final ObjectMapper objectMapper = new ObjectMapper();
 
   /**
    *
@@ -50,7 +47,7 @@ public class ParquetMetadata {
    * @return the json representation
    */
   public static String toJSON(ParquetMetadata parquetMetaData) {
-    return toJSON(parquetMetaData, objectMapper);
+    return toJSON(parquetMetaData, false);
   }
 
   /**
@@ -59,13 +56,17 @@ public class ParquetMetadata {
    * @return the pretty printed json representation
    */
   public static String toPrettyJSON(ParquetMetadata parquetMetaData) {
-    return toJSON(parquetMetaData, prettyObjectMapper);
+    return toJSON(parquetMetaData, true);
   }
 
-  private static String toJSON(ParquetMetadata parquetMetaData, ObjectMapper mapper) {
+  private static String toJSON(ParquetMetadata parquetMetaData, boolean isPrettyPrint) {
     StringWriter stringWriter = new StringWriter();
     try {
-      mapper.writeValue(stringWriter, parquetMetaData);
+      if (isPrettyPrint) {
+        objectMapper.writerWithDefaultPrettyPrinter().writeValue(stringWriter, parquetMetaData);
+      } else {
+        objectMapper.writeValue(stringWriter, parquetMetaData);
+      }
     } catch (JsonGenerationException e) {
       throw new RuntimeException(e);
     } catch (JsonMappingException e) {

http://git-wip-us.apache.org/repos/asf/parquet-mr/blob/367fe13b/parquet-hadoop/src/test/java/org/apache/parquet/format/converter/TestParquetMetadataConverter.java
----------------------------------------------------------------------
diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/format/converter/TestParquetMetadataConverter.java
b/parquet-hadoop/src/test/java/org/apache/parquet/format/converter/TestParquetMetadataConverter.java
index e44d140..eb109c0 100644
--- a/parquet-hadoop/src/test/java/org/apache/parquet/format/converter/TestParquetMetadataConverter.java
+++ b/parquet-hadoop/src/test/java/org/apache/parquet/format/converter/TestParquetMetadataConverter.java
@@ -262,7 +262,7 @@ public class TestParquetMetadataConverter {
   }
 
   @Test
-  public void testNullFieldMetadataDebugLogging() throws NoSuchFieldException, IllegalAccessException,
IOException {
+  public void testNullFieldMetadataDebugLogging() {
     MessageType schema = parseMessageType("message test { optional binary some_null_field;
}");
     org.apache.parquet.hadoop.metadata.FileMetaData fileMetaData = new org.apache.parquet.hadoop.metadata.FileMetaData(schema,
new HashMap<String, String>(), null);
     List<BlockMetaData> blockMetaDataList = new ArrayList<BlockMetaData>();
@@ -273,6 +273,16 @@ public class TestParquetMetadataConverter {
     ParquetMetadata.toJSON(metadata);
   }
 
+  @Test
+  public void testMetadataToJson() {
+    ParquetMetadata metadata = new ParquetMetadata(null, null);
+    assertEquals("{\"fileMetaData\":null,\"blocks\":null}", ParquetMetadata.toJSON(metadata));
+    assertEquals("{\n" +
+            "  \"fileMetaData\" : null,\n" +
+            "  \"blocks\" : null\n" +
+            "}", ParquetMetadata.toPrettyJSON(metadata));
+  }
+
   private ColumnChunkMetaData createColumnChunkMetaData() {
     Set<org.apache.parquet.column.Encoding> e = new HashSet<org.apache.parquet.column.Encoding>();
     PrimitiveTypeName t = PrimitiveTypeName.BINARY;


Mime
View raw message