Skip to content

Commit

Permalink
Custom Source Choropleth Chart Results in Signal 6 (#7463)
Browse files Browse the repository at this point in the history
* Add rel alg optimization logic: remove redundant projection

* Add tests

* Address comments

* Address comments

Signed-off-by: Misiu Godfrey <misiu.godfrey@kraken.mapd.com>
  • Loading branch information
yoonminnam authored and misiugodfrey committed Sep 28, 2023
1 parent 6afe3e7 commit e6a71a1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
25 changes: 25 additions & 0 deletions QueryEngine/RelAlgDag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2168,6 +2168,30 @@ void handle_agg_over_join(
}
}

void eliminate_redundant_projection(std::vector<std::shared_ptr<RelAlgNode>>& nodes) {
for (auto& node : nodes) {
if (auto* proj_node = dynamic_cast<RelProject*>(node.get())) {
if (proj_node->isSimple()) {
if (auto child_proj_node =
dynamic_cast<RelProject const*>(proj_node->getInput(0))) {
std::vector<std::unique_ptr<RexScalar const>> scalar_exprs;
RexDeepCopyVisitor copier;
for (size_t i = 0; i < proj_node->size(); i++) {
auto rex_abs_input =
dynamic_cast<RexAbstractInput const*>(proj_node->getProjectAt(i));
scalar_exprs.push_back(
copier.visit(child_proj_node->getProjectAt(rex_abs_input->getIndex())));
}
CHECK_EQ(scalar_exprs.size(), proj_node->getFields().size());
proj_node->setExpressions(scalar_exprs);
proj_node->replaceInput(proj_node->getAndOwnInput(0),
child_proj_node->getAndOwnInput(0));
}
}
}
}
}

class WindowFunctionCollector : public RexVisitor<void*> {
public:
WindowFunctionCollector(
Expand Down Expand Up @@ -3408,6 +3432,7 @@ void RelAlgDagBuilder::optimizeDag(RelAlgDag& rel_alg_dag) {
CHECK(nodes.back().use_count() == 1);
create_left_deep_join(nodes);
handle_agg_over_join(nodes, query_hints);
eliminate_redundant_projection(nodes);

setBuildState(rel_alg_dag, RelAlgDag::BuildState::kBuiltOptimized);
}
Expand Down
21 changes: 21 additions & 0 deletions Tests/ExecuteTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26825,6 +26825,27 @@ TEST_F(Select, AutoQueryCaching) {
}
}

TEST_F(Select, RedundantProjectionRemoving) {
// in dist mode, we cannot get RaExecutionSequence from QR
SKIP_ALL_ON_AGGREGATOR();
auto perform_test = [](std::string query) {
auto const ra_exec_seq = QR::get()->getRaExecutionSequence(query);
EXPECT_EQ(ra_exec_seq.size(), size_t(1));
};
std::string q1 =
"select fn, f from (select R.f, abs(R.ff) v, R.fn from test R, test_inner S where "
"R.x = "
"S.x and S.str is not null) where f > 0";
std::string q2 = q1 + " order by 1";
std::string q3 =
"select f, fn from (select fn, abs(ff), f from (select R.f, R.ff, abs(R.fn) fn "
"from test R, test_inner S where R.x = S.x and S.str is not null) where fn > 0) "
"where f > 0";
perform_test(q1);
perform_test(q2);
perform_test(q3);
}

class SubqueryTestEnv : public ::testing::Test {
protected:
void SetUp() override {
Expand Down

0 comments on commit e6a71a1

Please sign in to comment.