-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathduckherder_extension.cpp
More file actions
95 lines (75 loc) · 3.04 KB
/
Copy pathduckherder_extension.cpp
File metadata and controls
95 lines (75 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#define DUCKDB_EXTENSION_MAIN
#include "duckdb.hpp"
#include "duckdb/storage/storage_extension.hpp"
#include "duckherder_extension.hpp"
#include "duckherder_extension_instance_state.hpp"
#include "duckherder_pragmas.hpp"
#include "duckherder_storage.hpp"
#include "query_history_query_function.hpp"
#include "query_execution_stats_query_function.hpp"
#include "server/driver/distributed_server_function.hpp"
namespace duckdb {
namespace {
// Successful execution result.
constexpr bool SUCCESS = true;
// Get database instance from expression state.
// Returned instance ownership lies in the given [`state`].
DatabaseInstance &GetDatabaseInstance(ExpressionState &state) {
auto *executor = state.root.executor;
auto &client_context = executor->GetContext();
return *client_context.db.get();
}
// Clear stats for query recorder.
void ClearQueryRecorderStats(const DataChunk &args, ExpressionState &state, Vector &result) {
auto &duckdb_instance = GetDatabaseInstance(state);
auto &instance_state = GetInstanceStateOrThrow(duckdb_instance);
instance_state.GetQueryRecorder()->ClearQueryRecords();
result.Reference(Value(SUCCESS));
}
void LoadInternal(ExtensionLoader &loader) {
auto &db = loader.GetDatabaseInstance();
auto &config = DBConfig::GetConfig(db);
StorageExtension::Register(config, "duckherder", make_shared_ptr<DuckherderStorageExtension>());
// Set extension state.
SetInstanceState(db, make_shared_ptr<DuckherderInstanceState>());
// Register pragma functions to register and unregister remote table.
DuckherderPragmas::RegisterPragmas(loader);
// Register function to get query stats.
loader.RegisterFunction(GetQueryHistory());
// Register function to get query execution stats from driver.
loader.RegisterFunction(GetQueryExecutionStats());
// Register function to clear query recorder stats.
ScalarFunction clear_recorder_stats_function("duckherder_clear_query_recorder_stats",
/*arguments=*/ {},
/*return_type=*/LogicalType {LogicalTypeId::BOOLEAN},
ClearQueryRecorderStats);
loader.RegisterFunction(clear_recorder_stats_function);
// Register distributed server control functions, which could be local usage.
loader.RegisterFunction(GetStartLocalServerFunction());
loader.RegisterFunction(GetStopLocalServerFunction());
loader.RegisterFunction(GetRegisterOrReplaceDriverFunction());
// Register worker management functions.
loader.RegisterFunction(GetWorkerCountFunction());
loader.RegisterFunction(GetRegisterWorkerFunction());
loader.RegisterFunction(GetStartStandaloneWorkerFunction());
}
} // namespace
void DuckherderExtension::Load(ExtensionLoader &loader) {
LoadInternal(loader);
}
std::string DuckherderExtension::Name() {
return "duckherder";
}
std::string DuckherderExtension::Version() const {
#ifdef EXT_VERSION_QUACK
return EXT_VERSION_QUACK;
#else
return "";
#endif
}
} // namespace duckdb
extern "C" {
DUCKDB_CPP_EXTENSION_ENTRY(duckherder, loader) {
duckdb::LoadInternal(loader);
}
}