Return the expected [`DataTypeLayout`] Arrays of this data type are expected to have
(data_type: &DataType)
| 1728 | /// Return the expected [`DataTypeLayout`] Arrays of this data |
| 1729 | /// type are expected to have |
| 1730 | pub fn layout(data_type: &DataType) -> DataTypeLayout { |
| 1731 | // based on C/C++ implementation in |
| 1732 | // https://github.com/apache/arrow/blob/661c7d749150905a63dd3b52e0a04dac39030d95/cpp/src/arrow/type.h (and .cc) |
| 1733 | use arrow_schema::IntervalUnit::*; |
| 1734 | |
| 1735 | match data_type { |
| 1736 | DataType::Null => DataTypeLayout { |
| 1737 | buffers: vec![], |
| 1738 | can_contain_null_mask: false, |
| 1739 | variadic: false, |
| 1740 | }, |
| 1741 | DataType::Boolean => DataTypeLayout { |
| 1742 | buffers: vec![BufferSpec::BitMap], |
| 1743 | can_contain_null_mask: true, |
| 1744 | variadic: false, |
| 1745 | }, |
| 1746 | DataType::Int8 => DataTypeLayout::new_fixed_width::<i8>(), |
| 1747 | DataType::Int16 => DataTypeLayout::new_fixed_width::<i16>(), |
| 1748 | DataType::Int32 => DataTypeLayout::new_fixed_width::<i32>(), |
| 1749 | DataType::Int64 => DataTypeLayout::new_fixed_width::<i64>(), |
| 1750 | DataType::UInt8 => DataTypeLayout::new_fixed_width::<u8>(), |
| 1751 | DataType::UInt16 => DataTypeLayout::new_fixed_width::<u16>(), |
| 1752 | DataType::UInt32 => DataTypeLayout::new_fixed_width::<u32>(), |
| 1753 | DataType::UInt64 => DataTypeLayout::new_fixed_width::<u64>(), |
| 1754 | DataType::Float16 => DataTypeLayout::new_fixed_width::<half::f16>(), |
| 1755 | DataType::Float32 => DataTypeLayout::new_fixed_width::<f32>(), |
| 1756 | DataType::Float64 => DataTypeLayout::new_fixed_width::<f64>(), |
| 1757 | DataType::Timestamp(_, _) => DataTypeLayout::new_fixed_width::<i64>(), |
| 1758 | DataType::Date32 => DataTypeLayout::new_fixed_width::<i32>(), |
| 1759 | DataType::Date64 => DataTypeLayout::new_fixed_width::<i64>(), |
| 1760 | DataType::Time32(_) => DataTypeLayout::new_fixed_width::<i32>(), |
| 1761 | DataType::Time64(_) => DataTypeLayout::new_fixed_width::<i64>(), |
| 1762 | DataType::Interval(YearMonth) => DataTypeLayout::new_fixed_width::<i32>(), |
| 1763 | DataType::Interval(DayTime) => DataTypeLayout::new_fixed_width::<IntervalDayTime>(), |
| 1764 | DataType::Interval(MonthDayNano) => { |
| 1765 | DataTypeLayout::new_fixed_width::<IntervalMonthDayNano>() |
| 1766 | } |
| 1767 | DataType::Duration(_) => DataTypeLayout::new_fixed_width::<i64>(), |
| 1768 | DataType::Decimal32(_, _) => DataTypeLayout::new_fixed_width::<i32>(), |
| 1769 | DataType::Decimal64(_, _) => DataTypeLayout::new_fixed_width::<i64>(), |
| 1770 | DataType::Decimal128(_, _) => DataTypeLayout::new_fixed_width::<i128>(), |
| 1771 | DataType::Decimal256(_, _) => DataTypeLayout::new_fixed_width::<i256>(), |
| 1772 | DataType::FixedSizeBinary(size) => { |
| 1773 | let spec = BufferSpec::FixedWidth { |
| 1774 | byte_width: (*size).try_into().unwrap(), |
| 1775 | alignment: mem::align_of::<u8>(), |
| 1776 | }; |
| 1777 | DataTypeLayout { |
| 1778 | buffers: vec![spec], |
| 1779 | can_contain_null_mask: true, |
| 1780 | variadic: false, |
| 1781 | } |
| 1782 | } |
| 1783 | DataType::Binary => DataTypeLayout::new_binary::<i32>(), |
| 1784 | DataType::LargeBinary => DataTypeLayout::new_binary::<i64>(), |
| 1785 | DataType::Utf8 => DataTypeLayout::new_binary::<i32>(), |
| 1786 | DataType::LargeUtf8 => DataTypeLayout::new_binary::<i64>(), |
| 1787 | DataType::BinaryView | DataType::Utf8View => DataTypeLayout::new_view(), |
no outgoing calls