-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add graph projection * Run clang-format --------- Co-authored-by: CI Bot <[email protected]>
- Loading branch information
1 parent
2bb28c2
commit 5460249
Showing
32 changed files
with
3,466 additions
and
4,088 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 |
---|---|---|
@@ -1 +1 @@ | ||
81546847023f2a4c8d1fec8ef8ff0d88 | ||
8836c17d54a52a955eddd8a411a02dba |
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 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 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,92 @@ | ||
#include "catalog/catalog.h" | ||
#include "common/exception/binder.h" | ||
#include "common/exception/runtime.h" | ||
#include "common/types/value/nested.h" | ||
#include "function/table/simple_table_functions.h" | ||
#include "graph/graph_entry.h" | ||
#include "processor/execution_context.h" | ||
|
||
using namespace kuzu::common; | ||
using namespace kuzu::catalog; | ||
|
||
namespace kuzu { | ||
namespace function { | ||
|
||
struct CreateProjectGraphBindData : SimpleTableFuncBindData { | ||
std::string graphName; | ||
std::vector<TableCatalogEntry*> nodeEntries; | ||
std::vector<TableCatalogEntry*> relEntries; | ||
|
||
CreateProjectGraphBindData(std::string graphName, std::vector<TableCatalogEntry*> nodeEntries, | ||
std::vector<TableCatalogEntry*> relEntries) | ||
: SimpleTableFuncBindData{0}, graphName{graphName}, nodeEntries{nodeEntries}, | ||
relEntries{relEntries} {} | ||
|
||
std::unique_ptr<TableFuncBindData> copy() const override { | ||
return std::make_unique<CreateProjectGraphBindData>(graphName, nodeEntries, relEntries); | ||
} | ||
}; | ||
|
||
static common::offset_t tableFunc(TableFuncInput& input, TableFuncOutput& /*output*/) { | ||
auto bindData = ku_dynamic_cast<CreateProjectGraphBindData*>(input.bindData); | ||
auto& graphEntrySet = input.context->clientContext->getGraphEntrySetUnsafe(); | ||
if (graphEntrySet.hasGraph(bindData->graphName)) { | ||
throw RuntimeException( | ||
stringFormat("Project graph {} already exists.", bindData->graphName)); | ||
} | ||
auto entry = graph::GraphEntry(bindData->nodeEntries, bindData->relEntries); | ||
graphEntrySet.addGraph(bindData->graphName, std::move(entry)); | ||
return 0; | ||
} | ||
|
||
static std::vector<std::string> getAsStringVector(const Value& value) { | ||
std::vector<std::string> result; | ||
for (auto i = 0u; i < NestedVal::getChildrenSize(&value); ++i) { | ||
result.push_back(NestedVal::getChildVal(&value, i)->getValue<std::string>()); | ||
} | ||
return result; | ||
} | ||
|
||
static std::vector<catalog::TableCatalogEntry*> getTableEntries( | ||
const std::vector<std::string>& tableNames, CatalogEntryType expectedType, | ||
main::ClientContext& context) { | ||
std::vector<catalog::TableCatalogEntry*> entries; | ||
for (auto& tableName : tableNames) { | ||
auto entry = context.getCatalog()->getTableCatalogEntry(context.getTx(), tableName); | ||
if (entry->getType() != expectedType) { | ||
throw BinderException(stringFormat("Expect catalog entry type {} but got {}.", | ||
CatalogEntryTypeUtils::toString(expectedType), | ||
CatalogEntryTypeUtils::toString(entry->getType()))); | ||
} | ||
entries.push_back(entry); | ||
} | ||
return entries; | ||
} | ||
|
||
static std::unique_ptr<TableFuncBindData> bindFunc(main::ClientContext* context, | ||
TableFuncBindInput* input) { | ||
auto graphName = input->getLiteralVal<std::string>(0); | ||
auto nodeTableNames = getAsStringVector(input->getValue(1)); | ||
auto relTableNames = getAsStringVector(input->getValue(2)); | ||
auto nodeEntries = | ||
getTableEntries(nodeTableNames, CatalogEntryType::NODE_TABLE_ENTRY, *context); | ||
auto relEntries = getTableEntries(relTableNames, CatalogEntryType::REL_TABLE_ENTRY, *context); | ||
return std::make_unique<CreateProjectGraphBindData>(graphName, nodeEntries, relEntries); | ||
} | ||
|
||
function_set CreateProjectGraphFunction::getFunctionSet() { | ||
function_set functionSet; | ||
auto func = | ||
std::make_unique<TableFunction>(name, std::vector<LogicalTypeID>{LogicalTypeID::STRING, | ||
LogicalTypeID::LIST, LogicalTypeID::LIST}); | ||
func->bindFunc = bindFunc; | ||
func->tableFunc = tableFunc; | ||
func->initSharedStateFunc = initSharedState; | ||
func->initLocalStateFunc = initEmptyLocalState; | ||
func->canParallelFunc = []() { return false; }; | ||
functionSet.push_back(std::move(func)); | ||
return functionSet; | ||
} | ||
|
||
} // namespace function | ||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include "common/exception/runtime.h" | ||
#include "function/table/simple_table_functions.h" | ||
#include "graph/graph_entry.h" | ||
#include "processor/execution_context.h" | ||
|
||
using namespace kuzu::common; | ||
|
||
namespace kuzu { | ||
namespace function { | ||
|
||
struct DropProjectGraphBindData : SimpleTableFuncBindData { | ||
std::string graphName; | ||
|
||
explicit DropProjectGraphBindData(std::string graphName) | ||
: SimpleTableFuncBindData{0}, graphName{graphName} {} | ||
|
||
std::unique_ptr<TableFuncBindData> copy() const override { | ||
return std::make_unique<DropProjectGraphBindData>(graphName); | ||
} | ||
}; | ||
|
||
static common::offset_t tableFunc(TableFuncInput& input, TableFuncOutput& /*output*/) { | ||
auto bindData = ku_dynamic_cast<DropProjectGraphBindData*>(input.bindData); | ||
auto& graphEntrySet = input.context->clientContext->getGraphEntrySetUnsafe(); | ||
if (!graphEntrySet.hasGraph(bindData->graphName)) { | ||
throw RuntimeException( | ||
stringFormat("Project graph {} does not exists.", bindData->graphName)); | ||
} | ||
graphEntrySet.dropGraph(bindData->graphName); | ||
return 0; | ||
} | ||
|
||
static std::unique_ptr<TableFuncBindData> bindFunc(main::ClientContext*, | ||
TableFuncBindInput* input) { | ||
auto graphName = input->getLiteralVal<std::string>(0); | ||
return std::make_unique<DropProjectGraphBindData>(graphName); | ||
} | ||
|
||
function_set DropProjectGraphFunction::getFunctionSet() { | ||
function_set functionSet; | ||
auto func = | ||
std::make_unique<TableFunction>(name, std::vector<LogicalTypeID>{LogicalTypeID::STRING}); | ||
func->bindFunc = bindFunc; | ||
func->tableFunc = tableFunc; | ||
func->initSharedStateFunc = initSharedState; | ||
func->initLocalStateFunc = initEmptyLocalState; | ||
func->canParallelFunc = []() { return false; }; | ||
functionSet.push_back(std::move(func)); | ||
return functionSet; | ||
} | ||
|
||
} // namespace function | ||
} // namespace kuzu |
Oops, something went wrong.