Skip to content
Snippets Groups Projects
Unverified Commit 7b253d12 authored by cpw's avatar cpw Committed by GitHub
Browse files

Fix yield (#546)

* Fix yield.

* Add test.

* Set var for tail.

* Add more yield test.

* Skip update minloglevel test.
parent fe823549
No related branches found
No related tags found
No related merge requests found
......@@ -26,7 +26,6 @@ folly::Future<Status> ProjectExecutor::execute() {
DataSet ds;
ds.colNames = project->colNames();
for (; iter->valid(); iter->next()) {
VLOG(1) << "row: " << *iter->row();
Row row;
for (auto& col : columns) {
Value val = col->expr()->eval(ctx(iter.get()));
......
......@@ -48,11 +48,15 @@ Status YieldValidator::validateImpl() {
NG_RETURN_IF_ERROR(checkAggFunAndBuildGroupItems(yield->yield()));
}
if (exprProps_.inputProps().empty() && exprProps_.varProps().empty()) {
if (exprProps_.inputProps().empty() && exprProps_.varProps().empty() && inputVarName_.empty()) {
// generate constant expression result into querycontext
genConstantExprValues();
}
if (!exprProps_.varProps().empty() && !userDefinedVarNameList_.empty()) {
userDefinedVarName_ = *userDefinedVarNameList_.begin();
}
return Status::OK();
}
......@@ -187,6 +191,13 @@ Status YieldValidator::validateWhere(const WhereClause *clause) {
Status YieldValidator::toPlan() {
auto yield = static_cast<const YieldSentence *>(sentence_);
std::string inputVar;
if (!userDefinedVarName_.empty()) {
inputVar = userDefinedVarName_;
} else if (!constantExprVar_.empty()) {
inputVar = constantExprVar_;
}
Filter *filter = nullptr;
if (yield->where()) {
filter = Filter::make(qctx_, nullptr, filterCondition_);
......@@ -194,9 +205,6 @@ Status YieldValidator::toPlan() {
std::transform(
inputs_.cbegin(), inputs_.cend(), colNames.begin(), [](auto &col) { return col.name; });
filter->setColNames(std::move(colNames));
if (!constantExprVar_.empty()) {
filter->setInputVar(constantExprVar_);
}
}
SingleInputNode *dedupDep = nullptr;
......@@ -206,6 +214,9 @@ Status YieldValidator::toPlan() {
// We do not use group items later, so move it is safe
dedupDep = Aggregate::make(qctx_, filter, {}, std::move(groupItems_));
}
if (filter == nullptr && !inputVar.empty()) {
dedupDep->setInputVar(inputVar);
}
dedupDep->setColNames(std::move(outputColumnNames_));
if (filter != nullptr) {
......@@ -215,10 +226,9 @@ Status YieldValidator::toPlan() {
tail_ = dedupDep;
}
if (!exprProps_.varProps().empty()) {
DCHECK_EQ(exprProps_.varProps().size(), 1u);
auto var = exprProps_.varProps().cbegin()->first;
static_cast<SingleInputNode *>(tail_)->setInputVar(var);
// Otherwise the input of tail_ would be set by pipe.
if (!inputVar.empty()) {
static_cast<SingleInputNode *>(tail_)->setInputVar(inputVar);
}
if (yield->yield()->isDistinct()) {
......
......@@ -47,6 +47,7 @@ private:
std::vector<std::string> outputColumnNames_;
std::vector<Aggregate::GroupItem> groupItems_;
std::string constantExprVar_;
std::string userDefinedVarName_;
Expression *filterCondition_{nullptr};
};
......
......@@ -5,6 +5,7 @@
# This source code is licensed under Apache 2.0 License,
# attached with Common Clause Condition 1.0, found in the LICENSES directory.
import pytest
from tests.common.nebula_test_suite import NebulaTestSuite
......@@ -79,6 +80,24 @@ class TestConfigs(NebulaTestSuite):
['STORAGE', 'rocksdb_block_based_table_options', 'map', 'MUTABLE', {"block_size":"8192"}]]
self.check_out_of_order_result(resp, expected_result)
# update rocksdb
resp = self.client.execute('''
UPDATE CONFIGS storage:rocksdb_column_family_options={
max_bytes_for_level_base=1024,
write_buffer_size=1024,
max_write_buffer_number=4}
''')
self.check_resp_succeeded(resp)
# get result
resp = self.client.execute('GET CONFIGS storage:rocksdb_column_family_options')
self.check_resp_succeeded(resp)
value = {"max_bytes_for_level_base": 1024, "write_buffer_size": 1024, "max_write_buffer_number": 4}
expected_result = [['STORAGE', 'rocksdb_column_family_options', 'map', 'MUTABLE', value]]
self.check_result(resp, expected_result)
@pytest.mark.skip("The change of minloglevel will infulence the whole test.")
def test_update_configs(self):
# set and get a config of all module
resp = self.client.execute('UPDATE CONFIGS minloglevel={}'.format(2))
self.check_resp_succeeded(resp)
......@@ -101,18 +120,4 @@ class TestConfigs(NebulaTestSuite):
['STORAGE', 'minloglevel', 'int', 'MUTABLE', 3]]
self.check_result(resp, expected_result)
# update rocksdb
resp = self.client.execute('''
UPDATE CONFIGS storage:rocksdb_column_family_options={
max_bytes_for_level_base=1024,
write_buffer_size=1024,
max_write_buffer_number=4}
''')
self.check_resp_succeeded(resp)
# get result
resp = self.client.execute('GET CONFIGS storage:rocksdb_column_family_options')
self.check_resp_succeeded(resp)
value = {"max_bytes_for_level_base": 1024, "write_buffer_size": 1024, "max_write_buffer_number": 4}
expected_result = [['STORAGE', 'rocksdb_column_family_options', 'map', 'MUTABLE', value]]
self.check_result(resp, expected_result)
# Copyright (c) 2020 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License,
# attached with Common Clause Condition 1.0, found in the LICENSES directory.
Feature: Test yield constant after pipe
Background:
Given a graph with space named "nba"
Scenario: yield constant after pipe
When executing query:
"""
GO FROM "Tim Duncan" OVER * | YIELD 1 AS a;
"""
Then the result should be, in any order:
| a |
| 1 |
| 1 |
| 1 |
| 1 |
| 1 |
| 1 |
| 1 |
When executing query:
"""
GO FROM "Tim Duncan" OVER * | YIELD 1 AS a WHERE true;
"""
Then the result should be, in any order:
| a |
| 1 |
| 1 |
| 1 |
| 1 |
| 1 |
| 1 |
| 1 |
When executing query:
"""
GO FROM "Tim Duncan" OVER * | YIELD 1 AS a WHERE false;
"""
Then the result should be, in any order:
| a |
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