Skip to content

Commit

Permalink
Merge branch 'master' into cache
Browse files Browse the repository at this point in the history
  • Loading branch information
dangleptr authored Nov 19, 2019
2 parents 461dad2 + e4b8af7 commit 3d460f6
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 78 deletions.
2 changes: 1 addition & 1 deletion docker/Dockerfile.graph
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ EXPOSE 45500 45501 11000 11002
# storage ports
EXPOSE 44500 44501 12000 12002
# graph ports
EXPOSE 3369 13000 13002
EXPOSE 3699 13000 13002
2 changes: 1 addition & 1 deletion docker/Dockerfile.graphd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RUN rpm -ivh *.rpm \
&& mkdir -p ./{logs,data,pids} \
&& rm -rf *.rpm

EXPOSE 3369 13000 13002
EXPOSE 3699 13000 13002

ENTRYPOINT ["./bin/nebula-graphd", \
"--flagfile=./etc/nebula-graphd.conf", \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ nebula> FETCH PROP ON player 1 YIELD player.name, player.age
nebula> FETCH PROP ON player hash(\"nebula\") YIELD player.name, player.age
-- 沿边 e1 寻找节点 1 的所有近邻,返回其姓名和年龄属性
nebula> GO FROM 1 over e1 YIELD e1._dst AS id | FETCH PROP ON player $-.id YIELD player.name, player.age
-- 与上述语句相同
-- 与上述语法相同
nebula> $var = GO FROM 1 over e1 YIELD e1._dst AS id; FETCH PROP ON player $var.id YIELD player.name, player.age
-- 获取 1,2,3 三个节点,返回姓名和年龄都不相同的记录
nebula> FETCH PROP ON player 1,2,3 YIELD DISTINCT player.name, player.age
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The `FETCH` syntax is used to get vertex/edge's properties.

## Fetch Vertex property

Use `FETCH PROP ON` to return a (list of) vertex's properties. Currently, you can get multiple vertices' properties with the same tag in one sentence.
Use `FETCH PROP ON` to return a (list of) vertex's properties. Currently, you can get multiple vertices' properties with the same tag in one sentence.

```ngql
FETCH PROP ON <tag_name> <vertex_id_list> [YIELD [DISTINCT] <return_list>]
Expand Down
19 changes: 4 additions & 15 deletions src/common/filter/test/ExpressionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -786,39 +786,28 @@ TEST_F(ExpressionTest, InvalidExpressionTest) {


TEST_F(ExpressionTest, StringLengthLimitTest) {
constexpr auto MAX = 4096UL;
std::string valid(MAX, 'X');
std::string invalid(MAX + 1, 'X');
constexpr auto MAX = (1UL<<20);
std::string str(MAX, 'X');

// double quote
{
GQLParser parser;
auto *fmt = "GO FROM 1 OVER follow WHERE \"%s\"";
{
auto query = folly::stringPrintf(fmt, valid.c_str());
auto query = folly::stringPrintf(fmt, str.c_str());
auto parsed = parser.parse(query);
ASSERT_TRUE(parsed.ok()) << parsed.status();
}
{
auto query = folly::stringPrintf(fmt, invalid.c_str());
auto parsed = parser.parse(query);
ASSERT_FALSE(parsed.ok());
}
}
// single quote
{
GQLParser parser;
auto *fmt = "GO FROM 1 OVER follow WHERE '%s'";
{
auto query = folly::stringPrintf(fmt, valid.c_str());
auto query = folly::stringPrintf(fmt, str.c_str());
auto parsed = parser.parse(query);
ASSERT_TRUE(parsed.ok()) << parsed.status();
}
{
auto query = folly::stringPrintf(fmt, invalid.c_str());
auto parsed = parser.parse(query);
ASSERT_FALSE(parsed.ok());
}
}
}

Expand Down
13 changes: 7 additions & 6 deletions src/graph/FetchEdgesExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,17 @@ Status FetchEdgesExecutor::setupEdgeKeysFromRef() {
const InterimResult *inputs;
if (sentence_->ref()->isInputExpr()) {
inputs = inputs_.get();
if (inputs == nullptr || !inputs->hasData()) {
// we have empty imputs from pipe.
return Status::OK();
}
} else {
inputs = ectx()->variableHolder()->get(varname_);
if (inputs == nullptr || !inputs->hasData()) {
bool existing = false;
inputs = ectx()->variableHolder()->get(varname_, &existing);
if (!existing) {
return Status::Error("Variable `%s' not defined", varname_.c_str());
}
}
if (inputs == nullptr || !inputs->hasData()) {
// we have empty imputs from pipe.
return Status::OK();
}

