Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yixinglu committed Jun 30, 2021
1 parent 14a87d8 commit 3f76b5e
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/optimizer/rule/EdgeIndexFullScanRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
*/

#include "optimizer/rule/EdgeIndexFullScanRule.h"
#include "optimizer/OptContext.h"
#include "planner/plan/Query.h"
#include "planner/plan/Scan.h"

using nebula::graph::EdgeIndexFullScan;
using nebula::graph::IndexScan;

using Kind = nebula::graph::PlanNode::Kind;

Expand All @@ -27,5 +33,10 @@ std::string EdgeIndexFullScanRule::toString() const {
return "EdgeIndexFullScanRule";
}

IndexScan* EdgeIndexFullScanRule::scan(OptContext* ctx, const graph::PlanNode* node) const {
auto scan = static_cast<const EdgeIndexFullScan*>(node);
return EdgeIndexFullScan::make(ctx->qctx(), nullptr, scan->edgeType());
}

} // namespace opt
} // namespace nebula
3 changes: 2 additions & 1 deletion src/optimizer/rule/EdgeIndexFullScanRule.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ namespace opt {

class EdgeIndexFullScanRule final : public IndexFullScanBaseRule {
public:
const Pattern &pattern() const override;
const Pattern& pattern() const override;
std::string toString() const override;

private:
EdgeIndexFullScanRule();
graph::IndexScan* scan(OptContext* ctx, const graph::PlanNode* node) const override;

static std::unique_ptr<OptRule> kInstance;
};
Expand Down
3 changes: 2 additions & 1 deletion src/optimizer/rule/IndexFullScanBaseRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "optimizer/rule/IndexFullScanBaseRule.h"

#include "common/interface/gen-cpp2/storage_types.h"
#include "context/QueryContext.h"
#include "optimizer/OptContext.h"
#include "optimizer/OptGroup.h"
#include "optimizer/OptRule.h"
Expand Down Expand Up @@ -58,7 +59,7 @@ StatusOr<TransformResult> IndexFullScanBaseRule::transform(OptContext* ctx,
ictx.set_index_id(idxId);
idxCtxs.emplace_back(std::move(ictx));

auto scanNode = static_cast<IndexScan*>(scan->clone());
auto scanNode = this->scan(ctx, scan);
OptimizerUtils::copyIndexScanData(scan, scanNode);
scanNode->setOutputVar(scan->outputVar());
scanNode->setColNames(scan->colNames());
Expand Down
9 changes: 9 additions & 0 deletions src/optimizer/rule/IndexFullScanBaseRule.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@
#include "optimizer/OptRule.h"

namespace nebula {
class PlanNode;

namespace graph {
class IndexScan;
} // namespace graph

namespace opt {

class IndexFullScanBaseRule : public OptRule {
public:
bool match(OptContext *ctx, const MatchedResult &matched) const override;
StatusOr<TransformResult> transform(OptContext *ctx,
const MatchedResult &matched) const override;

protected:
virtual graph::IndexScan *scan(OptContext *ctx, const graph::PlanNode *node) const = 0;
};

} // namespace opt
Expand Down
7 changes: 7 additions & 0 deletions src/optimizer/rule/TagIndexFullScanRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/

#include "optimizer/rule/TagIndexFullScanRule.h"
#include "optimizer/OptContext.h"
#include "planner/plan/Scan.h"

using Kind = nebula::graph::PlanNode::Kind;

Expand All @@ -27,5 +29,10 @@ std::string TagIndexFullScanRule::toString() const {
return "TagIndexFullScanRule";
}

graph::IndexScan* TagIndexFullScanRule::scan(OptContext* ctx, const graph::PlanNode* node) const {
auto scan = static_cast<const graph::TagIndexFullScan*>(node);
return graph::TagIndexFullScan::make(ctx->qctx(), nullptr, scan->tagName());
}

} // namespace opt
} // namespace nebula
3 changes: 2 additions & 1 deletion src/optimizer/rule/TagIndexFullScanRule.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ namespace opt {

class TagIndexFullScanRule final : public IndexFullScanBaseRule {
public:
const Pattern &pattern() const override;
const Pattern& pattern() const override;
std::string toString() const override;

private:
TagIndexFullScanRule();
graph::IndexScan* scan(OptContext* ctx, const graph::PlanNode* node) const override;

static std::unique_ptr<OptRule> kInstance;
};
Expand Down
8 changes: 7 additions & 1 deletion tests/tck/features/lookup/LookupEdge.feature
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ Feature: Test lookup on edge index
Then a SemanticError should be raised at runtime: Expression (col1==201) not supported yet
When executing query:
"""
LOOKUP ON lookup_edge_1 WHERE lookup_edge_1.col1 == 201 OR lookup_edge_1.col5 == 20
LOOKUP ON lookup_edge_1 WHERE lookup_edge_1.col1 == 201 OR lookup_edge_1.col5 == 201
"""
Then a SemanticError should be raised at runtime: Invalid column: col5
When executing query:
"""
LOOKUP ON lookup_edge_1 WHERE lookup_edge_1.col1 == 201 OR lookup_edge_1.col2 == 201 AND lookup_edge_1.col3 == 202
"""
Then a SemanticError should be raised at runtime: Not supported filter
When executing query:
"""
LOOKUP ON lookup_edge_1 WHERE lookup_edge_1.col1 == 300
Expand Down Expand Up @@ -91,6 +96,7 @@ Feature: Test lookup on edge index
| lookup_edge_1.col1 >= 201 AND lookup_edge_1.col2 >= 201 AND lookup_edge_1.col3 == 201 |
| lookup_edge_1.col1 >= 201 AND lookup_edge_1.col2 != 200 AND lookup_edge_1.col3 == 201 |
| lookup_edge_1.col1 != 200 AND lookup_edge_1.col2 != 200 AND lookup_edge_1.col3 == 201 |
| lookup_edge_1.col1 == 201 OR lookup_edge_1.col2 == 201 |

# TODO(yee): Test bool expression
# TODO(yee): Test or expression
Expand Down
6 changes: 6 additions & 0 deletions tests/tck/features/lookup/LookupTag.feature
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ Feature: Test lookup on tag index
LOOKUP ON lookup_tag_1 WHERE lookup_tag_1.col1 == 200 OR lookup_tag_1.col5 == 20;
"""
Then a SemanticError should be raised at runtime: Invalid column: col5
When executing query:
"""
LOOKUP ON lookup_tag_1 WHERE lookup_tag_1.col1 == 201 OR lookup_tag_1.col2 == 201 AND lookup_tag_1.col3 == 202
"""
Then a SemanticError should be raised at runtime: Not supported filter
When executing query:
"""
LOOKUP ON lookup_tag_1 WHERE lookup_tag_1.col1 == 300
Expand Down Expand Up @@ -90,6 +95,7 @@ Feature: Test lookup on tag index
| lookup_tag_1.col1 != 202 AND lookup_tag_1.col2 == 201 AND lookup_tag_1.col3 == 201 |
| lookup_tag_1.col1 != 202 AND lookup_tag_1.col2 == 201 AND lookup_tag_1.col3 >= 201 |
| lookup_tag_1.col1 != 202 AND lookup_tag_1.col2 >= 201 AND lookup_tag_1.col3 >= 201 |
| lookup_tag_1.col1 == 201 OR lookup_tag_1.col2 == 201 |

Scenario Outline: [tag] scan without hints
When executing query:
Expand Down

0 comments on commit 3f76b5e

Please sign in to comment.