@@ -332,45 +332,28 @@ impl DataFrame {
332332 let original_schema_fields = self . schema ( ) . fields ( ) . iter ( ) ;
333333
334334 //define describe column
335- let mut describe_schemas = original_schema_fields
336- . clone ( )
337- . map ( |field| {
338- if field. data_type ( ) . is_numeric ( ) {
339- Field :: new ( field. name ( ) , DataType :: Float64 , true )
340- } else {
341- Field :: new ( field. name ( ) , DataType :: Utf8 , true )
342- }
343- } )
344- . collect :: < Vec < _ > > ( ) ;
345- describe_schemas. insert ( 0 , Field :: new ( "describe" , DataType :: Utf8 , false ) ) ;
335+ let mut describe_schemas = vec ! [ Field :: new( "describe" , DataType :: Utf8 , false ) ] ;
336+ describe_schemas. extend ( original_schema_fields. clone ( ) . map ( |field| {
337+ if field. data_type ( ) . is_numeric ( ) {
338+ Field :: new ( field. name ( ) , DataType :: Float64 , true )
339+ } else {
340+ Field :: new ( field. name ( ) , DataType :: Utf8 , true )
341+ }
342+ } ) ) ;
346343
347- //count aggregation
348- let cnt = self . clone ( ) . aggregate (
349- vec ! [ ] ,
350- original_schema_fields
351- . clone ( )
352- . map ( |f| count ( col ( f. name ( ) ) ) )
353- . collect :: < Vec < _ > > ( ) ,
354- ) ?;
355- // The optimization of AggregateStatistics will rewrite the physical plan
356- // for the count function and ignore alias functions,
357- // as shown in https://github.com/apache/arrow-datafusion/issues/5444.
358- // This logic should be removed when #5444 is fixed.
359- let cnt = cnt. clone ( ) . select (
360- cnt. schema ( )
361- . fields ( )
362- . iter ( )
363- . zip ( original_schema_fields. clone ( ) )
364- . map ( |( count_field, orgin_field) | {
365- col ( count_field. name ( ) ) . alias ( orgin_field. name ( ) )
366- } )
367- . collect :: < Vec < _ > > ( ) ,
368- ) ?;
369- //should be removed when #5444 is fixed
370344 //collect recordBatch
371345 let describe_record_batch = vec ! [
372346 // count aggregation
373- cnt. collect( ) . await ?,
347+ self . clone( )
348+ . aggregate(
349+ vec![ ] ,
350+ original_schema_fields
351+ . clone( )
352+ . map( |f| count( col( f. name( ) ) ) . alias( f. name( ) ) )
353+ . collect:: <Vec <_>>( ) ,
354+ ) ?
355+ . collect( )
356+ . await ?,
374357 // null_count aggregation
375358 self . clone( )
376359 . aggregate(
@@ -448,10 +431,14 @@ impl DataFrame {
448431 . await ?,
449432 ] ;
450433
451- let mut array_ref_vec: Vec < ArrayRef > = vec ! [ ] ;
434+ // first column with function names
435+ let mut array_ref_vec: Vec < ArrayRef > = vec ! [ Arc :: new( StringArray :: from_slice(
436+ supported_describe_functions. clone( ) ,
437+ ) ) ] ;
452438 for field in original_schema_fields {
453439 let mut array_datas = vec ! [ ] ;
454440 for record_batch in describe_record_batch. iter ( ) {
441+ // safe unwrap since aggregate record batches should have at least 1 record
455442 let column = record_batch. get ( 0 ) . unwrap ( ) . column_by_name ( field. name ( ) ) ;
456443 match column {
457444 Some ( c) => {
@@ -477,14 +464,6 @@ impl DataFrame {
477464 ) ?) ;
478465 }
479466
480- //insert first column with function names
481- array_ref_vec. insert (
482- 0 ,
483- Arc :: new ( StringArray :: from_slice (
484- supported_describe_functions. clone ( ) ,
485- ) ) ,
486- ) ;
487-
488467 let describe_record_batch =
489468 RecordBatch :: try_new ( Arc :: new ( Schema :: new ( describe_schemas) ) , array_ref_vec) ?;
490469
0 commit comments