auto ret = inputs->getVIDs(*srcid_);
if (!ret.ok()) {
Expand Down
11 changes: 6 additions & 5 deletions src/graph/FetchVerticesExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,16 @@ Status FetchVerticesExecutor::setupVidsFromRef() {
const InterimResult *inputs;
if (varname_ == nullptr) {
inputs = inputs_.get();
if (inputs == nullptr || !inputs->hasData()) {
return Status::OK();
}
} else {
inputs = ectx()->variableHolder()->get(*varname_);
if (inputs == nullptr || !inputs->hasData()) {
bool existing = false;
inputs = ectx()->variableHolder()->get(*varname_, &existing);
if (!existing) {
return Status::Error("Variable `%s' not defined", varname_->c_str());
}
}
if (inputs == nullptr || !inputs->hasData()) {
return Status::OK();
}

StatusOr<std::vector<VertexID>> result;
if (distinct_) {
Expand Down
33 changes: 30 additions & 3 deletions src/parser/GraphScanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,41 @@ class GraphScanner : public yyFlexLexer {
return readBuffer_(buf, maxSize);
}

void makeSpaceForString(size_t len) {
constexpr auto defaultSize = 256UL;
if (sbuf_ == nullptr) {
sbufSize_ = defaultSize > len ? defaultSize : len;
sbuf_ = std::make_unique<char[]>(sbufSize_);
return;
}

if (sbufSize_ - sbufPos_ >= len) {
return;
}

auto newSize = sbufSize_ * 2;
newSize = newSize > len ? newSize : len;
auto newBuffer = std::make_unique<char[]>(newSize);
::memcpy(newBuffer.get(), sbuf_.get(), sbufPos_);
sbuf_ = std::move(newBuffer);
sbufSize_ = newSize;
}

char* sbuf() {
return sbuf_.get();
}


private:
friend class Scanner_Basic_Test;
int yylex() override;

nebula::GraphParser::semantic_type * yylval{nullptr};
nebula::GraphParser::location_type * yylloc{nullptr};
std::function<int(char*, int)> readBuffer_;
nebula::GraphParser::semantic_type *yylval{nullptr};
nebula::GraphParser::location_type *yylloc{nullptr};
std::unique_ptr<char[]> sbuf_{nullptr};
size_t sbufSize_{0};
size_t sbufPos_{0};
std::function<int(char*, int)> readBuffer_;
};

} // namespace nebula
Expand Down
69 changes: 24 additions & 45 deletions src/parser/scanner.lex
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@ IP_OCTET ([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])

%%

thread_local static char sbuf[MAX_STRING];
size_t pos = 0;

{GO} { return TokenType::KW_GO; }
{AS} { return TokenType::KW_AS; }
{TO} { return TokenType::KW_TO; }
Expand Down Expand Up @@ -391,15 +388,15 @@ IP_OCTET ([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])
\${LABEL} { yylval->strval = new std::string(yytext + 1, yyleng - 1); return TokenType::VARIABLE; }


\" { BEGIN(DQ_STR); pos = 0; }
\' { BEGIN(SQ_STR); pos = 0; }
\" { BEGIN(DQ_STR); sbufPos_ = 0; }
\' { BEGIN(SQ_STR); sbufPos_ = 0; }
<DQ_STR>\" {
yylval->strval = new std::string(sbuf, pos);
yylval->strval = new std::string(sbuf(), sbufPos_);
BEGIN(INITIAL);
return TokenType::STRING;
}
<SQ_STR>\' {
yylval->strval = new std::string(sbuf, pos);
yylval->strval = new std::string(sbuf(), sbufPos_);
BEGIN(INITIAL);
return TokenType::STRING;
}
Expand All @@ -409,66 +406,48 @@ IP_OCTET ([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])
}
<DQ_STR,SQ_STR>\n { yyterminate(); }
<DQ_STR>[^\\\n\"]+ {
if (pos + yyleng > MAX_STRING) {
throw GraphParser::syntax_error(*yylloc, "string too long");
}
::strncpy(sbuf + pos, yytext, yyleng);
pos += yyleng;
makeSpaceForString(yyleng);
::strncpy(sbuf() + sbufPos_, yytext, yyleng);
sbufPos_ += yyleng;
}
<SQ_STR>[^\\\n\']+ {
if (pos + yyleng > MAX_STRING) {
throw GraphParser::syntax_error(*yylloc, "string too long");
}
::strncpy(sbuf + pos, yytext, yyleng);
pos += yyleng;
makeSpaceForString(yyleng);
::strncpy(sbuf() + sbufPos_, yytext, yyleng);
sbufPos_ += yyleng;
}
<DQ_STR,SQ_STR>\\{OCT}{1,3} {
if (pos + 1 > MAX_STRING) {
throw GraphParser::syntax_error(*yylloc, "string too long");
}
makeSpaceForString(1);
int val = 0;
sscanf(yytext + 1, "%o", &val);
if (val > 0xFF) {
yyterminate();
}
sbuf[pos++] = val;
sbuf()[sbufPos_++] = val;
}
<DQ_STR,SQ_STR>\\{DEC}+ { yyterminate(); }
<DQ_STR,SQ_STR>\\n {
if (pos + 1 > MAX_STRING) {
throw GraphParser::syntax_error(*yylloc, "string too long");
}
sbuf[pos++] = '\n';
makeSpaceForString(1);
sbuf()[sbufPos_++] = '\n';
}
<DQ_STR,SQ_STR>\\t {
if (pos + 1 > MAX_STRING) {
throw GraphParser::syntax_error(*yylloc, "string too long");
}
sbuf[pos++] = '\t';
makeSpaceForString(1);
sbuf()[sbufPos_++] = '\t';
}
<DQ_STR,SQ_STR>\\r {
if (pos + 1 > MAX_STRING) {
throw GraphParser::syntax_error(*yylloc, "string too long");
}
sbuf[pos++] = '\r';
makeSpaceForString(1);
sbuf()[sbufPos_++] = '\r';
}
<DQ_STR,SQ_STR>\\b {
if (pos + 1 > MAX_STRING) {
throw GraphParser::syntax_error(*yylloc, "string too long");
}
sbuf[pos++] = '\b';
makeSpaceForString(1);
sbuf()[sbufPos_++] = '\b';
}
<DQ_STR,SQ_STR>\\f {
if (pos + 1 > MAX_STRING) {
throw GraphParser::syntax_error(*yylloc, "string too long");
}
sbuf[pos++] = '\f';
makeSpaceForString(1);
sbuf()[sbufPos_++] = '\f';
}
<DQ_STR,SQ_STR>\\(.|\n) {
if (pos + 1 > MAX_STRING) {
throw GraphParser::syntax_error(*yylloc, "string too long");
}
sbuf[pos++] = yytext[1];
makeSpaceForString(1);
sbuf()[sbufPos_++] = yytext[1];
}
<DQ_STR,SQ_STR>\\ {
// This rule should have never been matched,
Expand Down

0 comments on commit 3d460f6

Please sign in to comment.