From acf6a72cda61de510ff853b28a15e056cc153a8e Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Mon, 19 Oct 2020 16:48:38 -0400 Subject: [PATCH] Extract a macro for string dictionary conversion --- rust/parquet/src/arrow/array_reader.rs | 72 ++++++++++---------------- 1 file changed, 27 insertions(+), 45 deletions(-) diff --git a/rust/parquet/src/arrow/array_reader.rs b/rust/parquet/src/arrow/array_reader.rs index cc3498f7c0e1b..a59a3caef9bdd 100644 --- a/rust/parquet/src/arrow/array_reader.rs +++ b/rust/parquet/src/arrow/array_reader.rs @@ -1552,54 +1552,36 @@ impl<'a> ArrayReaderBuilder { page_iterator: Box, column_desc: ColumnDescPtr, ) -> Result> { - match key_type { - ArrowType::Int8 => { - let converter = DictionaryConverter::new(DictionaryArrayConverter {}); + macro_rules! convert_string_dictionary { + ($(($kt: pat, $at: ident),)*) => ( + match key_type { + $($kt => { + let converter = DictionaryConverter::new(DictionaryArrayConverter {}); - Ok(Box::new(ComplexObjectArrayReader::< - ByteArrayType, - DictionaryConverter, - >::new( - page_iterator, column_desc, converter - )?)) - } - ArrowType::Int16 => { - let converter = DictionaryConverter::new(DictionaryArrayConverter {}); - - Ok(Box::new(ComplexObjectArrayReader::< - ByteArrayType, - DictionaryConverter, - >::new( - page_iterator, column_desc, converter - )?)) - } - ArrowType::Int32 => { - let converter = DictionaryConverter::new(DictionaryArrayConverter {}); - - Ok(Box::new(ComplexObjectArrayReader::< - ByteArrayType, - DictionaryConverter, - >::new( - page_iterator, column_desc, converter - )?)) - } - ArrowType::Int64 => { - let converter = DictionaryConverter::new(DictionaryArrayConverter {}); + Ok(Box::new(ComplexObjectArrayReader::< + ByteArrayType, + DictionaryConverter<$at>, + >::new( + page_iterator, column_desc, converter + )?)) - Ok(Box::new(ComplexObjectArrayReader::< - ByteArrayType, - DictionaryConverter, - >::new( - page_iterator, column_desc, converter - )?)) - } - ref other => { - return Err(general_err!( - "Invalid/Unsupported index type for dictionary: {:?}", - other - )) - } + })* + ref other => { + return Err(general_err!( + "Invalid/Unsupported index type for dictionary: {:?}", + other + )) + } + } + ); } + + convert_string_dictionary!( + (ArrowType::Int8, ArrowInt8Type), + (ArrowType::Int16, ArrowInt16Type), + (ArrowType::Int32, ArrowInt32Type), + (ArrowType::Int64, ArrowInt64Type), + ) } /// Constructs struct array reader without considering repetition.