1#include "duckdb/main/client_data.hpp"
2
3#include "duckdb/catalog/catalog.hpp"
4#include "duckdb/catalog/catalog_search_path.hpp"
5#include "duckdb/common/http_state.hpp"
6#include "duckdb/common/random_engine.hpp"
7#include "duckdb/common/serializer/buffered_file_writer.hpp"
8#include "duckdb/main/attached_database.hpp"
9#include "duckdb/main/client_context.hpp"
10#include "duckdb/main/client_context_file_opener.hpp"
11#include "duckdb/main/database.hpp"
12#include "duckdb/main/database_manager.hpp"
13#include "duckdb/main/query_profiler.hpp"
14#include "duckdb/common/opener_file_system.hpp"
15
16namespace duckdb {
17
18class ClientFileSystem : public OpenerFileSystem {
19public:
20 explicit ClientFileSystem(ClientContext &context_p) : context(context_p) {
21 }
22
23 FileSystem &GetFileSystem() const override {
24 auto &config = DBConfig::GetConfig(context);
25 return *config.file_system;
26 }
27 optional_ptr<FileOpener> GetOpener() const override {
28 return ClientData::Get(context).file_opener.get();
29 }
30
31private:
32 ClientContext &context;
33};
34
35ClientData::ClientData(ClientContext &context) : catalog_search_path(make_uniq<CatalogSearchPath>(args&: context)) {
36 auto &db = DatabaseInstance::GetDatabase(context);
37 profiler = make_shared<QueryProfiler>(args&: context);
38 query_profiler_history = make_uniq<QueryProfilerHistory>();
39 temporary_objects = make_shared<AttachedDatabase>(args&: db, args: AttachedDatabaseType::TEMP_DATABASE);
40 temporary_objects->oid = DatabaseManager::Get(db).ModifyCatalog();
41 random_engine = make_uniq<RandomEngine>();
42 file_opener = make_uniq<ClientContextFileOpener>(args&: context);
43 client_file_system = make_uniq<ClientFileSystem>(args&: context);
44 temporary_objects->Initialize();
45}
46ClientData::~ClientData() {
47}
48
49ClientData &ClientData::Get(ClientContext &context) {
50 return *context.client_data;
51}
52
53RandomEngine &RandomEngine::Get(ClientContext &context) {
54 return *ClientData::Get(context).random_engine;
55}
56
57} // namespace duckdb
58