Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix invalid filter in GetProp make storage crashed #4568

Merged
merged 2 commits into from
Aug 23, 2022
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
3 changes: 3 additions & 0 deletions src/storage/exec/QueryUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class QueryUtils final {

if (nullType == NullType::UNKNOWN_PROP) {
VLOG(1) << "Fail to read prop " << propName;
if (!field) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just return null outside the if block?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is null here~ NullType::UNKNOWN_PROP

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, NullType::UNKNOWN_PROP is not necessary, which can lead to more problems due to graphd's unreasonable handling of runtime errors.
For example, filter operator execution will throw a runtime error if UNKNOWN_PROP is fed to it.

if (val.isBadNull() || (!val.empty() && !val.isImplicitBool() && !val.isNull())) {
return Status::Error("Wrong type result, the type should be NULL, EMPTY, BOOL");
}

return value;
}
if (field->hasDefault()) {
DefaultValueContext expCtx;
ObjectPool pool;
Expand Down
51 changes: 51 additions & 0 deletions src/storage/test/GetPropTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,57 @@ TEST(GetPropTest, FilterTest) {
// }
ASSERT_EQ(expected, *resp.props_ref());
}
// invalid vertex filter
{
LOG(INFO) << "GetVertexPropInValue";
std::vector<VertexID> vertices = {"Tim Duncan"};
std::vector<std::pair<TagID, std::vector<std::string>>> tags;
tags.emplace_back(player, std::vector<std::string>{"name", "age", "avgScore"});
Expression* filter = RelationalExpression::makeEQ(
&pool,
TagPropertyExpression::make(&pool, std::to_string(player), "invalid_property"),
ConstantExpression::make(&pool, 42));
auto req = buildVertexRequest(totalParts, vertices, tags, filter);

auto* processor = GetPropProcessor::instance(env, nullptr, nullptr);
auto fut = processor->getFuture();
processor->process(req);
auto resp = std::move(fut).get();

ASSERT_EQ(0, (*resp.result_ref()).failed_parts.size());
nebula::DataSet expected;
expected.colNames = {kVid, "1.name", "1.age", "1.avgScore"};
ASSERT_EQ(expected, *resp.props_ref());
}
// invalid edge filter
{
std::vector<cpp2::EdgeKey> edgeKeys;
{
cpp2::EdgeKey edgeKey;
edgeKey.src_ref() = "Tim Duncan";
edgeKey.edge_type_ref() = 101;
edgeKey.ranking_ref() = 1997;
edgeKey.dst_ref() = "Spurs";
edgeKeys.emplace_back(std::move(edgeKey));
}
std::vector<std::pair<TagID, std::vector<std::string>>> edges;
edges.emplace_back(serve, std::vector<std::string>{"teamName", "startYear", "endYear"});
Expression* filter = RelationalExpression::makeEQ(
&pool,
EdgePropertyExpression::make(&pool, std::to_string(serve), "invalid_property"),
ConstantExpression::make(&pool, 42));
auto req = buildEdgeRequest(totalParts, edgeKeys, edges, filter);

auto* processor = GetPropProcessor::instance(env, nullptr, nullptr);
auto fut = processor->getFuture();
processor->process(req);
auto resp = std::move(fut).get();

ASSERT_EQ(0, (*resp.result_ref()).failed_parts.size());
nebula::DataSet expected;
expected.colNames = {"101.teamName", "101.startYear", "101.endYear"};
ASSERT_EQ(expected, *resp.props_ref());
}
}

TEST(GetPropTest, LimitTest) {
Expand Down