xiedeyantu commented on code in PR #21362:
URL: https://github.com/apache/datafusion/pull/21362#discussion_r3058256894
##########
datafusion/common/src/functional_dependencies.rs:
##########
@@ -590,6 +590,46 @@ pub fn get_required_group_by_exprs_indices(
.collect()
}
+/// Returns indices for the minimal subset of ORDER BY expressions that are
+/// functionally equivalent to the original set of ORDER BY expressions.
+pub fn get_required_sort_exprs_indices(
+ schema: &DFSchema,
+ sort_expr_names: &[String],
+) -> Option<Vec<usize>> {
+ let dependencies = schema.functional_dependencies();
+ let field_names = schema.field_names();
+
+ let mut known_field_indices = HashSet::new();
+ let mut required_sort_expr_indices = Vec::new();
+
+ for (sort_expr_idx, sort_expr_name) in sort_expr_names.iter().enumerate() {
+ let Some(field_idx) = field_names
Review Comment:
I have Added some comments.
##########
datafusion/common/src/functional_dependencies.rs:
##########
@@ -590,6 +590,46 @@ pub fn get_required_group_by_exprs_indices(
.collect()
}
+/// Returns indices for the minimal subset of ORDER BY expressions that are
+/// functionally equivalent to the original set of ORDER BY expressions.
+pub fn get_required_sort_exprs_indices(
+ schema: &DFSchema,
+ sort_expr_names: &[String],
+) -> Option<Vec<usize>> {
+ let dependencies = schema.functional_dependencies();
+ let field_names = schema.field_names();
+
+ let mut known_field_indices = HashSet::new();
+ let mut required_sort_expr_indices = Vec::new();
+
+ for (sort_expr_idx, sort_expr_name) in sort_expr_names.iter().enumerate() {
+ let Some(field_idx) = field_names
+ .iter()
+ .position(|field_name| field_name == sort_expr_name)
+ else {
+ required_sort_expr_indices.push(sort_expr_idx);
+ continue;
+ };
+
+ let removable = dependencies.deps.iter().any(|dependency| {
+ dependency.target_indices.contains(&field_idx)
+ && dependency
+ .source_indices
+ .iter()
+ .all(|source_idx| known_field_indices.contains(source_idx))
+ });
Review Comment:
Yes, done!
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]