duckdb 0.7.1-dev2.0 → 0.7.1-dev284.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.
Files changed (140) hide show
  1. package/binding.gyp +7 -7
  2. package/package.json +1 -1
  3. package/src/duckdb/extension/json/buffered_json_reader.cpp +50 -9
  4. package/src/duckdb/extension/json/include/buffered_json_reader.hpp +7 -2
  5. package/src/duckdb/extension/json/include/json_common.hpp +2 -2
  6. package/src/duckdb/extension/json/include/json_scan.hpp +29 -10
  7. package/src/duckdb/extension/json/json_functions/copy_json.cpp +35 -22
  8. package/src/duckdb/extension/json/json_functions/json_create.cpp +8 -8
  9. package/src/duckdb/extension/json/json_functions/json_transform.cpp +47 -8
  10. package/src/duckdb/extension/json/json_functions/read_json.cpp +104 -49
  11. package/src/duckdb/extension/json/json_functions/read_json_objects.cpp +5 -3
  12. package/src/duckdb/extension/json/json_functions.cpp +6 -0
  13. package/src/duckdb/extension/json/json_scan.cpp +144 -34
  14. package/src/duckdb/extension/parquet/parquet-extension.cpp +3 -2
  15. package/src/duckdb/src/catalog/catalog.cpp +15 -0
  16. package/src/duckdb/src/catalog/catalog_entry/index_catalog_entry.cpp +8 -7
  17. package/src/duckdb/src/common/enums/logical_operator_type.cpp +2 -0
  18. package/src/duckdb/src/common/enums/physical_operator_type.cpp +2 -0
  19. package/src/duckdb/src/common/enums/statement_type.cpp +2 -0
  20. package/src/duckdb/src/common/file_system.cpp +14 -0
  21. package/src/duckdb/src/common/hive_partitioning.cpp +1 -0
  22. package/src/duckdb/src/common/operator/cast_operators.cpp +14 -8
  23. package/src/duckdb/src/common/printer.cpp +1 -1
  24. package/src/duckdb/src/common/types/time.cpp +1 -1
  25. package/src/duckdb/src/common/types/timestamp.cpp +35 -4
  26. package/src/duckdb/src/common/types.cpp +36 -10
  27. package/src/duckdb/src/execution/column_binding_resolver.cpp +5 -2
  28. package/src/duckdb/src/execution/index/art/art.cpp +117 -67
  29. package/src/duckdb/src/execution/index/art/art_key.cpp +24 -12
  30. package/src/duckdb/src/execution/index/art/leaf.cpp +7 -8
  31. package/src/duckdb/src/execution/index/art/node.cpp +13 -27
  32. package/src/duckdb/src/execution/index/art/node16.cpp +5 -8
  33. package/src/duckdb/src/execution/index/art/node256.cpp +3 -5
  34. package/src/duckdb/src/execution/index/art/node4.cpp +4 -7
  35. package/src/duckdb/src/execution/index/art/node48.cpp +5 -8
  36. package/src/duckdb/src/execution/index/art/prefix.cpp +2 -3
  37. package/src/duckdb/src/execution/operator/join/physical_iejoin.cpp +7 -9
  38. package/src/duckdb/src/execution/operator/persistent/base_csv_reader.cpp +6 -11
  39. package/src/duckdb/src/execution/operator/persistent/buffered_csv_reader.cpp +13 -13
  40. package/src/duckdb/src/execution/operator/persistent/parallel_csv_reader.cpp +1 -1
  41. package/src/duckdb/src/execution/operator/schema/physical_detach.cpp +37 -0
  42. package/src/duckdb/src/execution/operator/schema/physical_drop.cpp +0 -5
  43. package/src/duckdb/src/execution/physical_plan/plan_simple.cpp +4 -0
  44. package/src/duckdb/src/execution/physical_plan_generator.cpp +1 -0
  45. package/src/duckdb/src/function/pragma/pragma_queries.cpp +38 -11
  46. package/src/duckdb/src/function/table/read_csv.cpp +17 -5
  47. package/src/duckdb/src/function/table/table_scan.cpp +3 -0
  48. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  49. package/src/duckdb/src/include/duckdb/catalog/catalog.hpp +5 -1
  50. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_index_entry.hpp +1 -1
  51. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/index_catalog_entry.hpp +1 -1
  52. package/src/duckdb/src/include/duckdb/common/enums/logical_operator_type.hpp +1 -0
  53. package/src/duckdb/src/include/duckdb/common/enums/physical_operator_type.hpp +1 -0
  54. package/src/duckdb/src/include/duckdb/common/enums/statement_type.hpp +3 -2
  55. package/src/duckdb/src/include/duckdb/common/enums/wal_type.hpp +3 -0
  56. package/src/duckdb/src/include/duckdb/common/exception.hpp +10 -0
  57. package/src/duckdb/src/include/duckdb/common/file_system.hpp +1 -0
  58. package/src/duckdb/src/include/duckdb/common/hive_partitioning.hpp +9 -1
  59. package/src/duckdb/src/include/duckdb/common/radix_partitioning.hpp +4 -4
  60. package/src/duckdb/src/include/duckdb/common/types/timestamp.hpp +5 -1
  61. package/src/duckdb/src/include/duckdb/execution/index/art/art.hpp +37 -41
  62. package/src/duckdb/src/include/duckdb/execution/index/art/art_key.hpp +8 -11
  63. package/src/duckdb/src/include/duckdb/execution/operator/persistent/base_csv_reader.hpp +1 -3
  64. package/src/duckdb/src/include/duckdb/execution/operator/persistent/buffered_csv_reader.hpp +0 -2
  65. package/src/duckdb/src/include/duckdb/execution/operator/persistent/csv_reader_options.hpp +2 -0
  66. package/src/duckdb/src/include/duckdb/execution/operator/schema/physical_detach.hpp +32 -0
  67. package/src/duckdb/src/include/duckdb/main/client_data.hpp +2 -2
  68. package/src/duckdb/src/include/duckdb/main/config.hpp +0 -3
  69. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_database_info.hpp +0 -4
  70. package/src/duckdb/src/include/duckdb/parser/parsed_data/detach_info.hpp +32 -0
  71. package/src/duckdb/src/include/duckdb/parser/query_node/select_node.hpp +1 -1
  72. package/src/duckdb/src/include/duckdb/parser/sql_statement.hpp +2 -2
  73. package/src/duckdb/src/include/duckdb/parser/statement/copy_statement.hpp +1 -1
  74. package/src/duckdb/src/include/duckdb/parser/statement/detach_statement.hpp +29 -0
  75. package/src/duckdb/src/include/duckdb/parser/statement/list.hpp +1 -0
  76. package/src/duckdb/src/include/duckdb/parser/statement/select_statement.hpp +3 -3
  77. package/src/duckdb/src/include/duckdb/parser/tableref/subqueryref.hpp +1 -1
  78. package/src/duckdb/src/include/duckdb/parser/tokens.hpp +1 -0
  79. package/src/duckdb/src/include/duckdb/parser/transformer.hpp +1 -0
  80. package/src/duckdb/src/include/duckdb/planner/binder.hpp +4 -0
  81. package/src/duckdb/src/include/duckdb/planner/expression_binder/index_binder.hpp +10 -3
  82. package/src/duckdb/src/include/duckdb/planner/operator/logical_execute.hpp +1 -5
  83. package/src/duckdb/src/include/duckdb/planner/operator/logical_show.hpp +1 -2
  84. package/src/duckdb/src/include/duckdb/storage/data_table.hpp +7 -1
  85. package/src/duckdb/src/include/duckdb/storage/index.hpp +47 -38
  86. package/src/duckdb/src/include/duckdb/storage/storage_extension.hpp +7 -0
  87. package/src/duckdb/src/include/duckdb/storage/table/update_segment.hpp +2 -0
  88. package/src/duckdb/src/include/duckdb/storage/write_ahead_log.hpp +7 -0
  89. package/src/duckdb/src/main/client_context.cpp +2 -0
  90. package/src/duckdb/src/main/extension/extension_alias.cpp +2 -1
  91. package/src/duckdb/src/optimizer/statistics/operator/propagate_join.cpp +2 -6
  92. package/src/duckdb/src/parser/parsed_data/create_index_info.cpp +3 -0
  93. package/src/duckdb/src/parser/statement/copy_statement.cpp +2 -13
  94. package/src/duckdb/src/parser/statement/delete_statement.cpp +3 -0
  95. package/src/duckdb/src/parser/statement/detach_statement.cpp +15 -0
  96. package/src/duckdb/src/parser/statement/insert_statement.cpp +9 -0
  97. package/src/duckdb/src/parser/statement/update_statement.cpp +3 -0
  98. package/src/duckdb/src/parser/transform/expression/transform_case.cpp +3 -3
  99. package/src/duckdb/src/parser/transform/statement/transform_create_database.cpp +0 -1
  100. package/src/duckdb/src/parser/transform/statement/transform_detach.cpp +19 -0
  101. package/src/duckdb/src/parser/transformer.cpp +2 -0
  102. package/src/duckdb/src/planner/binder/expression/bind_aggregate_expression.cpp +3 -0
  103. package/src/duckdb/src/planner/binder/statement/bind_copy.cpp +6 -3
  104. package/src/duckdb/src/planner/binder/statement/bind_create.cpp +16 -14
  105. package/src/duckdb/src/planner/binder/statement/bind_create_table.cpp +13 -0
  106. package/src/duckdb/src/planner/binder/statement/bind_detach.cpp +19 -0
  107. package/src/duckdb/src/planner/binder/statement/bind_drop.cpp +29 -4
  108. package/src/duckdb/src/planner/binder/statement/bind_insert.cpp +22 -1
  109. package/src/duckdb/src/planner/binder/tableref/bind_joinref.cpp +2 -1
  110. package/src/duckdb/src/planner/binder.cpp +2 -0
  111. package/src/duckdb/src/planner/expression_binder/index_binder.cpp +32 -1
  112. package/src/duckdb/src/planner/expression_binder/lateral_binder.cpp +21 -5
  113. package/src/duckdb/src/planner/logical_operator.cpp +4 -0
  114. package/src/duckdb/src/planner/planner.cpp +1 -0
  115. package/src/duckdb/src/storage/compression/bitpacking.cpp +16 -7
  116. package/src/duckdb/src/storage/data_table.cpp +66 -3
  117. package/src/duckdb/src/storage/index.cpp +1 -1
  118. package/src/duckdb/src/storage/local_storage.cpp +1 -1
  119. package/src/duckdb/src/storage/storage_info.cpp +2 -1
  120. package/src/duckdb/src/storage/table/column_data.cpp +4 -2
  121. package/src/duckdb/src/storage/table/update_segment.cpp +15 -0
  122. package/src/duckdb/src/storage/table_index_list.cpp +1 -2
  123. package/src/duckdb/src/storage/wal_replay.cpp +68 -0
  124. package/src/duckdb/src/storage/write_ahead_log.cpp +21 -1
  125. package/src/duckdb/src/transaction/commit_state.cpp +5 -2
  126. package/src/duckdb/third_party/fmt/include/fmt/core.h +1 -2
  127. package/src/duckdb/third_party/libpg_query/include/nodes/nodes.hpp +1 -0
  128. package/src/duckdb/third_party/libpg_query/include/nodes/parsenodes.hpp +14 -0
  129. package/src/duckdb/third_party/libpg_query/include/parser/gram.hpp +530 -1006
  130. package/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp +17659 -17626
  131. package/src/duckdb/third_party/thrift/thrift/Thrift.h +8 -2
  132. package/src/duckdb/ub_extension_icu_third_party_icu_i18n.cpp +4 -4
  133. package/src/duckdb/ub_src_execution_operator_schema.cpp +2 -0
  134. package/src/duckdb/ub_src_parser_statement.cpp +2 -0
  135. package/src/duckdb/ub_src_parser_transform_statement.cpp +2 -0
  136. package/src/duckdb/ub_src_planner_binder_statement.cpp +2 -0
  137. package/src/statement.cpp +46 -12
  138. package/test/prepare.test.ts +39 -1
  139. package/test/typescript_decls.test.ts +1 -1
  140. package/src/duckdb/src/include/duckdb/function/create_database_extension.hpp +0 -37
