Skip to content

Commit

Permalink
Deprecate Buffer::from_bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb committed Jan 4, 2025
1 parent 247ce3f commit e8a796a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
19 changes: 10 additions & 9 deletions arrow-buffer/src/buffer/immutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,9 @@ impl Buffer {
/// and is different than [`bytes::Bytes`].
///
/// See examples on [`Buffer`] for ways to create a buffer from a [`bytes::Bytes`].
#[inline]
#[deprecated(since = "54.1.0", note = "Use Buffer::from instead")]
pub fn from_bytes(bytes: Bytes) -> Self {
let length = bytes.len();
let ptr = bytes.as_ptr();
Buffer {
data: Arc::new(bytes),
ptr,
length,
}
Self::from(bytes)
}

/// Returns the offset, in bytes, of `Self::ptr` to `Self::data`
Expand Down Expand Up @@ -462,8 +456,15 @@ impl<T: ArrowNativeType> From<ScalarBuffer<T>> for Buffer {

/// Convert from internal `Bytes`, not [`bytes::Bytes`] to `Buffer`
impl From<Bytes> for Buffer {
#[inline]
fn from(bytes: Bytes) -> Self {
Self::from_bytes(bytes)
let length = bytes.len();
let ptr = bytes.as_ptr();
Self {
data: Arc::new(bytes),
ptr,
length,
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion arrow-buffer/src/buffer/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ impl MutableBuffer {
pub(super) fn into_buffer(self) -> Buffer {
let bytes = unsafe { Bytes::new(self.data, self.len, Deallocation::Standard(self.layout)) };
std::mem::forget(self);
Buffer::from_bytes(bytes)
Buffer::from(bytes)
}

/// View this buffer as a mutable slice of a specific type.
Expand Down
2 changes: 1 addition & 1 deletion arrow-flight/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ impl FlightDataDecoder {
));
};

let buffer = Buffer::from_bytes(data.data_body.into());
let buffer = Buffer::from(data.data_body);
let dictionary_batch = message.header_as_dictionary_batch().ok_or_else(|| {
FlightError::protocol(
"Could not get dictionary batch from DictionaryBatch message",
Expand Down
2 changes: 1 addition & 1 deletion arrow-flight/src/sql/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ pub fn arrow_data_from_flight_data(

let dictionaries_by_field = HashMap::new();
let record_batch = read_record_batch(
&Buffer::from_bytes(flight_data.data_body.into()),
&Buffer::from(flight_data.data_body),
ipc_record_batch,
arrow_schema_ref.clone(),
&dictionaries_by_field,
Expand Down

0 comments on commit e8a796a

Please sign in to comment.