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

Changed DataType::FixedSize*(i32) to DataType::FixedSize*(usize) #556

Merged
merged 1 commit into from
Oct 30, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/array/fixed_size_binary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl FixedSizeBinaryArray {

/// Returns a new [`FixedSizeBinaryArray`].
pub fn from_data(data_type: DataType, values: Buffer<u8>, validity: Option<Bitmap>) -> Self {
let size = *Self::get_size(&data_type) as usize;
let size = Self::get_size(&data_type);

assert_eq!(values.len() % size, 0);

Expand Down Expand Up @@ -135,9 +135,9 @@ impl FixedSizeBinaryArray {
}

impl FixedSizeBinaryArray {
pub(crate) fn get_size(data_type: &DataType) -> &i32 {
pub(crate) fn get_size(data_type: &DataType) -> usize {
match data_type.to_logical_type() {
DataType::FixedSizeBinary(size) => size,
DataType::FixedSizeBinary(size) => *size,
_ => panic!("Wrong DataType"),
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/array/fixed_size_binary/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl MutableFixedSizeBinaryArray {
values: MutableBuffer<u8>,
validity: Option<MutableBitmap>,
) -> Self {
let size = *FixedSizeBinaryArray::get_size(&data_type) as usize;
let size = FixedSizeBinaryArray::get_size(&data_type);
assert_eq!(
values.len() % size,
0,
Expand Down Expand Up @@ -68,7 +68,7 @@ impl MutableFixedSizeBinaryArray {
/// Creates a new [`MutableFixedSizeBinaryArray`] with capacity for `capacity` entries.
pub fn with_capacity(size: usize, capacity: usize) -> Self {
Self::from_data(
DataType::FixedSizeBinary(size as i32),
DataType::FixedSizeBinary(size),
MutableBuffer::<u8>::with_capacity(capacity * size),
None,
)
Expand Down Expand Up @@ -189,15 +189,15 @@ impl MutableArray for MutableFixedSizeBinaryArray {

fn as_box(&mut self) -> Box<dyn Array> {
Box::new(FixedSizeBinaryArray::from_data(
DataType::FixedSizeBinary(self.size as i32),
DataType::FixedSizeBinary(self.size),
std::mem::take(&mut self.values).into(),
std::mem::take(&mut self.validity).map(|x| x.into()),
))
}

fn as_arc(&mut self) -> Arc<dyn Array> {
Arc::new(FixedSizeBinaryArray::from_data(
DataType::FixedSizeBinary(self.size as i32),
DataType::FixedSizeBinary(self.size),
std::mem::take(&mut self.values).into(),
std::mem::take(&mut self.validity).map(|x| x.into()),
))
Expand Down
2 changes: 1 addition & 1 deletion src/array/fixed_size_list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl FixedSizeListArray {
/// Returns a [`DataType`] consistent with [`FixedSizeListArray`].
pub fn default_datatype(data_type: DataType, size: usize) -> DataType {
let field = Box::new(Field::new("item", data_type, true));
DataType::FixedSizeList(field, size as i32)
DataType::FixedSizeList(field, size)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/array/growable/fixed_binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl<'a> GrowableFixedSizeBinary<'a> {
.map(|array| build_extend_null_bits(*array, use_validity))
.collect();

let size = *FixedSizeBinaryArray::get_size(arrays[0].data_type()) as usize;
let size = FixedSizeBinaryArray::get_size(arrays[0].data_type());
Self {
arrays,
values: MutableBuffer::with_capacity(0),
Expand Down
4 changes: 2 additions & 2 deletions src/datatypes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub enum DataType {
Binary,
/// Opaque binary data of fixed size.
/// Enum parameter specifies the number of bytes per value.
FixedSizeBinary(i32),
FixedSizeBinary(usize),
/// Opaque binary data of variable length and 64-bit offsets.
LargeBinary,
/// A variable-length string in Unicode with UTF-8 encoding.
Expand All @@ -84,7 +84,7 @@ pub enum DataType {
/// A list of some logical data type with variable length.
List(Box<Field>),
/// A list of some logical data type with fixed length.
FixedSizeList(Box<Field>, i32),
FixedSizeList(Box<Field>, usize),
/// A list of some logical data type with variable length and 64-bit offsets.
LargeList(Box<Field>),
/// A nested datatype that contains a number of sub-fields.
Expand Down
2 changes: 1 addition & 1 deletion src/io/avro/read/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ fn schema_to_field(
false,
))
}
AvroSchema::Fixed { size, .. } => DataType::FixedSizeBinary(*size as i32),
AvroSchema::Fixed { size, .. } => DataType::FixedSizeBinary(*size),
AvroSchema::Decimal {
precision, scale, ..
} => DataType::Decimal(*precision, *scale),
Expand Down
4 changes: 2 additions & 2 deletions src/io/ipc/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ fn get_data_type(field: ipc::Field, extension: Extension, may_be_dictionary: boo
ipc::Type::LargeUtf8 => DataType::LargeUtf8,
ipc::Type::FixedSizeBinary => {
let fsb = field.type_as_fixed_size_binary().unwrap();
DataType::FixedSizeBinary(fsb.byteWidth())
DataType::FixedSizeBinary(fsb.byteWidth() as usize)
}
ipc::Type::FloatingPoint => {
let float = field.type_as_floating_point().unwrap();
Expand Down Expand Up @@ -273,7 +273,7 @@ fn get_data_type(field: ipc::Field, extension: Extension, may_be_dictionary: boo
panic!("expect a list to have one child")
}
let fsl = field.type_as_fixed_size_list().unwrap();
DataType::FixedSizeList(Box::new(children.get(0).into()), fsl.listSize())
DataType::FixedSizeList(Box::new(children.get(0).into()), fsl.listSize() as usize)
}
ipc::Type::Struct_ => {
let mut fields = vec![];
Expand Down
3 changes: 1 addition & 2 deletions src/io/ipc/read/array/fixed_size_binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ pub fn read_fixed_size_binary<R: Read + Seek>(
compression,
)?;

let length =
field_node.length() as usize * (*FixedSizeBinaryArray::get_size(&data_type) as usize);
let length = field_node.length() as usize * FixedSizeBinaryArray::get_size(&data_type);
let values = read_buffer(
buffers,
length,
Expand Down
4 changes: 2 additions & 2 deletions src/io/json_integration/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ fn to_data_type(item: &Value, mut children: Vec<Field>) -> Result<DataType> {
"fixedsizebinary" => {
// return a list with any type as its child isn't defined in the map
if let Some(Value::Number(size)) = item.get("byteWidth") {
DataType::FixedSizeBinary(size.as_i64().unwrap() as i32)
DataType::FixedSizeBinary(size.as_i64().unwrap() as usize)
} else {
return Err(ArrowError::Schema(
"Expecting a byteWidth for fixedsizebinary".to_string(),
Expand Down Expand Up @@ -385,7 +385,7 @@ fn to_data_type(item: &Value, mut children: Vec<Field>) -> Result<DataType> {
if let Some(Value::Number(size)) = item.get("listSize") {
DataType::FixedSizeList(
Box::new(children.pop().unwrap()),
size.as_i64().unwrap() as i32,
size.as_i64().unwrap() as usize,
)
} else {
return Err(ArrowError::Schema(
Expand Down
4 changes: 2 additions & 2 deletions src/io/parquet/read/fixed_size_binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ where
ArrowError: From<E>,
I: FallibleStreamingIterator<Item = DataPage, Error = E>,
{
let size = *FixedSizeBinaryArray::get_size(&data_type) as usize;
let size = FixedSizeBinaryArray::get_size(&data_type);

let capacity = metadata.num_values() as usize;
let mut values = MutableBuffer::<u8>::with_capacity(capacity * size);
Expand Down Expand Up @@ -168,7 +168,7 @@ where
E: Clone,
I: Stream<Item = std::result::Result<DataPage, E>>,
{
let size = *FixedSizeBinaryArray::get_size(&data_type) as usize;
let size = FixedSizeBinaryArray::get_size(&data_type);

let capacity = metadata.num_values() as usize;
let mut values = MutableBuffer::<u8>::with_capacity(capacity * size);
Expand Down
2 changes: 1 addition & 1 deletion src/io/parquet/read/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ pub fn page_iter_to_array<I: FallibleStreamingIterator<Item = DataPage, Error =
let paddings = (0..(16 - *n)).map(|_| 0u8).collect::<Vec<_>>();
fixed_size_binary::iter_to_array(
iter,
DataType::FixedSizeBinary(*n),
DataType::FixedSizeBinary(*n as usize),
metadata,
)
.map(|e| {
Expand Down
2 changes: 1 addition & 1 deletion src/io/parquet/read/schema/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ pub fn from_fixed_len_byte_array(
// would be incorrect if all 12 bytes of the interval are populated
DataType::Interval(IntervalUnit::DayTime)
}
_ => DataType::FixedSizeBinary(*length),
_ => DataType::FixedSizeBinary(*length as usize),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/io/parquet/read/statistics/fixlen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl From<&ParquetFixedLenStatistics> for FixedLenStatistics {
distinct_count: stats.distinct_count,
min_value: stats.min_value.clone(),
max_value: stats.max_value.clone(),
data_type: DataType::FixedSizeBinary(byte_lens),
data_type: DataType::FixedSizeBinary(byte_lens as usize),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/io/parquet/write/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ pub fn array_to_page(
values.extend_from_slice(bytes)
});
let array = FixedSizeBinaryArray::from_data(
DataType::FixedSizeBinary(size as i32),
DataType::FixedSizeBinary(size),
values.into(),
array.validity().cloned(),
);
Expand Down Expand Up @@ -449,7 +449,7 @@ fn nested_array_to_page(
DataType::FixedSizeList(_, size) => {
let array = array.as_any().downcast_ref::<FixedSizeListArray>().unwrap();
let offsets = (0..array.len())
.map(|x| size * x as i32)
.map(|x| (*size * x) as i32)
.collect::<Vec<_>>();
list_array_to_page(
&offsets,
Expand Down
2 changes: 1 addition & 1 deletion src/io/parquet/write/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ pub fn to_parquet_type(field: &Field) -> Result<ParquetType> {
}
DataType::FixedSizeBinary(size) => Ok(ParquetType::try_from_primitive(
name,
PhysicalType::FixedLenByteArray(*size),
PhysicalType::FixedLenByteArray(*size as i32),
repetition,
None,
None,
Expand Down