Dandandan commented on a change in pull request #365: URL: https://github.com/apache/arrow-datafusion/pull/365#discussion_r635553323
########## File path: datafusion/src/physical_optimizer/pruning.rs ########## @@ -0,0 +1,769 @@ +// 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. + +//! This module contains code to rule out row groups / partitions / +//! etc based on statistics prior in order to skip evaluating entire +//! swaths of rows. +//! +//! This code is currently specific to Parquet, but soon (TM), via +//! https://github.com/apache/arrow-datafusion/issues/363 it will +//! be genericized. + +use std::{collections::HashSet, sync::Arc}; + +use arrow::{ + array::{ + make_array, new_null_array, ArrayData, ArrayRef, BooleanArray, + BooleanBufferBuilder, + }, + buffer::MutableBuffer, + datatypes::{DataType, Field, Schema}, + record_batch::RecordBatch, +}; + +use parquet::file::{ + metadata::RowGroupMetaData, statistics::Statistics as ParquetStatistics, +}; + +use crate::{ + error::{DataFusionError, Result}, + execution::context::ExecutionContextState, + logical_plan::{Expr, Operator}, + optimizer::utils, + physical_plan::{planner::DefaultPhysicalPlanner, ColumnarValue, PhysicalExpr}, +}; + +#[derive(Debug, Clone)] +/// Builder used for generating predicate functions that can be used +/// to prune data based on statistics (e.g. parquet row group metadata) +pub struct PruningPredicateBuilder { + schema: Schema, + predicate_expr: Arc<dyn PhysicalExpr>, + stat_column_req: Vec<(String, StatisticsType, Field)>, +} + +impl PruningPredicateBuilder { + /// Try to create a new instance of [`PruningPredicateBuilder`] + /// + /// This will translate the filter expression into a statistics predicate expression + /// + /// For example, `(column / 2) = 4` becomes `(column_min / 2) <= 4 && 4 <= (column_max / 2))` + pub fn try_new(expr: &Expr, schema: Schema) -> Result<Self> { + // build predicate expression once + let mut stat_column_req = Vec::<(String, StatisticsType, Field)>::new(); + let logical_predicate_expr = + build_predicate_expression(expr, &schema, &mut stat_column_req)?; + // println!( + // "PruningPredicateBuilder::try_new, logical_predicate_expr: {:?}", Review comment: (they were there in the original code but I think would be better to remove them) -- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org