duckdb 0.6.2-dev1170.0 → 0.6.2-dev1178.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 CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "duckdb",
3
3
  "main": "./lib/duckdb.js",
4
4
  "types": "./lib/duckdb.d.ts",
5
- "version": "0.6.2-dev1170.0",
5
+ "version": "0.6.2-dev1178.0",
6
6
  "description": "DuckDB node.js API",
7
7
  "gypfile": true,
8
8
  "dependencies": {
@@ -1,8 +1,8 @@
1
1
  #ifndef DUCKDB_VERSION
2
- #define DUCKDB_VERSION "0.6.2-dev1170"
2
+ #define DUCKDB_VERSION "0.6.2-dev1178"
3
3
  #endif
4
4
  #ifndef DUCKDB_SOURCE_ID
5
- #define DUCKDB_SOURCE_ID "72d187c5ff"
5
+ #define DUCKDB_SOURCE_ID "b0c4f53085"
6
6
  #endif
7
7
  #include "duckdb/function/table/system_functions.hpp"
8
8
  #include "duckdb/main/database.hpp"
@@ -0,0 +1,37 @@
1
+ //===----------------------------------------------------------------------===//
2
+ // DuckDB
3
+ //
4
+ // duckdb/function/create_database_extension.hpp
5
+ //
6
+ //
7
+ //===----------------------------------------------------------------------===//
8
+
9
+ #pragma once
10
+
11
+ #include "duckdb/common/common.hpp"
12
+
13
+ namespace duckdb {
14
+
15
+ class ClientContext;
16
+ class TableFunctionRef;
17
+
18
+ struct CreateDatabaseExtensionData {
19
+ virtual ~CreateDatabaseExtensionData() {
20
+ }
21
+ };
22
+
23
+ typedef unique_ptr<TableFunctionRef> (*create_database_t)(ClientContext &context, const string &extension_name,
24
+ const string &database_name, const string &source_path,
25
+ CreateDatabaseExtensionData *data);
26
+
27
+ struct CreateDatabaseExtension {
28
+ explicit CreateDatabaseExtension(create_database_t function,
29
+ unique_ptr<CreateDatabaseExtensionData> data_p = nullptr)
30
+ : function(function), data(move(data_p)) {
31
+ }
32
+
33
+ create_database_t function;
34
+ unique_ptr<CreateDatabaseExtensionData> data;
35
+ };
36
+
37
+ } // namespace duckdb
@@ -25,6 +25,7 @@
25
25
  #include "duckdb/function/cast/default_casts.hpp"
26
26
  #include "duckdb/function/replacement_open.hpp"
27
27
  #include "duckdb/function/replacement_scan.hpp"
28
+ #include "duckdb/function/create_database_extension.hpp"
28
29
  #include "duckdb/optimizer/optimizer_extension.hpp"
29
30
  #include "duckdb/parser/parser_extension.hpp"
30
31
  #include "duckdb/planner/operator_extension.hpp"
@@ -183,6 +184,8 @@ public:
183
184
  shared_ptr<Allocator> default_allocator;
184
185
  //! Extensions made to binder
185
186
  vector<std::unique_ptr<OperatorExtension>> operator_extensions;
187
+ //! Extensions made to binder to implement the create_database functionality
188
+ vector<CreateDatabaseExtension> create_database_extensions;
186
189
 
187
190
  public:
188
191
  DUCKDB_API static DBConfig &GetConfig(ClientContext &context);
@@ -0,0 +1,50 @@
1
+ //===----------------------------------------------------------------------===//
2
+ // DuckDB
3
+ //
4
+ // duckdb/parser/parsed_data/create_database_info.hpp
5
+ //
6
+ //
7
+ //===----------------------------------------------------------------------===//
8
+
9
+ #pragma once
10
+
11
+ #include "duckdb/parser/parsed_data/create_info.hpp"
12
+
13
+ namespace duckdb {
14
+
15
+ struct CreateDatabaseInfo : public CreateInfo {
16
+ CreateDatabaseInfo() : CreateInfo(CatalogType::DATABASE_ENTRY) {
17
+ }
18
+
19
+ //! Extension name which creates databases
20
+ string extension_name;
21
+
22
+ //! Name of the database
23
+ string name;
24
+
25
+ //! Source path of the database if it's created from another database
26
+ string path;
27
+
28
+ public:
29
+ unique_ptr<CreateInfo> Copy() const override {
30
+ auto result = make_unique<CreateDatabaseInfo>();
31
+ CopyProperties(*result);
32
+ result->extension_name = extension_name;
33
+ result->name = name;
34
+ result->path = path;
35
+ return move(result);
36
+ }
37
+
38
+ static unique_ptr<CreateDatabaseInfo> Deserialize(Deserializer &deserializer) {
39
+ auto result = make_unique<CreateDatabaseInfo>();
40
+ result->DeserializeBase(deserializer);
41
+ return result;
42
+ }
43
+
44
+ protected:
45
+ void SerializeInternal(Serializer &) const override {
46
+ throw NotImplementedException("Cannot serialize '%s'", CatalogTypeToString(type));
47
+ }
48
+ };
49
+
50
+ } // namespace duckdb
@@ -119,6 +119,8 @@ private:
119
119
  unique_ptr<CreateStatement> TransformCreateFunction(duckdb_libpgquery::PGNode *node);
120
120
  //! Transform a Postgres duckdb_libpgquery::T_PGCreateTypeStmt node into CreateStatement
121
121
  unique_ptr<CreateStatement> TransformCreateType(duckdb_libpgquery::PGNode *node);
122
+ //! Transform a Postgres duckdb_libpgquery::T_PGCreateDatabaseStmt node into a CreateStatement
123
+ unique_ptr<CreateStatement> TransformCreateDatabase(duckdb_libpgquery::PGNode *node);
122
124
  //! Transform a Postgres duckdb_libpgquery::T_PGAlterSeqStmt node into CreateStatement
123
125
  unique_ptr<AlterStatement> TransformAlterSequence(duckdb_libpgquery::PGNode *node);
124
126
  //! Transform a Postgres duckdb_libpgquery::T_PGDropStmt node into a Drop[Table,Schema]Statement
@@ -4,6 +4,7 @@
4
4
  #include "duckdb/parser/parsed_data/create_schema_info.hpp"
5
5
  #include "duckdb/parser/parsed_data/create_table_info.hpp"
6
6
  #include "duckdb/parser/parsed_data/create_view_info.hpp"
7
+ #include "duckdb/parser/parsed_data/create_database_info.hpp"
7
8
  #include "duckdb/parser/parsed_data/alter_info.hpp"
8
9
 
9
10
  namespace duckdb {
@@ -38,6 +39,8 @@ unique_ptr<CreateInfo> CreateInfo::Deserialize(Deserializer &deserializer) {
38
39
  return CreateSchemaInfo::Deserialize(deserializer);
39
40
  case CatalogType::VIEW_ENTRY:
40
41
  return CreateViewInfo::Deserialize(deserializer);
42
+ case CatalogType::DATABASE_ENTRY:
43
+ return CreateDatabaseInfo::Deserialize(deserializer);
41
44
  default:
42
45
  throw NotImplementedException("Cannot deserialize '%s'", CatalogTypeToString(type));
43
46
  }
@@ -816,6 +816,8 @@ std::string Transformer::NodetypeToString(duckdb_libpgquery::PGNodeTag type) { /
816
816
  return "T_PGAttachStmt";
817
817
  case duckdb_libpgquery::T_PGUseStmt:
818
818
  return "T_PGUseStmt";
819
+ case duckdb_libpgquery::T_PGCreateDatabaseStmt:
820
+ return "T_PGCreateDatabaseStmt";
819
821
  default:
820
822
  return "(UNKNOWN)";
821
823
  }
@@ -0,0 +1,29 @@
1
+ #include "duckdb/parser/statement/create_statement.hpp"
2
+ #include "duckdb/parser/parsed_data/create_database_info.hpp"
3
+ #include "duckdb/parser/transformer.hpp"
4
+ #include "duckdb/common/unordered_set.hpp"
5
+ #include "duckdb/common/operator/cast_operators.hpp"
6
+
7
+ namespace duckdb {
8
+
9
+ unique_ptr<CreateStatement> Transformer::TransformCreateDatabase(duckdb_libpgquery::PGNode *node) {
10
+ auto stmt = reinterpret_cast<duckdb_libpgquery::PGCreateDatabaseStmt *>(node);
11
+ auto result = make_unique<CreateStatement>();
12
+ auto info = make_unique<CreateDatabaseInfo>();
13
+
14
+ info->extension_name = stmt->extension ? stmt->extension : string();
15
+ info->path = stmt->path ? stmt->path : string();
16
+
17
+ auto qualified_name = TransformQualifiedName(stmt->name);
18
+ if (!IsInvalidCatalog(qualified_name.catalog)) {
19
+ throw ParserException("Expected \"CREATE DATABASE database\" ");
20
+ }
21
+
22
+ info->catalog = qualified_name.catalog;
23
+ info->name = qualified_name.name;
24
+
25
+ result->info = move(info);
26
+ return result;
27
+ }
28
+
29
+ } // namespace duckdb
@@ -147,6 +147,8 @@ unique_ptr<SQLStatement> Transformer::TransformStatementInternal(duckdb_libpgque
147
147
  return TransformAttach(stmt);
148
148
  case duckdb_libpgquery::T_PGUseStmt:
149
149
  return TransformUse(stmt);
150
+ case duckdb_libpgquery::T_PGCreateDatabaseStmt:
151
+ return TransformCreateDatabase(stmt);
150
152
  default:
151
153
  throw NotImplementedException(NodetypeToString(stmt->type));
152
154
  }
@@ -10,6 +10,9 @@
10
10
  #include "duckdb/parser/parsed_data/create_index_info.hpp"
11
11
  #include "duckdb/parser/parsed_data/create_macro_info.hpp"
12
12
  #include "duckdb/parser/parsed_data/create_view_info.hpp"
13
+ #include "duckdb/parser/parsed_data/create_database_info.hpp"
14
+ #include "duckdb/function/create_database_extension.hpp"
15
+ #include "duckdb/parser/tableref/table_function_ref.hpp"
13
16
  #include "duckdb/parser/parsed_expression_iterator.hpp"
14
17
  #include "duckdb/parser/statement/create_statement.hpp"
15
18
  #include "duckdb/planner/binder.hpp"
@@ -615,6 +618,28 @@ BoundStatement Binder::Bind(CreateStatement &stmt) {
615
618
  }
616
619
  break;
617
620
  }
621
+ case CatalogType::DATABASE_ENTRY: {
622
+ // not supported in DuckDB yet but allow extensions to intercept and implement this functionality
623
+ auto &base = (CreateDatabaseInfo &)*stmt.info;
624
+ string extension_name = base.extension_name;
625
+ string database_name = base.name;
626
+ string source_path = base.path;
627
+
628
+ auto &config = DBConfig::GetConfig(context);
629
+ for (auto &extension : config.create_database_extensions) {
630
+ auto create_database_function_ref =
631
+ extension.function(context, extension_name, database_name, source_path, extension.data.get());
632
+ if (create_database_function_ref) {
633
+ auto bound_create_database_func = Bind(*create_database_function_ref);
634
+ result.plan = CreatePlan(*bound_create_database_func);
635
+ break;
636
+ }
637
+ }
638
+ if (!result.plan) {
639
+ throw NotImplementedException("CREATE DATABASE not supported in DuckDB yet");
640
+ }
641
+ break;
642
+ }
618
643
  default:
619
644
  throw Exception("Unrecognized type!");
620
645
  }
@@ -422,6 +422,7 @@ typedef enum PGNodeTag {
422
422
  T_PGExportStmt,
423
423
  T_PGImportStmt,
424
424
  T_PGAttachStmt,
425
+ T_PGCreateDatabaseStmt,
425
426
  T_PGUseStmt,
426
427
 
427
428
  /*
@@ -2069,6 +2069,17 @@ typedef struct PGAttachStmt
2069
2069
  PGNode *query;
2070
2070
  } PGAttachStmt;
2071
2071
 
2072
+ /* ----------------------
2073
+ * CREATE DATABASE Statement
2074
+ * ----------------------
2075
+ */
2076
+ typedef struct PGCreateDatabaseStmt
2077
+ {
2078
+ PGNodeTag type;
2079
+ PGRangeVar *name; /* The name of the created database */
2080
+ char *extension; /* The name of the extension which will create the database */
2081
+ char *path; /* The file path of the to-be-created database */
2082
+ } PGCreateDatabaseStmt;
2072
2083
 
2073
2084
  /* ----------------------
2074
2085
  * Use Statement