| 15 | namespace binder { |
| 16 | |
| 17 | std::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 |
nothing calls this directly
no test coverage detected