Skip to content
Snippets Groups Projects
Unverified Commit 817cdd6f authored by Shylock Hg's avatar Shylock Hg Committed by GitHub
Browse files

Fix the logical of space require for nested sentences (#829)


Co-authored-by: default avatarYee <2520865+yixinglu@users.noreply.github.com>
parent 44fa09ee
No related branches found
No related tags found
No related merge requests found
......@@ -14,7 +14,6 @@ namespace graph {
Status AssignmentValidator::validateImpl() {
auto* assignSentence = static_cast<AssignmentSentence*>(sentence_);
validator_ = makeValidator(assignSentence->sentence(), qctx_);
NG_RETURN_IF_ERROR(validator_->validate());
auto outputs = validator_->outputCols();
......
......@@ -15,7 +15,14 @@ namespace graph {
class AssignmentValidator final : public Validator {
public:
AssignmentValidator(Sentence* sentence, QueryContext* context)
: Validator(sentence, context) {}
: Validator(sentence, context) {
auto* assignSentence = static_cast<AssignmentSentence*>(sentence_);
validator_ = makeValidator(assignSentence->sentence(), qctx_);
if (validator_->noSpaceRequired()) {
setNoSpaceRequired();
}
}
private:
Status validateImpl() override;
......
......@@ -24,7 +24,12 @@ static const std::vector<std::string> kAllowedFmtType = {"row", "dot", "dot:stru
ExplainValidator::ExplainValidator(Sentence* sentence, QueryContext* context)
: Validator(sentence, context) {
DCHECK_EQ(sentence->kind(), Sentence::Kind::kExplain);
setNoSpaceRequired();
auto explain = static_cast<ExplainSentence*>(sentence_);
auto sentences = explain->seqSentences();
validator_ = std::make_unique<SequentialValidator>(sentences, qctx_);
if (validator_->noSpaceRequired()) {
setNoSpaceRequired();
}
}
static StatusOr<std::string> toExplainFormatType(const std::string& formatType) {
......@@ -57,8 +62,6 @@ Status ExplainValidator::validateImpl() {
planDesc->format = std::move(status).value();
qctx_->setPlanDescription(std::move(planDesc));
auto sentences = explain->seqSentences();
validator_ = std::make_unique<SequentialValidator>(sentences, qctx_);
NG_RETURN_IF_ERROR(validator_->validate());
outputs_ = validator_->outputCols();
......
......@@ -14,15 +14,10 @@ namespace nebula {
namespace graph {
Status PipeValidator::validateImpl() {
auto pipeSentence = static_cast<PipedSentence*>(sentence_);
auto left = pipeSentence->left();
lValidator_ = makeValidator(left, qctx_);
lValidator_->setInputCols(std::move(inputs_));
lValidator_->setInputVarName(inputVarName_);
NG_RETURN_IF_ERROR(lValidator_->validate());
auto right = pipeSentence->right();
rValidator_ = makeValidator(right, qctx_);
rValidator_->setInputCols(lValidator_->outputCols());
rValidator_->setInputVarName(lValidator_->root()->outputVar());
NG_RETURN_IF_ERROR(rValidator_->validate());
......
......@@ -16,7 +16,18 @@ namespace graph {
class PipeValidator final : public Validator {
public:
PipeValidator(Sentence* sentence, QueryContext* context)
: Validator(sentence, context) {}
: Validator(sentence, context) {
auto pipeSentence = static_cast<PipedSentence*>(sentence_);
auto left = pipeSentence->left();
lValidator_ = makeValidator(left, qctx_);
auto right = pipeSentence->right();
rValidator_ = makeValidator(right, qctx_);
if (lValidator_->noSpaceRequired() && rValidator_->noSpaceRequired()) {
setNoSpaceRequired();
}
}
private:
Status validateImpl() override;
......
......@@ -13,10 +13,7 @@ namespace nebula {
namespace graph {
Status SetValidator::validateImpl() {
auto setSentence = static_cast<SetSentence *>(sentence_);
lValidator_ = makeValidator(setSentence->left(), qctx_);
NG_RETURN_IF_ERROR(lValidator_->validate());
rValidator_ = makeValidator(setSentence->right(), qctx_);
NG_RETURN_IF_ERROR(rValidator_->validate());
auto lCols = lValidator_->outputCols();
......
......@@ -16,7 +16,15 @@ namespace graph {
class SetValidator final : public Validator {
public:
SetValidator(Sentence* sentence, QueryContext* context)
: Validator(sentence, context) {}
: Validator(sentence, context) {
auto setSentence = static_cast<SetSentence *>(sentence_);
lValidator_ = makeValidator(setSentence->left(), qctx_);
rValidator_ = makeValidator(setSentence->right(), qctx_);
if (lValidator_->noSpaceRequired() && rValidator_->noSpaceRequired()) {
setNoSpaceRequired();
}
}
private:
Status validateImpl() override;
......
......@@ -106,6 +106,11 @@ public:
noSpaceRequired_ = true;
}
// Whether require choosen space
bool noSpaceRequired() const {
return noSpaceRequired_;
}
const Sentence* sentence() const {
return sentence_;
}
......
......@@ -44,6 +44,44 @@ Feature: Yield
| ((!(false) OR (false AND false)) XOR false) |
| true |
Scenario: nested
When executing query:
"""
YIELD 1 AS number | YIELD $-.number AS number
"""
Then the result should be, in any order:
| number |
| 1 |
When executing query:
"""
$a = YIELD 1 AS number;
YIELD $a.number AS number;
"""
Then the result should be, in any order:
| number |
| 1 |
When executing query:
"""
YIELD 1 AS number UNION YIELD 2 AS number
"""
Then the result should be, in any order:
| number |
| 1 |
| 2 |
When executing query:
"""
YIELD 1 AS number INTERSECT YIELD 2 AS number
"""
Then the result should be, in any order:
| number |
When executing query:
"""
YIELD 1 AS number MINUS YIELD 2 AS number
"""
Then the result should be, in any order:
| number |
| 1 |
Scenario: tagProp
When executing query:
"""
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment