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 : Relation(child_p->context, RelationType::WRITE_CSV_RELATION), child(move(child_p)), csv_file(move(csv_file_p)) {
11 context.TryBindRelation(*this, this->columns);
12}
13
14unique_ptr<QueryNode> WriteCSVRelation::GetQueryNode() {
15 throw InternalException("Cannot create a query node from a WriteCSVRelation!");
16}
17
18BoundStatement WriteCSVRelation::Bind(Binder &binder) {
19 CopyStatement copy;
20 copy.select_statement = child->GetQueryNode();
21 auto info = make_unique<CopyInfo>();
22 info->is_from = false;
23 info->file_path = csv_file;
24 copy.info = move(info);
25 return binder.Bind((SQLStatement &)copy);
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 + 1);
35}
36
37} // namespace duckdb
38