alamb commented on code in PR #7318:
URL: https://github.com/apache/arrow-rs/pull/7318#discussion_r2008212575


##########
arrow-ipc/src/writer.rs:
##########
@@ -3075,4 +3098,111 @@ mod tests {
         assert_eq!(stream_bytes_written_on_flush, 
expected_stream_flushed_bytes);
         assert_eq!(file_bytes_written_on_flush, expected_file_flushed_bytes);
     }
+
+    #[test]
+    fn test_roundtrip_list_of_fixed_list() -> Result<(), ArrowError> {
+        let l0_builder = Float32Builder::new();
+        let l1_builder = FixedSizeListBuilder::new(l0_builder, 3);
+        let mut l2_builder = ListBuilder::new(l1_builder);
+
+        for point in [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]] {
+            l2_builder.values().values().append_value(point[0]);
+            l2_builder.values().values().append_value(point[1]);
+            l2_builder.values().values().append_value(point[2]);
+
+            l2_builder.values().append(true);
+        }
+        l2_builder.append(true);
+
+        let point = [10., 11., 12.];
+        l2_builder.values().values().append_value(point[0]);
+        l2_builder.values().values().append_value(point[1]);
+        l2_builder.values().values().append_value(point[2]);
+
+        l2_builder.values().append(true);
+        l2_builder.append(true);
+
+        let array = Arc::new(l2_builder.finish()) as ArrayRef;
+
+        let schema = Arc::new(Schema::new_with_metadata(
+            vec![Field::new(
+                "points",
+                DataType::List(Arc::new(Field::new(
+                    "item",
+                    DataType::FixedSizeList(
+                        Arc::new(Field::new("item", DataType::Float32, true)),
+                        3,
+                    ),
+                    true,
+                ))),
+                true,
+            )],
+            HashMap::default(),
+        ));
+
+        // Test a variety of combinations that include 0 and non-zero offsets
+        // and also portions or the rest of the array
+        test_subarray(&array, &schema, 0, 1)?;
+        test_subarray(&array, &schema, 0, 2)?;
+        test_subarray(&array, &schema, 1, 1)?;
+
+        Ok(())
+    }
+
+    fn test_subarray(

Review Comment:
   Minor nit is I would call this "test_slices" as it is testing sliced arrays
   
   ```suggestion
       fn test_slices(
   ```



##########
arrow-ipc/src/writer.rs:
##########
@@ -3075,4 +3098,111 @@ mod tests {
         assert_eq!(stream_bytes_written_on_flush, 
expected_stream_flushed_bytes);
         assert_eq!(file_bytes_written_on_flush, expected_file_flushed_bytes);
     }
+
+    #[test]
+    fn test_roundtrip_list_of_fixed_list() -> Result<(), ArrowError> {

Review Comment:
   I verified that this test fails without the code in this PR
   
   ```shell
   
   assertion `left == right` failed
     left: RecordBatch { schema: Schema { fields: [Field { name: "points", 
data_type: List(Field { name: "item", data_type: FixedSizeList(Field { name: 
"item", data_type: Float32, nullable: true, dict_id: 0, dict_is_ordered: false, 
metadata: {} }, 3), nullable: true, dict_id: 0, dict_is_ordered: false, 
metadata: {} }), nullable: true, dict_id: 0, dict_is_ordered: false, metadata: 
{} }], metadata: {} }, columns: [ListArray
   [
     FixedSizeListArray<3>
   [
     PrimitiveArray<Float32>
   [
     10.0,
     11.0,
     12.0,
   ],
   ],
   ]], row_count: 1 }
    right: RecordBatch { schema: Schema { fields: [Field { name: "points", 
data_type: List(Field { name: "item", data_type: FixedSizeList(Field { name: 
"item", data_type: Float32, nullable: true, dict_id: 0, dict_is_ordered: false, 
metadata: {} }, 3), nullable: true, dict_id: 0, dict_is_ordered: false, 
metadata: {} }), nullable: true, dict_id: 0, dict_is_ordered: false, metadata: 
{} }], metadata: {} }, columns: [ListArray
   [
     FixedSizeListArray<3>
   [
     PrimitiveArray<Float32>
   [
     1.0,
     2.0,
     3.0,
   ],
   ],
   ]], row_count: 1 }
   
   <Click to see difference>
   
   thread 'writer::tests::test_roundtrip_list_of_fixed_list' panicked at 
arrow-ipc/src/writer.rs:3150:9:
   assertion `left == right` failed
     left: RecordBatch { schema: Schema { fields: [Field { name: "points", 
data_type: List(Field { name: "item", data_type: FixedSizeList(Field { name: 
"item", data_type: Float32, nullable: true, dict_id: 0, dict_is_ordered: false, 
metadata: {} }, 3), nullable: true, dict_id: 0, dict_is_ordered: false, 
metadata: {} }), nullable: true, dict_id: 0, dict_is_ordered: false, metadata: 
{} }], metadata: {} }, columns: [ListArray
   [
     FixedSizeListArray<3>
   [
     PrimitiveArray<Float32>
   [
     10.0,
     11.0,
     12.0,
   ],
   ],
   ]], row_count: 1 }
    right: RecordBatch { schema: Schema { fields: [Field { name: "points", 
data_type: List(Field { name: "item", data_type: FixedSizeList(Field { name: 
"item", data_type: Float32, nullable: true, dict_id: 0, dict_is_ordered: false, 
metadata: {} }, 3), nullable: true, dict_id: 0, dict_is_ordered: false, 
metadata: {} }), nullable: true, dict_id: 0, dict_is_ordered: false, metadata: 
{} }], metadata: {} }, columns: [ListArray
   [
     FixedSizeListArray<3>
   [
     PrimitiveArray<Float32>
   [
     1.0,
     2.0,
     3.0,
   ],
   ],
   ]], row_count: 1 }
   stack backtrace:
      0: rust_begin_unwind
                at 
/rustc/4eb161250e340c8f48f66e2b929ef4a5bed7c181/library/std/src/panicking.rs:692:5
      1: core::panicking::panic_fmt
                at 
/rustc/4eb161250e340c8f48f66e2b929ef4a5bed7c181/library/core/src/panicking.rs:75:14
      2: core::panicking::assert_failed_inner
      3: core::panicking::assert_failed
                at 
/Users/andrewlamb/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/panicking.rs:364:5
      4: arrow_ipc::writer::tests::test_subarray
                at ./src/writer.rs:3150:9
      5: arrow_ipc::writer::tests::test_roundtrip_list_of_fixed_list
                at ./src/writer.rs:3127:9
      6: 
arrow_ipc::writer::tests::test_roundtrip_list_of_fixed_list::{{closure}}
                at ./src/writer.rs:3083:47
      7: core::ops::function::FnOnce::call_once
                at 
/Users/andrewlamb/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
      8: core::ops::function::FnOnce::call_once
                at 
/rustc/4eb161250e340c8f48f66e2b929ef4a5bed7c181/library/core/src/ops/function.rs:250:5
   note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose 
backtrace.
   ```



##########
arrow-ipc/src/writer.rs:
##########
@@ -3075,4 +3098,111 @@ mod tests {
         assert_eq!(stream_bytes_written_on_flush, 
expected_stream_flushed_bytes);
         assert_eq!(file_bytes_written_on_flush, expected_file_flushed_bytes);
     }
+
+    #[test]
+    fn test_roundtrip_list_of_fixed_list() -> Result<(), ArrowError> {
+        let l0_builder = Float32Builder::new();
+        let l1_builder = FixedSizeListBuilder::new(l0_builder, 3);
+        let mut l2_builder = ListBuilder::new(l1_builder);
+
+        for point in [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]] {

Review Comment:
   Can you also add a test case that has nulls too? Like `4.0, NULL, 5.0` ? 
Maybe as a different test case



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