Skip to content

Commit accce97

Browse files
authored
Move transpose code to under common (#10409)
1 parent 161d0f2 commit accce97

File tree

4 files changed

+27
-28
lines changed

4 files changed

+27
-28
lines changed

datafusion/common/src/utils.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,22 @@ pub fn find_indices<T: PartialEq, S: Borrow<T>>(
651651
.ok_or_else(|| DataFusionError::Execution("Target not found".to_string()))
652652
}
653653

654+
/// Transposes the given vector of vectors.
655+
pub fn transpose<T>(original: Vec<Vec<T>>) -> Vec<Vec<T>> {
656+
match original.as_slice() {
657+
[] => vec![],
658+
[first, ..] => {
659+
let mut result = (0..first.len()).map(|_| vec![]).collect::<Vec<_>>();
660+
for row in original {
661+
for (item, transposed_row) in row.into_iter().zip(&mut result) {
662+
transposed_row.push(item);
663+
}
664+
}
665+
result
666+
}
667+
}
668+
}
669+
654670
#[cfg(test)]
655671
mod tests {
656672
use crate::ScalarValue::Null;
@@ -990,4 +1006,13 @@ mod tests {
9901006
assert!(find_indices(&[0, 3, 4], [0, 2]).is_err());
9911007
Ok(())
9921008
}
1009+
1010+
#[test]
1011+
fn test_transpose() -> Result<()> {
1012+
let in_data = vec![vec![1, 2, 3], vec![4, 5, 6]];
1013+
let transposed = transpose(in_data);
1014+
let expected = vec![vec![1, 4], vec![2, 5], vec![3, 6]];
1015+
assert_eq!(expected, transposed);
1016+
Ok(())
1017+
}
9931018
}

datafusion/physical-plan/src/common.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -171,22 +171,6 @@ pub fn compute_record_batch_statistics(
171171
}
172172
}
173173

174-
/// Transposes the given vector of vectors.
175-
pub fn transpose<T>(original: Vec<Vec<T>>) -> Vec<Vec<T>> {
176-
match original.as_slice() {
177-
[] => vec![],
178-
[first, ..] => {
179-
let mut result = (0..first.len()).map(|_| vec![]).collect::<Vec<_>>();
180-
for row in original {
181-
for (item, transposed_row) in row.into_iter().zip(&mut result) {
182-
transposed_row.push(item);
183-
}
184-
}
185-
result
186-
}
187-
}
188-
}
189-
190174
/// Calculates the "meet" of given orderings.
191175
/// The meet is the finest ordering that satisfied by all the given
192176
/// orderings, see <https://en.wikipedia.org/wiki/Join_and_meet>.
@@ -703,13 +687,4 @@ mod tests {
703687
assert_eq!(actual, expected);
704688
Ok(())
705689
}
706-
707-
#[test]
708-
fn test_transpose() -> Result<()> {
709-
let in_data = vec![vec![1, 2, 3], vec![4, 5, 6]];
710-
let transposed = transpose(in_data);
711-
let expected = vec![vec![1, 4], vec![2, 5], vec![3, 6]];
712-
assert_eq!(expected, transposed);
713-
Ok(())
714-
}
715690
}

datafusion/physical-plan/src/repartition/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use super::metrics::{self, ExecutionPlanMetricsSet, MetricBuilder, MetricsSet};
2929
use super::{
3030
DisplayAs, ExecutionPlanProperties, RecordBatchStream, SendableRecordBatchStream,
3131
};
32-
use crate::common::transpose;
3332
use crate::hash_utils::create_hashes;
3433
use crate::metrics::BaselineMetrics;
3534
use crate::repartition::distributor_channels::{
@@ -42,6 +41,7 @@ use crate::{DisplayFormatType, ExecutionPlan, Partitioning, PlanProperties, Stat
4241
use arrow::array::{ArrayRef, UInt64Builder};
4342
use arrow::datatypes::SchemaRef;
4443
use arrow::record_batch::RecordBatch;
44+
use datafusion_common::utils::transpose;
4545
use datafusion_common::{arrow_datafusion_err, not_impl_err, DataFusionError, Result};
4646
use datafusion_common_runtime::SpawnedTask;
4747
use datafusion_execution::memory_pool::MemoryConsumer;

datafusion/physical-plan/src/windows/window_agg_exec.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use std::pin::Pin;
2222
use std::sync::Arc;
2323
use std::task::{Context, Poll};
2424

25-
use crate::common::transpose;
2625
use crate::expressions::PhysicalSortExpr;
2726
use crate::metrics::{BaselineMetrics, ExecutionPlanMetricsSet, MetricsSet};
2827
use crate::windows::{
@@ -41,7 +40,7 @@ use arrow::datatypes::{Schema, SchemaBuilder, SchemaRef};
4140
use arrow::error::ArrowError;
4241
use arrow::record_batch::RecordBatch;
4342
use datafusion_common::stats::Precision;
44-
use datafusion_common::utils::evaluate_partition_ranges;
43+
use datafusion_common::utils::{evaluate_partition_ranges, transpose};
4544
use datafusion_common::{internal_err, Result};
4645
use datafusion_execution::TaskContext;
4746
use datafusion_physical_expr::PhysicalSortRequirement;

0 commit comments

Comments
 (0)