arrow2 icon indicating copy to clipboard operation
arrow2 copied to clipboard

Export `values` of MutableArray

Open sundy-li opened this issue 2 years ago • 5 comments

For example:

pub struct MutableBinaryArray<O: Offset> {
    data_type: DataType,
    offsets: MutableBuffer<O>,
    values: MutableBuffer<u8>,
    validity: Option<MutableBitmap>,
}

When we want to add methods into MutableBinaryArray, we can't access the fields like values...

sundy-li avatar Dec 24 '21 14:12 sundy-li

The rational is that values and offsets are coupled: we can't expose values as a mut reference because the user may truncate it, leading to UB.

jorgecarleitao avatar Dec 28 '21 06:12 jorgecarleitao

We can still offer a &mut [u8] reference to it.

jorgecarleitao avatar Dec 28 '21 06:12 jorgecarleitao

Ok. Get it, seems we should build values and offsets on my own then construct them into MutableArray.

We don't like TryPush method in this MutableArray, if our array is not null, just need to push the values and offsets without option wrap.

sundy-li avatar Dec 28 '21 07:12 sundy-li

You mean to avoid the conditional branch that checks for the validity, right? I agree.

There is a use-case here to introduce an auxiliary struct that just cares about offsets, values and its invariants, and have the MutableBinaryArray use it. This way both you and MutableBinaryArray can use it, and you do not have to worry about unsafe on your side.

jorgecarleitao avatar Dec 28 '21 07:12 jorgecarleitao

Yes, that's right. Since MutableBinaryArray is not very complex now, we can have our own NoneNullMutableBinaryArray instead.

sundy-li avatar Dec 28 '21 08:12 sundy-li