Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
210360228
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2021
210360228
Commits
66c064b1
Unverified
Commit
66c064b1
authored
4 years ago
by
CBS
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
fixed toString method of create index sentence (#818)
parent
a08ca708
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/parser/MaintainSentences.cpp
+14
-4
14 additions, 4 deletions
src/parser/MaintainSentences.cpp
src/parser/Sentence.h
+1
-1
1 addition, 1 deletion
src/parser/Sentence.h
src/parser/test/ParserTest.cpp
+38
-0
38 additions, 0 deletions
src/parser/test/ParserTest.cpp
with
53 additions
and
5 deletions
src/parser/MaintainSentences.cpp
+
14
−
4
View file @
66c064b1
...
...
@@ -232,14 +232,19 @@ std::string CreateTagIndexSentence::toString() const {
std
::
string
buf
;
buf
.
reserve
(
256
);
buf
+=
"CREATE TAG INDEX "
;
if
(
isIfNotExist
())
{
buf
+=
"IF NOT EXISTS "
;
}
buf
+=
*
indexName_
;
buf
+=
" ON "
;
buf
+=
*
tagName_
;
buf
+=
"
("
;
buf
+=
"("
;
std
::
vector
<
std
::
string
>
fieldDefs
;
for
(
const
auto
&
field
:
this
->
fields
())
{
std
::
string
f
=
field
.
get_name
();
if
(
field
.
__isset
.
type_length
)
f
+
"("
+
field
.
get_type_length
()
+
")"
;
if
(
field
.
__isset
.
type_length
)
{
f
+=
"("
+
std
::
to_string
(
*
field
.
get_type_length
())
+
")"
;
}
fieldDefs
.
emplace_back
(
std
::
move
(
f
));
}
std
::
string
fields
;
...
...
@@ -254,14 +259,19 @@ std::string CreateEdgeIndexSentence::toString() const {
std
::
string
buf
;
buf
.
reserve
(
256
);
buf
+=
"CREATE EDGE INDEX "
;
if
(
isIfNotExist
())
{
buf
+=
"IF NOT EXISTS "
;
}
buf
+=
*
indexName_
;
buf
+=
" ON "
;
buf
+=
*
edgeName_
;
buf
+=
"
("
;
buf
+=
"("
;
std
::
vector
<
std
::
string
>
fieldDefs
;
for
(
const
auto
&
field
:
this
->
fields
())
{
std
::
string
f
=
field
.
get_name
();
if
(
field
.
__isset
.
type_length
)
f
+
"("
+
field
.
get_type_length
()
+
")"
;
if
(
field
.
__isset
.
type_length
)
{
f
+=
"("
+
std
::
to_string
(
*
field
.
get_type_length
())
+
")"
;
}
fieldDefs
.
emplace_back
(
std
::
move
(
f
));
}
std
::
string
fields
;
...
...
This diff is collapsed.
Click to expand it.
src/parser/Sentence.h
+
1
−
1
View file @
66c064b1
...
...
@@ -144,7 +144,7 @@ public:
explicit
CreateSentence
(
bool
ifNotExist
)
:
ifNotExist_
{
ifNotExist
}
{}
virtual
~
CreateSentence
()
{}
bool
isIfNotExist
()
{
bool
isIfNotExist
()
const
{
return
ifNotExist_
;
}
...
...
This diff is collapsed.
Click to expand it.
src/parser/test/ParserTest.cpp
+
38
−
0
View file @
66c064b1
...
...
@@ -495,96 +495,134 @@ TEST(Parser, IndexOperation) {
std
::
string
query
=
"CREATE TAG INDEX empty_field_index ON person()"
;
auto
result
=
parse
(
query
);
ASSERT_TRUE
(
result
.
ok
())
<<
result
.
status
();
auto
&
sentence
=
result
.
value
();
EXPECT_EQ
(
query
,
sentence
->
toString
());
}
{
std
::
string
query
=
"CREATE TAG INDEX name_index ON person(name)"
;
auto
result
=
parse
(
query
);
ASSERT_TRUE
(
result
.
ok
())
<<
result
.
status
();
auto
&
sentence
=
result
.
value
();
EXPECT_EQ
(
query
,
sentence
->
toString
());
}
{
std
::
string
query
=
"CREATE TAG INDEX IF NOT EXISTS name_index ON person(name)"
;
auto
result
=
parse
(
query
);
ASSERT_TRUE
(
result
.
ok
())
<<
result
.
status
();
auto
&
sentence
=
result
.
value
();
EXPECT_EQ
(
query
,
sentence
->
toString
());
}
{
std
::
string
query
=
"CREATE TAG INDEX IF NOT EXISTS name_index ON person(name, age)"
;
auto
result
=
parse
(
query
);
ASSERT_TRUE
(
result
.
ok
())
<<
result
.
status
();
auto
&
sentence
=
result
.
value
();
EXPECT_EQ
(
query
,
sentence
->
toString
());
}
{
std
::
string
query
=
"CREATE EDGE INDEX IF NOT EXISTS empty_field_index ON service()"
;
auto
result
=
parse
(
query
);
ASSERT_TRUE
(
result
.
ok
())
<<
result
.
status
();
auto
&
sentence
=
result
.
value
();
EXPECT_EQ
(
query
,
sentence
->
toString
());
}
{
std
::
string
query
=
"CREATE EDGE INDEX IF NOT EXISTS like_index ON service(like)"
;
auto
result
=
parse
(
query
);
ASSERT_TRUE
(
result
.
ok
())
<<
result
.
status
();
auto
&
sentence
=
result
.
value
();
EXPECT_EQ
(
query
,
sentence
->
toString
());
}
{
std
::
string
query
=
"CREATE EDGE INDEX IF NOT EXISTS like_index ON service(like, score)"
;
auto
result
=
parse
(
query
);
ASSERT_TRUE
(
result
.
ok
())
<<
result
.
status
();
auto
&
sentence
=
result
.
value
();
EXPECT_EQ
(
query
,
sentence
->
toString
());
}
{
std
::
string
query
=
"CREATE EDGE INDEX IF NOT EXISTS std_index ON t1(c1(10), c2(20))"
;
auto
result
=
parse
(
query
);
ASSERT_TRUE
(
result
.
ok
())
<<
result
.
status
();
auto
&
sentence
=
result
.
value
();
EXPECT_EQ
(
query
,
sentence
->
toString
());
}
{
std
::
string
query
=
"CREATE EDGE INDEX IF NOT EXISTS std_index ON t1(c1, c2(20))"
;
auto
result
=
parse
(
query
);
ASSERT_TRUE
(
result
.
ok
())
<<
result
.
status
();
auto
&
sentence
=
result
.
value
();
EXPECT_EQ
(
query
,
sentence
->
toString
());
}
{
std
::
string
query
=
"CREATE EDGE INDEX IF NOT EXISTS std_index ON t1(c1(10), c2)"
;
auto
result
=
parse
(
query
);
ASSERT_TRUE
(
result
.
ok
())
<<
result
.
status
();
auto
&
sentence
=
result
.
value
();
EXPECT_EQ
(
query
,
sentence
->
toString
());
}
{
std
::
string
query
=
"CREATE TAG INDEX IF NOT EXISTS std_index ON t1(c1(10), c2(20))"
;
auto
result
=
parse
(
query
);
ASSERT_TRUE
(
result
.
ok
())
<<
result
.
status
();
auto
&
sentence
=
result
.
value
();
EXPECT_EQ
(
query
,
sentence
->
toString
());
}
{
std
::
string
query
=
"CREATE TAG INDEX IF NOT EXISTS std_index ON t1(c1, c2(20))"
;
auto
result
=
parse
(
query
);
ASSERT_TRUE
(
result
.
ok
())
<<
result
.
status
();
auto
&
sentence
=
result
.
value
();
EXPECT_EQ
(
query
,
sentence
->
toString
());
}
{
std
::
string
query
=
"CREATE TAG INDEX IF NOT EXISTS std_index ON t1(c1(10), c2)"
;
auto
result
=
parse
(
query
);
ASSERT_TRUE
(
result
.
ok
())
<<
result
.
status
();
auto
&
sentence
=
result
.
value
();
EXPECT_EQ
(
query
,
sentence
->
toString
());
}
{
std
::
string
query
=
"DROP TAG INDEX name_index"
;
auto
result
=
parse
(
query
);
ASSERT_TRUE
(
result
.
ok
())
<<
result
.
status
();
auto
&
sentence
=
result
.
value
();
EXPECT_EQ
(
query
,
sentence
->
toString
());
}
{
std
::
string
query
=
"DROP EDGE INDEX like_index"
;
auto
result
=
parse
(
query
);
ASSERT_TRUE
(
result
.
ok
())
<<
result
.
status
();
auto
&
sentence
=
result
.
value
();
EXPECT_EQ
(
query
,
sentence
->
toString
());
}
{
std
::
string
query
=
"DESCRIBE TAG INDEX name_index"
;
auto
result
=
parse
(
query
);
ASSERT_TRUE
(
result
.
ok
())
<<
result
.
status
();
auto
&
sentence
=
result
.
value
();
EXPECT_EQ
(
query
,
sentence
->
toString
());
}
{
std
::
string
query
=
"DESCRIBE EDGE INDEX like_index"
;
auto
result
=
parse
(
query
);
ASSERT_TRUE
(
result
.
ok
())
<<
result
.
status
();
auto
&
sentence
=
result
.
value
();
EXPECT_EQ
(
query
,
sentence
->
toString
());
}
{
std
::
string
query
=
"REBUILD TAG INDEX name_index"
;
auto
result
=
parse
(
query
);
ASSERT_TRUE
(
result
.
ok
())
<<
result
.
status
();
auto
&
sentence
=
result
.
value
();
EXPECT_EQ
(
query
,
sentence
->
toString
());
}
{
std
::
string
query
=
"REBUILD EDGE INDEX like_index"
;
auto
result
=
parse
(
query
);
ASSERT_TRUE
(
result
.
ok
())
<<
result
.
status
();
auto
&
sentence
=
result
.
value
();
EXPECT_EQ
(
query
,
sentence
->
toString
());
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment