MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / bindFunc

Function bindFunc

src/function/table/show_connection.cpp:53–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51}
52
53static std::unique_ptr<TableFuncBindData> bindFunc(const ClientContext* context,
54 const TableFuncBindInput* input) {
55 std::vector<std::string> columnNames;
56 std::vector<LogicalType> columnTypes;
57 columnNames.emplace_back("source table name");
58 columnTypes.emplace_back(LogicalType::STRING());
59 columnNames.emplace_back("destination table name");
60 columnTypes.emplace_back(LogicalType::STRING());
61 columnNames.emplace_back("source table primary key");
62 columnTypes.emplace_back(LogicalType::STRING());
63 columnNames.emplace_back("destination table primary key");
64 columnTypes.emplace_back(LogicalType::STRING());
65 const auto name = input->getLiteralVal<std::string>(0);
66 const auto catalog = Catalog::Get(*context);
67 auto transaction = transaction::Transaction::Get(*context);
68 std::vector<std::pair<NodeTableCatalogEntry*, NodeTableCatalogEntry*>> srcDstEntries;
69 if (catalog->containsTable(transaction, name)) {
70 auto entry = catalog->getTableCatalogEntry(transaction, name);
71 if (entry->getType() != catalog::CatalogEntryType::REL_GROUP_ENTRY) {
72 throw BinderException{"Show connection can only be called on a rel table!"};
73 }
74 for (auto& info : entry->ptrCast<RelGroupCatalogEntry>()
75 ->getRelEntryInfos()) { // Skip foreign-backed rel tables (they have
76 // FOREIGN_TABLE_ID)
77 if (info.nodePair.srcTableID == common::FOREIGN_TABLE_ID) {
78 continue;
79 }
80 auto srcEntry = catalog->getTableCatalogEntry(transaction, info.nodePair.srcTableID)
81 ->ptrCast<NodeTableCatalogEntry>();
82 auto dstEntry = catalog->getTableCatalogEntry(transaction, info.nodePair.dstTableID)
83 ->ptrCast<NodeTableCatalogEntry>();
84 srcDstEntries.emplace_back(srcEntry, dstEntry);
85 }
86 } else {
87 throw BinderException{"Show connection can only be called on a rel table!"};
88 }
89 columnNames = TableFunction::extractYieldVariables(columnNames, input->yieldVariables);
90 auto columns = input->binder->createVariables(columnNames, columnTypes);
91 return std::make_unique<ShowConnectionBindData>(srcDstEntries, columns, srcDstEntries.size());
92}
93
94function_set ShowConnectionFunction::getFunctionSet() {
95 function_set functionSet;

Callers

nothing calls this directly

Calls 6

emplace_backMethod · 0.80
containsTableMethod · 0.80
getTableCatalogEntryMethod · 0.80
createVariablesMethod · 0.80
getTypeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected