gruuya commented on code in PR #880: URL: https://github.com/apache/iceberg-rust/pull/880#discussion_r1907869791
########## crates/integrations/datafusion/src/statistics.rs: ########## @@ -0,0 +1,112 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use std::collections::HashMap; + +use datafusion::common::stats::Precision; +use datafusion::common::{ColumnStatistics, Statistics}; +use iceberg::spec::ManifestStatus; +use iceberg::table::Table; +use iceberg::Result; + +use crate::physical_plan::expr_to_predicate::datum_to_scalar_value; + +// Compute DataFusion table statistics for a given table/snapshot +pub async fn compute_statistics(table: &Table, snapshot_id: Option<i64>) -> Result<Statistics> { + let file_io = table.file_io(); + let metadata = table.metadata(); + let snapshot = table.snapshot(snapshot_id)?; + + let mut num_rows = 0; + let mut lower_bounds = HashMap::new(); + let mut upper_bounds = HashMap::new(); + let mut null_counts = HashMap::new(); + + let manifest_list = snapshot.load_manifest_list(file_io, metadata).await?; + + // For each existing/added manifest in the snapshot aggregate the row count, as well as null + // count and min/max values. + for manifest_file in manifest_list.entries() { + let manifest = manifest_file.load_manifest(file_io).await?; Review Comment: Ah yes, good point; I've omitted the equality/position delete files from stats computation process, so only pure data files are included [now](https://github.com/apache/iceberg-rust/pull/880/commits/17383089d8d9aa39dae569ed3d453ac61c4b5f9b). I assume that data files with associated row-level deletes don't get lower-upper bounds updated during commit time. I think that's ok, it just means that the real lower-upper range is strictly contained/nested within the reported lower-upper range (because the rows with actual min/max might be refuted by row level deletes), so the later is more conservative. This information is conveyed by using the `Inexact` variant for the bounds. (Perhaps this could be made `Exact` for the row count by subtracting rows from row-deletion files, but I think that could be done separately.) I've also [moved](https://github.com/apache/iceberg-rust/pull/880/commits/98bdd8a309861dc0c27000d0c24949d8d4b3ec0f) the statistics computation into IcebergTableProvider constructors. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org