Skip to content

Commit

Permalink
fix extractfiltervisitor
Browse files Browse the repository at this point in the history
  • Loading branch information
nevermore3 committed Jul 6, 2022
1 parent adf5287 commit 3d6a2ee
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
23 changes: 18 additions & 5 deletions src/graph/validator/GetSubgraphValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ Status GetSubgraphValidator::validateBothInOutBound(BothInOutClause* out) {
return Status::OK();
}

static Expression* rewriteDstProp2SrcProp(const Expression* expr) {
ObjectPool* pool = expr->getObjPool();
auto matcher = [](const Expression* e) -> bool {
return e->kind() == Expression::Kind::kDstProperty;
};
auto rewriter = [pool](const Expression* e) -> Expression* {
auto dstExpr = static_cast<const DestPropertyExpression*>(e);
return SourcePropertyExpression::make(pool, dstExpr->sym(), dstExpr->prop());
};

return RewriteVisitor::transform(expr, std::move(matcher), std::move(rewriter));
}

// Check validity of filter expression, rewrites expression to fit its sementic,
// disable some invalid expression types, collect properties used in filter.
Status GetSubgraphValidator::validateWhere(WhereClause* where) {
Expand Down Expand Up @@ -132,18 +145,18 @@ Status GetSubgraphValidator::validateWhere(WhereClause* where) {

NG_RETURN_IF_ERROR(deduceProps(filter, subgraphCtx_->exprProps));

auto condition = filter->clone();
if (ExpressionUtils::findAny(expr, {Expression::Kind::kDstProperty})) {
auto visitor = ExtractFilterExprVisitor::makePushGetNeighbors(qctx_->objPool());
auto visitor = ExtractFilterExprVisitor::makePushGetVertices(qctx_->objPool());
filter->accept(&visitor);
if (!visitor.ok()) {
return Status::SemanticError("filter error");
}
auto remainedExpr = std::move(visitor).remainedExpr();
subgraphCtx_->filter = filter;
subgraphCtx_->edgeFilter = remainedExpr;
subgraphCtx_->edgeFilter = std::move(visitor).remainedExpr();
} else {
subgraphCtx_->filter = subgraphCtx_->edgeFilter = filter;
subgraphCtx_->edgeFilter = condition;
}
subgraphCtx_->filter = rewriteDstProp2SrcProp(condition);
return Status::OK();
}

Expand Down
10 changes: 9 additions & 1 deletion src/graph/visitor/ExtractFilterExprVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,15 @@ void ExtractFilterExprVisitor::visit(VariablePropertyExpression *) {
}

void ExtractFilterExprVisitor::visit(DestPropertyExpression *) {
canBePushed_ = false;
switch (pushType_) {
case PushType::kGetNeighbors:
case PushType::kGetEdges:
canBePushed_ = false;
break;
case PushType::kGetVertices:
canBePushed_ = true;
break;
}
}

void ExtractFilterExprVisitor::visit(SourcePropertyExpression *) {
Expand Down

0 comments on commit 3d6a2ee

Please sign in to comment.