jorgecarleitao commented on a change in pull request #8561:
URL: https://github.com/apache/arrow/pull/8561#discussion_r517097606



##########
File path: rust/parquet/src/arrow/arrow_writer.rs
##########
@@ -283,48 +280,40 @@ trait Materialize<K, V> {
     fn materialize(&self) -> Vec<Self::Output>;
 }
 
-macro_rules! materialize_string {
-    ($($k:ty,)*) => {
-        $(impl Materialize<$k, arrow_array::StringArray> for dyn Array {
-            type Output = ByteArray;
-
-            fn materialize(&self) -> Vec<Self::Output> {
-                use std::convert::TryFrom;
-
-                let typed_array = self.as_any()
-                    .downcast_ref::<$k>()
-                    .expect("Unable to get dictionary array");
-
-                let keys = typed_array.keys();
-
-                let value_buffer = typed_array.values();
-                let values = value_buffer
-                    .as_any()
-                    .downcast_ref::<arrow_array::StringArray>()
-                    .unwrap();
-
-                // This removes NULL values from the NullableIter, but
-                // they're encoded by the levels, so that's fine.
-                keys
-                    .flatten()
-                    .map(|key| usize::try_from(key).unwrap_or_else(|k| 
panic!("key {} does not fit in usize", k)))
-                    .map(|key| values.value(key))
-                    .map(ByteArray::from)
-                    .collect()
-            }
-        })*
-    };
-}
+impl<K> Materialize<K, arrow_array::StringArray> for dyn Array
+where
+    K: arrow::datatypes::ArrowDictionaryKeyType,
+{
+    type Output = ByteArray;
+
+    fn materialize(&self) -> Vec<Self::Output> {
+        use arrow::datatypes::ArrowNativeType;
 
-materialize_string! {
-    arrow_array::Int8DictionaryArray,
-    arrow_array::Int16DictionaryArray,
-    arrow_array::Int32DictionaryArray,
-    arrow_array::Int64DictionaryArray,
-    arrow_array::UInt8DictionaryArray,
-    arrow_array::UInt16DictionaryArray,
-    arrow_array::UInt32DictionaryArray,
-    arrow_array::UInt64DictionaryArray,
+        let typed_array = self
+            .as_any()
+            .downcast_ref::<arrow_array::DictionaryArray<K>>()
+            .expect("Unable to get dictionary array");
+
+        let keys = typed_array.keys();
+
+        let value_buffer = typed_array.values();
+        let values = value_buffer
+            .as_any()
+            .downcast_ref::<arrow_array::StringArray>()
+            .unwrap();
+
+        // This removes NULL values from the keys, but
+        // they're encoded by the levels, so that's fine.
+        keys.into_iter()
+            .flatten()
+            .map(|key| {
+                key.to_usize()
+                    .unwrap_or_else(|| panic!("key {:?} does not fit in 
usize", key))
+            })
+            .map(|key| values.value(key))
+            .map(ByteArray::from)
+            .collect()

Review comment:
       what @nevi-me wrote: this is only a simplification (consequent of the 
fact that the `keys` now allow us to write this as a generic).




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to