duckdb 0.7.1-dev68.0 → 0.7.1-dev90.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/duckdb/src/common/enums/logical_operator_type.cpp +2 -0
- package/src/duckdb/src/common/enums/physical_operator_type.cpp +2 -0
- package/src/duckdb/src/common/enums/statement_type.cpp +2 -0
- package/src/duckdb/src/execution/operator/schema/physical_detach.cpp +37 -0
- package/src/duckdb/src/execution/operator/schema/physical_drop.cpp +0 -5
- package/src/duckdb/src/execution/physical_plan/plan_simple.cpp +4 -0
- package/src/duckdb/src/execution/physical_plan_generator.cpp +1 -0
- package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
- package/src/duckdb/src/include/duckdb/common/enums/logical_operator_type.hpp +1 -0
- package/src/duckdb/src/include/duckdb/common/enums/physical_operator_type.hpp +1 -0
- package/src/duckdb/src/include/duckdb/common/enums/statement_type.hpp +2 -1
- package/src/duckdb/src/include/duckdb/execution/operator/schema/physical_detach.hpp +32 -0
- package/src/duckdb/src/include/duckdb/main/config.hpp +0 -3
- package/src/duckdb/src/include/duckdb/parser/parsed_data/create_database_info.hpp +0 -4
- package/src/duckdb/src/include/duckdb/parser/parsed_data/detach_info.hpp +32 -0
- package/src/duckdb/src/include/duckdb/parser/statement/detach_statement.hpp +29 -0
- package/src/duckdb/src/include/duckdb/parser/statement/list.hpp +1 -0
- package/src/duckdb/src/include/duckdb/parser/tokens.hpp +1 -0
- package/src/duckdb/src/include/duckdb/parser/transformer.hpp +1 -0
- package/src/duckdb/src/include/duckdb/planner/binder.hpp +1 -0
- package/src/duckdb/src/include/duckdb/storage/storage_extension.hpp +7 -0
- package/src/duckdb/src/parser/statement/detach_statement.cpp +15 -0
- package/src/duckdb/src/parser/transform/statement/transform_create_database.cpp +0 -1
- package/src/duckdb/src/parser/transform/statement/transform_detach.cpp +19 -0
- package/src/duckdb/src/parser/transformer.cpp +2 -0
- package/src/duckdb/src/planner/binder/statement/bind_create.cpp +16 -14
- package/src/duckdb/src/planner/binder/statement/bind_detach.cpp +19 -0
- package/src/duckdb/src/planner/binder/statement/bind_drop.cpp +29 -4
- package/src/duckdb/src/planner/binder.cpp +2 -0
- package/src/duckdb/src/planner/logical_operator.cpp +2 -0
- package/src/duckdb/src/planner/planner.cpp +1 -0
- package/src/duckdb/third_party/libpg_query/include/nodes/nodes.hpp +1 -0
- package/src/duckdb/third_party/libpg_query/include/nodes/parsenodes.hpp +14 -0
- package/src/duckdb/third_party/libpg_query/include/parser/gram.hpp +530 -1006
- package/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp +17659 -17626
- package/src/duckdb/ub_src_execution_operator_schema.cpp +2 -0
- package/src/duckdb/ub_src_parser_statement.cpp +2 -0
- package/src/duckdb/ub_src_parser_transform_statement.cpp +2 -0
- package/src/duckdb/ub_src_planner_binder_statement.cpp +2 -0
- package/src/duckdb/src/include/duckdb/function/create_database_extension.hpp +0 -37
package/package.json
CHANGED
|
@@ -100,6 +100,8 @@ string LogicalOperatorToString(LogicalOperatorType type) {
|
|
|
100
100
|
return "CREATE_SCHEMA";
|
|
101
101
|
case LogicalOperatorType::LOGICAL_ATTACH:
|
|
102
102
|
return "ATTACH";
|
|
103
|
+
case LogicalOperatorType::LOGICAL_DETACH:
|
|
104
|
+
return "ATTACH";
|
|
103
105
|
case LogicalOperatorType::LOGICAL_DROP:
|
|
104
106
|
return "DROP";
|
|
105
107
|
case LogicalOperatorType::LOGICAL_PRAGMA:
|
|
@@ -133,6 +133,8 @@ string PhysicalOperatorToString(PhysicalOperatorType type) {
|
|
|
133
133
|
return "CREATE_TYPE";
|
|
134
134
|
case PhysicalOperatorType::ATTACH:
|
|
135
135
|
return "ATTACH";
|
|
136
|
+
case PhysicalOperatorType::DETACH:
|
|
137
|
+
return "DETACH";
|
|
136
138
|
case PhysicalOperatorType::RESULT_COLLECTOR:
|
|
137
139
|
return "RESULT_COLLECTOR";
|
|
138
140
|
case PhysicalOperatorType::EXTENSION:
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#include "duckdb/execution/operator/schema/physical_detach.hpp"
|
|
2
|
+
#include "duckdb/parser/parsed_data/detach_info.hpp"
|
|
3
|
+
#include "duckdb/catalog/catalog.hpp"
|
|
4
|
+
#include "duckdb/main/database_manager.hpp"
|
|
5
|
+
#include "duckdb/main/attached_database.hpp"
|
|
6
|
+
#include "duckdb/main/database.hpp"
|
|
7
|
+
#include "duckdb/storage/storage_extension.hpp"
|
|
8
|
+
|
|
9
|
+
namespace duckdb {
|
|
10
|
+
|
|
11
|
+
//===--------------------------------------------------------------------===//
|
|
12
|
+
// Source
|
|
13
|
+
//===--------------------------------------------------------------------===//
|
|
14
|
+
class DetachSourceState : public GlobalSourceState {
|
|
15
|
+
public:
|
|
16
|
+
DetachSourceState() : finished(false) {
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
bool finished;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
unique_ptr<GlobalSourceState> PhysicalDetach::GetGlobalSourceState(ClientContext &context) const {
|
|
23
|
+
return make_unique<DetachSourceState>();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
void PhysicalDetach::GetData(ExecutionContext &context, DataChunk &chunk, GlobalSourceState &gstate,
|
|
27
|
+
LocalSourceState &lstate) const {
|
|
28
|
+
auto &state = (DetachSourceState &)gstate;
|
|
29
|
+
if (state.finished) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
auto &db_manager = DatabaseManager::Get(context.client);
|
|
33
|
+
db_manager.DetachDatabase(context.client, info->name, info->if_exists);
|
|
34
|
+
state.finished = true;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
} // namespace duckdb
|
|
@@ -38,11 +38,6 @@ void PhysicalDrop::GetData(ExecutionContext &context, DataChunk &chunk, GlobalSo
|
|
|
38
38
|
}
|
|
39
39
|
break;
|
|
40
40
|
}
|
|
41
|
-
case CatalogType::DATABASE_ENTRY: {
|
|
42
|
-
auto &db_manager = DatabaseManager::Get(context.client);
|
|
43
|
-
db_manager.DetachDatabase(context.client, info->name, info->if_exists);
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
41
|
case CatalogType::SCHEMA_ENTRY: {
|
|
47
42
|
auto &catalog = Catalog::GetCatalog(context.client, info->catalog);
|
|
48
43
|
catalog.DropEntry(context.client, info.get());
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
#include "duckdb/execution/operator/schema/physical_create_schema.hpp"
|
|
7
7
|
#include "duckdb/execution/operator/schema/physical_create_sequence.hpp"
|
|
8
8
|
#include "duckdb/execution/operator/schema/physical_create_view.hpp"
|
|
9
|
+
#include "duckdb/execution/operator/schema/physical_detach.hpp"
|
|
9
10
|
#include "duckdb/execution/operator/schema/physical_drop.hpp"
|
|
10
11
|
#include "duckdb/execution/physical_plan_generator.hpp"
|
|
11
12
|
#include "duckdb/planner/logical_operator.hpp"
|
|
@@ -39,6 +40,9 @@ unique_ptr<PhysicalOperator> PhysicalPlanGenerator::CreatePlan(LogicalSimple &op
|
|
|
39
40
|
case LogicalOperatorType::LOGICAL_ATTACH:
|
|
40
41
|
return make_unique<PhysicalAttach>(unique_ptr_cast<ParseInfo, AttachInfo>(std::move(op.info)),
|
|
41
42
|
op.estimated_cardinality);
|
|
43
|
+
case LogicalOperatorType::LOGICAL_DETACH:
|
|
44
|
+
return make_unique<PhysicalDetach>(unique_ptr_cast<ParseInfo, DetachInfo>(std::move(op.info)),
|
|
45
|
+
op.estimated_cardinality);
|
|
42
46
|
default:
|
|
43
47
|
throw NotImplementedException("Unimplemented type for logical simple operator");
|
|
44
48
|
}
|
|
@@ -184,6 +184,7 @@ unique_ptr<PhysicalOperator> PhysicalPlanGenerator::CreatePlan(LogicalOperator &
|
|
|
184
184
|
case LogicalOperatorType::LOGICAL_VACUUM:
|
|
185
185
|
case LogicalOperatorType::LOGICAL_LOAD:
|
|
186
186
|
case LogicalOperatorType::LOGICAL_ATTACH:
|
|
187
|
+
case LogicalOperatorType::LOGICAL_DETACH:
|
|
187
188
|
plan = CreatePlan((LogicalSimple &)op);
|
|
188
189
|
break;
|
|
189
190
|
case LogicalOperatorType::LOGICAL_RECURSIVE_CTE:
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#ifndef DUCKDB_VERSION
|
|
2
|
-
#define DUCKDB_VERSION "0.7.1-
|
|
2
|
+
#define DUCKDB_VERSION "0.7.1-dev90"
|
|
3
3
|
#endif
|
|
4
4
|
#ifndef DUCKDB_SOURCE_ID
|
|
5
|
-
#define DUCKDB_SOURCE_ID "
|
|
5
|
+
#define DUCKDB_SOURCE_ID "1b87fb94ca"
|
|
6
6
|
#endif
|
|
7
7
|
#include "duckdb/function/table/system_functions.hpp"
|
|
8
8
|
#include "duckdb/main/database.hpp"
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//===----------------------------------------------------------------------===//
|
|
2
|
+
// DuckDB
|
|
3
|
+
//
|
|
4
|
+
// duckdb/execution/operator/schema/physical_detach.hpp
|
|
5
|
+
//
|
|
6
|
+
//
|
|
7
|
+
//===----------------------------------------------------------------------===//
|
|
8
|
+
|
|
9
|
+
#pragma once
|
|
10
|
+
|
|
11
|
+
#include "duckdb/execution/physical_operator.hpp"
|
|
12
|
+
#include "duckdb/parser/parsed_data/detach_info.hpp"
|
|
13
|
+
|
|
14
|
+
namespace duckdb {
|
|
15
|
+
|
|
16
|
+
class PhysicalDetach : public PhysicalOperator {
|
|
17
|
+
public:
|
|
18
|
+
explicit PhysicalDetach(unique_ptr<DetachInfo> info, idx_t estimated_cardinality)
|
|
19
|
+
: PhysicalOperator(PhysicalOperatorType::DETACH, {LogicalType::BOOLEAN}, estimated_cardinality),
|
|
20
|
+
info(std::move(info)) {
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
unique_ptr<DetachInfo> info;
|
|
24
|
+
|
|
25
|
+
public:
|
|
26
|
+
// Source interface
|
|
27
|
+
unique_ptr<GlobalSourceState> GetGlobalSourceState(ClientContext &context) const override;
|
|
28
|
+
void GetData(ExecutionContext &context, DataChunk &chunk, GlobalSourceState &gstate,
|
|
29
|
+
LocalSourceState &lstate) const override;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
} // namespace duckdb
|
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
#include "duckdb/storage/compression/bitpacking.hpp"
|
|
26
26
|
#include "duckdb/function/cast/default_casts.hpp"
|
|
27
27
|
#include "duckdb/function/replacement_scan.hpp"
|
|
28
|
-
#include "duckdb/function/create_database_extension.hpp"
|
|
29
28
|
#include "duckdb/optimizer/optimizer_extension.hpp"
|
|
30
29
|
#include "duckdb/parser/parser_extension.hpp"
|
|
31
30
|
#include "duckdb/planner/operator_extension.hpp"
|
|
@@ -185,8 +184,6 @@ public:
|
|
|
185
184
|
vector<std::unique_ptr<OperatorExtension>> operator_extensions;
|
|
186
185
|
//! Extensions made to storage
|
|
187
186
|
case_insensitive_map_t<std::unique_ptr<StorageExtension>> storage_extensions;
|
|
188
|
-
//! Extensions made to binder to implement the create_database functionality
|
|
189
|
-
vector<CreateDatabaseExtension> create_database_extensions;
|
|
190
187
|
|
|
191
188
|
public:
|
|
192
189
|
DUCKDB_API static DBConfig &GetConfig(ClientContext &context);
|
|
@@ -16,9 +16,6 @@ struct CreateDatabaseInfo : public CreateInfo {
|
|
|
16
16
|
CreateDatabaseInfo() : CreateInfo(CatalogType::DATABASE_ENTRY) {
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
//! Extension name which creates databases
|
|
20
|
-
string extension_name;
|
|
21
|
-
|
|
22
19
|
//! Name of the database
|
|
23
20
|
string name;
|
|
24
21
|
|
|
@@ -29,7 +26,6 @@ public:
|
|
|
29
26
|
unique_ptr<CreateInfo> Copy() const override {
|
|
30
27
|
auto result = make_unique<CreateDatabaseInfo>();
|
|
31
28
|
CopyProperties(*result);
|
|
32
|
-
result->extension_name = extension_name;
|
|
33
29
|
result->name = name;
|
|
34
30
|
result->path = path;
|
|
35
31
|
return unique_ptr<CreateInfo>(result.release());
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//===----------------------------------------------------------------------===//
|
|
2
|
+
// DuckDB
|
|
3
|
+
//
|
|
4
|
+
// duckdb/parser/parsed_data/detach_info.hpp
|
|
5
|
+
//
|
|
6
|
+
//
|
|
7
|
+
//===----------------------------------------------------------------------===//
|
|
8
|
+
|
|
9
|
+
#pragma once
|
|
10
|
+
|
|
11
|
+
#include "duckdb/parser/parsed_data/parse_info.hpp"
|
|
12
|
+
|
|
13
|
+
namespace duckdb {
|
|
14
|
+
|
|
15
|
+
struct DetachInfo : public ParseInfo {
|
|
16
|
+
DetachInfo() {
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//! The alias of the attached database
|
|
20
|
+
string name;
|
|
21
|
+
//! Whether to throw an exception if alias is not found
|
|
22
|
+
bool if_exists;
|
|
23
|
+
|
|
24
|
+
public:
|
|
25
|
+
unique_ptr<DetachInfo> Copy() const {
|
|
26
|
+
auto result = make_unique<DetachInfo>();
|
|
27
|
+
result->name = name;
|
|
28
|
+
result->if_exists = if_exists;
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
} // namespace duckdb
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//===----------------------------------------------------------------------===//
|
|
2
|
+
// DuckDB
|
|
3
|
+
//
|
|
4
|
+
// duckdb/parser/statement/detach_statement.hpp
|
|
5
|
+
//
|
|
6
|
+
//
|
|
7
|
+
//===----------------------------------------------------------------------===//
|
|
8
|
+
|
|
9
|
+
#pragma once
|
|
10
|
+
|
|
11
|
+
#include "duckdb/parser/parsed_data/detach_info.hpp"
|
|
12
|
+
#include "duckdb/parser/sql_statement.hpp"
|
|
13
|
+
|
|
14
|
+
namespace duckdb {
|
|
15
|
+
|
|
16
|
+
class DetachStatement : public SQLStatement {
|
|
17
|
+
public:
|
|
18
|
+
DetachStatement();
|
|
19
|
+
|
|
20
|
+
unique_ptr<DetachInfo> info;
|
|
21
|
+
|
|
22
|
+
protected:
|
|
23
|
+
DetachStatement(const DetachStatement &other);
|
|
24
|
+
|
|
25
|
+
public:
|
|
26
|
+
unique_ptr<SQLStatement> Copy() const override;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
} // namespace duckdb
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
#include "duckdb/parser/statement/copy_statement.hpp"
|
|
5
5
|
#include "duckdb/parser/statement/create_statement.hpp"
|
|
6
6
|
#include "duckdb/parser/statement/delete_statement.hpp"
|
|
7
|
+
#include "duckdb/parser/statement/detach_statement.hpp"
|
|
7
8
|
#include "duckdb/parser/statement/drop_statement.hpp"
|
|
8
9
|
#include "duckdb/parser/statement/execute_statement.hpp"
|
|
9
10
|
#include "duckdb/parser/statement/explain_statement.hpp"
|
|
@@ -156,6 +156,7 @@ private:
|
|
|
156
156
|
unique_ptr<SQLStatement> TransformShow(duckdb_libpgquery::PGNode *node);
|
|
157
157
|
unique_ptr<ShowStatement> TransformShowSelect(duckdb_libpgquery::PGNode *node);
|
|
158
158
|
unique_ptr<AttachStatement> TransformAttach(duckdb_libpgquery::PGNode *node);
|
|
159
|
+
unique_ptr<DetachStatement> TransformDetach(duckdb_libpgquery::PGNode *node);
|
|
159
160
|
unique_ptr<SetStatement> TransformUse(duckdb_libpgquery::PGNode *node);
|
|
160
161
|
|
|
161
162
|
unique_ptr<PrepareStatement> TransformPrepare(duckdb_libpgquery::PGNode *node);
|
|
@@ -247,6 +247,7 @@ private:
|
|
|
247
247
|
BoundStatement Bind(LoadStatement &stmt);
|
|
248
248
|
BoundStatement Bind(LogicalPlanStatement &stmt);
|
|
249
249
|
BoundStatement Bind(AttachStatement &stmt);
|
|
250
|
+
BoundStatement Bind(DetachStatement &stmt);
|
|
250
251
|
|
|
251
252
|
BoundStatement BindReturning(vector<unique_ptr<ParsedExpression>> returning_list, TableCatalogEntry *table,
|
|
252
253
|
idx_t update_table_index, unique_ptr<LogicalOperator> child_operator,
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
#include "duckdb/common/common.hpp"
|
|
12
12
|
#include "duckdb/common/enums/access_mode.hpp"
|
|
13
|
+
#include "duckdb/parser/tableref/table_function_ref.hpp"
|
|
13
14
|
|
|
14
15
|
namespace duckdb {
|
|
15
16
|
class AttachedDatabase;
|
|
@@ -27,11 +28,17 @@ typedef unique_ptr<Catalog> (*attach_function_t)(StorageExtensionInfo *storage_i
|
|
|
27
28
|
const string &name, AttachInfo &info, AccessMode access_mode);
|
|
28
29
|
typedef unique_ptr<TransactionManager> (*create_transaction_manager_t)(StorageExtensionInfo *storage_info,
|
|
29
30
|
AttachedDatabase &db, Catalog &catalog);
|
|
31
|
+
typedef unique_ptr<TableFunctionRef> (*create_database_t)(StorageExtensionInfo *info, ClientContext &context,
|
|
32
|
+
const string &database_name, const string &source_path);
|
|
33
|
+
typedef unique_ptr<TableFunctionRef> (*drop_database_t)(StorageExtensionInfo *storage_info, ClientContext &context,
|
|
34
|
+
const string &database_name);
|
|
30
35
|
|
|
31
36
|
class StorageExtension {
|
|
32
37
|
public:
|
|
33
38
|
attach_function_t attach;
|
|
34
39
|
create_transaction_manager_t create_transaction_manager;
|
|
40
|
+
create_database_t create_database;
|
|
41
|
+
drop_database_t drop_database;
|
|
35
42
|
|
|
36
43
|
//! Additional info passed to the various storage functions
|
|
37
44
|
shared_ptr<StorageExtensionInfo> storage_info;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#include "duckdb/parser/statement/detach_statement.hpp"
|
|
2
|
+
|
|
3
|
+
namespace duckdb {
|
|
4
|
+
|
|
5
|
+
DetachStatement::DetachStatement() : SQLStatement(StatementType::DETACH_STATEMENT) {
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
DetachStatement::DetachStatement(const DetachStatement &other) : SQLStatement(other), info(other.info->Copy()) {
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
unique_ptr<SQLStatement> DetachStatement::Copy() const {
|
|
12
|
+
return unique_ptr<DetachStatement>(new DetachStatement(*this));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
} // namespace duckdb
|
|
@@ -11,7 +11,6 @@ unique_ptr<CreateStatement> Transformer::TransformCreateDatabase(duckdb_libpgque
|
|
|
11
11
|
auto result = make_unique<CreateStatement>();
|
|
12
12
|
auto info = make_unique<CreateDatabaseInfo>();
|
|
13
13
|
|
|
14
|
-
info->extension_name = stmt->extension ? stmt->extension : string();
|
|
15
14
|
info->path = stmt->path ? stmt->path : string();
|
|
16
15
|
|
|
17
16
|
auto qualified_name = TransformQualifiedName(stmt->name);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#include "duckdb/parser/transformer.hpp"
|
|
2
|
+
#include "duckdb/parser/statement/detach_statement.hpp"
|
|
3
|
+
#include "duckdb/parser/expression/constant_expression.hpp"
|
|
4
|
+
#include "duckdb/common/string_util.hpp"
|
|
5
|
+
|
|
6
|
+
namespace duckdb {
|
|
7
|
+
|
|
8
|
+
unique_ptr<DetachStatement> Transformer::TransformDetach(duckdb_libpgquery::PGNode *node) {
|
|
9
|
+
auto stmt = reinterpret_cast<duckdb_libpgquery::PGDetachStmt *>(node);
|
|
10
|
+
auto result = make_unique<DetachStatement>();
|
|
11
|
+
auto info = make_unique<DetachInfo>();
|
|
12
|
+
info->name = stmt->db_name;
|
|
13
|
+
info->if_exists = stmt->missing_ok;
|
|
14
|
+
|
|
15
|
+
result->info = std::move(info);
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
} // namespace duckdb
|
|
@@ -145,6 +145,8 @@ unique_ptr<SQLStatement> Transformer::TransformStatementInternal(duckdb_libpgque
|
|
|
145
145
|
return TransformAlterSequence(stmt);
|
|
146
146
|
case duckdb_libpgquery::T_PGAttachStmt:
|
|
147
147
|
return TransformAttach(stmt);
|
|
148
|
+
case duckdb_libpgquery::T_PGDetachStmt:
|
|
149
|
+
return TransformDetach(stmt);
|
|
148
150
|
case duckdb_libpgquery::T_PGUseStmt:
|
|
149
151
|
return TransformUse(stmt);
|
|
150
152
|
case duckdb_libpgquery::T_PGCreateDatabaseStmt:
|
|
@@ -12,13 +12,11 @@
|
|
|
12
12
|
#include "duckdb/parser/parsed_data/create_macro_info.hpp"
|
|
13
13
|
#include "duckdb/parser/parsed_data/create_view_info.hpp"
|
|
14
14
|
#include "duckdb/parser/parsed_data/create_database_info.hpp"
|
|
15
|
-
#include "duckdb/function/create_database_extension.hpp"
|
|
16
15
|
#include "duckdb/parser/tableref/table_function_ref.hpp"
|
|
17
16
|
#include "duckdb/parser/parsed_expression_iterator.hpp"
|
|
18
17
|
#include "duckdb/parser/statement/create_statement.hpp"
|
|
19
18
|
#include "duckdb/planner/binder.hpp"
|
|
20
19
|
#include "duckdb/planner/bound_query_node.hpp"
|
|
21
|
-
#include "duckdb/planner/expression_binder/aggregate_binder.hpp"
|
|
22
20
|
#include "duckdb/planner/expression_binder/index_binder.hpp"
|
|
23
21
|
#include "duckdb/planner/expression_binder/select_binder.hpp"
|
|
24
22
|
#include "duckdb/planner/operator/logical_create.hpp"
|
|
@@ -26,13 +24,13 @@
|
|
|
26
24
|
#include "duckdb/planner/operator/logical_create_table.hpp"
|
|
27
25
|
#include "duckdb/planner/operator/logical_get.hpp"
|
|
28
26
|
#include "duckdb/planner/operator/logical_distinct.hpp"
|
|
29
|
-
#include "duckdb/planner/parsed_data/bound_create_function_info.hpp"
|
|
30
27
|
#include "duckdb/planner/parsed_data/bound_create_table_info.hpp"
|
|
31
28
|
#include "duckdb/planner/query_node/bound_select_node.hpp"
|
|
32
29
|
#include "duckdb/planner/tableref/bound_basetableref.hpp"
|
|
33
30
|
#include "duckdb/parser/constraints/foreign_key_constraint.hpp"
|
|
34
31
|
#include "duckdb/function/scalar_macro_function.hpp"
|
|
35
32
|
#include "duckdb/storage/data_table.hpp"
|
|
33
|
+
#include "duckdb/storage/storage_extension.hpp"
|
|
36
34
|
#include "duckdb/main/client_data.hpp"
|
|
37
35
|
#include "duckdb/parser/constraints/unique_constraint.hpp"
|
|
38
36
|
#include "duckdb/parser/constraints/list.hpp"
|
|
@@ -651,23 +649,27 @@ BoundStatement Binder::Bind(CreateStatement &stmt) {
|
|
|
651
649
|
case CatalogType::DATABASE_ENTRY: {
|
|
652
650
|
// not supported in DuckDB yet but allow extensions to intercept and implement this functionality
|
|
653
651
|
auto &base = (CreateDatabaseInfo &)*stmt.info;
|
|
654
|
-
string extension_name = base.extension_name;
|
|
655
652
|
string database_name = base.name;
|
|
656
653
|
string source_path = base.path;
|
|
657
654
|
|
|
658
655
|
auto &config = DBConfig::GetConfig(context);
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
extension.function(context, extension_name, database_name, source_path, extension.data.get());
|
|
662
|
-
if (create_database_function_ref) {
|
|
663
|
-
auto bound_create_database_func = Bind(*create_database_function_ref);
|
|
664
|
-
result.plan = CreatePlan(*bound_create_database_func);
|
|
665
|
-
break;
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
if (!result.plan) {
|
|
656
|
+
|
|
657
|
+
if (config.storage_extensions.empty()) {
|
|
669
658
|
throw NotImplementedException("CREATE DATABASE not supported in DuckDB yet");
|
|
670
659
|
}
|
|
660
|
+
// for now assume only one storage extension provides the custom create_database impl
|
|
661
|
+
for (auto &extension_entry : config.storage_extensions) {
|
|
662
|
+
if (extension_entry.second->create_database != nullptr) {
|
|
663
|
+
auto &storage_extension = extension_entry.second;
|
|
664
|
+
auto create_database_function_ref = storage_extension->create_database(
|
|
665
|
+
storage_extension->storage_info.get(), context, database_name, source_path);
|
|
666
|
+
if (create_database_function_ref) {
|
|
667
|
+
auto bound_create_database_func = Bind(*create_database_function_ref);
|
|
668
|
+
result.plan = CreatePlan(*bound_create_database_func);
|
|
669
|
+
break;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
}
|
|
671
673
|
break;
|
|
672
674
|
}
|
|
673
675
|
default:
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#include "duckdb/parser/statement/detach_statement.hpp"
|
|
2
|
+
#include "duckdb/planner/binder.hpp"
|
|
3
|
+
#include "duckdb/planner/operator/logical_simple.hpp"
|
|
4
|
+
#include "duckdb/main/config.hpp"
|
|
5
|
+
|
|
6
|
+
namespace duckdb {
|
|
7
|
+
|
|
8
|
+
BoundStatement Binder::Bind(DetachStatement &stmt) {
|
|
9
|
+
BoundStatement result;
|
|
10
|
+
|
|
11
|
+
result.plan = make_unique<LogicalSimple>(LogicalOperatorType::LOGICAL_DETACH, std::move(stmt.info));
|
|
12
|
+
result.names = {"Success"};
|
|
13
|
+
result.types = {LogicalType::BOOLEAN};
|
|
14
|
+
properties.allow_stream_result = false;
|
|
15
|
+
properties.return_type = StatementReturnType::NOTHING;
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
} // namespace duckdb
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
#include "duckdb/parser/statement/drop_statement.hpp"
|
|
2
2
|
#include "duckdb/planner/binder.hpp"
|
|
3
|
+
#include "duckdb/planner/bound_tableref.hpp"
|
|
3
4
|
#include "duckdb/planner/operator/logical_simple.hpp"
|
|
4
5
|
#include "duckdb/catalog/catalog.hpp"
|
|
5
6
|
#include "duckdb/catalog/standard_entry.hpp"
|
|
6
7
|
#include "duckdb/catalog/catalog_entry/schema_catalog_entry.hpp"
|
|
8
|
+
#include "duckdb/parser/parsed_data/drop_info.hpp"
|
|
9
|
+
#include "duckdb/main/config.hpp"
|
|
10
|
+
#include "duckdb/storage/storage_extension.hpp"
|
|
7
11
|
|
|
8
12
|
namespace duckdb {
|
|
9
13
|
|
|
@@ -43,10 +47,31 @@ BoundStatement Binder::Bind(DropStatement &stmt) {
|
|
|
43
47
|
stmt.info->schema = entry->schema->name;
|
|
44
48
|
break;
|
|
45
49
|
}
|
|
46
|
-
case CatalogType::DATABASE_ENTRY:
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
case CatalogType::DATABASE_ENTRY: {
|
|
51
|
+
auto &base = (DropInfo &)*stmt.info;
|
|
52
|
+
string database_name = base.name;
|
|
53
|
+
|
|
54
|
+
auto &config = DBConfig::GetConfig(context);
|
|
55
|
+
// for now assume only one storage extension provides the custom drop_database impl
|
|
56
|
+
for (auto &extension_entry : config.storage_extensions) {
|
|
57
|
+
if (extension_entry.second->drop_database != nullptr) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
auto &storage_extension = extension_entry.second;
|
|
61
|
+
auto drop_database_function_ref =
|
|
62
|
+
storage_extension->drop_database(storage_extension->storage_info.get(), context, database_name);
|
|
63
|
+
if (drop_database_function_ref) {
|
|
64
|
+
auto bound_drop_database_func = Bind(*drop_database_function_ref);
|
|
65
|
+
result.plan = CreatePlan(*bound_drop_database_func);
|
|
66
|
+
result.names = {"Success"};
|
|
67
|
+
result.types = {LogicalType::BOOLEAN};
|
|
68
|
+
properties.allow_stream_result = false;
|
|
69
|
+
properties.return_type = StatementReturnType::NOTHING;
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
throw BinderException("Drop is not supported for this database!");
|
|
74
|
+
}
|
|
50
75
|
default:
|
|
51
76
|
throw BinderException("Unknown catalog type for drop statement!");
|
|
52
77
|
}
|
|
@@ -90,6 +90,8 @@ BoundStatement Binder::Bind(SQLStatement &statement) {
|
|
|
90
90
|
return Bind((LogicalPlanStatement &)statement);
|
|
91
91
|
case StatementType::ATTACH_STATEMENT:
|
|
92
92
|
return Bind((AttachStatement &)statement);
|
|
93
|
+
case StatementType::DETACH_STATEMENT:
|
|
94
|
+
return Bind((DetachStatement &)statement);
|
|
93
95
|
default: // LCOV_EXCL_START
|
|
94
96
|
throw NotImplementedException("Unimplemented statement type \"%s\" for Bind",
|
|
95
97
|
StatementTypeToString(statement.type));
|
|
@@ -338,6 +338,8 @@ unique_ptr<LogicalOperator> LogicalOperator::Deserialize(Deserializer &deseriali
|
|
|
338
338
|
case LogicalOperatorType::LOGICAL_DROP:
|
|
339
339
|
result = LogicalSimple::Deserialize(state, reader);
|
|
340
340
|
break;
|
|
341
|
+
case LogicalOperatorType::LOGICAL_DETACH:
|
|
342
|
+
throw SerializationException("Logical Detach does not support serialization");
|
|
341
343
|
case LogicalOperatorType::LOGICAL_EXTENSION_OPERATOR:
|
|
342
344
|
result = LogicalExtensionOperator::Deserialize(state, reader);
|
|
343
345
|
break;
|
|
@@ -133,6 +133,7 @@ void Planner::CreatePlan(unique_ptr<SQLStatement> statement) {
|
|
|
133
133
|
case StatementType::EXECUTE_STATEMENT:
|
|
134
134
|
case StatementType::LOGICAL_PLAN_STATEMENT:
|
|
135
135
|
case StatementType::ATTACH_STATEMENT:
|
|
136
|
+
case StatementType::DETACH_STATEMENT:
|
|
136
137
|
CreatePlan(*statement);
|
|
137
138
|
break;
|
|
138
139
|
default:
|
|
@@ -2070,6 +2070,20 @@ typedef struct PGAttachStmt
|
|
|
2070
2070
|
PGNode *query;
|
|
2071
2071
|
} PGAttachStmt;
|
|
2072
2072
|
|
|
2073
|
+
/* ----------------------
|
|
2074
|
+
* Dettach Statement
|
|
2075
|
+
* ----------------------
|
|
2076
|
+
*/
|
|
2077
|
+
|
|
2078
|
+
typedef struct PGDetachStmt
|
|
2079
|
+
{
|
|
2080
|
+
PGNodeTag type;
|
|
2081
|
+
char *db_name; /* list of names of attached databases */
|
|
2082
|
+
bool missing_ok;
|
|
2083
|
+
} PGDetachStmt;
|
|
2084
|
+
|
|
2085
|
+
|
|
2086
|
+
|
|
2073
2087
|
/* ----------------------
|
|
2074
2088
|
* CREATE DATABASE Statement
|
|
2075
2089
|
* ----------------------
|