Skip to content
Snippets Groups Projects
Select Git revision
  • c8554c302f69bba71dcbb8d00c8be63f65e062f6
  • master default protected
  • 3.0
  • develop
  • revert-2069-tripleVersion
  • 3.1
  • rest-protocol
  • feat/remoting_rocketmq
  • dapr-support
  • 1.5
  • 1.4
  • 1.3
  • 1.2
  • 1.1
  • v3.0.3-rc2
  • v3.0.3-rc1
  • v3.0.2
  • v1.5.8
  • v1.5.9-rc1
  • v3.0.1
  • v1.5.8-rc1
  • v3.0.0
  • v3.0.0-rc4-1
  • v3.0.0-rc4
  • v3.0.0-rc3
  • v1.5.7
  • v1.5.7-rc2
  • v3.0.0-rc2
  • remove
  • v1.5.7-rc1
  • v3.0.0-rc1
  • v1.5.7-rc1-tmp
  • 1.5.6
  • v1.5.6
34 results

server.go

Blame
  • RewriteInputPropVisitor.cpp 6.26 KiB
    /* Copyright (c) 2020 vesoft inc. All rights reserved.
     *
     * This source code is licensed under Apache 2.0 License,
     * attached with Common Clause Condition 1.0, found in the LICENSES directory.
     */
    
    #include "visitor/RewriteInputPropVisitor.h"
    
    namespace nebula {
    namespace graph {
    
    void RewriteInputPropVisitor::visit(UUIDExpression* expr) {
        reportError(expr);
    }
    
    void RewriteInputPropVisitor::visit(VariableExpression* expr) {
        reportError(expr);
    }
    
    void RewriteInputPropVisitor::visit(VersionedVariableExpression* expr) {
        reportError(expr);
    }
    
    void RewriteInputPropVisitor::visit(LabelAttributeExpression* expr) {
        reportError(expr);
    }
    
    void RewriteInputPropVisitor::visit(LabelExpression* expr) {
        reportError(expr);
    }
    
    void RewriteInputPropVisitor::visit(AttributeExpression* expr) {
        reportError(expr);
    }
    
    void RewriteInputPropVisitor::visit(SubscriptExpression* expr) {
        reportError(expr);
    }
    
    void RewriteInputPropVisitor::visit(ConstantExpression* expr) {
        UNUSED(expr);
    }
    
    void RewriteInputPropVisitor::visit(VertexExpression* expr) {
        UNUSED(expr);
    }
    
    void RewriteInputPropVisitor::visit(EdgeExpression* expr) {
        UNUSED(expr);
    }
    
    void RewriteInputPropVisitor::visit(InputPropertyExpression* expr) {
        UNUSED(expr);
    }
    
    void RewriteInputPropVisitor::visit(ArithmeticExpression* expr) {
        visitBinaryExpr(expr);
    }
    
    void RewriteInputPropVisitor::visit(RelationalExpression* expr) {
        visitBinaryExpr(expr);
    }
    
    void RewriteInputPropVisitor::visit(LogicalExpression* expr) {
        visitBinaryExpr(expr);
    }
    
    void RewriteInputPropVisitor::visit(UnaryExpression* expr) {
        switch (expr->kind()) {
            case Expression::Kind::kUnaryPlus:
            case Expression::Kind::kUnaryNegate:
            case Expression::Kind::kUnaryNot: {
                visitUnaryExpr(expr);
                break;
            }
            case Expression::Kind::kUnaryIncr:
            case Expression::Kind::kUnaryDecr: {
                reportError(expr);
                break;
            }
            default: {
                LOG(FATAL) << "Invalid kind " << expr->kind();
            }
        }
    }
    
    void RewriteInputPropVisitor::visit(TagPropertyExpression* expr) {
        visitVertexEdgePropExpr(expr);
    }
    
    void RewriteInputPropVisitor::visit(SourcePropertyExpression* expr) {
        visitVertexEdgePropExpr(expr);
    }
    
    void RewriteInputPropVisitor::visit(DestPropertyExpression* expr) {
        visitVertexEdgePropExpr(expr);
    }
    
    void RewriteInputPropVisitor::visit(EdgePropertyExpression* expr) {
        visitVertexEdgePropExpr(expr);
    }
    
    void RewriteInputPropVisitor::visit(EdgeSrcIdExpression* expr) {
        visitVertexEdgePropExpr(expr);
    }
    
    void RewriteInputPropVisitor::visit(EdgeTypeExpression* expr) {
        visitVertexEdgePropExpr(expr);
    }
    
    void RewriteInputPropVisitor::visit(EdgeRankExpression* expr) {
        visitVertexEdgePropExpr(expr);
    }
    
    void RewriteInputPropVisitor::visit(EdgeDstIdExpression* expr) {
        visitVertexEdgePropExpr(expr);
    }
    
    void RewriteInputPropVisitor::visit(VariablePropertyExpression* expr) {
        visitVertexEdgePropExpr(expr);
    }
    
    void RewriteInputPropVisitor::visit(ListExpression* expr) {
        const auto& items = expr->items();
        for (size_t i = 0; i < items.size(); ++i) {
            items[i]->accept(this);
            if (ok()) {
                expr->setItem(i, std::move(result_));
            }
        }
    }
    
    void RewriteInputPropVisitor::visit(SetExpression* expr) {
        const auto& items = expr->items();
        for (size_t i = 0; i < items.size(); ++i) {
            items[i]->accept(this);
            if (ok()) {
                expr->setItem(i, std::move(result_));
            }
        }
    }
    
    void RewriteInputPropVisitor::visit(MapExpression* expr) {
        const auto& items = expr->items();
        for (size_t i = 0; i < items.size(); ++i) {
            items[i].second->accept(this);
            if (ok()) {
                auto key = std::make_unique<std::string>(*items[i].first);
                expr->setItem(i, {std::move(key), std::move(result_)});
            }
        }
    }
    
    void RewriteInputPropVisitor::visit(FunctionCallExpression* expr) {
        auto& args = expr->args()->args();
        for (size_t i = 0; i < args.size(); ++i) {
            args[i]->accept(this);
            if (ok()) {
                expr->args()->setArg(i, std::move(result_));
            }
        }
    }
    
    void RewriteInputPropVisitor::visit(TypeCastingExpression* expr) {
        expr->operand()->accept(this);
        if (ok()) {
            expr->setOperand(result_.release());
        }
    }
    
    void RewriteInputPropVisitor::visit(CaseExpression* expr) {
        if (expr->hasCondition()) {
            expr->condition()->accept(this);
            if (ok()) {
                expr->setCondition(result_.release());
            }
        }
        if (expr->hasDefault()) {
            expr->defaultResult()->accept(this);
            if (ok()) {
                expr->setDefault(result_.release());
            }
        }
        for (size_t i = 0; i < expr->cases().size(); ++i) {
            const auto& whenThen = expr->cases()[i];
            whenThen.when->accept(this);
            if (ok()) {
                expr->setWhen(i, result_.release());
            }
            whenThen.then->accept(this);
            if (ok()) {
                expr->setThen(i, result_.release());
            }
        }
    }
    
    void RewriteInputPropVisitor::visitBinaryExpr(BinaryExpression* expr) {
        expr->left()->accept(this);
        if (ok()) {
            expr->setLeft(result_.release());
        }
        expr->right()->accept(this);
        if (ok()) {
            expr->setRight(result_.release());
        }
    }
    
    void RewriteInputPropVisitor::visitUnaryExpr(UnaryExpression* expr) {
        expr->operand()->accept(this);
        if (ok()) {
            expr->setOperand(result_.release());
        }
    }
    
    void RewriteInputPropVisitor::visitVertexEdgePropExpr(PropertyExpression* expr) {
        auto found = propExprColMap_.find(expr->toString());
        DCHECK(found != propExprColMap_.end());
        auto alias = new std::string(*(found->second->alias()));
        result_ = std::make_unique<InputPropertyExpression>(alias);
    }
    
    void RewriteInputPropVisitor::reportError(const Expression* expr) {
        std::stringstream ss;
        ss << "Not supported expression `" << expr->toString() << "' for RewriteInputProps.";
        status_ = Status::SemanticError(ss.str());
    }
    
    void RewriteInputPropVisitor::visit(PathBuildExpression* expr) {
        const auto& items = expr->items();
        for (size_t i = 0; i < items.size(); ++i) {
            items[i]->accept(this);
            if (ok()) {
                expr->setItem(i, std::move(result_));
            }
        }
    }
    }   // namespace graph
    }   // namespace nebula