Skip to content

Commit

Permalink
add unlabeled support
Browse files Browse the repository at this point in the history
  • Loading branch information
andyfengHKU committed Dec 12, 2022
1 parent 5a685bf commit fa08d5b
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 27 deletions.
29 changes: 20 additions & 9 deletions src/binder/bind/bind_graph_pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,12 @@ shared_ptr<NodeExpression> Binder::bindQueryNode(
auto prevVariable = variablesInScope.at(parsedName);
ExpressionBinder::validateExpectedDataType(*prevVariable, NODE);
queryNode = static_pointer_cast<NodeExpression>(prevVariable);
auto otherTableIDs = bindNodeTableIDs(nodePattern.getTableNames());
queryNode->addTableIDs(otherTableIDs);
// E.g. MATCH (a:person) MATCH (a:organisation)
// We bind to single node a with both labels
if (!nodePattern.getTableNames().empty()) {
auto otherTableIDs = bindNodeTableIDs(nodePattern.getTableNames());
queryNode->addTableIDs(otherTableIDs);
}
} else {
queryNode = createQueryNode(nodePattern);
}
Expand Down Expand Up @@ -152,11 +156,23 @@ vector<table_id_t> Binder::bindTableIDs(
unordered_set<table_id_t> result;
switch (nodeOrRelType) {
case NODE: {
for (auto& tableName : tableNames) {
result.insert(bindNodeTableID(tableName));
if (tableNames.empty()) {
for (auto tableID : catalog.getReadOnlyVersion()->getNodeTableIDs()) {
result.insert(tableID);
}
} else {
for (auto& tableName : tableNames) {
result.insert(bindNodeTableID(tableName));
}
}

} break;
case REL: {
if (tableNames.empty()) {
for (auto tableID : catalog.getReadOnlyVersion()->getRelTableIDs()) {
result.insert(tableID);
}
}
for (auto& tableName : tableNames) {
result.insert(bindRelTableID(tableName));
}
Expand All @@ -165,11 +181,6 @@ vector<table_id_t> Binder::bindTableIDs(
throw NotImplementedException(
"bindTableIDs(" + Types::dataTypeToString(nodeOrRelType) + ").");
}
for (auto& tableID : result) {
if (tableID == ANY_TABLE_ID) {
throw BinderException("Any-table is not supported.");
}
}
return vector<table_id_t>{result.begin(), result.end()};
}

Expand Down
6 changes: 0 additions & 6 deletions src/binder/binder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,13 @@ shared_ptr<Expression> Binder::bindWhereExpression(const ParsedExpression& parse
}

table_id_t Binder::bindRelTableID(const string& tableName) const {
if (tableName.empty()) {
return ANY_TABLE_ID;
}
if (!catalog.getReadOnlyVersion()->containRelTable(tableName)) {
throw BinderException("Rel table " + tableName + " does not exist.");
}
return catalog.getReadOnlyVersion()->getRelTableIDFromName(tableName);
}

table_id_t Binder::bindNodeTableID(const string& tableName) const {
if (tableName.empty()) {
return ANY_TABLE_ID;
}
if (!catalog.getReadOnlyVersion()->containNodeTable(tableName)) {
throw BinderException("Node table " + tableName + " does not exist.");
}
Expand Down
3 changes: 2 additions & 1 deletion src/include/binder/expression/node_rel_expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ namespace binder {

class NodeOrRelExpression : public Expression {
public:
NodeOrRelExpression(DataTypeID dataTypeID, const string& uniqueName, vector<table_id_t> tableIDs)
NodeOrRelExpression(
DataTypeID dataTypeID, const string& uniqueName, vector<table_id_t> tableIDs)
: Expression{VARIABLE, dataTypeID, uniqueName}, tableIDs{std::move(tableIDs)} {}

inline void addTableIDs(const vector<table_id_t>& tableIDsToAdd) {
Expand Down
1 change: 0 additions & 1 deletion src/include/binder/query/reading_clause/query_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
namespace kuzu {
namespace binder {

const table_id_t ANY_TABLE_ID = numeric_limits<uint32_t>::max();
const uint8_t MAX_NUM_VARIABLES = 64;

class QueryGraph;
Expand Down
14 changes: 14 additions & 0 deletions src/include/catalog/catalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ class CatalogContent {
inline const vector<Property>& getRelProperties(table_id_t tableID) const {
return relTableSchemas.at(tableID)->properties;
}
inline vector<table_id_t> getNodeTableIDs() const {
vector<table_id_t> nodeTableIDs;
for (auto& [tableID, _] : nodeTableSchemas) {
nodeTableIDs.push_back(tableID);
}
return nodeTableIDs;
}
inline vector<table_id_t> getRelTableIDs() const {
vector<table_id_t> relTableIDs;
for (auto& [tableID, _] : relTableSchemas) {
relTableIDs.push_back(tableID);
}
return relTableIDs;
}
inline unordered_map<table_id_t, unique_ptr<NodeTableSchema>>& getNodeTableSchemas() {
return nodeTableSchemas;
}
Expand Down
26 changes: 26 additions & 0 deletions test/test_files/tinysnb/match/multi_label.test
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
-NAME UnLabelTest
-QUERY MATCH () RETURN COUNT(*)
---- 1
14

-NAME MultiLabelNodeTest
-QUERY MATCH (a:organisation:person) RETURN COUNT(*)
---- 1
11

-NAME MultiLabelNodeTest
-QUERY MATCH (a:organisation:person) MATCH (a:movies) RETURN COUNT(*)
---- 1
14

-NAME MultiLabelCrossProductTest
-QUERY MATCH (a:person), (b:person), (c:person:movies) RETURN COUNT(*)
-ENUMERATE
---- 1
704

-NAME UnLabelOneHopTest
-QUERY MATCH ()-[]->() RETURN COUNT(*)
---- 1
40

-NAME MultiLabelOneHopTest1
-QUERY MATCH (a:person)-[e:knows|:marries]->(b:person) RETURN COUNT(*)
---- 1
Expand Down
10 changes: 0 additions & 10 deletions test/test_files/tinysnb/match/node.test
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,3 @@
---- 1
3

-NAME node3
-QUERY MATCH (a:organisation:person) RETURN COUNT(*)
---- 1
11

-NAME nodeCrossProductTest
-QUERY MATCH (a:person), (b:person), (c:person:movies) RETURN COUNT(*)
-ENUMERATE
---- 1
704

0 comments on commit fa08d5b

Please sign in to comment.