MCPcopy Create free account
hub / github.com/apache/datafusion / build_is_null_column_expr

Function build_is_null_column_expr

datafusion/pruning/src/pruning_predicate.rs:1316–1360  ·  view source on GitHub ↗

Given an expression reference to `expr`, if `expr` is a column expression, returns a pruning expression in terms of IsNull that will evaluate to true if the column may contain null, and false if definitely does not contain null. If `with_not` is true, build a pruning expression for `col IS NOT NULL`: `col_count != col_null_count` The pruning expression evaluates to true ONLY if the column definite

(
    expr: &Arc<dyn PhysicalExpr>,
    schema: &Schema,
    required_columns: &mut RequiredColumns,
    with_not: bool,
)

Source from the content-addressed store, hash-verified

1314/// at least one NULL value. In this case we can know that `IS NOT NULL` can not be true and
1315/// thus can prune the row group / value
1316fn build_is_null_column_expr(
1317 expr: &Arc<dyn PhysicalExpr>,
1318 schema: &Schema,
1319 required_columns: &mut RequiredColumns,
1320 with_not: bool,
1321) -> Option<Arc<dyn PhysicalExpr>> {
1322 if let Some(col) = expr.downcast_ref::<phys_expr::Column>() {
1323 let field = schema.field_with_name(col.name()).ok()?;
1324
1325 let null_count_field = &Field::new(field.name(), DataType::UInt64, true);
1326 if with_not {
1327 if let Ok(row_count_expr) =
1328 required_columns.row_count_column_expr(col, expr, null_count_field)
1329 {
1330 required_columns
1331 .null_count_column_expr(col, expr, null_count_field)
1332 .map(|null_count_column_expr| {
1333 // IsNotNull(column) => null_count != row_count
1334 Arc::new(phys_expr::BinaryExpr::new(
1335 null_count_column_expr,
1336 Operator::NotEq,
1337 row_count_expr,
1338 )) as _
1339 })
1340 .ok()
1341 } else {
1342 None
1343 }
1344 } else {
1345 required_columns
1346 .null_count_column_expr(col, expr, null_count_field)
1347 .map(|null_count_column_expr| {
1348 // IsNull(column) => null_count > 0
1349 Arc::new(phys_expr::BinaryExpr::new(
1350 null_count_column_expr,
1351 Operator::Gt,
1352 Arc::new(phys_expr::Literal::new(ScalarValue::UInt64(Some(0)))),
1353 )) as _
1354 })
1355 .ok()
1356 }
1357 } else {
1358 None
1359 }
1360}
1361
1362/// The maximum number of entries in an `InList` that might be rewritten into
1363/// an OR chain

Callers 1

Calls 6

newFunction · 0.85
field_with_nameMethod · 0.80
row_count_column_exprMethod · 0.80
nameMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…