1#include "duckdb/main/relation/write_parquet_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
9WriteParquetRelation::WriteParquetRelation(shared_ptr<Relation> child_p, string parquet_file_p,
10 case_insensitive_map_t<vector<Value>> options_p)
11 : Relation(child_p->context, RelationType::WRITE_PARQUET_RELATION), child(std::move(child_p)),
12 parquet_file(std::move(parquet_file_p)), options(std::move(options_p)) {
13 context.GetContext()->TryBindRelation(relation&: *this, result_columns&: this->columns);
14}
15
16BoundStatement WriteParquetRelation::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 = parquet_file;
22 info->format = "parquet";
23 info->options = options;
24 copy.info = std::move(info);
25 return binder.Bind(statement&: copy.Cast<SQLStatement>());
26}
27
28const vector<ColumnDefinition> &WriteParquetRelation::Columns() {
29 return columns;
30}
31
32string WriteParquetRelation::ToString(idx_t depth) {
33 string str = RenderWhitespace(depth) + "Write To Parquet [" + parquet_file + "]\n";
34 return str + child->ToString(depth: depth + 1);
35}
36
37} // namespace duckdb
38