Skip to content

Commit

Permalink
fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
xtcyclist committed Dec 1, 2022
1 parent accf511 commit f24450b
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 7 deletions.
7 changes: 7 additions & 0 deletions src/common/datatypes/DataSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,13 @@ struct DataSet {
bool operator==(const DataSet& rhs) const {
return colNames == rhs.colNames && rows == rhs.rows;
}

void removeColumn(size_t idx) {
for (auto& row : rows) {
row.values.erase(row.values.begin() + idx);
}
colNames.erase(colNames.begin() + idx);
}
};

inline std::ostream& operator<<(std::ostream& os, const DataSet& d) {
Expand Down
5 changes: 5 additions & 0 deletions src/common/datatypes/Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,11 @@ const DataSet& Value::getDataSet() const {
return *(value_.gVal);
}

DataSet& Value::getMutableDataSet() {
CHECK_EQ(type_, Type::DATASET);
return *(value_.gVal);
}

const DataSet* Value::getDataSetPtr() const {
CHECK_EQ(type_, Type::DATASET);
return value_.gVal.get();
Expand Down
1 change: 1 addition & 0 deletions src/common/datatypes/Value.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ struct Value {
const Set& getSet() const;
const Set* getSetPtr() const;
const DataSet& getDataSet() const;
DataSet& getMutableDataSet();
const DataSet* getDataSetPtr() const;
const Geography& getGeography() const;
const Geography* getGeographyPtr() const;
Expand Down
1 change: 1 addition & 0 deletions src/graph/context/Symbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct Variable {

// the count of use the variable
std::atomic<uint64_t> userCount{0};
std::vector<size_t> invisibleColIndicies;
};

class SymbolTable final {
Expand Down
6 changes: 2 additions & 4 deletions src/graph/executor/query/ProjectExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ DataSet ProjectExecutor::handleJob(size_t begin, size_t end, Iterator *iter) {
for (; iter->valid() && begin++ < end; iter->next()) {
Row row;
for (auto &col : columns->columns()) {
if (col->isVisible()) {
Value val = col->expr()->eval(ctx(iter));
row.values.emplace_back(std::move(val));
}
Value val = col->expr()->eval(ctx(iter));
row.values.emplace_back(std::move(val));
}
ds.rows.emplace_back(std::move(row));
}
Expand Down
3 changes: 3 additions & 0 deletions src/graph/executor/query/SortExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ folly::Future<Status> SortExecutor::execute() {

auto seqIter = static_cast<SequentialIter *>(iter);
std::sort(seqIter->begin(), seqIter->end(), comparator);
for (auto &idx : sort->inputVars()[0]->invisibleColIndicies) {
result.valuePtr()->getMutableDataSet().removeColumn(idx);
}
return finish(ResultBuilder().value(result.valuePtr()).iter(std::move(result).iter()).build());
}

Expand Down
7 changes: 7 additions & 0 deletions src/graph/planner/match/ReturnClausePlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ Status ReturnClausePlanner::buildReturn(ReturnClauseContext* rctx, SubPlan& subP
NG_RETURN_IF_ERROR(orderPlan);
auto plan = std::move(orderPlan).value();
subPlan = SegmentsConnector::addInput(plan, subPlan, true);
size_t idx = 0;
for (auto& yiledCol : rctx->yield->yieldColumns->columns()) {
if (!yiledCol->isVisible()) {
subPlan.root->mutableInputVars()[0]->invisibleColIndicies.push_back(idx);
}
idx++;
}
}

if (rctx->pagination != nullptr &&
Expand Down
4 changes: 4 additions & 0 deletions src/graph/planner/plan/PlanNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ class PlanNode {
return inputVars_;
}

std::vector<Variable*>& mutableInputVars() {
return inputVars_;
}

void releaseSymbols();

void updateSymbols();
Expand Down
3 changes: 2 additions & 1 deletion src/graph/validator/MatchValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ Status MatchValidator::validateReturn(MatchReturn *ret,
col->setVisible(false);
columns->addColumn(col->clone().release());
found = true;
orderByCtx->indexedOrderFactors.emplace_back(columns->size(), factor->orderType());
orderByCtx->indexedOrderFactors.emplace_back(columns->size() - 1, factor->orderType());
break;
}
}
Expand All @@ -518,6 +518,7 @@ Status MatchValidator::validateReturn(MatchReturn *ret,
orderByCtx->indexedOrderFactors.emplace_back(iter->second, factor->orderType());
}
}
retClauseCtx.order = std::move(orderByCtx);
preValidatedOrderBy = true;
}
// finished producing columns for further validations
Expand Down
5 changes: 3 additions & 2 deletions src/parser/Clauses.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,14 @@ class WhenClause : public WhereClause {

class YieldColumn final {
public:
explicit YieldColumn(Expression *expr, const std::string &alias = "") {
explicit YieldColumn(Expression *expr, const std::string &alias = "", bool visible = true) {
expr_ = expr;
alias_ = alias;
visible_ = visible;
}

std::unique_ptr<YieldColumn> clone() const {
return std::make_unique<YieldColumn>(expr_->clone(), alias_);
return std::make_unique<YieldColumn>(expr_->clone(), alias_, visible_);
}

void setExpr(Expression *expr) {
Expand Down

0 comments on commit f24450b

Please sign in to comment.