1#include "duckdb/execution/operator/persistent/physical_copy_from_file.hpp"
2#include "duckdb/execution/operator/persistent/buffered_csv_reader.hpp"
3
4#include "duckdb/catalog/catalog_entry/table_catalog_entry.hpp"
5
6#include <algorithm>
7#include <fstream>
8
9using namespace duckdb;
10using namespace std;
11
12class PhysicalCopyFromFileOperatorState : public PhysicalOperatorState {
13public:
14 PhysicalCopyFromFileOperatorState();
15 ~PhysicalCopyFromFileOperatorState();
16
17 //! The CSV reader
18 unique_ptr<BufferedCSVReader> csv_reader;
19};
20
21void PhysicalCopyFromFile::GetChunkInternal(ClientContext &context, DataChunk &chunk, PhysicalOperatorState *state_) {
22 auto &state = (PhysicalCopyFromFileOperatorState &)*state_;
23 auto &info = *this->info;
24
25 if (!state.csv_reader) {
26 // initialize CSV reader
27 state.csv_reader = make_unique<BufferedCSVReader>(context, info, sql_types);
28 }
29 // read from the CSV reader
30 state.csv_reader->ParseCSV(chunk);
31}
32
33unique_ptr<PhysicalOperatorState> PhysicalCopyFromFile::GetOperatorState() {
34 return make_unique<PhysicalCopyFromFileOperatorState>();
35}
36
37PhysicalCopyFromFileOperatorState::PhysicalCopyFromFileOperatorState() : PhysicalOperatorState(nullptr) {
38}
39
40PhysicalCopyFromFileOperatorState::~PhysicalCopyFromFileOperatorState() {
41}
42