| 759 | } |
| 760 | |
| 761 | fn make_decoder( |
| 762 | ctx: &DecoderContext, |
| 763 | data_type: &DataType, |
| 764 | is_nullable: bool, |
| 765 | ) -> Result<Box<dyn ArrayDecoder>, ArrowError> { |
| 766 | macro_rules! primitive_decoder { |
| 767 | ($t:ty, $data_type:expr) => { |
| 768 | Ok(Box::new(PrimitiveArrayDecoder::<$t>::new(ctx, $data_type))) |
| 769 | }; |
| 770 | } |
| 771 | macro_rules! timestamp_decoder { |
| 772 | ($t:ty, $data_type:expr, $tz:expr) => {{ |
| 773 | Ok(Box::new(TimestampArrayDecoder::<$t, _>::new( |
| 774 | ctx, $data_type, $tz, |
| 775 | ))) |
| 776 | }}; |
| 777 | } |
| 778 | macro_rules! decimal_decoder { |
| 779 | ($t:ty, $p:expr, $s:expr) => { |
| 780 | Ok(Box::new(DecimalArrayDecoder::<$t>::new(ctx, $p, $s))) |
| 781 | }; |
| 782 | } |
| 783 | |
| 784 | downcast_integer! { |
| 785 | *data_type => (primitive_decoder, data_type), |
| 786 | DataType::Null => Ok(Box::new(NullArrayDecoder::new(ctx))), |
| 787 | DataType::Float16 => primitive_decoder!(Float16Type, data_type), |
| 788 | DataType::Float32 => primitive_decoder!(Float32Type, data_type), |
| 789 | DataType::Float64 => primitive_decoder!(Float64Type, data_type), |
| 790 | DataType::Timestamp(TimeUnit::Second, None) => { |
| 791 | timestamp_decoder!(TimestampSecondType, data_type, Utc) |
| 792 | }, |
| 793 | DataType::Timestamp(TimeUnit::Millisecond, None) => { |
| 794 | timestamp_decoder!(TimestampMillisecondType, data_type, Utc) |
| 795 | }, |
| 796 | DataType::Timestamp(TimeUnit::Microsecond, None) => { |
| 797 | timestamp_decoder!(TimestampMicrosecondType, data_type, Utc) |
| 798 | }, |
| 799 | DataType::Timestamp(TimeUnit::Nanosecond, None) => { |
| 800 | timestamp_decoder!(TimestampNanosecondType, data_type, Utc) |
| 801 | }, |
| 802 | DataType::Timestamp(TimeUnit::Second, Some(ref tz)) => { |
| 803 | let tz: Tz = tz.parse()?; |
| 804 | timestamp_decoder!(TimestampSecondType, data_type, tz) |
| 805 | }, |
| 806 | DataType::Timestamp(TimeUnit::Millisecond, Some(ref tz)) => { |
| 807 | let tz: Tz = tz.parse()?; |
| 808 | timestamp_decoder!(TimestampMillisecondType, data_type, tz) |
| 809 | }, |
| 810 | DataType::Timestamp(TimeUnit::Microsecond, Some(ref tz)) => { |
| 811 | let tz: Tz = tz.parse()?; |
| 812 | timestamp_decoder!(TimestampMicrosecondType, data_type, tz) |
| 813 | }, |
| 814 | DataType::Timestamp(TimeUnit::Nanosecond, Some(ref tz)) => { |
| 815 | let tz: Tz = tz.parse()?; |
| 816 | timestamp_decoder!(TimestampNanosecondType, data_type, tz) |
| 817 | }, |
| 818 | DataType::Date32 => primitive_decoder!(Date32Type, data_type), |