Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename OffsetSize::fn is_large to const OffsetSize::IS_LARGE #1664

Merged
merged 1 commit into from
May 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions arrow/src/array/array_binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ pub struct GenericBinaryArray<OffsetSize: OffsetSizeTrait> {
}

impl<OffsetSize: OffsetSizeTrait> GenericBinaryArray<OffsetSize> {
/// Get the data type of the array.
// Declare this function as `pub const fn` after
// https://github.com/rust-lang/rust/issues/93706 is merged.
Comment on lines +47 to +49
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make consistent comment style?

Suggested change
/// Get the data type of the array.
// Declare this function as `pub const fn` after
// https://github.com/rust-lang/rust/issues/93706 is merged.
// Get the data type of the array.
// Declare this function as `pub const fn` after
// https://github.com/rust-lang/rust/issues/93706 is merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just want to make the first line (Get the data type of the array.) be the doc of this function. And it is not necessary to expose the 2nd and 3rd line to users, so I use //.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense.

pub fn get_data_type() -> DataType {
if OffsetSize::is_large() {
if OffsetSize::IS_LARGE {
DataType::LargeBinary
} else {
DataType::Binary
Expand Down Expand Up @@ -226,7 +229,7 @@ impl<'a, T: OffsetSizeTrait> GenericBinaryArray<T> {

impl<OffsetSize: OffsetSizeTrait> fmt::Debug for GenericBinaryArray<OffsetSize> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let prefix = if OffsetSize::is_large() { "Large" } else { "" };
let prefix = if OffsetSize::IS_LARGE { "Large" } else { "" };

write!(f, "{}BinaryArray\n[\n", prefix)?;
print_long_array(self, f, |array, index, f| {
Expand Down
18 changes: 6 additions & 12 deletions arrow/src/array/array_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,15 @@ use crate::{

/// trait declaring an offset size, relevant for i32 vs i64 array types.
pub trait OffsetSizeTrait: ArrowNativeType + Num + Ord + std::ops::AddAssign {
fn is_large() -> bool;
const IS_LARGE: bool;
}

impl OffsetSizeTrait for i32 {
#[inline]
fn is_large() -> bool {
false
}
const IS_LARGE: bool = false;
}

impl OffsetSizeTrait for i64 {
#[inline]
fn is_large() -> bool {
true
}
const IS_LARGE: bool = true;
}

/// Generic struct for a variable-size list array.
Expand Down Expand Up @@ -118,7 +112,7 @@ impl<OffsetSize: OffsetSizeTrait> GenericListArray<OffsetSize> {

#[inline]
fn get_type(data_type: &DataType) -> Option<&DataType> {
match (OffsetSize::is_large(), data_type) {
match (OffsetSize::IS_LARGE, data_type) {
(true, DataType::LargeList(child)) | (false, DataType::List(child)) => {
Some(child.data_type())
}
Expand Down Expand Up @@ -175,7 +169,7 @@ impl<OffsetSize: OffsetSizeTrait> GenericListArray<OffsetSize> {
.collect();

let field = Box::new(Field::new("item", T::DATA_TYPE, true));
let data_type = if OffsetSize::is_large() {
let data_type = if OffsetSize::IS_LARGE {
DataType::LargeList(field)
} else {
DataType::List(field)
Expand Down Expand Up @@ -255,7 +249,7 @@ impl<OffsetSize: 'static + OffsetSizeTrait> Array for GenericListArray<OffsetSiz

impl<OffsetSize: OffsetSizeTrait> fmt::Debug for GenericListArray<OffsetSize> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let prefix = if OffsetSize::is_large() { "Large" } else { "" };
let prefix = if OffsetSize::IS_LARGE { "Large" } else { "" };

write!(f, "{}ListArray\n[\n", prefix)?;
print_long_array(self, f, |array, index, f| {
Expand Down
7 changes: 5 additions & 2 deletions arrow/src/array/array_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ pub struct GenericStringArray<OffsetSize: OffsetSizeTrait> {
}

impl<OffsetSize: OffsetSizeTrait> GenericStringArray<OffsetSize> {
/// Get the data type of the array.
// Declare this function as `pub const fn` after
// https://github.com/rust-lang/rust/issues/93706 is merged.
pub fn get_data_type() -> DataType {
if OffsetSize::is_large() {
if OffsetSize::IS_LARGE {
DataType::LargeUtf8
} else {
DataType::Utf8
Expand Down Expand Up @@ -273,7 +276,7 @@ impl<'a, T: OffsetSizeTrait> GenericStringArray<T> {

impl<OffsetSize: OffsetSizeTrait> fmt::Debug for GenericStringArray<OffsetSize> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let prefix = if OffsetSize::is_large() { "Large" } else { "" };
let prefix = if OffsetSize::IS_LARGE { "Large" } else { "" };

write!(f, "{}StringArray\n[\n", prefix)?;
print_long_array(self, f, |array, index, f| {
Expand Down
2 changes: 1 addition & 1 deletion arrow/src/array/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ where
values_data.data_type().clone(),
true, // TODO: find a consistent way of getting this
));
let data_type = if OffsetSize::is_large() {
let data_type = if OffsetSize::IS_LARGE {
DataType::LargeList(field)
} else {
DataType::List(field)
Expand Down
2 changes: 1 addition & 1 deletion arrow/src/array/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ fn preallocate_offset_and_binary_buffer<Offset: OffsetSizeTrait>(
// offsets
let mut buffer = MutableBuffer::new((1 + capacity) * mem::size_of::<Offset>());
// safety: `unsafe` code assumes that this buffer is initialized with one element
if Offset::is_large() {
if Offset::IS_LARGE {
buffer.push(0i64);
} else {
buffer.push(0i32)
Expand Down
2 changes: 1 addition & 1 deletion parquet/src/arrow/array_reader/byte_array_dictionary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ where
let validate_utf8 = col.converted_type() == ConvertedType::UTF8;

let value_type =
match (V::is_large(), col.converted_type() == ConvertedType::UTF8) {
match (V::IS_LARGE, col.converted_type() == ConvertedType::UTF8) {
(true, true) => ArrowType::LargeUtf8,
(true, false) => ArrowType::LargeBinary,
(false, true) => ArrowType::Utf8,
Expand Down