Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
andyfengHKU committed Jul 1, 2023
1 parent da999a9 commit 2754a3c
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 34 deletions.
13 changes: 0 additions & 13 deletions src/binder/expression/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,5 @@ expression_vector ExpressionUtil::excludeExpressions(
return result;
}

expression_vector ExpressionUtil::removeDuplication(const expression_vector& expressions) {
expression_set excludeSet;
expression_vector result;
for (auto& expression : expressions) {
if (excludeSet.contains(expression)) {
continue;
}
excludeSet.insert(expression);
result.push_back(expression);
}
return result;
}

} // namespace binder
} // namespace kuzu
2 changes: 0 additions & 2 deletions src/include/binder/expression/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ struct ExpressionUtil {
static expression_vector excludeExpressions(
const expression_vector& expressions, const expression_vector& expressionsToExclude);

static expression_vector removeDuplication(const expression_vector& expressions);

inline static bool isNodeVariable(const Expression& expression) {
return expression.expressionType == common::ExpressionType::VARIABLE &&
expression.dataType.getLogicalTypeID() == common::LogicalTypeID::NODE;
Expand Down
7 changes: 4 additions & 3 deletions src/include/planner/logical_plan/logical_operator/schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,13 @@ class Schema {
f_group_pos createGroup();

void insertToScope(const std::shared_ptr<binder::Expression>& expression, uint32_t groupPos);

void insertToGroupAndScope(
const std::shared_ptr<binder::Expression>& expression, uint32_t groupPos);
// Use this function only if the operator may work with duplicate expressions.
// Use these unsafe insert functions only if the operator may work with duplicate expressions.
// E.g. group by a.age, a.age
void insertToGroupAndScopeUnsafe(
void insertToScopeMayRepeat(
const std::shared_ptr<binder::Expression>& expression, uint32_t groupPos);
void insertToGroupAndScopeMayRepeat(
const std::shared_ptr<binder::Expression>& expression, uint32_t groupPos);

void insertToGroupAndScope(const binder::expression_vector& expressions, uint32_t groupPos);
Expand Down
6 changes: 3 additions & 3 deletions src/planner/operator/logical_aggregate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ bool LogicalAggregate::hasDistinctAggregate() {

void LogicalAggregate::insertAllExpressionsToGroupAndScope(f_group_pos groupPos) {
for (auto& expression : keyExpressions) {
schema->insertToGroupAndScopeUnsafe(expression, groupPos);
schema->insertToGroupAndScopeMayRepeat(expression, groupPos);
}
for (auto& expression : dependentKeyExpressions) {
schema->insertToGroupAndScopeUnsafe(expression, groupPos);
schema->insertToGroupAndScopeMayRepeat(expression, groupPos);

Check warning on line 82 in src/planner/operator/logical_aggregate.cpp

View check run for this annotation

Codecov / codecov/patch

src/planner/operator/logical_aggregate.cpp#L82

Added line #L82 was not covered by tests
}
for (auto& expression : aggregateExpressions) {
schema->insertToGroupAndScopeUnsafe(expression, groupPos);
schema->insertToGroupAndScopeMayRepeat(expression, groupPos);
}
}

Expand Down
16 changes: 4 additions & 12 deletions src/planner/operator/logical_projection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@ void LogicalProjection::computeFactorizedSchema() {
schema = childSchema->copy();
schema->clearExpressionsInScope();
for (auto& expression : expressions) {
// E.g. RETURN MIN(a.age), MAX(a.age). We first project each expression in aggregate. So
// a.age might be projected twice.
if (schema->isExpressionInScope(*expression)) {
continue;
}
auto groupPos = INVALID_F_GROUP_POS;
if (childSchema->isExpressionInScope(*expression)) { // expression to reference
groupPos = childSchema->getGroupPos(*expression);
schema->insertToScope(expression, groupPos);
schema->insertToScopeMayRepeat(expression, groupPos);
} else { // expression to evaluate
auto dependentGroupPos = childSchema->getDependentGroupsPos(expression);
SchemaUtils::validateAtMostOneUnFlatGroup(dependentGroupPos, *childSchema);
Expand All @@ -26,7 +21,7 @@ void LogicalProjection::computeFactorizedSchema() {
} else {
groupPos = SchemaUtils::getLeadingGroupPos(dependentGroupPos, *childSchema);
}
schema->insertToGroupAndScope(expression, groupPos);
schema->insertToGroupAndScopeMayRepeat(expression, groupPos);
}
}
}
Expand All @@ -36,13 +31,10 @@ void LogicalProjection::computeFlatSchema() {
auto childSchema = children[0]->getSchema();
schema->clearExpressionsInScope();
for (auto& expression : expressions) {
if (schema->isExpressionInScope(*expression)) {
continue;
}
if (childSchema->isExpressionInScope(*expression)) {
schema->insertToScope(expression, 0);
schema->insertToScopeMayRepeat(expression, 0);
} else {
schema->insertToGroupAndScope(expression, 0);
schema->insertToGroupAndScopeMayRepeat(expression, 0);
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/planner/operator/schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ void Schema::insertToGroupAndScope(
expressionsInScope.push_back(expression);
}

void Schema::insertToGroupAndScopeUnsafe(
void Schema::insertToScopeMayRepeat(
const std::shared_ptr<binder::Expression>& expression, uint32_t groupPos) {
if (expressionNameToGroupPos.contains(expression->getUniqueName())) {
return;
}
insertToScope(expression, groupPos);
}

void Schema::insertToGroupAndScopeMayRepeat(
const std::shared_ptr<binder::Expression>& expression, uint32_t groupPos) {
if (expressionNameToGroupPos.contains(expression->getUniqueName())) {
return;
Expand Down

0 comments on commit 2754a3c

Please sign in to comment.