#NEWLINE# def _dump( fo , options , out = sys . stdout ) : #NEWLINE# #INDENT# def println( value ) : #NEWLINE# #INDENT# out . write ( ( value + '\n' ) ) #NEWLINE# #UNINDENT# footer = _read_footer ( fo ) #NEWLINE# schema_helper = schema . SchemaHelper ( footer . schema ) #NEWLINE# total_count = 0 #NEWLINE# for rg in footer . row_groups : #NEWLINE# #INDENT# res = defaultdict ( list ) #NEWLINE# row_group_rows = rg . num_rows #NEWLINE# for ( idx , cg ) in enumerate ( rg . columns ) : #NEWLINE# #INDENT# dict_items = [ ] #NEWLINE# cmd = cg . meta_data #NEWLINE# if ( options . col and ( not ( '.' . join ( cmd . path_in_schema ) in options . col ) ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# offset = _get_offset ( cmd ) #NEWLINE# fo . seek ( offset , 0 ) #NEWLINE# values_seen = 0 #NEWLINE# logger . debug ( 'reading column chunk of type: %s' , _get_name ( Type , cmd . type ) ) #NEWLINE# while ( values_seen < row_group_rows ) : #NEWLINE# #INDENT# ph = _read_page_header ( fo ) #NEWLINE# logger . debug ( 'Reading page (type=%s, uncompressed=%s bytes, compressed=%s bytes)' , _get_name ( PageType , ph . type ) , ph . uncompressed_page_size , ph . compressed_page_size ) #NEWLINE# if ( ph . type == PageType . DATA_PAGE ) : #NEWLINE# #INDENT# values = read_data_page ( cg , schema_helper , ph , cmd , dict_items ) #NEWLINE# res [ '.' . join ( cmd . path_in_schema ) ] += values #NEWLINE# values_seen += ph . data_page_header . num_values #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ph . type == PageType . DICTIONARY_PAGE ) : #NEWLINE# #INDENT# logger . debug ( ph ) #NEWLINE# assert ( dict_items == [ ] ) #NEWLINE# dict_items = read_dictionary_page ( fo , ph , cmd ) #NEWLINE# logger . debug ( 'Dictionary: %s' , str ( dict_items ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# logger . warn ( 'Skipping unknown page type={0}' . format ( _get_name ( PageType , ph . type ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# keys = ( options . col if options . col else [ s . name for s in footer . schema if ( s . name in res ) ] ) #NEWLINE# if ( options . format == 'custom' ) : #NEWLINE# #INDENT# custom_datatype = out ( res , keys ) #NEWLINE# return custom_datatype #NEWLINE# #UNINDENT# if ( ( options . format == 'csv' ) and ( not options . no_headers ) ) : #NEWLINE# #INDENT# println ( '\t' . join ( keys ) ) #NEWLINE# #UNINDENT# for i in range ( rg . num_rows ) : #NEWLINE# #INDENT# if ( ( options . limit != ( - 1 ) ) and ( ( i + total_count ) >= options . limit ) ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# if ( options . format == 'csv' ) : #NEWLINE# #INDENT# println ( '\t' . join ( ( str ( res [ k ] [ i ] ) for k in keys ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( options . format == 'json' ) : #NEWLINE# #INDENT# println ( json . dumps ( dict ( [ ( k , res [ k ] [ i ] ) for k in keys ] ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# total_count += rg . num_rows