tustvold commented on code in PR #2826:
URL: https://github.com/apache/arrow-rs/pull/2826#discussion_r988725400


##########
arrow/src/row/mod.rs:
##########
@@ -243,68 +285,135 @@ pub struct Rows {
     buffer: Box<[u8]>,
     /// Row `i` has data `&buffer[offsets[i]..offsets[i+1]]`
     offsets: Box<[usize]>,
+    /// The schema for these rows
+    fields: Arc<[SortField]>,
 }
 
 impl Rows {
     pub fn row(&self, row: usize) -> Row<'_> {
         let end = self.offsets[row + 1];
         let start = self.offsets[row];
-        Row(&self.buffer[start..end])
+        Row {
+            data: &self.buffer[start..end],
+            fields: &self.fields,
+        }
     }
 
     pub fn num_rows(&self) -> usize {
         self.offsets.len() - 1
     }
 }
 
+impl<'a> IntoIterator for &'a Rows {
+    type Item = Row<'a>;
+    type IntoIter = RowsIter<'a>;
+
+    fn into_iter(self) -> Self::IntoIter {
+        RowsIter {
+            rows: self,
+            start: 0,
+            end: self.num_rows(),
+        }
+    }
+}
+
+/// An iterator over [`Rows`]
+#[derive(Debug)]
+pub struct RowsIter<'a> {
+    rows: &'a Rows,
+    start: usize,
+    end: usize,
+}
+
+impl<'a> Iterator for RowsIter<'a> {
+    type Item = Row<'a>;
+
+    fn next(&mut self) -> Option<Self::Item> {
+        if self.end == self.start {
+            return None;
+        }
+        let row = self.rows.row(self.start);
+        self.start += 1;
+        Some(row)
+    }
+
+    fn size_hint(&self) -> (usize, Option<usize>) {
+        let len = self.len();
+        (len, Some(len))
+    }
+}
+
+impl<'a> ExactSizeIterator for RowsIter<'a> {
+    fn len(&self) -> usize {
+        self.end - self.start
+    }
+}
+
+impl<'a> DoubleEndedIterator for RowsIter<'a> {
+    fn next_back(&mut self) -> Option<Self::Item> {
+        if self.end == self.start {
+            return None;
+        }
+        let row = self.rows.row(self.end);
+        self.end -= 1;
+        Some(row)
+    }
+}
+
 /// A comparable representation of a row
 ///
 /// Two [`Row`] can be compared if they both belong to [`Rows`] returned by 
calls to
 /// [`RowConverter::convert_columns`] on the same [`RowConverter`]
 ///
 /// Otherwise any ordering established by comparing the [`Row`] is arbitrary
-#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
-pub struct Row<'a>(&'a [u8]);
+#[derive(Debug, Copy, Clone)]
+pub struct Row<'a> {
+    data: &'a [u8],
+    fields: &'a Arc<[SortField]>,
+}
 
-impl<'a> AsRef<[u8]> for Row<'a> {
-    fn as_ref(&self) -> &[u8] {
-        self.0
+impl<'a> PartialEq for Row<'a> {
+    #[inline]
+    fn eq(&self, other: &Self) -> bool {
+        self.data.eq(other.data)
     }
 }
 
-/// Computes the dictionary mapping for the given dictionary values
-fn compute_dictionary_mapping(
-    interner: &mut OrderPreservingInterner,
-    values: &ArrayRef,
-) -> Result<Vec<Option<Interned>>> {
-    use fixed::FixedLengthEncoding;
-    Ok(downcast_primitive_array! {
-        values => interner
-            .intern(values.iter().map(|x| x.map(|x| x.encode()))),
-        DataType::Binary => {
-            let iter = as_generic_binary_array::<i64>(values).iter();
-            interner.intern(iter)
-        }
-        DataType::LargeBinary => {
-            let iter = as_generic_binary_array::<i64>(values).iter();
-            interner.intern(iter)
-        }
-        DataType::Utf8 => {
-            let iter = as_string_array(values).iter().map(|x| x.map(|x| 
x.as_bytes()));
-            interner.intern(iter)
-        }
-        DataType::LargeUtf8 => {
-            let iter = as_largestring_array(values).iter().map(|x| x.map(|x| 
x.as_bytes()));
-            interner.intern(iter)
-        }
-        t => return Err(ArrowError::NotYetImplemented(format!("dictionary 
value {} is not supported", t))),
-    })
+impl<'a> Eq for Row<'a> {}

Review Comment:
   We don't want to include fields, will add a comment



-- 
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.

To unsubscribe, e-mail: [email protected]

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

Reply via email to