-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Apply workaround for #5444 to DataFrame::describe
#5468
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ | |
| use std::any::Any; | ||
| use std::sync::Arc; | ||
|
|
||
| use arrow::array::{ArrayRef, Int64Array, StringArray}; | ||
| use arrow::array::{Array, ArrayRef, Int64Array, StringArray}; | ||
| use arrow::compute::{cast, concat}; | ||
| use arrow::datatypes::{DataType, Field}; | ||
| use async_trait::async_trait; | ||
|
|
@@ -329,10 +329,10 @@ impl DataFrame { | |
| let supported_describe_functions = | ||
| vec!["count", "null_count", "mean", "std", "min", "max", "median"]; | ||
|
|
||
| let fields_iter = self.schema().fields().iter(); | ||
| let original_schema_fields = self.schema().fields().iter(); | ||
|
|
||
| //define describe column | ||
| let mut describe_schemas = fields_iter | ||
| let mut describe_schemas = original_schema_fields | ||
| .clone() | ||
| .map(|field| { | ||
| if field.data_type().is_numeric() { | ||
|
|
@@ -344,24 +344,38 @@ impl DataFrame { | |
| .collect::<Vec<_>>(); | ||
| describe_schemas.insert(0, Field::new("describe", DataType::Utf8, false)); | ||
|
|
||
| //count aggregation | ||
| let cnt = self.clone().aggregate( | ||
| vec![], | ||
| original_schema_fields | ||
| .clone() | ||
| .map(|f| count(col(f.name()))) | ||
| .collect::<Vec<_>>(), | ||
| )?; | ||
| // The optimization of AggregateStatistics will rewrite the physical plan | ||
| // for the count function and ignore alias functions, | ||
| // as shown in https://github.com/apache/arrow-datafusion/issues/5444. | ||
| // This logic should be removed when #5444 is fixed. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 -- thank you this comment makes it much clearer what is going on |
||
| let cnt = cnt.clone().select( | ||
| cnt.schema() | ||
| .fields() | ||
| .iter() | ||
| .zip(original_schema_fields.clone()) | ||
| .map(|(count_field, orgin_field)| { | ||
| col(count_field.name()).alias(orgin_field.name()) | ||
| }) | ||
| .collect::<Vec<_>>(), | ||
| )?; | ||
| //should be removed when #5444 is fixed | ||
| //collect recordBatch | ||
| let describe_record_batch = vec![ | ||
| // count aggregation | ||
| self.clone() | ||
| .aggregate( | ||
| vec![], | ||
| fields_iter | ||
| .clone() | ||
| .map(|f| count(col(f.name())).alias(f.name())) | ||
| .collect::<Vec<_>>(), | ||
| )? | ||
| .collect() | ||
| .await?, | ||
| cnt.collect().await?, | ||
| // null_count aggregation | ||
| self.clone() | ||
| .aggregate( | ||
| vec![], | ||
| fields_iter | ||
| original_schema_fields | ||
| .clone() | ||
| .map(|f| count(is_null(col(f.name()))).alias(f.name())) | ||
| .collect::<Vec<_>>(), | ||
|
|
@@ -372,7 +386,7 @@ impl DataFrame { | |
| self.clone() | ||
| .aggregate( | ||
| vec![], | ||
| fields_iter | ||
| original_schema_fields | ||
| .clone() | ||
| .filter(|f| f.data_type().is_numeric()) | ||
| .map(|f| avg(col(f.name())).alias(f.name())) | ||
|
|
@@ -384,7 +398,7 @@ impl DataFrame { | |
| self.clone() | ||
| .aggregate( | ||
| vec![], | ||
| fields_iter | ||
| original_schema_fields | ||
| .clone() | ||
| .filter(|f| f.data_type().is_numeric()) | ||
| .map(|f| stddev(col(f.name())).alias(f.name())) | ||
|
|
@@ -396,7 +410,7 @@ impl DataFrame { | |
| self.clone() | ||
| .aggregate( | ||
| vec![], | ||
| fields_iter | ||
| original_schema_fields | ||
| .clone() | ||
| .filter(|f| { | ||
| !matches!(f.data_type(), DataType::Binary | DataType::Boolean) | ||
|
|
@@ -410,7 +424,7 @@ impl DataFrame { | |
| self.clone() | ||
| .aggregate( | ||
| vec![], | ||
| fields_iter | ||
| original_schema_fields | ||
| .clone() | ||
| .filter(|f| { | ||
| !matches!(f.data_type(), DataType::Binary | DataType::Boolean) | ||
|
|
@@ -424,7 +438,7 @@ impl DataFrame { | |
| self.clone() | ||
| .aggregate( | ||
| vec![], | ||
| fields_iter | ||
| original_schema_fields | ||
| .clone() | ||
| .filter(|f| f.data_type().is_numeric()) | ||
| .map(|f| median(col(f.name())).alias(f.name())) | ||
|
|
@@ -435,7 +449,7 @@ impl DataFrame { | |
| ]; | ||
|
|
||
| let mut array_ref_vec: Vec<ArrayRef> = vec![]; | ||
| for field in fields_iter { | ||
| for field in original_schema_fields { | ||
| let mut array_datas = vec![]; | ||
| for record_batch in describe_record_batch.iter() { | ||
| let column = record_batch.get(0).unwrap().column_by_name(field.name()); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.