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

Method bindCopyToClause

src/binder/bind/copy/bind_copy_to.cpp:17–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15namespace binder {
16
17std::unique_ptr<BoundStatement> Binder::bindCopyToClause(const Statement& statement) {
18 auto& copyToStatement = statement.constCast<CopyTo>();
19 auto boundFilePath = copyToStatement.getFilePath();
20 auto fileTypeInfo = bindFileTypeInfo({boundFilePath});
21 std::vector<std::string> columnNames;
22 auto parsedQuery = copyToStatement.getStatement();
23 auto query = bindQuery(*parsedQuery);
24 auto columns = query->getStatementResult()->getColumns();
25 auto fileTypeStr = fileTypeInfo.fileTypeStr;
26 auto name = std::format("COPY_{}", fileTypeStr);
27 catalog::CatalogEntry* entry = nullptr;
28 try {
29 entry = catalog::Catalog::Get(*clientContext)
30 ->getFunctionEntry(transaction::Transaction::Get(*clientContext), name);
31 } catch (CatalogException& exception) {
32 throw RuntimeException{std::format(
33 "Exporting query result to the '{}' file is currently not supported.", fileTypeStr)};
34 }
35 auto exportFunc = function::BuiltInFunctionsUtils::matchFunction(name,
36 entry->ptrCast<catalog::FunctionCatalogEntry>())
37 ->constPtrCast<function::ExportFunction>();
38 for (auto& column : columns) {
39 auto columnName = column->hasAlias() ? column->getAlias() : column->toString();
40 columnNames.push_back(columnName);
41 }
42 function::ExportFuncBindInput bindInput{std::move(columnNames), std::move(boundFilePath),
43 bindParsingOptions(copyToStatement.getParsingOptions())};
44 auto bindData = exportFunc->bind(bindInput);
45 return std::make_unique<BoundCopyTo>(std::move(bindData), *exportFunc, std::move(query));
46}
47
48} // namespace binder
49} // namespace lbug

Callers

nothing calls this directly

Calls 10

getStatementMethod · 0.80
getFunctionEntryMethod · 0.80
hasAliasMethod · 0.80
getAliasMethod · 0.80
bindMethod · 0.80
getFilePathMethod · 0.45
getColumnsMethod · 0.45
getStatementResultMethod · 0.45
toStringMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected