Skip to content

Commit b1ef8ce

Browse files
committed
update
1 parent 6d2635b commit b1ef8ce

2 files changed

Lines changed: 55 additions & 4 deletions

File tree

parquet-cli/src/main/java/org/apache/parquet/cli/commands/ShowSizeStatisticsCommand.java

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import com.google.common.collect.Lists;
2828
import java.io.IOException;
2929
import java.util.List;
30+
import java.util.Set;
31+
import java.util.HashSet;
3032
import org.apache.commons.text.TextStringBuilder;
3133
import org.apache.parquet.cli.BaseCommand;
3234
import org.apache.parquet.column.statistics.SizeStatistics;
@@ -47,6 +49,16 @@ public ShowSizeStatisticsCommand(Logger console) {
4749
@Parameter(description = "<parquet path>")
4850
List<String> targets;
4951

52+
@Parameter(
53+
names = {"-c", "--column", "--columns"},
54+
description = "List of columns (dot paths) to include")
55+
List<String> columns;
56+
57+
@Parameter(
58+
names = {"-r", "--row-group", "--row-groups"},
59+
description = "List of row-group indexes to include (0-based)")
60+
List<Integer> rowGroups;
61+
5062
@Override
5163
@SuppressWarnings("unchecked")
5264
public int run() throws IOException {
@@ -60,9 +72,13 @@ public int run() throws IOException {
6072

6173
console.info("\nFile path: {}", source);
6274

63-
List<BlockMetaData> rowGroups = footer.getBlocks();
64-
for (int index = 0, n = rowGroups.size(); index < n; index++) {
65-
printRowGroupSizeStats(console, index, rowGroups.get(index), schema);
75+
List<BlockMetaData> blocks = footer.getBlocks();
76+
Set<Integer> allowedRowGroups = rowGroups == null ? null : new HashSet<>(rowGroups);
77+
for (int index = 0, n = blocks.size(); index < n; index++) {
78+
if (allowedRowGroups != null && !allowedRowGroups.contains(index)) {
79+
continue;
80+
}
81+
printRowGroupSizeStats(console, index, blocks.get(index), schema);
6682
console.info("");
6783
}
6884
}
@@ -84,7 +100,16 @@ private void printRowGroupSizeStats(Logger console, int index, BlockMetaData row
84100
console.info(
85101
String.format(formatString, "column", "unencoded bytes", "rep level histogram", "def level histogram"));
86102

103+
Set<String> allowedColumns = null;
104+
if (columns != null && !columns.isEmpty()) {
105+
allowedColumns = new HashSet<>(columns);
106+
}
107+
87108
for (ColumnChunkMetaData column : rowGroup.getColumns()) {
109+
String dotPath = column.getPath().toDotString();
110+
if (allowedColumns != null && !allowedColumns.contains(dotPath)) {
111+
continue;
112+
}
88113
printColumnSizeStats(console, column, schema, maxColumnWidth);
89114
}
90115
}
@@ -111,6 +136,12 @@ private void printColumnSizeStats(Logger console, ColumnChunkMetaData column, Me
111136

112137
@Override
113138
public List<String> getExamples() {
114-
return Lists.newArrayList("# Show size statistics for a Parquet file", "sample.parquet");
139+
return Lists.newArrayList(
140+
"# Show size statistics for a Parquet file",
141+
"sample.parquet",
142+
"# Show size statistics for selected columns",
143+
"sample.parquet -c name,tags",
144+
"# Show size statistics for a specific row-group",
145+
"sample.parquet -r 0");
115146
}
116147
}

parquet-cli/src/test/java/org/apache/parquet/cli/commands/ShowSizeStatisticsCommandTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,24 @@ public void testShowSizeStatisticsCommand() throws IOException {
3434
command.setConf(new Configuration());
3535
Assert.assertEquals(0, command.run());
3636
}
37+
38+
@Test
39+
public void testShowSizeStatisticsWithColumnFilter() throws IOException {
40+
File file = parquetFile();
41+
ShowSizeStatisticsCommand command = new ShowSizeStatisticsCommand(createLogger());
42+
command.targets = Arrays.asList(file.getAbsolutePath());
43+
command.columns = Arrays.asList(INT32_FIELD, INT64_FIELD);
44+
command.setConf(new Configuration());
45+
Assert.assertEquals(0, command.run());
46+
}
47+
48+
@Test
49+
public void testShowSizeStatisticsWithRowGroupFilter() throws IOException {
50+
File file = parquetFile();
51+
ShowSizeStatisticsCommand command = new ShowSizeStatisticsCommand(createLogger());
52+
command.targets = Arrays.asList(file.getAbsolutePath());
53+
command.rowGroups = Arrays.asList(0);
54+
command.setConf(new Configuration());
55+
Assert.assertEquals(0, command.run());
56+
}
3757
}

0 commit comments

Comments
 (0)