forked from pola-rs/polars
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "refactor(rust): Purge arrow-rs support (pola-rs#19312)"
This reverts commit f88bd6a.
- Loading branch information
1 parent
1d144c8
commit 75a6063
Showing
37 changed files
with
1,178 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use arrow_data::{ArrayData, ArrayDataBuilder}; | ||
|
||
use crate::array::{Arrow2Arrow, BinaryArray}; | ||
use crate::bitmap::Bitmap; | ||
use crate::offset::{Offset, OffsetsBuffer}; | ||
|
||
impl<O: Offset> Arrow2Arrow for BinaryArray<O> { | ||
fn to_data(&self) -> ArrayData { | ||
let dtype = self.dtype.clone().into(); | ||
let builder = ArrayDataBuilder::new(dtype) | ||
.len(self.offsets().len_proxy()) | ||
.buffers(vec![ | ||
self.offsets.clone().into_inner().into(), | ||
self.values.clone().into(), | ||
]) | ||
.nulls(self.validity.as_ref().map(|b| b.clone().into())); | ||
|
||
// SAFETY: Array is valid | ||
unsafe { builder.build_unchecked() } | ||
} | ||
|
||
fn from_data(data: &ArrayData) -> Self { | ||
let dtype = data.data_type().clone().into(); | ||
|
||
if data.is_empty() { | ||
// Handle empty offsets | ||
return Self::new_empty(dtype); | ||
} | ||
|
||
let buffers = data.buffers(); | ||
|
||
// SAFETY: ArrayData is valid | ||
let mut offsets = unsafe { OffsetsBuffer::new_unchecked(buffers[0].clone().into()) }; | ||
offsets.slice(data.offset(), data.len() + 1); | ||
|
||
Self { | ||
dtype, | ||
offsets, | ||
values: buffers[1].clone().into(), | ||
validity: data.nulls().map(|n| Bitmap::from_null_buffer(n.clone())), | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use arrow_buffer::{BooleanBuffer, NullBuffer}; | ||
use arrow_data::{ArrayData, ArrayDataBuilder}; | ||
|
||
use crate::array::{Arrow2Arrow, BooleanArray}; | ||
use crate::bitmap::Bitmap; | ||
use crate::datatypes::ArrowDataType; | ||
|
||
impl Arrow2Arrow for BooleanArray { | ||
fn to_data(&self) -> ArrayData { | ||
let buffer = NullBuffer::from(self.values.clone()); | ||
|
||
let builder = ArrayDataBuilder::new(arrow_schema::DataType::Boolean) | ||
.len(buffer.len()) | ||
.offset(buffer.offset()) | ||
.buffers(vec![buffer.into_inner().into_inner()]) | ||
.nulls(self.validity.as_ref().map(|b| b.clone().into())); | ||
|
||
// SAFETY: Array is valid | ||
unsafe { builder.build_unchecked() } | ||
} | ||
|
||
fn from_data(data: &ArrayData) -> Self { | ||
assert_eq!(data.data_type(), &arrow_schema::DataType::Boolean); | ||
|
||
let buffers = data.buffers(); | ||
let buffer = BooleanBuffer::new(buffers[0].clone(), data.offset(), data.len()); | ||
// Use NullBuffer to compute set count | ||
let values = Bitmap::from_null_buffer(NullBuffer::new(buffer)); | ||
|
||
Self { | ||
dtype: ArrowDataType::Boolean, | ||
values, | ||
validity: data.nulls().map(|n| Bitmap::from_null_buffer(n.clone())), | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use arrow_data::{ArrayData, ArrayDataBuilder}; | ||
|
||
use crate::array::{ | ||
from_data, to_data, Arrow2Arrow, DictionaryArray, DictionaryKey, PrimitiveArray, | ||
}; | ||
use crate::datatypes::{ArrowDataType, PhysicalType}; | ||
|
||
impl<K: DictionaryKey> Arrow2Arrow for DictionaryArray<K> { | ||
fn to_data(&self) -> ArrayData { | ||
let keys = self.keys.to_data(); | ||
let builder = keys | ||
.into_builder() | ||
.data_type(self.dtype.clone().into()) | ||
.child_data(vec![to_data(self.values.as_ref())]); | ||
|
||
// SAFETY: Dictionary is valid | ||
unsafe { builder.build_unchecked() } | ||
} | ||
|
||
fn from_data(data: &ArrayData) -> Self { | ||
let key = match data.data_type() { | ||
arrow_schema::DataType::Dictionary(k, _) => k.as_ref(), | ||
d => panic!("unsupported dictionary type {d}"), | ||
}; | ||
|
||
let dtype = ArrowDataType::from(data.data_type().clone()); | ||
assert_eq!( | ||
dtype.to_physical_type(), | ||
PhysicalType::Dictionary(K::KEY_TYPE) | ||
); | ||
|
||
let key_builder = ArrayDataBuilder::new(key.clone()) | ||
.buffers(vec![data.buffers()[0].clone()]) | ||
.offset(data.offset()) | ||
.len(data.len()) | ||
.nulls(data.nulls().cloned()); | ||
|
||
// SAFETY: Dictionary is valid | ||
let key_data = unsafe { key_builder.build_unchecked() }; | ||
let keys = PrimitiveArray::from_data(&key_data); | ||
let values = from_data(&data.child_data()[0]); | ||
|
||
Self { | ||
dtype, | ||
keys, | ||
values, | ||
} | ||
} | ||
} |
This file contains 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
Oops, something went wrong.