forked from vesoft-inc/nebula
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExplainSentence.cpp
29 lines (23 loc) · 1.01 KB
/
ExplainSentence.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/* Copyright (c) 2020 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License.
*/
#include "parser/ExplainSentence.h"
#include "parser/SequentialSentences.h"
namespace nebula {
ExplainSentence::ExplainSentence(SequentialSentences* seqSentences,
bool isProfile,
std::string* formatType)
: Sentence(Kind::kExplain),
isProfile_(isProfile),
formatType_(!formatType ? new std::string() : formatType),
seqSentences_(DCHECK_NOTNULL(seqSentences)) {}
std::string ExplainSentence::toString() const {
auto seqStr = seqSentences_->toString();
const char* keyword = isProfile_ ? "PROFILE " : "EXPLAIN ";
auto format = formatType_->empty() ? "" : "FORMAT=\"" + formatType() + "\" ";
bool hasMultiSentences = seqSentences_->sentences().size() > 1;
const char* fmt = hasMultiSentences ? "%s%s{%s}" : "%s%s%s";
return folly::stringPrintf(fmt, keyword, format.c_str(), seqStr.c_str());
}
} // namespace nebula