[ 
https://issues.apache.org/jira/browse/ARROW-8508?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17089356#comment-17089356
 ] 

Christian Beilschmidt commented on ARROW-8508:
----------------------------------------------

As an addition, you can extend the assertion checks:
{code:java}
…

let multi_point = dbg!(multi_point_builder.finish());

// test first multi point

let first_multi_point_ref = multi_point.value(0);
let first_multi_point: &arrow::array::FixedSizeListArray = 
first_multi_point_ref.as_any().downcast_ref().unwrap();

assert_eq!(first_multi_point.len(), 2);

let coordinate_0_ref = first_multi_point.value(0);
let coordinate_0: &Float64Array = 
coordinate_0_ref.as_any().downcast_ref().unwrap();

assert_eq!(coordinate_0.len(), 2);
assert_eq!(coordinate_0.value_slice(0, 2), &[0.0, 0.1]);

let coordinate_1_ref = first_multi_point.value(1);
let coordinate_1: &Float64Array = 
coordinate_1_ref.as_any().downcast_ref().unwrap();

assert_eq!(coordinate_1.len(), 2);
assert_eq!(coordinate_1.value_slice(0, 2), &[1.0, 1.1]);

// test second multi point

let second_multi_point_ref = multi_point.value(1);
let second_multi_point: &arrow::array::FixedSizeListArray = 
second_multi_point_ref.as_any().downcast_ref().unwrap();

assert_eq!(second_multi_point.len(), 3);

let coordinate_2_ref = second_multi_point.value(0);
let coordinate_2: &Float64Array = 
coordinate_2_ref.as_any().downcast_ref().unwrap();

assert_eq!(coordinate_2.len(), 2);
assert_eq!(coordinate_2.value_slice(0, 2), &[2.0, 2.1]);

let coordinate_3_ref = second_multi_point.value(1);
let coordinate_3: &Float64Array = 
coordinate_3_ref.as_any().downcast_ref().unwrap();

assert_eq!(coordinate_3.len(), 2);
assert_eq!(coordinate_3.value_slice(0, 2), &[3.0, 3.1]);

let coordinate_4_ref = second_multi_point.value(2);
let coordinate_4: &Float64Array = 
coordinate_4_ref.as_any().downcast_ref().unwrap();

assert_eq!(coordinate_4.len(), 2);
assert_eq!(coordinate_4.value_slice(0, 2), &[4.0, 4.1]);
{code}
It fails with
{noformat}
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `[0.0, 0.1]`,
 right: `[2.0, 2.1]`', src/main.rs:76:5{noformat}
which corresponds to {{assert_eq!(coordinate_2.value_slice(0, 2), &[2.0, 
2.1]);}}

 

I tried your PR and it runs through just fine! (y)

> [Rust] ListBuilder of FixedSizeListBuilder creates wrong offsets
> ----------------------------------------------------------------
>
>                 Key: ARROW-8508
>                 URL: https://issues.apache.org/jira/browse/ARROW-8508
>             Project: Apache Arrow
>          Issue Type: Bug
>          Components: Rust
>    Affects Versions: 0.16.0
>            Reporter: Christian Beilschmidt
>            Priority: Major
>              Labels: pull-request-available
>
> I created an example of storing multi points with Arrow.
>  # A coordinate consists of two floats (Float64Builder)
>  # A multi point consists of one or more coordinates (FixedSizeListBuilder)
>  # A list of multi points consists of multiple multi points (ListBuilder)
> This is the corresponding code snippet:
> {code:java}
> let float_builder = arrow::array::Float64Builder::new(0);
> let coordinate_builder = 
> arrow::array::FixedSizeListBuilder::new(float_builder, 2);
> let mut multi_point_builder = 
> arrow::array::ListBuilder::new(coordinate_builder);
> multi_point_builder
>     .values()
>     .values()
>     .append_slice(&[0.0, 0.1])
>     .unwrap();
> multi_point_builder.values().append(true).unwrap();
> multi_point_builder
>     .values()
>     .values()
>     .append_slice(&[1.0, 1.1])
>     .unwrap();
> multi_point_builder.values().append(true).unwrap();
> multi_point_builder.append(true).unwrap(); // first multi point
> multi_point_builder
>     .values()
>     .values()
>     .append_slice(&[2.0, 2.1])
>     .unwrap();
> multi_point_builder.values().append(true).unwrap();
> multi_point_builder
>     .values()
>     .values()
>     .append_slice(&[3.0, 3.1])
>     .unwrap();
> multi_point_builder.values().append(true).unwrap();
> multi_point_builder
>     .values()
>     .values()
>     .append_slice(&[4.0, 4.1])
>     .unwrap();
> multi_point_builder.values().append(true).unwrap();
> multi_point_builder.append(true).unwrap(); // second multi point
> let multi_point = dbg!(multi_point_builder.finish());
> let first_multi_point_ref = multi_point.value(0);
> let first_multi_point: &arrow::array::FixedSizeListArray = 
> first_multi_point_ref.as_any().downcast_ref().unwrap();
> let coordinates_ref = first_multi_point.values();
> let coordinates: &Float64Array = 
> coordinates_ref.as_any().downcast_ref().unwrap();
> assert_eq!(coordinates.value_slice(0, 2 * 2), &[0.0, 0.1, 1.0, 1.1]);
> let second_multi_point_ref = multi_point.value(1);
> let second_multi_point: &arrow::array::FixedSizeListArray = 
> second_multi_point_ref.as_any().downcast_ref().unwrap();
> let coordinates_ref = second_multi_point.values();
> let coordinates: &Float64Array = 
> coordinates_ref.as_any().downcast_ref().unwrap();
> assert_eq!(coordinates.value_slice(0, 2 * 3), &[2.0, 2.1, 3.0, 3.1, 4.0, 
> 4.1]);
> {code}
> The second assertion fails and the output is {{[0.0, 0.1, 1.0, 1.1, 2.0, 
> 2.1]}}.
> Moreover, the debug output produced from {{dbg!}} confirms this:
> {noformat}
> [
>   FixedSizeListArray<2>
> [
>   PrimitiveArray<Float64>
> [
>   0.0,
>   0.1,
> ],
>   PrimitiveArray<Float64>
> [
>   1.0,
>   1.1,
> ],
> ],
>   FixedSizeListArray<2>
> [
>   PrimitiveArray<Float64>
> [
>   0.0,
>   0.1,
> ],
>   PrimitiveArray<Float64>
> [
>   1.0,
>   1.1,
> ],
>   PrimitiveArray<Float64>
> [
>   2.0,
>   2.1,
> ],
> ],
> ]{noformat}
> The second list should contain the values 2-4.
>  
> So either I am using the builder wrong or there is a bug with the offsets. I 
> used {{0.16}} as well as the current {{master}} from GitHub.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to