Skip to content

Commit c0ec801

Browse files
committed
Improve comments around WithOrdinality
1 parent 633c6c5 commit c0ec801

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/expr/src/relation/func.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3784,10 +3784,7 @@ pub enum TableFunc {
37843784
relation: RelationType,
37853785
},
37863786
RegexpMatches,
3787-
/// Evaluates the inner table function, expands its results into unary (repeating each row as
3788-
/// many times as the diff indicates), and appends an integer corresponding to the ordinal
3789-
/// position (starting from 1). For example, it numbers the elements of a list when calling
3790-
/// `unnest_list`.
3787+
/// Implements the WITH ORDINALITY clause.
37913788
///
37923789
/// Don't construct `TableFunc::WithOrdinality` manually! Use the `with_ordinality` constructor
37933790
/// function instead, which checks whether the given table function supports `WithOrdinality`.
@@ -3798,6 +3795,11 @@ pub enum TableFunc {
37983795
/// Private enum variant of `TableFunc`. Don't construct this directly, but use
37993796
/// `TableFunc::with_ordinality` instead.
38003797
///
3798+
/// Evaluates the inner table function, expands its results into unary (repeating each row as
3799+
/// many times as the diff indicates), and appends an integer corresponding to the ordinal
3800+
/// position (starting from 1). For example, it numbers the elements of a list when calling
3801+
/// `unnest_list`.
3802+
///
38013803
/// TODO(ggevay): This struct (and its field) is pub only temporarily, until we make
38023804
/// `FlatMapElimination` not dive into it.
38033805
#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize, Hash, MzReflect)]
@@ -3832,8 +3834,7 @@ impl TableFunc {
38323834
inner: Box::new(inner),
38333835
})),
38343836
// IMPORTANT: Before adding a new table function here, consider negative diffs:
3835-
// `WithOrdinality::eval` currently asserts that the inner table function never emits
3836-
// negative diffs.
3837+
// `WithOrdinality::eval` will panic if the inner table function emits a negative diff.
38373838
_ => None,
38383839
}
38393840
}
@@ -3974,6 +3975,7 @@ impl RustType<ProtoTableFunc> for TableFunc {
39743975
}
39753976

39763977
impl TableFunc {
3978+
/// Executes `self` on the given input row (`datums`).
39773979
pub fn eval<'a>(
39783980
&'a self,
39793981
datums: &'a [Datum<'a>],
@@ -4334,13 +4336,19 @@ impl fmt::Display for TableFunc {
43344336
}
43354337

43364338
impl WithOrdinality {
4339+
/// Executes the `self.inner` table function on the given input row (`datums`), and zips
4340+
/// 1, 2, 3, ... to the result as a new column. We need to expand rows with non-1 diffs into the
4341+
/// corresponding number of rows with unit diffs, because the ordinality column will have
4342+
/// different values for each copy.
4343+
///
4344+
/// # Panics
4345+
///
4346+
/// Panics if the `inner` table function emits a negative diff.
43374347
fn eval<'a>(
43384348
&'a self,
43394349
datums: &'a [Datum<'a>],
43404350
temp_storage: &'a RowArena,
43414351
) -> Result<Box<dyn Iterator<Item = (Row, Diff)> + 'a>, EvalError> {
4342-
// zip 1, 2, 3, 4, ... to the output of the table function. We need to blow up non-1 diffs,
4343-
// because the ordinality column will have different values for each copy.
43444352
let mut next_ordinal: i64 = 1;
43454353
let it = self
43464354
.inner

0 commit comments

Comments
 (0)