@@ -11,6 +11,7 @@ use arrow_array::{
11
11
ArrayRef , RecordBatch , StringArray ,
12
12
} ;
13
13
use arrow_schema:: { DataType , Field , Schema , SchemaRef } ;
14
+ use datafusion:: common:: ColumnStatistics ;
14
15
use datafusion:: error:: { DataFusionError , Result as DataFusionResult } ;
15
16
use datafusion:: physical_plan:: PlanProperties ;
16
17
use datafusion:: physical_plan:: {
@@ -184,18 +185,30 @@ impl ExecutionPlan for KNNVectorDistanceExec {
184
185
185
186
fn statistics ( & self ) -> DataFusionResult < Statistics > {
186
187
let inner_stats = self . input . statistics ( ) ?;
187
- let dist_col_stats = inner_stats. column_statistics [ 0 ] . clone ( ) ;
188
+ let schema = self . input . schema ( ) ;
189
+ let dist_stats = inner_stats
190
+ . column_statistics
191
+ . iter ( )
192
+ . zip ( schema. fields ( ) )
193
+ . find ( |( _, field) | field. name ( ) == & self . column )
194
+ . map ( |( stats, _) | ColumnStatistics {
195
+ null_count : stats. null_count ,
196
+ ..Default :: default ( )
197
+ } )
198
+ . unwrap_or_default ( ) ;
188
199
let column_statistics = inner_stats
189
200
. column_statistics
190
201
. into_iter ( )
191
- . chain ( [ dist_col_stats] )
202
+ . zip ( schema. fields ( ) )
203
+ . filter ( |( _, field) | field. name ( ) != DIST_COL )
204
+ . map ( |( stats, _) | stats)
205
+ . chain ( std:: iter:: once ( dist_stats) )
192
206
. collect :: < Vec < _ > > ( ) ;
193
207
Ok ( Statistics {
194
208
num_rows : inner_stats. num_rows ,
195
209
column_statistics,
196
210
..Statistics :: new_unknown ( self . schema ( ) . as_ref ( ) )
197
211
} )
198
- // self.input.statistics()
199
212
}
200
213
201
214
fn properties ( & self ) -> & PlanProperties {
0 commit comments