@@ -10,6 +10,7 @@
10
10
  #include "duckdb/parser/expression/function_expression.hpp"
11
11
  #include "duckdb/parser/tableref/table_function_ref.hpp"
12
12
  #include "duckdb/planner/operator/logical_get.hpp"
13
+ #include "duckdb/main/extension_helper.hpp"
13
14
 
14
15
  #include <limits>
15
16
 
@@ -29,7 +30,7 @@ void ReadCSVData::InitializeFiles(ClientContext &context, const vector<string> &
29
30
  for (auto &file_pattern : patterns) {
30
31
  auto found_files = fs.Glob(file_pattern, context);
31
32
  if (found_files.empty()) {
32
- throw IOException("No files found that match the pattern \"%s\"", file_pattern);
33
+ throw FileSystem::MissingFileException(file_pattern, context);
33
34
  }
34
35
  files.insert(files.end(), found_files.begin(), found_files.end());
35
36
  }
@@ -98,6 +99,17 @@ static unique_ptr<FunctionData> ReadCSVBind(ClientContext &context, TableFunctio
98
99
  if (names.empty()) {
99
100
  throw BinderException("read_csv requires at least a single column as input!");
100
101
  }
102
+ } else if (loption == "column_names" || loption == "names") {
103
+ if (!options.name_list.empty()) {
104
+ throw BinderException("read_csv_auto column_names/names can only be supplied once");
105
+ }
106
+ if (kv.second.IsNull()) {
107
+ throw BinderException("read_csv_auto %s cannot be NULL", kv.first);
108
+ }
109
+ auto &children = ListValue::GetChildren(kv.second);
110
+ for (auto &child : children) {
111
+ options.name_list.push_back(StringValue::Get(child));
112
+ }
101
113
  } else if (loption == "column_types" || loption == "types" || loption == "dtypes") {
102
114
  auto &child_type = kv.second.type();
103
115
  if (child_type.id() != LogicalTypeId::STRUCT && child_type.id() != LogicalTypeId::LIST) {
@@ -251,9 +263,6 @@ public:
251
263
  : file_handle(std::move(file_handle_p)), system_threads(system_threads_p), buffer_size(buffer_size_p),
252
264
  force_parallelism(force_parallelism_p) {
253
265
  current_file_path = files_path_p[0];
254
- for (idx_t i = 0; i < rows_to_skip; i++) {
255
- file_handle->ReadLine();
256
- }
257
266
  estimated_linenr = rows_to_skip;
258
267
  file_size = file_handle->FileSize();
259
268
  first_file_size = file_size;
@@ -303,7 +312,7 @@ public:
303
312
  progress = double(bytes_read) / double(file_size);
304
313
  }
305
314
  // now get the total percentage of files read
306
- double percentage = double(file_index) / total_files;
315
+ double percentage = double(file_index - 1) / total_files;
307
316
  percentage += (double(1) / double(total_files)) * progress;
308
317
  return percentage * 100;
309
318
  }
@@ -575,6 +584,7 @@ struct SingleThreadedCSVState : public GlobalTableFunctionState {
575
584
  {
576
585
  lock_guard<mutex> l(csv_lock);
577
586
  if (initial_reader) {
587
+ total_size = initial_reader->file_handle ? initial_reader->file_handle->FileSize() : 0;
578
588
  return std::move(initial_reader);
579
589
  }
580
590
  if (next_file >= total_files) {
@@ -963,6 +973,8 @@ TableFunction ReadCSVTableFunction::GetAutoFunction(bool list_parameter) {
963
973
  read_csv_auto.named_parameters["column_types"] = LogicalType::ANY;
964
974
  read_csv_auto.named_parameters["dtypes"] = LogicalType::ANY;
965
975
  read_csv_auto.named_parameters["types"] = LogicalType::ANY;
976
+ read_csv_auto.named_parameters["names"] = LogicalType::LIST(LogicalType::VARCHAR);
977
+ read_csv_auto.named_parameters["column_names"] = LogicalType::LIST(LogicalType::VARCHAR);
966
978
  return read_csv_auto;
967
979
  }
968
980
 
@@ -287,9 +287,12 @@ void TableScanPushdownComplexFilter(ClientContext &context, LogicalGet &get, Fun
287
287
  // behold
288
288
  storage.info->indexes.Scan([&](Index &index) {
289
289
  // first rewrite the index expression so the ColumnBindings align with the column bindings of the current table
290
+
290
291
  if (index.unbound_expressions.size() > 1) {
292
+ // NOTE: index scans are not (yet) supported for compound index keys
291
293
  return false;
292
294
  }
295
+
293
296
  auto index_expression = index.unbound_expressions[0]->Copy();
294
297
  bool rewrite_possible = true;
295
298
  RewriteIndexExpression(index, get, *index_expression, rewrite_possible);
@@ -1,8 +1,8 @@
1
1
  #ifndef DUCKDB_VERSION
2
- #define DUCKDB_VERSION "0.7.1-dev2"
2
+ #define DUCKDB_VERSION "0.7.1-dev284"
3
3
  #endif
4
4
  #ifndef DUCKDB_SOURCE_ID
5
- #define DUCKDB_SOURCE_ID "0f5e1ec507"
5
+ #define DUCKDB_SOURCE_ID "6b7362d2ca"
6
6
  #endif
7
7
  #include "duckdb/function/table/system_functions.hpp"
8
8
  #include "duckdb/main/database.hpp"
@@ -29,6 +29,7 @@ struct CreateFunctionInfo;
29
29
  struct CreateViewInfo;
30
30
  struct CreateSequenceInfo;
31
31
  struct CreateCollationInfo;
32
+ struct CreateIndexInfo;
32
33
  struct CreateTypeInfo;
33
34
  struct CreateTableInfo;
34
35
  struct DatabaseSize;
@@ -137,6 +138,9 @@ public:
137
138
  //! Creates a collation in the catalog
138
139
  DUCKDB_API CatalogEntry *CreateCollation(CatalogTransaction transaction, CreateCollationInfo *info);
139
140
  DUCKDB_API CatalogEntry *CreateCollation(ClientContext &context, CreateCollationInfo *info);
141
+ //! Creates an index in the catalog
142
+ DUCKDB_API CatalogEntry *CreateIndex(CatalogTransaction transaction, CreateIndexInfo *info);
143
+ DUCKDB_API CatalogEntry *CreateIndex(ClientContext &context, CreateIndexInfo *info);
140
144
 
141
145
  //! Creates a table in the catalog.
142
146
  DUCKDB_API CatalogEntry *CreateTable(CatalogTransaction transaction, SchemaCatalogEntry *schema,
@@ -153,7 +157,7 @@ public:
153
157
  //! Create a scalar or aggregate function in the catalog
154
158
  DUCKDB_API CatalogEntry *CreateFunction(CatalogTransaction transaction, SchemaCatalogEntry *schema,
155
159
  CreateFunctionInfo *info);
156
- //! Creates a table in the catalog.
160
+ //! Creates a view in the catalog
157
161
  DUCKDB_API CatalogEntry *CreateView(CatalogTransaction transaction, SchemaCatalogEntry *schema,
158
162
  CreateViewInfo *info);
159
163
  //! Creates a table in the catalog.
@@ -1,7 +1,7 @@
1
1
  //===----------------------------------------------------------------------===//
2
2
  // DuckDB
3
3
  //
4
- // duckdb/catalog/catalog_entry/dindex_catalog_entry.hpp
4
+ // duckdb/catalog/catalog_entry/duck_index_entry.hpp
5
5
  //
6
6
  //
7
7
  //===----------------------------------------------------------------------===//
@@ -34,7 +34,7 @@ public:
34
34
 
35
35
  public:
36
36
  string ToSQL() override;
37
- void Serialize(duckdb::MetaBlockWriter &serializer);
37
+ void Serialize(Serializer &serializer);
38
38
  static unique_ptr<CreateIndexInfo> Deserialize(Deserializer &source, ClientContext &context);
39
39
 
40
40
  virtual string GetSchemaName() = 0;
@@ -79,6 +79,7 @@ enum class LogicalOperatorType : uint8_t {
79
79
  LOGICAL_TRANSACTION = 134,
80
80
  LOGICAL_CREATE_TYPE = 135,
81
81
  LOGICAL_ATTACH = 136,
82
+ LOGICAL_DETACH = 137,
82
83
 
83
84
  // -----------------------------
84
85
  // Explain
@@ -87,6 +87,7 @@ enum class PhysicalOperatorType : uint8_t {
87
87
  TRANSACTION,
88
88
  CREATE_TYPE,
89
89
  ATTACH,
90
+ DETACH,
90
91
 
91
92
  // -----------------------------
92
93
  // Helpers
@@ -43,11 +43,12 @@ enum class StatementType : uint8_t {
43
43
  RELATION_STATEMENT,
44
44
  EXTENSION_STATEMENT,
45
45
  LOGICAL_PLAN_STATEMENT,
46
- ATTACH_STATEMENT
46
+ ATTACH_STATEMENT,
47
+ DETACH_STATEMENT
47
48
 
48
49
  };
49
50
 
50
- string StatementTypeToString(StatementType type);
51
+ DUCKDB_API string StatementTypeToString(StatementType type);
51
52
 
52
53
  enum class StatementReturnType : uint8_t {
53
54
  QUERY_RESULT, // the statement returns a query result (e.g. for display to the user)
@@ -41,6 +41,9 @@ enum class WALType : uint8_t {
41
41
  CREATE_TABLE_MACRO = 21,
42
42
  DROP_TABLE_MACRO = 22,
43
43
 
44
+ CREATE_INDEX = 23,
45
+ DROP_INDEX = 24,
46
+
44
47
  // -----------------------------
45
48
  // Data
46
49
  // -----------------------------
@@ -262,6 +262,16 @@ public:
262
262
  }
263
263
  };
264
264
 
265
+ class MissingExtensionException : public IOException {
266
+ public:
267
+ DUCKDB_API explicit MissingExtensionException(const string &msg);
268
+
269
+ template <typename... Args>
270
+ explicit MissingExtensionException(const string &msg, Args... params)
271
+ : IOException(ConstructMessage(msg, params...)) {
272
+ }
273
+ };
274
+
265
275
  class SerializationException : public Exception {
266
276
  public:
267
277
  DUCKDB_API explicit SerializationException(const string &msg);
@@ -201,6 +201,7 @@ public:
201
201
 
202
202
  //! Whether or not a sub-system can handle a specific file path
203
203
  DUCKDB_API virtual bool CanHandleFile(const string &fpath);
204
+ DUCKDB_API static IOException MissingFileException(const string &file_path, ClientContext &context);
204
205
 
205
206
  //! Set the file pointer of a file handle to a specified location. Reads and writes will happen from this location
206
207
  DUCKDB_API virtual void Seek(FileHandle &handle, idx_t location);
@@ -52,7 +52,15 @@ struct HivePartitionKey {
52
52
 
53
53
  struct Equality {
54
54
  bool operator()(const HivePartitionKey &a, const HivePartitionKey &b) const {
55
- return a.values == b.values;
55
+ if (a.values.size() != b.values.size()) {
56
+ return false;
57
+ }
58
+ for (idx_t i = 0; i < a.values.size(); i++) {
59
+ if (!Value::NotDistinctFrom(a.values[i], b.values[i])) {
60
+ return false;
61
+ }
62
+ }
63
+ return true;
56
64
  }
57
65
  };
58
66
  };
@@ -78,13 +78,13 @@ protected:
78
78
  case 2:
79
79
  case 3:
80
80
  case 4:
81
- return GetBufferSize(1);
81
+ return GetBufferSize(1 << 1);
82
82
  case 5:
83
- return GetBufferSize(2);
83
+ return GetBufferSize(1 << 2);
84
84
  case 6:
85
- return GetBufferSize(3);
85
+ return GetBufferSize(1 << 3);
86
86
  default:
87
- return GetBufferSize(4);
87
+ return GetBufferSize(1 << 4);
88
88
  }
89
89
  }
90
90
  void InitializeAppendStateInternal(PartitionedColumnDataAppendState &state) const override;
@@ -93,6 +93,8 @@ struct timestamp_ns_t : public timestamp_t {}; // NOLINT
93
93
  struct timestamp_ms_t : public timestamp_t {}; // NOLINT
94
94
  struct timestamp_sec_t : public timestamp_t {}; // NOLINT
95
95
 
96
+ enum class TimestampCastResult : uint8_t { SUCCESS, ERROR_INCORRECT_FORMAT, ERROR_NON_UTC_TIMEZONE };
97
+
96
98
  //! The Timestamp class is a static class that holds helper functions for the Timestamp
97
99
  //! type.
98
100
  class Timestamp {
@@ -110,7 +112,7 @@ public:
110
112
  //! If the tz is not empty, the result is still an instant, but the parts can be extracted and applied to the TZ
111
113
  DUCKDB_API static bool TryConvertTimestampTZ(const char *str, idx_t len, timestamp_t &result, bool &has_offset,
112
114
  string_t &tz);
113
- DUCKDB_API static bool TryConvertTimestamp(const char *str, idx_t len, timestamp_t &result);
115
+ DUCKDB_API static TimestampCastResult TryConvertTimestamp(const char *str, idx_t len, timestamp_t &result);
114
116
  DUCKDB_API static timestamp_t FromCString(const char *str, idx_t len);
115
117
  //! Convert a date object to a string in the format "YYYY-MM-DD hh:mm:ss"
116
118
  DUCKDB_API static string ToString(timestamp_t timestamp);
@@ -161,6 +163,8 @@ public:
161
163
 
162
164
  DUCKDB_API static string ConversionError(const string &str);
163
165
  DUCKDB_API static string ConversionError(string_t str);
166
+ DUCKDB_API static string UnsupportedTimezoneError(const string &str);
167
+ DUCKDB_API static string UnsupportedTimezoneError(string_t str);
164
168
  };
165
169
 
166
170
  } // namespace duckdb
@@ -29,24 +29,21 @@ namespace duckdb {
29
29
  class ConflictManager;
30
30
 
31
31
  struct ARTIndexScanState : public IndexScanState {
32
- ARTIndexScanState() : checked(false), result_index(0) {
33
- }
34
32
 
33
+ //! Scan predicates (single predicate scan or range scan)
35
34
  Value values[2];
35
+ //! Expressions of the scan predicates
36
36
  ExpressionType expressions[2];
37
- bool checked;
37
+ bool checked = false;
38
+ //! All scanned row IDs
38
39
  vector<row_t> result_ids;
39
40
  Iterator iterator;
40
- //! Stores the current leaf
41
- Leaf *cur_leaf = nullptr;
42
- //! Offset to leaf
43
- idx_t result_index = 0;
44
41
  };
45
42
 
46
43
  enum class VerifyExistenceType : uint8_t {
47
- APPEND = 0, // for purpose to append into table
48
- APPEND_FK = 1, // for purpose to append into table has foreign key
49
- DELETE_FK = 2 // for purpose to delete from table related to foreign key
44
+ APPEND = 0, // appends to a table
45
+ APPEND_FK = 1, // appends to a table that has a foreign key
46
+ DELETE_FK = 2 // delete from a table that has a foreign key
50
47
  };
51
48
 
52
49
  class ART : public Index {
@@ -62,47 +59,44 @@ public:
62
59
  Node *tree;
63
60
 
64
61
  public:
65
- //! Initialize a scan on the index with the given expression and column ids
66
- //! to fetch from the base table for a single predicate
62
+ //! Initialize a single predicate scan on the index with the given expression and column IDs
67
63
  unique_ptr<IndexScanState> InitializeScanSinglePredicate(const Transaction &transaction, const Value &value,
68
64
  ExpressionType expression_type) override;
69
-
70
- //! Initialize a scan on the index with the given expression and column ids
71
- //! to fetch from the base table for two predicates
65
+ //! Initialize a two predicate scan on the index with the given expression and column IDs
72
66
  unique_ptr<IndexScanState> InitializeScanTwoPredicates(Transaction &transaction, const Value &low_value,
73
67
  ExpressionType low_expression_type, const Value &high_value,
74
68
  ExpressionType high_expression_type) override;
75
-
76
- //! Perform a lookup on the index
69
+ //! Performs a lookup on the index, fetching up to max_count result IDs. Returns true if all row IDs were fetched,
70
+ //! and false otherwise
77
71
  bool Scan(Transaction &transaction, DataTable &table, IndexScanState &state, idx_t max_count,
78
72
  vector<row_t> &result_ids) override;
79
- //! Append entries to the index
73
+
74
+ //! Called when data is appended to the index. The lock obtained from InitializeLock must be held
80
75
  bool Append(IndexLock &lock, DataChunk &entries, Vector &row_identifiers) override;
81
- //! Verify that data can be appended to the index
76
+ //! Verify that data can be appended to the index without a constraint violation
82
77
  void VerifyAppend(DataChunk &chunk) override;
83
- //! Verify that data can be appended to the index
78
+ //! Verify that data can be appended to the index without a constraint violation using the conflict manager
84
79
  void VerifyAppend(DataChunk &chunk, ConflictManager &conflict_manager) override;
85
- //! Verify that data can be appended to the index for foreign key constraint
86
- void VerifyAppendForeignKey(DataChunk &chunk) override;
87
- //! Verify that data can be delete from the index for foreign key constraint
88
- void VerifyDeleteForeignKey(DataChunk &chunk) override;
89
- //! Delete entries in the index
80
+ //! Delete a chunk of entries from the index. The lock obtained from InitializeLock must be held
90
81
  void Delete(IndexLock &lock, DataChunk &entries, Vector &row_identifiers) override;
91
- //! Insert data into the index
82
+ //! Insert a chunk of entries into the index
92
83
  bool Insert(IndexLock &lock, DataChunk &data, Vector &row_ids) override;
93
84
 
94
85
  //! Construct an ART from a vector of sorted keys
95
86
  bool ConstructFromSorted(idx_t count, vector<Key> &keys, Vector &row_identifiers);
96
87
 
97
- //! Search Equal and fetches the row IDs
88
+ //! Search equal values and fetches the row IDs
98
89
  bool SearchEqual(Key &key, idx_t max_count, vector<row_t> &result_ids);
99
- //! Search Equal used for Joins that do not need to fetch data
90
+ //! Search equal values used for joins that do not need to fetch data
100
91
  void SearchEqualJoinNoFetch(Key &key, idx_t &result_size);
101
- //! Serialized the ART
92
+
93
+ //! Serializes the index and returns the pair of block_id offset positions
102
94
  BlockPointer Serialize(duckdb::MetaBlockWriter &writer) override;
103
95
 
104
- //! Merge two ARTs
96
+ //! Merge another index into this index. The lock obtained from InitializeLock must be held, and the other
97
+ //! index must also be locked during the merge
105
98
  bool MergeIndexes(IndexLock &state, Index *other_index) override;
99
+
106
100
  //! Generate ART keys for an input chunk
107
101
  static void GenerateKeys(ArenaAllocator &allocator, DataChunk &input, vector<Key> &keys);
108
102
 
@@ -110,30 +104,32 @@ public:
110
104
  string GenerateErrorKeyName(DataChunk &input, idx_t row);
111
105
  //! Generate the matching error message for a constraint violation
112
106
  string GenerateConstraintErrorMessage(VerifyExistenceType verify_type, const string &key_name);
107
+ //! Performs constraint checking for a chunk of input data
108
+ void CheckConstraintsForChunk(DataChunk &input, ConflictManager &conflict_manager) override;
113
109
 
114
110
  //! Returns the string representation of an ART
115
111
  string ToString() override;
116
- //! Verifies that the memory_size value of the ART matches its actual size
112
+ //! Verifies that the in-memory size value of the index matches its actual size
117
113
  void Verify() override;
114
+ //! Increases the memory size by the difference between the old size and the current size
115
+ //! and performs verifications
116
+ void IncreaseAndVerifyMemorySize(idx_t old_memory_size) override;
118
117
 
119
118
  private:
120
- //! Insert a row id into a leaf node
119
+ //! Insert a row ID into a leaf
121
120
  bool InsertToLeaf(Leaf &leaf, row_t row_id);
122
- //! Insert the leaf value into the tree
121
+ //! Insert a key into the tree
123
122
  bool Insert(Node *&node, Key &key, idx_t depth, row_t row_id);
124
-
125
- //! Erase element from leaf (if leaf has more than one value) or eliminate the leaf itself
123
+ //! Erase a key from the tree (if a leaf has more than one value) or erase the leaf itself
126
124
  void Erase(Node *&node, Key &key, idx_t depth, row_t row_id);
127
-
128
- //! Perform 'Lookup' for an entire chunk, marking which succeeded
129
- void LookupValues(DataChunk &input, ConflictManager &conflict_manager) final override;
130
-
131
- //! Find the node with a matching key, optimistic version
125
+ //! Find the node with a matching key, or return nullptr if not found
132
126
  Leaf *Lookup(Node *node, Key &key, idx_t depth);
133
-
127
+ //! Returns all row IDs belonging to a key greater (or equal) than the search key
134
128
  bool SearchGreater(ARTIndexScanState *state, Key &key, bool inclusive, idx_t max_count, vector<row_t> &result_ids);
129
+ //! Returns all row IDs belonging to a key less (or equal) than the upper_bound
135
130
  bool SearchLess(ARTIndexScanState *state, Key &upper_bound, bool inclusive, idx_t max_count,
136
131
  vector<row_t> &result_ids);
132
+ //! Returns all row IDs belonging to a key within the range of lower_bound and upper_bound
137
133
  bool SearchCloseRange(ARTIndexScanState *state, Key &lower_bound, Key &upper_bound, bool left_inclusive,
138
134
  bool right_inclusive, idx_t max_count, vector<row_t> &result_ids);
139
135
  };
@@ -28,24 +28,24 @@ public:
28
28
 
29
29
  public:
30
30
  template <class T>
31
- static inline Key CreateKey(ArenaAllocator &allocator, T element) {
31
+ static inline Key CreateKey(ArenaAllocator &allocator, const LogicalType &type, T element) {
32
32
  auto data = Key::CreateData<T>(allocator, element);
33
33
  return Key(data, sizeof(element));
34
34
  }
35
35
 
36
36
  template <class T>
37
- static inline Key CreateKey(ArenaAllocator &allocator, const Value &element) {
38
- return CreateKey(allocator, element.GetValueUnsafe<T>());
37
+ static inline Key CreateKey(ArenaAllocator &allocator, const LogicalType &type, const Value &element) {
38
+ return CreateKey(allocator, type, element.GetValueUnsafe<T>());
39
39
  }
40
40
 
41
41
  template <class T>
42
- static inline void CreateKey(ArenaAllocator &allocator, Key &key, T element) {
42
+ static inline void CreateKey(ArenaAllocator &allocator, const LogicalType &type, Key &key, T element) {
43
43
  key.data = Key::CreateData<T>(allocator, element);
44
44
  key.len = sizeof(element);
45
45
  }
46
46
 
47
47
  template <class T>
48
- static inline void CreateKey(ArenaAllocator &allocator, Key &key, const Value element) {
48
+ static inline void CreateKey(ArenaAllocator &allocator, const LogicalType &type, Key &key, const Value element) {
49
49
  key.data = Key::CreateData<T>(allocator, element.GetValueUnsafe<T>());
50
50
  key.len = sizeof(element);
51
51
  }
@@ -76,12 +76,9 @@ private:
76
76
  };
77
77
 
78
78
  template <>
79
- Key Key::CreateKey(ArenaAllocator &allocator, string_t value);
79
+ Key Key::CreateKey(ArenaAllocator &allocator, const LogicalType &type, string_t value);
80
80
  template <>
81
- Key Key::CreateKey(ArenaAllocator &allocator, const char *value);
81
+ Key Key::CreateKey(ArenaAllocator &allocator, const LogicalType &type, const char *value);
82
82
  template <>
83
- void Key::CreateKey(ArenaAllocator &allocator, Key &key, string_t value);
84
- template <>
85
- void Key::CreateKey(ArenaAllocator &allocator, Key &key, const char *value);
86
-
83
+ void Key::CreateKey(ArenaAllocator &allocator, const LogicalType &type, Key &key, string_t value);
87
84
  } // namespace duckdb
@@ -35,11 +35,9 @@ class BaseCSVReader {
35
35
  public:
36
36
  BaseCSVReader(ClientContext &context, BufferedCSVReaderOptions options,
37
37
  const vector<LogicalType> &requested_types = vector<LogicalType>());
38
-
39
- BaseCSVReader(FileSystem &fs, Allocator &allocator, FileOpener *opener, BufferedCSVReaderOptions options,
40
- const vector<LogicalType> &requested_types = vector<LogicalType>());
41
38
  ~BaseCSVReader();
42
39
 
40
+ ClientContext &context;
43
41
  FileSystem &fs;
44
42
  Allocator &allocator;
45
43
  FileOpener *opener;
@@ -55,8 +55,6 @@ class BufferedCSVReader : public BaseCSVReader {
55
55
  public:
56
56
  BufferedCSVReader(ClientContext &context, BufferedCSVReaderOptions options,
57
57
  const vector<LogicalType> &requested_types = vector<LogicalType>());
58
- BufferedCSVReader(FileSystem &fs, Allocator &allocator, FileOpener *opener, BufferedCSVReaderOptions options,
59
- const vector<LogicalType> &requested_types = vector<LogicalType>());
60
58
  BufferedCSVReader(ClientContext &context, string filename, BufferedCSVReaderOptions options,
61
59
  const vector<LogicalType> &requested_types = vector<LogicalType>());
62
60
  ~BufferedCSVReader();
@@ -75,6 +75,8 @@ struct BufferedCSVReaderOptions {
75
75
  case_insensitive_map_t<idx_t> sql_types_per_column;
76
76
  //! User-defined SQL type list
77
77
  vector<LogicalType> sql_type_list;
78
+ //! User-defined name list
79
+ vector<string> name_list;
78
80
  //===--------------------------------------------------------------------===//
79
81
  // ReadCSVOptions
80
82
  //===--------------------------------------------------------------------===//
@@ -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
@@ -11,7 +11,7 @@
11
11
  #include "duckdb/common/common.hpp"
12
12
  #include "duckdb/common/enums/output_type.hpp"
13
13
  #include "duckdb/common/types/value.hpp"
14
- #include "duckdb/common/unordered_map.hpp"
14
+ #include "duckdb/common/case_insensitive_map.hpp"
15
15
  #include "duckdb/common/atomic.hpp"
16
16
 
17
17
  namespace duckdb {
@@ -39,7 +39,7 @@ struct ClientData {
39
39
  //! The set of temporary objects that belong to this client
40
40
  shared_ptr<AttachedDatabase> temporary_objects;
41
41
  //! The set of bound prepared statements that belong to this client
42
- unordered_map<string, shared_ptr<PreparedStatementData>> prepared_statements;
42
+ case_insensitive_map_t<shared_ptr<PreparedStatementData>> prepared_statements;
43
43
 
44
44
  //! The writer used to log queries (if logging is enabled)
45
45
  unique_ptr<BufferedFileWriter> log_query_writer;
@@ -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
@@ -21,7 +21,7 @@ namespace duckdb {
21
21
  //! SelectNode represents a standard SELECT statement
22
22
  class SelectNode : public QueryNode {
23
23
  public:
24
- SelectNode();
24
+ DUCKDB_API SelectNode();
25
25
 
26
26
  //! The projection list
27
27
  vector<unique_ptr<ParsedExpression>> select_list;
@@ -40,11 +40,11 @@ protected:
40
40
  SQLStatement(const SQLStatement &other) = default;
41
41
 
42
42
  public:
43
- virtual string ToString() const {
43
+ DUCKDB_API virtual string ToString() const {
44
44
  throw InternalException("ToString not supported for this type of SQLStatement: '%s'",
45
45
  StatementTypeToString(type));
46
46
  }
47
47
  //! Create a copy of this SelectStatement
48
- virtual unique_ptr<SQLStatement> Copy() const = 0;
48
+ DUCKDB_API virtual unique_ptr<SQLStatement> Copy() const = 0;
49
49
  };
50
50
  } // namespace duckdb