Skip to content
Merged
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
32 changes: 31 additions & 1 deletion datafusion/physical-expr/src/equivalence/grouping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,40 @@ use datafusion_physical_expr_common::physical_expr::format_physical_expr_list;
/// order. Contiguity applies to the complete partition stream, not separately
/// to each record batch.
///
/// For example, consider the following table:
///
/// ```text
/// ┌───┬───┬───┐
/// │ a │ b │ c │
/// ├───┼───┼───┤
/// │ 2 │ 1 │ 5 │
/// │ 2 │ 1 │ 3 │
/// │ 1 │ 3 │ 4 │
/// │ 2 │ 2 │ 1 │
/// │ 2 │ 2 │ 2 │
/// └───┴───┴───┘
/// ```
///
/// * Is grouped by `[a, b]`, as rows with the same `(a, b)` are contiguous,
/// even though the table is not sorted by `a`, `b` nor `(a, b)`.
/// * Is grouped by `[b]`, since each value of `b` is in one run.
/// * Is grouped by `[c]`, and by any tuple that contains `c` such as `[a, c]`,
/// because each value of `c` is distinct.
/// * Is NOT grouped by `[a]`, because `a = 2` appears in two separate runs.
///
Comment on lines +28 to +45

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it also grouped by c, c,a, ...? 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so for this example because c is distinct.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a new bullet

Is grouped by [c], and by any tuple that contains c such as [a, c],
/// because each value of c is distinct.

/// Expression order within an entry is not significant: `[a, b]` and `[b, a]`
/// describe the same grouping. Entries do not imply properties for subsets;
/// `[a, b]` alone says nothing about whether all rows with the same `a` are
/// as the table shows, `[a, b]` does not imply `[a]` as the same `a` may not be
/// contiguous.
///
/// # See also
/// * [`OrderingEquivalenceClass`] for the stronger property that rows are
/// sorted.
/// * [`EquivalenceProperties`] for how groupings relate to the other
/// properties of a plan node.
///
/// [`EquivalenceProperties`]: crate::equivalence::EquivalenceProperties
/// [`OrderingEquivalenceClass`]: crate::equivalence::OrderingEquivalenceClass
#[derive(Clone, Debug, Default)]
pub struct GroupingEquivalenceClass {
groupings: Vec<Vec<Arc<dyn PhysicalExpr>>>,
Expand Down
Loading