Path: blob/main/crates/polars-stream/src/nodes/io_sinks2/components/hstack_columns.rs
7884 views
use std::sync::Arc;12use polars_core::prelude::Column;3use polars_core::schema::Schema;4use polars_utils::marked_usize::MarkedUsize;56/// Applies a `with_columns()` operation with pre-computed indices.7#[derive(Clone)]8pub struct HStackColumns {9gather_indices: Arc<[MarkedUsize]>,10}1112impl HStackColumns {13/// Note:14/// * Dtypes of the schemas are unused.15pub fn new(output_schema: &Schema, schema_left: &Schema, schema_right: &Schema) -> Self {16assert!(schema_left.len() <= MarkedUsize::UNMARKED_MAX);17assert!(schema_right.len() <= MarkedUsize::UNMARKED_MAX);1819let gather_indices: Arc<[MarkedUsize]> = output_schema20.iter_names()21.map(|name| {22if let Some((idx, ..)) = schema_right.get_full(name) {23MarkedUsize::new(idx, true)24} else {25MarkedUsize::new(schema_left.get_full(name).unwrap().0, false)26}27})28.collect();2930Self { gather_indices }31}3233#[expect(unused)]34pub fn output_width(&self) -> usize {35self.gather_indices.len()36}3738/// Broadcasts unit-length columns from the RHS.39pub fn hstack_columns_broadcast(40&self,41height: usize,42cols_left: &[Column],43cols_right: &[Column],44) -> Vec<Column> {45self.gather_indices46.iter()47.copied()48.map(|mi| {49let i = mi.to_usize();5051if mi.marked() {52let c = &cols_right[i];5354if c.len() != height {55assert_eq!(c.len(), 1);56c.new_from_index(0, height)57} else {58c.clone()59}60} else {61cols_left[i].clone()62}63})64.collect()65}66}676869