Skip to content

Commit 346e1eb

Browse files
mbasmanovafacebook-github-bot
authored andcommitted
feat: Enhance extractFiltersFromRemainingFilter to support an OR (#641)
Summary: X-link: facebookincubator/velox#15565 Add support for converting "f(a) OR g(a)" to subfield filter. For example, - a > 0 OR a < 10 becomes BigintRange(1, 9) Differential Revision: D87378318
1 parent a00981f commit 346e1eb

File tree

1 file changed

+35
-30
lines changed

1 file changed

+35
-30
lines changed

axiom/optimizer/tests/PlanTest.cpp

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,36 @@ TEST_F(PlanTest, filterToJoinEdge) {
556556
checkSame(logicalPlan, referencePlan);
557557
}
558558

559+
TEST_F(PlanTest, filterImport) {
560+
auto ordersType = ROW({"o_custkey", "o_totalprice"}, {BIGINT(), DOUBLE()});
561+
562+
auto logicalPlan = lp::PlanBuilder()
563+
.tableScan(exec::test::kHiveConnectorId, "orders")
564+
.aggregate({"o_custkey"}, {"sum(o_totalprice) as a0"})
565+
.filter("o_custkey < 100 and a0 > 200.0")
566+
.build();
567+
568+
{
569+
auto plan = toSingleNodePlan(logicalPlan);
570+
auto matcher = core::PlanMatcherBuilder()
571+
.tableScan("orders")
572+
.singleAggregation()
573+
.filter("a0 > 200.0")
574+
.build();
575+
576+
AXIOM_ASSERT_PLAN(plan, matcher);
577+
}
578+
579+
auto referencePlan =
580+
exec::test::PlanBuilder()
581+
.tableScan("orders", ordersType)
582+
.singleAggregation({"o_custkey"}, {"sum(o_totalprice)"})
583+
.filter("o_custkey < 100 and a0 > 200.0")
584+
.planNode();
585+
586+
checkSame(logicalPlan, referencePlan);
587+
}
588+
559589
TEST_F(PlanTest, filterBreakup) {
560590
const char* filterText =
561591
" (\n"
@@ -588,56 +618,31 @@ TEST_F(PlanTest, filterBreakup) {
588618
" and l_shipinstruct = 'DELIVER IN PERSON'\n"
589619
" )\n";
590620

591-
auto lineitemType = ROW(
592-
{{"l_partkey", BIGINT()},
593-
{"l_shipmode", VARCHAR()},
594-
{"l_shipinstruct", VARCHAR()},
595-
{"l_extendedprice", DOUBLE()},
596-
{"l_discount", DOUBLE()},
597-
{"l_quantity", DOUBLE()}});
598-
599-
auto partType = ROW(
600-
{{"p_partkey", BIGINT()},
601-
{"p_brand", VARCHAR()},
602-
{"p_container", VARCHAR()},
603-
{"p_size", INTEGER()}});
604-
605-
const auto connectorId = exec::test::kHiveConnectorId;
606-
607-
lp::PlanBuilder::Context context;
621+
lp::PlanBuilder::Context context(exec::test::kHiveConnectorId);
608622
auto logicalPlan =
609623
lp::PlanBuilder(context)
610-
.tableScan(connectorId, "lineitem", lineitemType->names())
611-
.crossJoin(
612-
lp::PlanBuilder(context).tableScan(
613-
connectorId, "part", partType->names()))
624+
.tableScan("lineitem")
625+
.crossJoin(lp::PlanBuilder(context).tableScan("part"))
614626
.filter(filterText)
615627
.project({"l_extendedprice * (1.0 - l_discount) as part_revenue"})
616628
.aggregate({}, {"sum(part_revenue)"})
617629
.build();
618630

619631
{
620632
// Expect the per table filters to be extracted from the OR.
621-
// TODO Verify remaining filters.
622633
auto lineitemFilters =
623634
common::test::SubfieldFiltersBuilder()
624635
.add("l_shipinstruct", exec::equal("DELIVER IN PERSON"))
625636
.add(
626637
"l_shipmode",
627638
exec::in(std::vector<std::string>{"AIR", "AIR REG"}))
639+
.add("l_quantity", exec::betweenDouble(1.0, 30.0))
628640
.build();
629641

630642
auto plan = toSingleNodePlan(logicalPlan);
631643
auto matcher =
632644
core::PlanMatcherBuilder()
633-
.hiveScan(
634-
"lineitem",
635-
std::move(lineitemFilters),
636-
// TODO Fix this plan. Compact the filter to between(1, 30) and
637-
// push down as subfield filter.
638-
"\"or\"(l_quantity >= 20.0 AND l_quantity <= 30.0, "
639-
" \"or\"(l_quantity >= 1.0 AND l_quantity <= 11.0, "
640-
" l_quantity >= 10.0 AND l_quantity <= 20.0))")
645+
.hiveScan("lineitem", std::move(lineitemFilters))
641646
.hashJoin(
642647
core::PlanMatcherBuilder()
643648
.hiveScan(

0 commit comments

Comments
 (0)