Skip to content

Commit 3887087

Browse files
authored
Encapsulate fields of EquivalenceProperties (#14040)
1 parent 81b50c4 commit 3887087

File tree

9 files changed

+34
-30
lines changed

9 files changed

+34
-30
lines changed

datafusion/core/src/physical_optimizer/sanity_checker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ pub fn check_plan_sanity(
144144
plan_str,
145145
format_physical_sort_requirement_list(&sort_req),
146146
idx,
147-
child_eq_props.oeq_class
147+
child_eq_props.oeq_class()
148148
);
149149
}
150150
}

datafusion/core/tests/fuzz_cases/equivalence/ordering.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ fn test_ordering_satisfy_with_equivalence_random() -> Result<()> {
6868
table_data_with_properties.clone(),
6969
)?;
7070
let err_msg = format!(
71-
"Error in test case requirement:{:?}, expected: {:?}, eq_properties.oeq_class: {:?}, eq_properties.eq_group: {:?}, eq_properties.constants: {:?}",
72-
requirement, expected, eq_properties.oeq_class, eq_properties.eq_group, eq_properties.constants
71+
"Error in test case requirement:{:?}, expected: {:?}, eq_properties {}",
72+
requirement, expected, eq_properties
7373
);
7474
// Check whether ordering_satisfy API result and
7575
// experimental result matches.
@@ -141,8 +141,8 @@ fn test_ordering_satisfy_with_equivalence_complex_random() -> Result<()> {
141141
table_data_with_properties.clone(),
142142
)?;
143143
let err_msg = format!(
144-
"Error in test case requirement:{:?}, expected: {:?}, eq_properties.oeq_class: {:?}, eq_properties.eq_group: {:?}, eq_properties.constants: {:?}",
145-
requirement, expected, eq_properties.oeq_class, eq_properties.eq_group, eq_properties.constants
144+
"Error in test case requirement:{:?}, expected: {:?}, eq_properties: {}",
145+
requirement, expected, eq_properties,
146146
);
147147
// Check whether ordering_satisfy API result and
148148
// experimental result matches.

datafusion/core/tests/fuzz_cases/equivalence/projection.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ fn project_orderings_random() -> Result<()> {
8282
// Make sure each ordering after projection is valid.
8383
for ordering in projected_eq.oeq_class().iter() {
8484
let err_msg = format!(
85-
"Error in test case ordering:{:?}, eq_properties.oeq_class: {:?}, eq_properties.eq_group: {:?}, eq_properties.constants: {:?}, proj_exprs: {:?}",
86-
ordering, eq_properties.oeq_class, eq_properties.eq_group, eq_properties.constants, proj_exprs
85+
"Error in test case ordering:{:?}, eq_properties {}, proj_exprs: {:?}",
86+
ordering, eq_properties, proj_exprs,
8787
);
8888
// Since ordered section satisfies schema, we expect
8989
// that result will be same after sort (e.g sort was unnecessary).
@@ -179,8 +179,8 @@ fn ordering_satisfy_after_projection_random() -> Result<()> {
179179
projected_batch.clone(),
180180
)?;
181181
let err_msg = format!(
182-
"Error in test case requirement:{:?}, expected: {:?}, eq_properties.oeq_class: {:?}, eq_properties.eq_group: {:?}, eq_properties.constants: {:?}, projected_eq.oeq_class: {:?}, projected_eq.eq_group: {:?}, projected_eq.constants: {:?}, projection_mapping: {:?}",
183-
requirement, expected, eq_properties.oeq_class, eq_properties.eq_group, eq_properties.constants, projected_eq.oeq_class, projected_eq.eq_group, projected_eq.constants, projection_mapping
182+
"Error in test case requirement:{:?}, expected: {:?}, eq_properties: {}, projected_eq: {}, projection_mapping: {:?}",
183+
requirement, expected, eq_properties, projected_eq, projection_mapping
184184
);
185185
// Check whether ordering_satisfy API result and
186186
// experimental result matches.

datafusion/core/tests/fuzz_cases/equivalence/properties.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ fn test_find_longest_permutation_random() -> Result<()> {
8383
);
8484

8585
let err_msg = format!(
86-
"Error in test case ordering:{:?}, eq_properties.oeq_class: {:?}, eq_properties.eq_group: {:?}, eq_properties.constants: {:?}",
87-
ordering, eq_properties.oeq_class, eq_properties.eq_group, eq_properties.constants
86+
"Error in test case ordering:{:?}, eq_properties: {}",
87+
ordering, eq_properties
8888
);
8989
assert_eq!(ordering.len(), indices.len(), "{}", err_msg);
9090
// Since ordered section satisfies schema, we expect

datafusion/core/tests/fuzz_cases/equivalence/utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ pub fn generate_table_for_eq_properties(
373373
};
374374

375375
// Fill constant columns
376-
for constant in &eq_properties.constants {
376+
for constant in eq_properties.constants() {
377377
let col = constant.expr().as_any().downcast_ref::<Column>().unwrap();
378378
let (idx, _field) = schema.column_with_name(col.name()).unwrap();
379379
let arr =
@@ -382,7 +382,7 @@ pub fn generate_table_for_eq_properties(
382382
}
383383

384384
// Fill columns based on ordering equivalences
385-
for ordering in eq_properties.oeq_class.iter() {
385+
for ordering in eq_properties.oeq_class().iter() {
386386
let (sort_columns, indices): (Vec<_>, Vec<_>) = ordering
387387
.iter()
388388
.map(|PhysicalSortExpr { expr, options }| {
@@ -406,7 +406,7 @@ pub fn generate_table_for_eq_properties(
406406
}
407407

408408
// Fill columns based on equivalence groups
409-
for eq_group in eq_properties.eq_group.iter() {
409+
for eq_group in eq_properties.eq_group().iter() {
410410
let representative_array =
411411
get_representative_arr(eq_group, &schema_vec, Arc::clone(schema))
412412
.unwrap_or_else(|| generate_random_array(n_elem, n_distinct));

datafusion/physical-expr/src/equivalence/ordering.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,17 @@ mod tests {
291291
},
292292
]);
293293
// finer ordering satisfies, crude ordering should return true
294-
let mut eq_properties_finer =
295-
EquivalenceProperties::new(Arc::clone(&input_schema));
296-
eq_properties_finer.oeq_class.push(finer.clone());
294+
let eq_properties_finer = EquivalenceProperties::new_with_orderings(
295+
Arc::clone(&input_schema),
296+
&[finer.clone()],
297+
);
297298
assert!(eq_properties_finer.ordering_satisfy(crude.as_ref()));
298299

299300
// Crude ordering doesn't satisfy finer ordering. should return false
300-
let mut eq_properties_crude =
301-
EquivalenceProperties::new(Arc::clone(&input_schema));
302-
eq_properties_crude.oeq_class.push(crude);
301+
let eq_properties_crude = EquivalenceProperties::new_with_orderings(
302+
Arc::clone(&input_schema),
303+
&[crude.clone()],
304+
);
303305
assert!(!eq_properties_crude.ordering_satisfy(finer.as_ref()));
304306
Ok(())
305307
}

datafusion/physical-expr/src/equivalence/properties.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,15 @@ use itertools::Itertools;
124124
/// ```
125125
#[derive(Debug, Clone)]
126126
pub struct EquivalenceProperties {
127-
/// Collection of equivalence classes that store expressions with the same
128-
/// value.
129-
pub eq_group: EquivalenceGroup,
130-
/// Equivalent sort expressions for this table.
131-
pub oeq_class: OrderingEquivalenceClass,
132-
/// Expressions whose values are constant throughout the table.
127+
/// Distinct equivalence classes (exprs known to have the same expressions)
128+
eq_group: EquivalenceGroup,
129+
/// Equivalent sort expressions
130+
oeq_class: OrderingEquivalenceClass,
131+
/// Expressions whose values are constant
132+
///
133133
/// TODO: We do not need to track constants separately, they can be tracked
134134
/// inside `eq_groups` as `Literal` expressions.
135-
pub constants: Vec<ConstExpr>,
135+
constants: Vec<ConstExpr>,
136136
/// Schema associated with this object.
137137
schema: SchemaRef,
138138
}

datafusion/physical-plan/src/memory.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,9 @@ impl MemoryExec {
260260
ProjectionMapping::try_new(&proj_exprs, &self.original_schema())?;
261261
sort_information = base_eqp
262262
.project(&projection_mapping, self.schema())
263-
.oeq_class
263+
.oeq_class()
264+
// TODO add a take / into to avoid the clone
265+
.clone()
264266
.orderings;
265267
}
266268

datafusion/physical-plan/src/union.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -843,9 +843,9 @@ mod tests {
843843
) {
844844
// Check whether orderings are same.
845845
let lhs_orderings = lhs.oeq_class();
846-
let rhs_orderings = &rhs.oeq_class.orderings;
846+
let rhs_orderings = rhs.oeq_class();
847847
assert_eq!(lhs_orderings.len(), rhs_orderings.len(), "{}", err_msg);
848-
for rhs_ordering in rhs_orderings {
848+
for rhs_ordering in rhs_orderings.iter() {
849849
assert!(lhs_orderings.contains(rhs_ordering), "{}", err_msg);
850850
}
851851
}

0 commit comments

Comments
 (0)