diff --git a/parquet-column/src/main/java/org/apache/parquet/column/ParquetProperties.java b/parquet-column/src/main/java/org/apache/parquet/column/ParquetProperties.java index 9aaef4b3cf..cb5931581f 100644 --- a/parquet-column/src/main/java/org/apache/parquet/column/ParquetProperties.java +++ b/parquet-column/src/main/java/org/apache/parquet/column/ParquetProperties.java @@ -708,6 +708,7 @@ public Builder withStatisticsEnabled(String columnPath, boolean enabled) { } public Builder withStatisticsEnabled(boolean enabled) { + this.statistics.withDefaultValue(enabled); this.statisticsEnabled = enabled; return this; } diff --git a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestParquetWriter.java b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestParquetWriter.java index c8e8f71a91..739aa85d2c 100644 --- a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestParquetWriter.java +++ b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestParquetWriter.java @@ -543,7 +543,7 @@ private void testParquetFileNumberOfBlocks( } @Test - public void testSizeStatisticsControl() throws Exception { + public void testSizeStatisticsAndStatisticsControl() throws Exception { MessageType schema = Types.buildMessage() .required(BINARY) .named("string_field") @@ -568,6 +568,7 @@ public void testSizeStatisticsControl() throws Exception { try (ParquetWriter writer = ExampleParquetWriter.builder(path) .withType(schema) .withSizeStatisticsEnabled(false) + .withStatisticsEnabled(false) // Disable column statistics globally .build()) { writer.write(group); } @@ -576,6 +577,7 @@ public void testSizeStatisticsControl() throws Exception { // Verify size statistics are disabled globally for (BlockMetaData block : reader.getFooter().getBlocks()) { for (ColumnChunkMetaData column : block.getColumns()) { + assertTrue(column.getStatistics().isEmpty()); // Make sure there is no column statistics assertNull(column.getSizeStatistics()); } } @@ -589,6 +591,7 @@ public void testSizeStatisticsControl() throws Exception { .withType(schema) .withSizeStatisticsEnabled(true) // enable globally .withSizeStatisticsEnabled("boolean_field", false) // disable for specific column + .withStatisticsEnabled("boolean_field", false) // disable column statistics .build()) { writer.write(group); } @@ -599,8 +602,10 @@ public void testSizeStatisticsControl() throws Exception { for (ColumnChunkMetaData column : block.getColumns()) { if (column.getPath().toDotString().equals("boolean_field")) { assertNull(column.getSizeStatistics()); + assertTrue(column.getStatistics().isEmpty()); } else { assertTrue(column.getSizeStatistics().isValid()); + assertFalse(column.getStatistics().isEmpty()); } } }