-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1557 from kuzudb/bound-ast-visitor
Add visitor pattern to bound statement
- Loading branch information
Showing
32 changed files
with
295 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#include "binder/bound_statement_visitor.h" | ||
|
||
using namespace kuzu::common; | ||
|
||
namespace kuzu { | ||
namespace binder { | ||
|
||
void BoundStatementVisitor::visit(const kuzu::binder::BoundStatement& statement) { | ||
switch (statement.getStatementType()) { | ||
case StatementType::QUERY: { | ||
visitRegularQuery((BoundRegularQuery&)statement); | ||
} break; | ||
case StatementType::CREATE_NODE_TABLE: { | ||
visitCreateNodeTable(statement); | ||
} break; | ||
case StatementType::CREATE_REL_TABLE: { | ||
visitCreateRelTable(statement); | ||
} break; | ||
case StatementType::DROP_TABLE: { | ||
visitDropTable(statement); | ||
} break; | ||
case StatementType::RENAME_TABLE: { | ||
visitRenameTable(statement); | ||
} break; | ||
case StatementType::ADD_PROPERTY: { | ||
visitAddProperty(statement); | ||
} break; | ||
case StatementType::DROP_PROPERTY: { | ||
visitDropProperty(statement); | ||
} break; | ||
case StatementType::RENAME_PROPERTY: { | ||
visitRenameProperty(statement); | ||
} break; | ||
case StatementType::COPY: { | ||
visitCopy(statement); | ||
} break; | ||
default: | ||
throw NotImplementedException("BoundStatementVisitor::visit"); | ||
} | ||
} | ||
|
||
void BoundStatementVisitor::visitRegularQuery(const BoundRegularQuery& regularQuery) { | ||
for (auto i = 0u; i < regularQuery.getNumSingleQueries(); ++i) { | ||
visitSingleQuery(*regularQuery.getSingleQuery(i)); | ||
} | ||
} | ||
|
||
void BoundStatementVisitor::visitSingleQuery(const NormalizedSingleQuery& singleQuery) { | ||
for (auto i = 0u; i < singleQuery.getNumQueryParts(); ++i) { | ||
visitQueryPart(*singleQuery.getQueryPart(i)); | ||
} | ||
} | ||
|
||
void BoundStatementVisitor::visitQueryPart(const NormalizedQueryPart& queryPart) { | ||
for (auto i = 0u; i < queryPart.getNumReadingClause(); ++i) { | ||
visitReadingClause(*queryPart.getReadingClause(i)); | ||
} | ||
for (auto i = 0u; i < queryPart.getNumUpdatingClause(); ++i) { | ||
visitUpdatingClause(*queryPart.getUpdatingClause(i)); | ||
} | ||
if (queryPart.hasProjectionBody()) { | ||
visitProjectionBody(*queryPart.getProjectionBody()); | ||
if (queryPart.hasProjectionBodyPredicate()) { | ||
visitProjectionBodyPredicate(*queryPart.getProjectionBodyPredicate()); | ||
} | ||
} | ||
} | ||
|
||
void BoundStatementVisitor::visitReadingClause(const BoundReadingClause& readingClause) { | ||
switch (readingClause.getClauseType()) { | ||
case common::ClauseType::MATCH: { | ||
visitMatch(readingClause); | ||
} break; | ||
case common::ClauseType::UNWIND: { | ||
visitUnwind(readingClause); | ||
} break; | ||
default: | ||
throw NotImplementedException("BoundStatementVisitor::visitReadingClause"); | ||
} | ||
} | ||
|
||
void BoundStatementVisitor::visitUpdatingClause(const BoundUpdatingClause& updatingClause) { | ||
switch (updatingClause.getClauseType()) { | ||
case common::ClauseType::SET: { | ||
visitSet(updatingClause); | ||
} break; | ||
case common::ClauseType::DELETE: { | ||
visitDelete(updatingClause); | ||
} break; | ||
case common::ClauseType::CREATE: { | ||
visitCreate(updatingClause); | ||
} break; | ||
default: | ||
throw NotImplementedException("BoundStatementVisitor::visitUpdatingClause"); | ||
} | ||
} | ||
|
||
} // namespace binder | ||
} // namespace kuzu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
add_library( | ||
kuzu_binder_visitor | ||
OBJECT | ||
property_collector.cpp) | ||
|
||
set(ALL_OBJECT_FILES | ||
${ALL_OBJECT_FILES} $<TARGET_OBJECTS:kuzu_binder_visitor> | ||
PARENT_SCOPE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#include "binder/visitor/property_collector.h" | ||
|
||
#include "binder/query/reading_clause/bound_match_clause.h" | ||
#include "binder/query/reading_clause/bound_unwind_clause.h" | ||
#include "binder/query/updating_clause/bound_create_clause.h" | ||
#include "binder/query/updating_clause/bound_delete_clause.h" | ||
#include "binder/query/updating_clause/bound_set_clause.h" | ||
|
||
namespace kuzu { | ||
namespace binder { | ||
|
||
expression_vector PropertyCollector::getProperties() { | ||
expression_vector result; | ||
for (auto& property : properties) { | ||
result.push_back(property); | ||
} | ||
return result; | ||
} | ||
|
||
void PropertyCollector::visitMatch(const BoundReadingClause& readingClause) { | ||
auto& matchClause = (BoundMatchClause&)readingClause; | ||
for (auto& rel : matchClause.getQueryGraphCollection()->getQueryRels()) { | ||
if (rel->hasInternalIDProperty()) { | ||
properties.insert(rel->getInternalIDProperty()); | ||
} | ||
} | ||
if (matchClause.hasWhereExpression()) { | ||
collectPropertyExpressions(*matchClause.getWhereExpression()); | ||
} | ||
} | ||
|
||
void PropertyCollector::visitUnwind(const BoundReadingClause& readingClause) { | ||
auto& unwindClause = (BoundUnwindClause&)readingClause; | ||
collectPropertyExpressions(*unwindClause.getExpression()); | ||
} | ||
|
||
void PropertyCollector::visitSet(const BoundUpdatingClause& updatingClause) { | ||
auto& boundSetClause = (BoundSetClause&)updatingClause; | ||
for (auto& setNodeProperty : boundSetClause.getSetNodeProperties()) { | ||
collectPropertyExpressions(*setNodeProperty->getSetItem().second); | ||
} | ||
for (auto& setRelProperty : boundSetClause.getSetRelProperties()) { | ||
collectPropertyExpressions(*setRelProperty->getSetItem().second); | ||
} | ||
} | ||
|
||
void PropertyCollector::visitDelete(const BoundUpdatingClause& updatingClause) { | ||
auto& boundDeleteClause = (BoundDeleteClause&)updatingClause; | ||
for (auto& deleteNode : boundDeleteClause.getDeleteNodes()) { | ||
properties.insert(deleteNode->getPrimaryKeyExpression()); | ||
} | ||
for (auto& deleteRel : boundDeleteClause.getDeleteRels()) { | ||
if (deleteRel->hasInternalIDProperty()) { | ||
properties.insert(deleteRel->getInternalIDProperty()); | ||
} | ||
} | ||
} | ||
|
||
void PropertyCollector::visitCreate(const BoundUpdatingClause& updatingClause) { | ||
auto& boundCreateClause = (BoundCreateClause&)updatingClause; | ||
for (auto& createNode : boundCreateClause.getCreateNodes()) { | ||
for (auto& setItem : createNode->getSetItems()) { | ||
collectPropertyExpressions(*setItem.second); | ||
} | ||
} | ||
for (auto& createRel : boundCreateClause.getCreateRels()) { | ||
for (auto& setItem : createRel->getSetItems()) { | ||
collectPropertyExpressions(*setItem.second); | ||
} | ||
} | ||
} | ||
|
||
void PropertyCollector::visitProjectionBody(const BoundProjectionBody& projectionBody) { | ||
for (auto& expression : projectionBody.getProjectionExpressions()) { | ||
collectPropertyExpressions(*expression); | ||
} | ||
for (auto& expression : projectionBody.getOrderByExpressions()) { | ||
collectPropertyExpressions(*expression); | ||
} | ||
} | ||
|
||
void PropertyCollector::visitProjectionBodyPredicate(Expression& predicate) { | ||
collectPropertyExpressions(predicate); | ||
} | ||
|
||
void PropertyCollector::collectPropertyExpressions(Expression& expression) { | ||
for (auto& property : expression.getSubPropertyExpressions()) { | ||
properties.insert(property); | ||
} | ||
} | ||
|
||
} // namespace binder | ||
} // namespace kuzu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.