Skip to content

Commit

Permalink
fix label length
Browse files Browse the repository at this point in the history
  • Loading branch information
knightast authored and tugraph committed Sep 25, 2023
1 parent 52fe8a5 commit 810f158
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/core/lightning_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ size_t LightningGraph::GetNumVertices() {

template <bool IS_LABEL>
inline void CheckIsValidLabelFieldName(const std::string& lof) {
if (lof.empty() || lof.size() > 64) {
if (lof.empty() || lof.size() > 255) {
throw InputError(std::string((IS_LABEL ? "Label" : "Field name")) +
" is invalid: must be between 1 and 64 bytes.");
" is invalid: must be between 1 and 255 bytes.");
}
if (fma_common::TextParserUtils::IsDigits(lof.front())) {
throw InputError(std::string((IS_LABEL ? "Label" : "Field name")) +
Expand Down
15 changes: 12 additions & 3 deletions test/test_lgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,12 @@ TEST_F(TestLGraph, LGraph) {
UT_EXPECT_ANY_THROW(db.AddLabel(
"", std::vector<FieldSpec>({{"id", FieldType::STRING, false}}),
true, VertexOptions("id")));
// label name
db.AddLabel(std::string(255, 'e'),
std::vector<FieldSpec>({{"id", FieldType::STRING, false}}),
true, VertexOptions("id"));
// long label name
UT_EXPECT_ANY_THROW(db.AddLabel(std::string(65, 'a'),
UT_EXPECT_ANY_THROW(db.AddLabel(std::string(256, 'a'),
std::vector<FieldSpec>({{"id", FieldType::STRING, false}}),
true, VertexOptions("id")));
// strange label names
Expand All @@ -243,11 +247,16 @@ TEST_F(TestLGraph, LGraph) {
db.AddLabel("field_name_start_with_digit",
std::vector<FieldSpec>{FieldSpec("10234_kkk", FieldType::STRING, false)},
true, VertexOptions("10234_kkk")));
// field name ok
db.AddLabel(
"field_name_not_long",
std::vector<FieldSpec>{FieldSpec(std::string(255, 'a'), FieldType::STRING, false)},
true, VertexOptions(std::string(255, 'a')));
// field name too long
UT_EXPECT_ANY_THROW(db.AddLabel(
"field_name_too_long",
std::vector<FieldSpec>{FieldSpec(std::string(65, 'a'), FieldType::STRING, false)}, true,
VertexOptions(std::string(65, 'a'))));
std::vector<FieldSpec>{FieldSpec(std::string(256, 'a'), FieldType::STRING, false)},
true, VertexOptions(std::string(256, 'a'))));
// invalid character in field name
for (auto& str : std::vector<std::string>{"#", "!", "+", "-", "*", "/"})
UT_EXPECT_ANY_THROW(db.AddLabel(
Expand Down

0 comments on commit 810f158

Please sign in to comment.