Skip to content

Commit

Permalink
fix: regression in out-of-core group-by by new string-type (#14464)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored Feb 13, 2024
1 parent ef8093e commit 0b106c1
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 9 deletions.
3 changes: 3 additions & 0 deletions crates/polars-core/src/series/implementations/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,7 @@ impl SeriesTrait for SeriesWrap<BinaryChunked> {
fn clone_inner(&self) -> Arc<dyn SeriesTrait> {
Arc::new(SeriesWrap(Clone::clone(&self.0)))
}
fn as_any(&self) -> &dyn Any {
&self.0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,7 @@ impl SeriesTrait for SeriesWrap<BinaryOffsetChunked> {
fn clone_inner(&self) -> Arc<dyn SeriesTrait> {
Arc::new(SeriesWrap(Clone::clone(&self.0)))
}
fn as_any(&self) -> &dyn Any {
&self.0
}
}
3 changes: 3 additions & 0 deletions crates/polars-core/src/series/implementations/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,7 @@ impl SeriesTrait for SeriesWrap<BooleanChunked> {
fn clone_inner(&self) -> Arc<dyn SeriesTrait> {
Arc::new(SeriesWrap(Clone::clone(&self.0)))
}
fn as_any(&self) -> &dyn Any {
&self.0
}
}
3 changes: 3 additions & 0 deletions crates/polars-core/src/series/implementations/categorical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ impl SeriesTrait for SeriesWrap<CategoricalChunked> {
fn max_as_series(&self) -> PolarsResult<Series> {
Ok(ChunkAggSeries::max_as_series(&self.0))
}
fn as_any(&self) -> &dyn Any {
&self.0
}
}

impl private::PrivateSeriesNumeric for SeriesWrap<CategoricalChunked> {
Expand Down
3 changes: 3 additions & 0 deletions crates/polars-core/src/series/implementations/dates_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,9 @@ macro_rules! impl_dyn_series {
fn clone_inner(&self) -> Arc<dyn SeriesTrait> {
Arc::new(SeriesWrap(Clone::clone(&self.0)))
}
fn as_any(&self) -> &dyn Any {
&self.0
}
}
};
}
Expand Down
3 changes: 3 additions & 0 deletions crates/polars-core/src/series/implementations/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,4 +367,7 @@ impl SeriesTrait for SeriesWrap<DatetimeChunked> {
fn clone_inner(&self) -> Arc<dyn SeriesTrait> {
Arc::new(SeriesWrap(Clone::clone(&self.0)))
}
fn as_any(&self) -> &dyn Any {
&self.0
}
}
3 changes: 3 additions & 0 deletions crates/polars-core/src/series/implementations/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,7 @@ impl SeriesTrait for SeriesWrap<DecimalChunked> {
Int128Chunked::from_slice_options(self.name(), &[max])
}))
}
fn as_any(&self) -> &dyn Any {
&self.0
}
}
3 changes: 3 additions & 0 deletions crates/polars-core/src/series/implementations/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,4 +445,7 @@ impl SeriesTrait for SeriesWrap<DurationChunked> {
fn clone_inner(&self) -> Arc<dyn SeriesTrait> {
Arc::new(SeriesWrap(Clone::clone(&self.0)))
}
fn as_any(&self) -> &dyn Any {
&self.0
}
}
4 changes: 4 additions & 0 deletions crates/polars-core/src/series/implementations/floats.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::any::Any;
use std::borrow::Cow;

use ahash::RandomState;
Expand Down Expand Up @@ -327,6 +328,9 @@ macro_rules! impl_dyn_series {
fn checked_div(&self, rhs: &Series) -> PolarsResult<Series> {
self.0.checked_div(rhs)
}
fn as_any(&self) -> &dyn Any {
&self.0
}
}
};
}
Expand Down
4 changes: 4 additions & 0 deletions crates/polars-core/src/series/implementations/null.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::any::Any;
use std::borrow::Cow;
use std::sync::Arc;

Expand Down Expand Up @@ -268,6 +269,9 @@ impl SeriesTrait for NullChunked {
fn clone_inner(&self) -> Arc<dyn SeriesTrait> {
Arc::new(self.clone())
}
fn as_any(&self) -> &dyn Any {
self
}
}

unsafe impl IntoSeries for NullChunked {
Expand Down
3 changes: 3 additions & 0 deletions crates/polars-core/src/series/implementations/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,7 @@ impl SeriesTrait for SeriesWrap<StringChunked> {
fn str_concat(&self, delimiter: &str) -> StringChunked {
self.0.str_concat(delimiter)
}
fn as_any(&self) -> &dyn Any {
&self.0
}
}
12 changes: 10 additions & 2 deletions crates/polars-core/src/series/ops/downcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@ use crate::series::implementations::null::NullChunked;
macro_rules! unpack_chunked {
($series:expr, $expected:pat => $ca:ty, $name:expr) => {
match $series.dtype() {
$expected => unsafe {
Ok(&*($series.as_ref() as *const dyn SeriesTrait as *const $ca))
$expected => {
// Check downcast in debug compiles
#[cfg(debug_assertions)]
{
Ok($series.as_ref().as_any().downcast_ref::<$ca>().unwrap())
}
#[cfg(not(debug_assertions))]
unsafe {
Ok(&*($series.as_ref() as *const dyn SeriesTrait as *const $ca))
}
},
dt => polars_bail!(
SchemaMismatch: "invalid series dtype: expected `{}`, got `{}`", $name, dt,
Expand Down
5 changes: 1 addition & 4 deletions crates/polars-core/src/series/series_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,7 @@ pub trait SeriesTrait:
}

/// Get a hold to self as `Any` trait reference.
/// Only implemented for ObjectType
fn as_any(&self) -> &dyn Any {
invalid_operation_panic!(as_any, self)
}
fn as_any(&self) -> &dyn Any;

/// Get a hold to self as `Any` trait reference.
/// Only implemented for ObjectType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::any::Any;
use std::hash::{Hash, Hasher};
use std::sync::Mutex;

use arrow::array::{ArrayRef, BinaryArray};
use arrow::array::BinaryArray;
use eval::Eval;
use hash_table::AggHashTable;
use hashbrown::hash_map::{RawEntryMut, RawVacantEntryMut};
Expand Down Expand Up @@ -63,7 +63,7 @@ impl SpillPayload {
let mut schema = Schema::with_capacity(self.aggs.len() + 2);
schema.with_column(HASH_COL.into(), DataType::UInt64);
schema.with_column(INDEX_COL.into(), IDX_DTYPE);
schema.with_column(KEYS_COL.into(), DataType::Binary);
schema.with_column(KEYS_COL.into(), DataType::BinaryOffset);
for s in &self.aggs {
schema.with_column(s.name().into(), s.dtype().clone());
}
Expand All @@ -76,7 +76,7 @@ impl SpillPayload {

let hashes = UInt64Chunked::from_vec(HASH_COL, self.hashes).into_series();
let chunk_idx = IdxCa::from_vec(INDEX_COL, self.chunk_idx).into_series();
let keys = Series::try_from((KEYS_COL, Box::new(self.keys) as ArrayRef)).unwrap();
let keys = BinaryOffsetChunked::with_chunk(KEYS_COL, self.keys).into_series();

let mut cols = Vec::with_capacity(self.aggs.len() + 3);
cols.push(hashes);
Expand Down

0 comments on commit 0b106c1

Please sign in to comment.