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

Function writeCopyRelStatement

src/processor/operator/simple/export_db.cpp:90–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88}
89
90static void writeCopyRelStatement(stringstream& ss, const ClientContext* context,
91 const TableCatalogEntry* entry, const FileScanInfo* info,
92 const std::unordered_map<std::string, const std::atomic<bool>*>& canUseParallelReader) {
93 const auto csvConfig = CSVReaderConfig::construct(info->options);
94 std::string columns = getTablePropertyDefinitions(entry);
95 auto transaction = Transaction::Get(*context);
96 const auto catalog = Catalog::Get(*context);
97 for (auto& entryInfo : entry->constCast<RelGroupCatalogEntry>().getRelEntryInfos()) {
98 auto fromTableName =
99 catalog->getTableCatalogEntry(transaction, entryInfo.nodePair.srcTableID)->getName();
100 auto toTableName =
101 catalog->getTableCatalogEntry(transaction, entryInfo.nodePair.dstTableID)->getName();
102 // TODO(Ziyi): We should pass fileName from binder phase to here.
103 auto fileName = std::format("{}_{}_{}.{}", entry->getName(), fromTableName, toTableName,
104 StringUtils::getLower(info->fileTypeInfo.fileTypeStr));
105 bool useParallelReader = true;
106 if (canUseParallelReader.contains(fileName)) {
107 useParallelReader = canUseParallelReader.at(fileName)->load();
108 }
109 auto copyOptionsMap = csvConfig.option.toOptionsMap(useParallelReader);
110 copyOptionsMap["from"] = std::format("'{}'", fromTableName);
111 copyOptionsMap["to"] = std::format("'{}'", toTableName);
112 auto copyOptions = CSVOption::toCypher(copyOptionsMap);
113 if (columns.empty()) {
114 ss << std::format("COPY `{}` FROM \"{}\" {};\n", entry->getName(), fileName,
115 copyOptions);
116 } else {
117 ss << std::format("COPY `{}` ({}) FROM \"{}\" {};\n", entry->getName(), columns,
118 fileName, copyOptions);
119 }
120 }
121}
122
123static void exportLoadedExtensions(stringstream& ss, const ClientContext* clientContext) {
124 auto extensionCypher = extension::ExtensionManager::Get(*clientContext)->toCypher();

Callers 1

getCopyCypherFunction · 0.85

Calls 9

constructFunction · 0.85
getTableCatalogEntryMethod · 0.80
toOptionsMapMethod · 0.80
toCypherFunction · 0.50
getNameMethod · 0.45
containsMethod · 0.45
loadMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected