1#include "duckdb/main/relation/write_csv_relation.hpp"
2#include "duckdb/parser/statement/copy_statement.hpp"
3#include "duckdb/parser/parsed_data/create_table_info.hpp"
4#include "duckdb/planner/binder.hpp"
5#include "duckdb/main/client_context.hpp"
6
7namespace duckdb {
8
9WriteCSVRelation::WriteCSVRelation(shared_ptr<Relation> child_p, string csv_file_p,
10 case_insensitive_map_t<vector<Value>> options_p)
11 : Relation(child_p->context, RelationType::WRITE_CSV_RELATION), child(std::move(child_p)),
12 csv_file(std::move(csv_file_p)), options(std::move(options_p)) {
13 context.GetContext()->TryBindRelation(relation&: *this, result_columns&: this->columns);
14}
15
16BoundStatement WriteCSVRelation::Bind(Binder &binder) {
17 CopyStatement copy;
18 copy.select_statement = child->GetQueryNode();
19 auto info = make_uniq<CopyInfo>();
20 info->is_from = false;
21 info->file_path = csv_file;
22 info->format = "csv";
23 info->options = options;
24 copy.info = std::move(info);
25 return binder.Bind(statement&: copy.Cast<SQLStatement>());
26}
27
28const vector<ColumnDefinition> &WriteCSVRelation::Columns() {
29 return columns;
30}
31
32string WriteCSVRelation::ToString(idx_t depth) {
33 string str = RenderWhitespace(depth) + "Write To CSV [" + csv_file + "]\n";
34 return str + child->ToString(depth: depth + 1);
35}
36
37} // namespace duckdb
38