Skip to content

Add specilized impl for array agg group accumulator #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: add-register_metadata
Choose a base branch
from

Conversation

rluvaton
Copy link
Owner

No description provided.

@rluvaton rluvaton mentioned this pull request Apr 17, 2025
Comment on lines +404 to +413
if matches!(group_indices_order_mode, InputOrderMode::Sorted) {
return Ok(Box::new(SortedArrayAggGroupAccumulator {
inputs: vec![],
lengths: vec![],
current_group: None,
item_data_type: self.data_type,
}));
} else {
return Ok(self);
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If self was mutable we would not be able to have special implementation for sorted

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One way to to that would be potentially to use an enum:

enum ArrayAggGroupAccumulator {
  Unsorted {
    data_type: DataType,
    adapter: GroupsAccumulatorAdapter,
  },
  Sorted {
    inputs: Vec<ArrayRef>,
    lengths: Vec<usize>,
    // (group_index, length)
    current_group: Option<(usize, usize)>,
    item_data_type: DataType,
  }     
}

So this code would look lke

impl GroupsAccumulator for ArrayAggGroupAccumulator {

    fn with_group_indices_order_mode(
        &mut self,
        group_indices_order_mode: &datafusion_expr_common::ordering::InputOrderMode,
    ) -> Result<()> {
        if matches!(group_indices_order_mode, InputOrderMode::Sorted) {
            *self = Self::Sorted {
                inputs: vec![],
                lengths: vec![],
                current_group: None,
                item_data_type: self.data_type,
            };
        }
       Ok(())
   }
...

}

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but this it has a cost rather for matching but I'm ok in using mutable as well

@rluvaton rluvaton force-pushed the add-register_metadata branch from 02e893b to c736bd8 Compare April 20, 2025 10:52
@rluvaton rluvaton marked this pull request as ready for review April 25, 2025 10:12
@rluvaton rluvaton marked this pull request as draft April 25, 2025 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants