fdb-rs / fdb

FoundationDB client API for Tokio
https://fdb-rs.github.io/
Apache License 2.0
44 stars 2 forks source link

Need a way to access Tuple elements and slice #30

Open ggilley opened 2 years ago

ggilley commented 2 years ago

I'm trying to read a block of tuples in and group them by a prefix. I need to be able to, for example, drop the first element of the tuple, then pass it on. It looks like you tried to prevent that unlike the other fdb apis? (e.g. java and golang).

I'm doing something like what is described here: https://forums.foundationdb.org/t/best-practice-of-storing-structs-should-i-pack-or-store-fields-separately/425/2?u=dongxineric

I'm storing the fields separately which means I need to be able to gather them by the "key" prefix.

rajivr commented 2 years ago

I'm trying to read a block of tuples in and group them by a prefix. I need to be able to, for example, drop the first element of the tuple, then pass it on. It looks like you tried to prevent that unlike the other fdb apis? (e.g. java and golang).

Thanks for opening this issue.

If I understand your issue correctly, what you are asking for is to take a tuple value of the form (("name", "john"), ("age", 34),) and drop the first element to create a tuple of the form (("age", 34),).

If that is so, then currently there is no public API that can address it. I think this feature will be useful for layer development and I'll add it in the next release.

I'll outline my initial thoughts on how we could implement this in case you are interested in contributing a PR. :-)

Internally, Tuple elements are stored as a Vec<TupleValue>. If we want to implement this feature, we will need to change this to VecDeque<TupleValue>. With that change, we will get push_{back,front} and pop_{back,front} APIs, which we can use to implement this feature. We will also need to check for versionstamp status when we mutate a tuple.

ggilley commented 2 years ago

Yes, I think what you are suggesting would work. Let me explain in detail.

If you think of a struct: User { first_name: String last_name: String} }

So I would have tuples (assuming the value is in the tuple) (user, $userid-1, first_name, Sam) (user, $userid-1, last_name, Burton) (user, $userid-2, first_name, Charles) (user, $userid-2, last_name, Barkley)

and I would drop the “user” prefix, then check the next level:

($userid-1, first_name, Sam)
($userid-1, last_name, Burton)
($userid-2, first_name, Charles)
($userid-2, last_name, Barkley)

Then find the common prefix, and create the user struct for each:

for User $userid-1:
    (first_name, Sam)
    (last_name, Burton

for User $userid-2: (first_name, Charles) (last_name, Barkley)

So you could think of it as a “slice” operation taking the everything after the first element. pop_front would work for this.

I have a work-around for insert(0) and push() using append().

But your solution would solve both problems.

On Jul 31, 2022, at 5:27 PM, Rajiv M Ranganath @.***> wrote:

I'm trying to read a block of tuples in and group them by a prefix. I need to be able to, for example, drop the first element of the tuple, then pass it on. It looks like you tried to prevent that unlike the other fdb apis? (e.g. java and golang).

Thanks for opening this issue.

If I understand your issue correctly, what you are asking for is to take a tuple value of the form (("name", "john"), ("age", 34),) and drop the first element to create a tuple of the form (("age", 34),).

If that is so, then currently there is no public API that can address it. I think this feature will be useful for layer development and I'll add it in the next release.

I'll outline my initial thoughts on how we could implement this in case you are interested in contributing a PR. :-)

Internally, Tuple elements are stored as a Vec. If we want to implement this feature, we will need to change this to VecDeque. With that change, we will get push{back,front} and pop{back,front} APIs, which we can use to implement this feature. We will also need to check for versionstamp status when we mutate a tuple.

— Reply to this email directly, view it on GitHub https://github.com/fdb-rs/fdb/issues/30#issuecomment-1200543906, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAXKK6I36OYKRIZCYA4CYELVW4KYZANCNFSM55FJ3FEQ. You are receiving this because you authored the thread.

rajivr commented 2 years ago

@ggilley I've pushed a new Tuple API modeled after Rust's VecDeque to a temporary repository here. The new API will land in 0.4.x release and should address your issue.

I don't know when I might do the next release as am currently busy with the layer crate. Feel free to use this repository in the meantime. Sorry for the delay!