MCPcopy Create free account
hub / github.com/apache/arrow / SimplifyWithGuarantee

Function SimplifyWithGuarantee

cpp/src/arrow/compute/expression.cc:1431–1478  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1429} // namespace
1430
1431Result<Expression> SimplifyWithGuarantee(Expression expr,
1432 const Expression& guaranteed_true_predicate) {
1433 KnownFieldValues known_values;
1434 auto conjunction_members = GuaranteeConjunctionMembers(guaranteed_true_predicate);
1435
1436 RETURN_NOT_OK(ExtractKnownFieldValues(&conjunction_members, &known_values));
1437
1438 ARROW_ASSIGN_OR_RAISE(expr,
1439 ReplaceFieldsWithKnownValues(known_values, std::move(expr)));
1440
1441 auto CanonicalizeAndFoldConstants = [&expr] {
1442 ARROW_ASSIGN_OR_RAISE(expr, Canonicalize(std::move(expr)));
1443 ARROW_ASSIGN_OR_RAISE(expr, FoldConstants(std::move(expr)));
1444 return Status::OK();
1445 };
1446 RETURN_NOT_OK(CanonicalizeAndFoldConstants());
1447
1448 for (const auto& guarantee : conjunction_members) {
1449 if (!guarantee.call()) continue;
1450
1451 if (auto inequality = Inequality::ExtractOne(guarantee)) {
1452 ARROW_ASSIGN_OR_RAISE(auto simplified,
1453 ModifyExpression(
1454 std::move(expr), [](Expression expr) { return expr; },
1455 [&](Expression expr, ...) -> Result<Expression> {
1456 return inequality->Simplify(std::move(expr));
1457 }));
1458
1459 if (Expression::Identical(simplified, expr)) continue;
1460
1461 expr = std::move(simplified);
1462 RETURN_NOT_OK(CanonicalizeAndFoldConstants());
1463 }
1464
1465 if (guarantee.call()->function_name == "is_valid") {
1466 ARROW_ASSIGN_OR_RAISE(
1467 auto simplified,
1468 SimplifyIsValidGuarantee(std::move(expr), *CallNotNull(guarantee)));
1469
1470 if (Expression::Identical(simplified, expr)) continue;
1471
1472 expr = std::move(simplified);
1473 RETURN_NOT_OK(CanonicalizeAndFoldConstants());
1474 }
1475 }
1476
1477 return expr;
1478}
1479
1480Result<Expression> RemoveNamedRefs(Expression src) {
1481 if (!src.IsBound()) {

Callers 7

TestRowGroupsMethod · 0.85
GetFragmentsMethod · 0.85
GetFragmentsAsyncMethod · 0.85
CountRowsMethod · 0.85
ASSERT_OK_AND_ASSIGNFunction · 0.85
TESTFunction · 0.85

Calls 8

ExtractKnownFieldValuesFunction · 0.85
CanonicalizeFunction · 0.85
FoldConstantsFunction · 0.85
callMethod · 0.80
ARROW_ASSIGN_OR_RAISEFunction · 0.50
OKFunction · 0.50

Tested by 3

TestRowGroupsMethod · 0.68
ASSERT_OK_AND_ASSIGNFunction · 0.68
TESTFunction · 0.68