| 51 | } |
| 52 | |
| 53 | static 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 | |
| 94 | function_set ShowConnectionFunction::getFunctionSet() { |
| 95 | function_set functionSet; |
nothing calls this directly
no test coverage detected