mustafasrepo commented on code in PR #6160:
URL: https://github.com/apache/arrow-datafusion/pull/6160#discussion_r1182209925
##########
datafusion/physical-expr/src/equivalence.rs:
##########
@@ -205,9 +209,56 @@ pub fn project_equivalence_properties(
for class in ec_classes.iter_mut() {
let mut columns_to_remove = vec![];
for column in class.iter() {
- if column.index() >= schema.fields().len()
- || schema.fields()[column.index()].name() != column.name()
+ let fields = schema.fields();
+ let idx = column.index();
+ if idx >= fields.len() || fields[idx].name() != column.name() {
+ columns_to_remove.push(column.clone());
+ }
+ }
+ for column in columns_to_remove {
+ class.remove(&column);
+ }
+ }
+ ec_classes.retain(|props| props.len() > 1);
+ output_eq.extend(ec_classes);
+}
+
+/// This function applies the given projection to the given ordering
+/// equivalence properties to compute the resulting (projected) ordering
+/// equivalence properties; e.g.
+/// 1) Adding an alias, which can introduce additional ordering equivalence
+/// properties, as in Projection(a, a as a1, a as a2) extends global
ordering
+/// of a to a1 and a2.
+/// 2) Truncate the [`OrderingEquivalentClass`]es that are not in the output
schema.
+pub fn project_ordering_equivalence_properties(
+ input_eq: OrderingEquivalenceProperties,
+ columns_map: &HashMap<Column, Vec<Column>>,
+ output_eq: &mut OrderingEquivalenceProperties,
+) {
+ let mut ec_classes = input_eq.classes().to_vec();
+ for (column, columns) in columns_map {
+ for class in ec_classes.iter_mut() {
+ if let Some(OrderedColumn { options, .. }) =
Review Comment:
I could move some of the common code to a function.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]