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

Fix multi path #1236

Merged
merged 3 commits into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions src/executor/algo/ProduceSemiShortestPathExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ void ProduceSemiShortestPathExecutor::dstNotInHistory(const Edge& edge,
auto cost = srcPath.second.cost_ + weight;

std::vector<Path> newPaths = createPaths(srcPath.second.paths_, edge);
std::unordered_map<Value, CostPaths> temp = {
{srcPath.first, CostPaths(cost, newPaths)}};
currentCostPathMap.emplace(dst, std::move(temp));
currentCostPathMap[dst].emplace(srcPath.first, CostPaths(cost, std::move(newPaths)));
}
} else {
// dst in current
Expand All @@ -102,6 +100,7 @@ void ProduceSemiShortestPathExecutor::removeSamePath(std::vector<Path>& paths,
auto iter = paths.begin();
while (iter != paths.end()) {
if (*iter == *ptr) {
VLOG(2) << "Erese Path :" << *iter;
iter = paths.erase(iter);
} else {
++iter;
Expand All @@ -124,9 +123,8 @@ void ProduceSemiShortestPathExecutor::dstInHistory(const Edge& edge,
// (dst, startVid)'s path not in history
auto newCost = srcPath.second.cost_ + weight;
std::vector<Path> newPaths = createPaths(srcPath.second.paths_, edge);
std::unordered_map<Value, CostPaths> temp = {
{srcPath.first, CostPaths(newCost, newPaths)}};
currentCostPathMap.emplace(dst, std::move(temp));
currentCostPathMap[dst].emplace(srcPath.first,
CostPaths(newCost, std::move(newPaths)));
} else {
// (dst, startVid)'s path in history, compare cost
auto newCost = srcPath.second.cost_ + weight;
Expand All @@ -136,19 +134,17 @@ void ProduceSemiShortestPathExecutor::dstInHistory(const Edge& edge,
} else if (newCost < historyCost) {
// update (dst, startVid)'s path
std::vector<Path> newPaths = createPaths(srcPath.second.paths_, edge);
std::unordered_map<Value, CostPaths> temp = {
{srcPath.first, CostPaths(newCost, newPaths)}};
currentCostPathMap.emplace(dst, std::move(temp));
currentCostPathMap[dst].emplace(srcPath.first,
CostPaths(newCost, std::move(newPaths)));
} else {
std::vector<Path> newPaths = createPaths(srcPath.second.paths_, edge);
// if same path in history, remove it
removeSamePath(newPaths, historyCostPathMap_[dst][srcPath.first].paths_);
if (newPaths.empty()) {
continue;
}
std::unordered_map<Value, CostPaths> temp = {
{srcPath.first, CostPaths(newCost, newPaths)}};
currentCostPathMap.emplace(dst, std::move(temp));
currentCostPathMap[dst].emplace(srcPath.first,
CostPaths(newCost, std::move(newPaths)));
}
}
}
Expand Down Expand Up @@ -220,11 +216,11 @@ folly::Future<Status> ProduceSemiShortestPathExecutor::execute() {
path.src = Vertex(src, {});
path.steps.emplace_back(Step(Vertex(dst, {}), edge.type, edge.name, edge.ranking, {}));
if (currentCostPathMap.find(dst) != currentCostPathMap.end()) {
// same (src, dst), diffrent edge type or rank
if (currentCostPathMap[dst].find(src) == currentCostPathMap[dst].end()) {
CostPaths costPaths(weight, {std::move(path)});
currentCostPathMap[dst].emplace(src, std::move(costPaths));
} else {
// same (src, dst), diffrent edge type or rank
auto currentCost = currentCostPathMap[dst][src].cost_;
if (weight == currentCost) {
currentCostPathMap[dst][src].paths_.emplace_back(std::move(path));
Expand All @@ -237,8 +233,7 @@ folly::Future<Status> ProduceSemiShortestPathExecutor::execute() {
}
} else {
CostPaths costPaths(weight, {std::move(path)});
std::unordered_map<Value, CostPaths> temp = {{src, std::move(costPaths)}};
currentCostPathMap.emplace(dst, std::move(temp));
currentCostPathMap[dst].emplace(src, std::move(costPaths));
}
} else {
if (historyCostPathMap_.find(dst) == historyCostPathMap_.end()) {
Expand Down Expand Up @@ -272,7 +267,7 @@ folly::Future<Status> ProduceSemiShortestPathExecutor::execute() {
updateHistory(dst, srcPath.first, cost, ds.rows.back().values.back());
}
}

VLOG(2) << "SemiShortPath : " << ds;
return finish(ResultBuilder().value(Value(std::move(ds))).finish());
}

Expand Down
2 changes: 1 addition & 1 deletion src/optimizer/OptimizerUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ bool OptimizerUtils::findOptimalIndex(const Expression* condition,
const std::vector<std::shared_ptr<IndexItem>>& indexItems,
bool* isPrefixScan,
IndexQueryContext* ictx) {
// Return directly if there is not valid index to use.
// Return directly if there is no valid index to use.
if (indexItems.empty()) {
return false;
}
Expand Down
69 changes: 69 additions & 0 deletions tests/tck/features/bugfix/StringFlaotAddition.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright (c) 2021 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.
Feature: Test return float plus string

Background:
Given a graph with space named "nba"

# Fix https://github.com/vesoft-inc/nebula-graph/issues/1214
Scenario: addition[1]
When executing query:
"""
RETURN 30.142857142857142 + "Yao Ming"
"""
Then the result should be, in any order, with relax comparison:
| (30.142857142857142+"Yao Ming") |
| "30.142857142857142Yao Ming" |
When executing query:
"""
RETURN -30.142857142857142 + "Yao Ming"
"""
Then the result should be, in any order, with relax comparison:
| (-(30.142857142857142)+"Yao Ming") |
| "-30.142857142857142Yao Ming" |
When executing query:
"""
RETURN "Yao Ming" + 30.142857142857142
"""
Then the result should be, in any order, with relax comparison:
| ("Yao Ming"+30.142857142857142) |
| "Yao Ming30.142857142857142" |
When executing query:
"""
RETURN "Yao Ming" + -30.142857142857142
"""
Then the result should be, in any order, with relax comparison:
| ("Yao Ming"+-(30.142857142857142)) |
| "Yao Ming-30.142857142857142" |

Scenario: addition[2]
When executing query:
"""
RETURN 30.14 + "Yao Ming"
"""
Then the result should be, in any order, with relax comparison:
| (30.14+"Yao Ming") |
| "30.14Yao Ming" |
When executing query:
"""
RETURN -30.14 + "Yao Ming"
"""
Then the result should be, in any order, with relax comparison:
| (-(30.14)+"Yao Ming") |
| "-30.14Yao Ming" |
When executing query:
"""
RETURN "Yao Ming" + 30.14
"""
Then the result should be, in any order, with relax comparison:
| ("Yao Ming"+30.14) |
| "Yao Ming30.14" |
When executing query:
"""
RETURN "Yao Ming" + -30.14
"""
Then the result should be, in any order, with relax comparison:
| ("Yao Ming"+-(30.14)) |
| "Yao Ming-30.14" |