Skip to content

Upserts with more selective update functionality #593

@mmottl

Description

@mmottl

The already available arrange_from_upsert function has the following signature:

pub fn arrange_from_upsert<G, K, V, Bu, Tr>(
    stream: &Stream<G, (K, Option<V>, G::Timestamp)>,
    name: &str,
) -> Arranged<G, TraceAgent<Tr>>
where ...

The stream of updates only allows for either deletion (None) of existing entries, or complete replacement of the value associated with a key with Some(new_value). But sometimes we want to update only part of an existing value.

We were thinking of a function with maybe the following signature:

pub fn arrange_from_update<G, K, V, U, F, Bu, Tr>(
    stream: &Stream<G, (K, U, G::Timestamp)>,
    name: &str,
    update_func: F,
) -> Arranged<G, TraceAgent<Tr>>
where
    U: ExchangeData, // Added U
    F: Fn(&K, Option<&V>, &U) -> Option<V> + Clone + 'static, // Added F
    ...

This adds two more generic types: U (update information) and F for an additional closure argument update_func that combines the key, an optional existing value, and the update information to generate an optional replacement.

Note that the current arrange_from_upsert function could be easily implemented on top of the above new function. U would be the same as V in that case, and update_func would return the optional replacement Some(new_value) if there were Some(old_value), or None otherwise.

There are at least two advantages offered by the new function:

  • Updating parts of existing values becomes possible or certainly much easier.
  • update_func can detect and act on the case where a key is missing (None being passed as argument), e.g. for emitting warnings if that indicates a problem.

It seems the suggested new function could be easily implemented reusing the existing code for arrange_from_upsert. Unless the compiler cannot optimize away the abstractions, we could then replace it with a suitable call to arrange_from_update.

Would it be possible to add this feature, or maybe comment on any potential issues with the proposal?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions