Skip to content

Commit 47e4765

Browse files
authored
doc: more comments to evaluate_selection function (#24485)
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> - Closes #. ## Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. Please explain the problem you are trying to solve in terms of the user-visible behavior, rather than the implementation. For example, "The code in `foo.rs` doesn't handle nulls" is a symptom of the implementation. "COUNT(DISTINCT) returns wrong results when the column contains nulls" is the user-visible problem. --> ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here, but it is sometimes worth providing a summary of the individual changes in this PR. --> ## Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. If there are any breaking changes to public APIs, please add the `api change` label. -->
1 parent 5c12114 commit 47e4765

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

‎datafusion/physical-expr-common/src/physical_expr.rs‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,30 @@ pub trait PhysicalExpr: Any + Send + Sync + Display + Debug + DynEq + DynHash {
9393
self.nullable(input_schema)?,
9494
)))
9595
}
96-
/// Evaluate an expression against a RecordBatch after first applying a validity array
96+
/// Evaluates this expression only for rows where `selection` is `true`.
97+
///
98+
/// Rows where `selection` is `false` or null are skipped during evaluation and
99+
/// produce `NULL` in the result. Thus, values in those rows cannot trigger
100+
/// evaluation errors such as division by zero.
101+
///
102+
/// # Example
103+
///
104+
/// Given `expr = 4 / val`:
105+
///
106+
/// ```text
107+
/// val selection | result
108+
/// 0 false | NULL
109+
/// 1 true | 4
110+
/// 2 true | 2
111+
/// ```
112+
///
113+
/// The first row is not evaluated, avoiding division by zero. Its result is
114+
/// `NULL`.
97115
///
98116
/// # Errors
99117
///
100-
/// Returns an `Err` if the expression could not be evaluated or if the length of the
101-
/// `selection` validity array and the number of row in `batch` is not equal.
118+
/// Returns an `Err` if the expression could not be evaluated or if the length of
119+
/// `selection` does not equal the number of rows in `batch`.
102120
fn evaluate_selection(
103121
&self,
104122
batch: &RecordBatch,

0 commit comments

Comments
 (0)