Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document the collection invariant #384

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ pub struct Collection<G: Scope, D, R: Semigroup = isize> {
///
/// This field is exposed to support direct timely dataflow manipulation when required, but it is
/// not intended to be the idiomatic way to work with the collection.
///
/// The timestamp in the data is required to always be at least the timestamp _of_ the data, in
/// the timely-dataflow sense. If this invariant is not upheld, differential operators may behave
/// unexpectedly.
pub inner: Stream<G, (D, G::Timestamp, R)>
}

Expand All @@ -52,6 +56,9 @@ impl<G: Scope, D: Data, R: Semigroup> Collection<G, D, R> where G::Timestamp: Da
/// idiomatic approach to convert timely streams to collections. Also, the `input::Input` trait
/// provides a `new_collection` method which will create a new collection for you without exposing
/// the underlying timely stream at all.
///
/// This stream should satisfy the timestamp invariant as documented on [Collection]; this
/// method does not check it.
pub fn new(stream: Stream<G, (D, G::Timestamp, R)>) -> Collection<G, D, R> {
Collection { inner: stream }
}
Expand Down Expand Up @@ -356,8 +363,9 @@ impl<G: Scope, D: Data, R: Semigroup> Collection<G, D, R> where G::Timestamp: Da
///
/// It is assumed that `func` only advances timestamps; this is not verified, and things may go horribly
/// wrong if that assumption is incorrect. It is also critical that `func` be monotonic: if two times are
/// ordered, they should have the same order once `func` is applied to them (this is because we advance the
/// timely capability with the same logic, and it must remain `less_equal` to all of the data timestamps).
/// ordered, they should have the same order or compare equal once `func` is applied to them (this
/// is because we advance the timely capability with the same logic, and it must remain `less_equal`
/// to all of the data timestamps).
pub fn delay<F>(&self, func: F) -> Collection<G, D, R>
where F: FnMut(&G::Timestamp) -> G::Timestamp + Clone + 'static {

Expand All @@ -369,6 +377,7 @@ impl<G: Scope, D: Data, R: Semigroup> Collection<G, D, R> where G::Timestamp: Da
.map_in_place(move |x| x.1 = func2(&x.1))
.as_collection()
}

/// Applies a supplied function to each update.
///
/// This method is most commonly used to report information back to the user, often for debugging purposes.
Expand Down Expand Up @@ -599,6 +608,10 @@ pub trait AsCollection<G: Scope, D: Data, R: Semigroup> {
}

impl<G: Scope, D: Data, R: Semigroup> AsCollection<G, D, R> for Stream<G, (D, G::Timestamp, R)> {
/// Converts the type to a differential dataflow collection.
///
/// By calling this method, you guarantee that the timestamp invariant (as documented on
/// [Collection]) is upheld. This method will not check it.
fn as_collection(&self) -> Collection<G, D, R> {
Collection::new(self.clone())
}
Expand Down
2 changes: 2 additions & 0 deletions src/lattice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub trait Lattice : PartialOrder {
/// assert_eq!(join, Product::new(4, 7));
/// # }
/// ```
#[must_use]
fn join(&self, other: &Self) -> Self;

/// Updates `self` to the smallest element greater than or equal to both arguments.
Expand Down Expand Up @@ -67,6 +68,7 @@ pub trait Lattice : PartialOrder {
/// assert_eq!(meet, Product::new(3, 6));
/// # }
/// ```
#[must_use]
fn meet(&self, other: &Self) -> Self;

/// Updates `self` to the largest element less than or equal to both arguments.
Expand Down