Skip to content

Commit

Permalink
X
Browse files Browse the repository at this point in the history
  • Loading branch information
andyfengHKU committed Jul 12, 2023
1 parent 1bec5fe commit 5b607a6
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 40 deletions.
54 changes: 28 additions & 26 deletions src/binder/bind/bind_graph_pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,39 +432,41 @@ void Binder::bindQueryNodeProperties(NodeExpression& node) {
}
}

std::vector<table_id_t> Binder::bindTableIDs(
const std::vector<std::string>& tableNames, LogicalTypeID nodeOrRelType) {
std::vector<common::table_id_t> Binder::bindNodeTableIDs(
const std::vector<std::string>& tableNames) {
if (!catalog.getReadOnlyVersion()->hasNodeTable()) {
throw common::BinderException("No node table exists in database.");
}
std::unordered_set<table_id_t> tableIDs;
switch (nodeOrRelType) {
case LogicalTypeID::NODE: {
if (tableNames.empty()) {
for (auto tableID : catalog.getReadOnlyVersion()->getNodeTableIDs()) {
tableIDs.insert(tableID);
}
} else {
for (auto& tableName : tableNames) {
tableIDs.insert(bindNodeTableID(tableName));
}
}
} break;
case LogicalTypeID::REL: {
if (tableNames.empty()) {
for (auto tableID : catalog.getReadOnlyVersion()->getRelTableIDs()) {
tableIDs.insert(tableID);
}
if (tableNames.empty()) {
for (auto tableID : catalog.getReadOnlyVersion()->getNodeTableIDs()) {
tableIDs.insert(tableID);
}
} else {
for (auto& tableName : tableNames) {
tableIDs.insert(bindRelTableID(tableName));
tableIDs.insert(bindNodeTableID(tableName));
}
} break;
default:
throw NotImplementedException(
"bindTableIDs(" + LogicalTypeUtils::dataTypeToString(nodeOrRelType) + ").");
}
auto result = std::vector<table_id_t>{tableIDs.begin(), tableIDs.end()};
if (result.empty() && tableNames.empty()) {
throw common::BinderException{"Expected a valid node name in MATCH clause."};
std::sort(result.begin(), result.end());
return result;
}

std::vector<common::table_id_t> Binder::bindRelTableIDs(
const std::vector<std::string>& tableNames) {
if (!catalog.getReadOnlyVersion()->hasRelTable()) {
throw common::BinderException("No rel table exists in database.");

Check warning on line 458 in src/binder/bind/bind_graph_pattern.cpp

View check run for this annotation

Codecov / codecov/patch

src/binder/bind/bind_graph_pattern.cpp#L458

Added line #L458 was not covered by tests
}
std::unordered_set<table_id_t> tableIDs;
if (tableNames.empty()) {
for (auto tableID : catalog.getReadOnlyVersion()->getRelTableIDs()) {
tableIDs.insert(tableID);
}
}
for (auto& tableName : tableNames) {
tableIDs.insert(bindRelTableID(tableName));
}
auto result = std::vector<table_id_t>{tableIDs.begin(), tableIDs.end()};
std::sort(result.begin(), result.end());
return result;
}
Expand Down
12 changes: 2 additions & 10 deletions src/include/binder/binder.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,8 @@ class Binder {
const std::string& parsedName, const std::vector<common::table_id_t>& tableIDs);
void bindQueryNodeProperties(NodeExpression& node);

inline std::vector<common::table_id_t> bindNodeTableIDs(
const std::vector<std::string>& tableNames) {
return bindTableIDs(tableNames, common::LogicalTypeID::NODE);
}
inline std::vector<common::table_id_t> bindRelTableIDs(
const std::vector<std::string>& tableNames) {
return bindTableIDs(tableNames, common::LogicalTypeID::REL);
}
std::vector<common::table_id_t> bindTableIDs(
const std::vector<std::string>& tableNames, common::LogicalTypeID nodeOrRelType);
std::vector<common::table_id_t> bindNodeTableIDs(const std::vector<std::string>& tableNames);
std::vector<common::table_id_t> bindRelTableIDs(const std::vector<std::string>& tableNames);

/*** validations ***/
// E.g. Optional MATCH (a) RETURN a.age
Expand Down
3 changes: 3 additions & 0 deletions src/include/catalog/catalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class CatalogContent {
common::table_id_t dstTableID, common::LogicalType srcPKDataType,
common::LogicalType dstPKDataType);

inline bool hasNodeTable() const { return !nodeTableSchemas.empty(); }
inline bool hasRelTable() const { return !relTableSchemas.empty(); }

inline bool containNodeTable(common::table_id_t tableID) const {
return nodeTableSchemas.contains(tableID);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
-CASE MissingQueryNode
-STATEMENT MATCH () WITH NULL AS a RETURN a;
---- error
Binder exception: Expected a valid node name in MATCH clause.
Binder exception: No node table exists in database.
5 changes: 2 additions & 3 deletions test/test_files/tck/match/match1.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@

# Match non-existent nodes returns empty
-CASE Scenario1
-STATEMENT CREATE NODE TABLE A(ID SERIAL, PRIMARY KEY(ID));
---- ok
-STATEMENT MATCH (n) RETURN n;
---- 0
---- error
Binder exception: No node table exists in database.

# Matching all nodes
# TODO(Guodong/Ziyi): Fixme
Expand Down
35 changes: 35 additions & 0 deletions test/test_files/tck/match/match2.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
-GROUP TCK
-DATASET CSV tck

--

# Match non-existent relationships returns empty
-CASE Scenario1
-STATEMENT CREATE NODE TABLE A(ID SERIAL, PRIMARY KEY(ID));
---- ok
-STATEMENT MATCH ()-[r]->() RETURN r;
---- error
Binder exception: No rel table exists in database.

# Matching a relationship pattern using a label predicate on both sides
-CASE Scenario2
-STATEMENT CREATE NODE TABLE A(ID SERIAL, PRIMARY KEY(ID));
---- ok
-STATEMENT CREATE NODE TABLE B(ID SERIAL, PRIMARY KEY(ID));
---- ok
-STATEMENT CREATE REL TABLE T1(FROM A TO B);
---- ok
-STATEMENT CREATE REL TABLE T2(FROM B TO A);
---- ok
-STATEMENT CREATE REL TABLE T3(FROM B TO B);
---- ok
-STATEMENT CREATE REL TABLE T4(FROM A TO A);
---- ok
-STATEMENT CREATE (:A)-[:T1]->(:B),
(:B)-[:T2]->(:A),
(:B)-[:T3]->(:B),
(:A)-[:T4]->(:A);
---- ok
-STATEMENT MATCH (:A)-[r]->(:B) RETURN r;
---- 1
(0:0)-{_LABEL: T1, _ID: 2:0}->(1:0)

0 comments on commit 5b607a6

Please sign in to comment.