2727import com .google .common .collect .Lists ;
2828import java .io .IOException ;
2929import java .util .List ;
30+ import java .util .Set ;
31+ import java .util .HashSet ;
3032import org .apache .commons .text .TextStringBuilder ;
3133import org .apache .parquet .cli .BaseCommand ;
3234import 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 ("\n File 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}
0 commit comments