Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
const IS_LARGE (#1002)
Browse files Browse the repository at this point in the history
Signed-off-by: remzi <[email protected]>
  • Loading branch information
HaoYang670 authored May 21, 2022
1 parent 267cac0 commit f129f71
Show file tree
Hide file tree
Showing 13 changed files with 16 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/array/binary/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl<O: Offset> Debug for BinaryArray<O> {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
let writer = |f: &mut Formatter, index| write_value(self, index, f);

let head = if O::is_large() {
let head = if O::IS_LARGE {
"LargeBinaryArray"
} else {
"BinaryArray"
Expand Down
2 changes: 1 addition & 1 deletion src/array/binary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl<O: Offset> BinaryArray<O> {

/// Returns the default [`DataType`], `DataType::Binary` or `DataType::LargeBinary`
pub fn default_data_type() -> DataType {
if O::is_large() {
if O::IS_LARGE {
DataType::LargeBinary
} else {
DataType::Binary
Expand Down
2 changes: 1 addition & 1 deletion src/array/list/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<O: Offset> Debug for ListArray<O> {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
let writer = |f: &mut Formatter, index| write_value(self, index, "None", f);

let head = if O::is_large() {
let head = if O::IS_LARGE {
"LargeListArray"
} else {
"ListArray"
Expand Down
4 changes: 2 additions & 2 deletions src/array/list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ impl<O: Offset> ListArray<O> {
/// Returns a default [`DataType`]: inner field is named "item" and is nullable
pub fn default_datatype(data_type: DataType) -> DataType {
let field = Box::new(Field::new("item", data_type, true));
if O::is_large() {
if O::IS_LARGE {
DataType::LargeList(field)
} else {
DataType::List(field)
Expand All @@ -310,7 +310,7 @@ impl<O: Offset> ListArray<O> {
/// # Errors
/// Panics iff the logical type is not consistent with this struct.
fn try_get_child(data_type: &DataType) -> Result<&Field, ArrowError> {
if O::is_large() {
if O::IS_LARGE {
match data_type.to_logical_type() {
DataType::LargeList(child) => Ok(child.as_ref()),
_ => Err(ArrowError::oos(
Expand Down
2 changes: 1 addition & 1 deletion src/array/list/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl<O: Offset, M: MutableArray> MutableListArray<O, M> {
/// Creates a new [`MutableListArray`] from a [`MutableArray`].
pub fn new_with_field(values: M, name: &str, nullable: bool) -> Self {
let field = Box::new(Field::new(name, values.data_type().clone(), nullable));
let data_type = if O::is_large() {
let data_type = if O::IS_LARGE {
DataType::LargeList(field)
} else {
DataType::List(field)
Expand Down
2 changes: 1 addition & 1 deletion src/array/utf8/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl<O: Offset> Debug for Utf8Array<O> {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
let writer = |f: &mut Formatter, index| write_value(self, index, f);

let head = if O::is_large() {
let head = if O::IS_LARGE {
"LargeUtf8Array"
} else {
"Utf8Array"
Expand Down
2 changes: 1 addition & 1 deletion src/array/utf8/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl<O: Offset> Utf8Array<O> {

/// Returns the default [`DataType`], `DataType::Utf8` or `DataType::LargeUtf8`
pub fn default_data_type() -> DataType {
if O::is_large() {
if O::IS_LARGE {
DataType::LargeUtf8
} else {
DataType::Utf8
Expand Down
2 changes: 1 addition & 1 deletion src/array/utf8/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ impl<O: Offset> MutableArray for MutableUtf8Array<O> {
}

fn data_type(&self) -> &DataType {
if O::is_large() {
if O::IS_LARGE {
&DataType::LargeUtf8
} else {
&DataType::Utf8
Expand Down
2 changes: 1 addition & 1 deletion src/compute/length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ where
.map(|offset| op(offset[1] - offset[0]))
.collect::<Vec<_>>();

let data_type = if O::is_large() {
let data_type = if O::IS_LARGE {
DataType::Int64
} else {
DataType::Int32
Expand Down
2 changes: 1 addition & 1 deletion src/scalar/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl<O: Offset> Scalar for BinaryScalar<O> {

#[inline]
fn data_type(&self) -> &DataType {
if O::is_large() {
if O::IS_LARGE {
&DataType::LargeBinary
} else {
&DataType::Binary
Expand Down
2 changes: 1 addition & 1 deletion src/scalar/utf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl<O: Offset> Scalar for Utf8Scalar<O> {

#[inline]
fn data_type(&self) -> &DataType {
if O::is_large() {
if O::IS_LARGE {
&DataType::LargeUtf8
} else {
&DataType::Utf8
Expand Down
12 changes: 3 additions & 9 deletions src/types/offset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@ use super::Index;
/// as offsets of variable-length Arrow arrays.
pub trait Offset: super::private::Sealed + Index {
/// Whether it is `i32` (false) or `i64` (true).
fn is_large() -> bool;
const IS_LARGE: bool;
}

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

impl Offset for i64 {
#[inline]
fn is_large() -> bool {
true
}
const IS_LARGE: bool = true;
}
2 changes: 1 addition & 1 deletion tests/it/compute/length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn length_test_string<O: Offset>() {
let array = Utf8Array::<O>::from(&input);
let result = length(&array).unwrap();

let data_type = if O::is_large() {
let data_type = if O::IS_LARGE {
DataType::Int64
} else {
DataType::Int32
Expand Down

0 comments on commit f129f71

Please sign in to comment.