Skip to content
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

simple mode f #11

Merged
merged 2 commits into from
Oct 8, 2024
Merged

simple mode f #11

merged 2 commits into from
Oct 8, 2024

Conversation

demetribu
Copy link
Collaborator

Closes: #10

@demetribu demetribu requested a review from alamb October 7, 2024 20:19
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

😍

Screenshot 2024-10-07 at 4 24 23 PM

Looks good to me @dmitrybugakov -- i had a question about the switched comparison that might be good to address if needed before merging

@@ -122,7 +122,7 @@ where
}
std::cmp::Ordering::Equal => {
max_value = match max_value {
Some(ref current_max_value) if value < current_max_value => Some(*value),
Some(ref current_max_value) if value > current_max_value => Some(*value),
Copy link
Contributor

Choose a reason for hiding this comment

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

why this change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Previously, we returned the MIN value for native types and the first encountered value for strings when multiple values had the same frequency. Now, MAX is used for both, but we can go with MIN in both cases, by the way.

DataType::Utf8 => Box::new(BytesModeAccumulator::<i32>::new(OutputType::Utf8)),
DataType::LargeUtf8 => Box::new(BytesModeAccumulator::<i64>::new(OutputType::Utf8)),
DataType::Utf8View => Box::new(BytesViewModeAccumulator::new(OutputType::Utf8View)),
DataType::Utf8 | DataType::Utf8View | DataType::LargeUtf8 => Box::new(BytesModeAccumulator::new(data_type)),
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

V: ArrayAccessor<Item = &'a str>,
{
for value in ArrayIter::new(array).flatten() {
let key = value.to_string();
Copy link
Contributor

Choose a reason for hiding this comment

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

if you can avoid converting the value to a string here it would likely be significantly faster (it would avoid allocating on each row)

So maybe you could only call to_string() right before you insert into the map

@demetribu demetribu requested a review from alamb October 8, 2024 10:48
@alamb
Copy link
Contributor

alamb commented Oct 8, 2024

😍

@alamb alamb merged commit fb87e64 into datafusion-contrib:main Oct 8, 2024
5 checks passed
@alamb
Copy link
Contributor

alamb commented Oct 8, 2024

Thanks @dmitrybugakov

@demetribu
Copy link
Collaborator Author

Thank you for the review, @alamb

@demetribu demetribu deleted the simple-mode branch October 8, 2024 16:19
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.

Simplify mode function logic
2 participants