Skip to content

Commit 9cc3921

Browse files
committed
Split constructor in try_new / try_new_with_config
1 parent 5d56cc3 commit 9cc3921

6 files changed

Lines changed: 34 additions & 26 deletions

File tree

‎datafusion-examples/examples/data_io/parquet_advanced_index.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ impl IndexTableProvider {
301301
// In this example, we use the PruningPredicate's literal guarantees to
302302
// analyze the predicate. In a real system, using
303303
// `PruningPredicate::prune` would likely be easier to do.
304-
let pruning_predicate = PruningPredicate::try_new(
304+
let pruning_predicate = PruningPredicate::try_new_with_config(
305305
Arc::clone(predicate),
306306
self.schema(),
307307
&PruningPredicateConfig::default(),

‎datafusion-examples/examples/data_io/parquet_index.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ impl ParquetMetadataIndex {
367367
) -> Result<Vec<(&str, u64)>> {
368368
// Use the PruningPredicate API to determine which files can not
369369
// possibly have any relevant data.
370-
let pruning_predicate = PruningPredicate::try_new(
370+
let pruning_predicate = PruningPredicate::try_new_with_config(
371371
predicate,
372372
self.schema().clone(),
373373
&PruningPredicateConfig::default(),

‎datafusion-examples/examples/query_planning/pruning.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ fn create_pruning_predicate(expr: Expr, schema: &SchemaRef) -> PruningPredicate
195195
let df_schema = DFSchema::try_from(Arc::clone(schema)).unwrap();
196196
let props = ExecutionProps::new();
197197
let physical_expr = create_physical_expr(&expr, &df_schema, &props).unwrap();
198-
PruningPredicate::try_new(
198+
PruningPredicate::try_new_with_config(
199199
physical_expr,
200200
Arc::clone(schema),
201201
&PruningPredicateConfig::default(),

‎datafusion/datasource-parquet/src/page_filter.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl PagePruningAccessPlanFilter {
128128
let predicates = split_conjunction(expr)
129129
.into_iter()
130130
.filter_map(|predicate| {
131-
let pp = match PruningPredicate::try_new(
131+
let pp = match PruningPredicate::try_new_with_config(
132132
Arc::clone(predicate),
133133
Arc::clone(&schema),
134134
config,

‎datafusion/datasource-parquet/src/row_group_filter.rs‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ impl RowGroupAccessPlanFilter {
341341
return;
342342
};
343343

344-
let Ok(inverted_predicate) = PruningPredicate::try_new(
344+
let Ok(inverted_predicate) = PruningPredicate::try_new_with_config(
345345
inverted_expr,
346346
Arc::clone(predicate.schema()),
347347
pruning_predicate_config,
@@ -740,7 +740,7 @@ mod tests {
740740
Arc::new(Schema::new(vec![Field::new("c1", DataType::Int32, false)]));
741741
let expr = col("c1").gt(lit(15));
742742
let expr = logical2physical(&expr, &schema);
743-
let pruning_predicate = PruningPredicate::try_new(
743+
let pruning_predicate = PruningPredicate::try_new_with_config(
744744
expr,
745745
schema.clone(),
746746
&PruningPredicateConfig::default(),
@@ -791,7 +791,7 @@ mod tests {
791791
Arc::new(Schema::new(vec![Field::new("c1", DataType::Int32, false)]));
792792
let expr = col("c1").gt(lit(15));
793793
let expr = logical2physical(&expr, &schema);
794-
let pruning_predicate = PruningPredicate::try_new(
794+
let pruning_predicate = PruningPredicate::try_new_with_config(
795795
expr,
796796
schema.clone(),
797797
&PruningPredicateConfig::default(),
@@ -840,7 +840,7 @@ mod tests {
840840
]));
841841
let expr = col("c1").gt(lit(15)).and(col("c2").rem(lit(2)).eq(lit(0)));
842842
let expr = logical2physical(&expr, &schema);
843-
let pruning_predicate = PruningPredicate::try_new(
843+
let pruning_predicate = PruningPredicate::try_new_with_config(
844844
expr,
845845
schema.clone(),
846846
&PruningPredicateConfig::default(),
@@ -885,7 +885,7 @@ mod tests {
885885
// this bypasses the entire predicate expression and no row groups are filtered out
886886
let expr = col("c1").gt(lit(15)).or(col("c2").rem(lit(2)).eq(lit(0)));
887887
let expr = logical2physical(&expr, &schema);
888-
let pruning_predicate = PruningPredicate::try_new(
888+
let pruning_predicate = PruningPredicate::try_new_with_config(
889889
expr,
890890
schema.clone(),
891891
&PruningPredicateConfig::default(),
@@ -917,7 +917,7 @@ mod tests {
917917
]));
918918
let expr = col("c1").gt(lit(0));
919919
let expr = logical2physical(&expr, &table_schema);
920-
let pruning_predicate = PruningPredicate::try_new(
920+
let pruning_predicate = PruningPredicate::try_new_with_config(
921921
expr,
922922
table_schema.clone(),
923923
&PruningPredicateConfig::default(),
@@ -1000,7 +1000,7 @@ mod tests {
10001000
let schema_descr = ArrowSchemaConverter::new().convert(&schema).unwrap();
10011001
let expr = col("c1").gt(lit(15)).and(col("c2").is_null());
10021002
let expr = logical2physical(&expr, &schema);
1003-
let pruning_predicate = PruningPredicate::try_new(
1003+
let pruning_predicate = PruningPredicate::try_new_with_config(
10041004
expr,
10051005
schema.clone(),
10061006
&PruningPredicateConfig::default(),
@@ -1037,7 +1037,7 @@ mod tests {
10371037
.gt(lit(15))
10381038
.and(col("c2").eq(lit(ScalarValue::Boolean(None))));
10391039
let expr = logical2physical(&expr, &schema);
1040-
let pruning_predicate = PruningPredicate::try_new(
1040+
let pruning_predicate = PruningPredicate::try_new_with_config(
10411041
expr,
10421042
schema.clone(),
10431043
&PruningPredicateConfig::default(),
@@ -1081,7 +1081,7 @@ mod tests {
10811081
let schema_descr = get_test_schema_descr(vec![field]);
10821082
let expr = col("c1").gt(lit(ScalarValue::Decimal128(Some(500), 9, 2)));
10831083
let expr = logical2physical(&expr, &schema);
1084-
let pruning_predicate = PruningPredicate::try_new(
1084+
let pruning_predicate = PruningPredicate::try_new_with_config(
10851085
expr,
10861086
schema.clone(),
10871087
&PruningPredicateConfig::default(),
@@ -1158,7 +1158,7 @@ mod tests {
11581158
Decimal128(11, 2),
11591159
));
11601160
let expr = logical2physical(&expr, &schema);
1161-
let pruning_predicate = PruningPredicate::try_new(
1161+
let pruning_predicate = PruningPredicate::try_new_with_config(
11621162
expr,
11631163
schema.clone(),
11641164
&PruningPredicateConfig::default(),
@@ -1256,7 +1256,7 @@ mod tests {
12561256
let schema_descr = get_test_schema_descr(vec![field]);
12571257
let expr = col("c1").lt(lit(ScalarValue::Decimal128(Some(500), 18, 2)));
12581258
let expr = logical2physical(&expr, &schema);
1259-
let pruning_predicate = PruningPredicate::try_new(
1259+
let pruning_predicate = PruningPredicate::try_new_with_config(
12601260
expr,
12611261
schema.clone(),
12621262
&PruningPredicateConfig::default(),
@@ -1323,7 +1323,7 @@ mod tests {
13231323
let left = cast(col("c1"), Decimal128(28, 3));
13241324
let expr = left.eq(lit(ScalarValue::Decimal128(Some(100000), 28, 3)));
13251325
let expr = logical2physical(&expr, &schema);
1326-
let pruning_predicate = PruningPredicate::try_new(
1326+
let pruning_predicate = PruningPredicate::try_new_with_config(
13271327
expr,
13281328
schema.clone(),
13291329
&PruningPredicateConfig::default(),
@@ -1407,7 +1407,7 @@ mod tests {
14071407
let left = cast(col("c1"), Decimal128(28, 3));
14081408
let expr = left.eq(lit(ScalarValue::Decimal128(Some(100000), 28, 3)));
14091409
let expr = logical2physical(&expr, &schema);
1410-
let pruning_predicate = PruningPredicate::try_new(
1410+
let pruning_predicate = PruningPredicate::try_new_with_config(
14111411
expr,
14121412
schema.clone(),
14131413
&PruningPredicateConfig::default(),
@@ -1584,7 +1584,7 @@ mod tests {
15841584
false,
15851585
);
15861586
let expr = logical2physical(&expr, &schema);
1587-
let pruning_predicate = PruningPredicate::try_new(
1587+
let pruning_predicate = PruningPredicate::try_new_with_config(
15881588
expr,
15891589
Arc::new(schema),
15901590
&PruningPredicateConfig::default(),
@@ -1811,7 +1811,7 @@ mod tests {
18111811
let data = bytes::Bytes::from(std::fs::read(path).unwrap());
18121812

18131813
let expr = logical2physical(&expr, &schema);
1814-
let pruning_predicate = PruningPredicate::try_new(
1814+
let pruning_predicate = PruningPredicate::try_new_with_config(
18151815
expr,
18161816
Arc::new(schema),
18171817
&PruningPredicateConfig::default(),

‎datafusion/pruning/src/pruning_predicate.rs‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ use datafusion_physical_plan::{ColumnarValue, PhysicalExpr};
106106
/// C: true (rows might match x = 5)
107107
/// ```
108108
///
109-
/// See [`PruningPredicate::try_new`] and [`PruningPredicate::prune`] for more information.
109+
/// See [`PruningPredicate::try_new_with_config`] and [`PruningPredicate::prune`] for more information.
110110
///
111111
/// # Background
112112
///
@@ -400,7 +400,11 @@ pub fn build_pruning_predicate(
400400
predicate_creation_errors: &Count,
401401
config: &PruningPredicateConfig,
402402
) -> Option<Arc<PruningPredicate>> {
403-
match PruningPredicate::try_new(predicate, Arc::clone(file_schema), config) {
403+
match PruningPredicate::try_new_with_config(
404+
predicate,
405+
Arc::clone(file_schema),
406+
config,
407+
) {
404408
Ok(pruning_predicate) => {
405409
if !pruning_predicate.always_true() {
406410
return Some(Arc::new(pruning_predicate));
@@ -445,6 +449,10 @@ impl UnhandledPredicateHook for ConstantUnhandledPredicateHook {
445449
}
446450

447451
impl PruningPredicate {
452+
pub fn try_new(expr: Arc<dyn PhysicalExpr>, schema: SchemaRef) -> Result<Self> {
453+
Self::try_new_with_config(expr, schema, &PruningPredicateConfig::default())
454+
}
455+
448456
/// Try to create a new instance of [`PruningPredicate`]
449457
///
450458
/// This will translate the provided `expr` filter expression into
@@ -473,7 +481,7 @@ impl PruningPredicate {
473481
/// returns a new expression.
474482
/// It is recommended that you pass the expressions through [`PhysicalExprSimplifier`]
475483
/// before calling this method to make sure the expressions can be used for pruning.
476-
pub fn try_new(
484+
pub fn try_new_with_config(
477485
mut expr: Arc<dyn PhysicalExpr>,
478486
schema: SchemaRef,
479487
config: &PruningPredicateConfig,
@@ -2400,7 +2408,7 @@ mod tests {
24002408
]));
24012409
let expr = col("c1").eq(lit(100)).and(col("c2").eq(lit(200)));
24022410
let expr = logical2physical(&expr, &schema);
2403-
let p = PruningPredicate::try_new(
2411+
let p = PruningPredicate::try_new_with_config(
24042412
expr,
24052413
Arc::clone(&schema),
24062414
&PruningPredicateConfig::default(),
@@ -3046,7 +3054,7 @@ mod tests {
30463054
dynamic_phys_expr.with_new_children(remapped_expr).unwrap();
30473055
// After substitution the expression is c1 > 5 AND part = "B" which should prune the file since the partition value is "A"
30483056
let expected = &[false];
3049-
let p = PruningPredicate::try_new(
3057+
let p = PruningPredicate::try_new_with_config(
30503058
dynamic_filter_expr,
30513059
Arc::clone(&schema),
30523060
&PruningPredicateConfig::default(),
@@ -5419,7 +5427,7 @@ mod tests {
54195427
) {
54205428
println!("Pruning with expr: {expr}");
54215429
let expr = logical2physical(&expr, schema);
5422-
let p = PruningPredicate::try_new(
5430+
let p = PruningPredicate::try_new_with_config(
54235431
expr,
54245432
Arc::<Schema>::clone(schema),
54255433
&PruningPredicateConfig::default(),
@@ -5439,7 +5447,7 @@ mod tests {
54395447
let expr = logical2physical(&expr, schema);
54405448
let simplifier = PhysicalExprSimplifier::new(schema);
54415449
let expr = simplifier.simplify(expr).unwrap();
5442-
let p = PruningPredicate::try_new(
5450+
let p = PruningPredicate::try_new_with_config(
54435451
expr,
54445452
Arc::<Schema>::clone(schema),
54455453
&PruningPredicateConfig::default(),

0 commit comments

Comments
 (0)