duckdb 0.7.2-dev717.0 → 0.7.2-dev865.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 (179) hide show
  1. package/binding.gyp +2 -0
  2. package/lib/duckdb.d.ts +12 -1
  3. package/lib/duckdb.js +19 -0
  4. package/package.json +1 -1
  5. package/src/duckdb/extension/json/include/json_common.hpp +1 -0
  6. package/src/duckdb/extension/json/include/json_functions.hpp +1 -0
  7. package/src/duckdb/extension/json/include/json_serializer.hpp +77 -0
  8. package/src/duckdb/extension/json/json_functions/json_serialize_sql.cpp +147 -0
  9. package/src/duckdb/extension/json/json_functions.cpp +1 -0
  10. package/src/duckdb/extension/json/json_scan.cpp +2 -2
  11. package/src/duckdb/extension/json/json_serializer.cpp +217 -0
  12. package/src/duckdb/src/catalog/catalog.cpp +21 -5
  13. package/src/duckdb/src/common/enums/expression_type.cpp +8 -222
  14. package/src/duckdb/src/common/enums/join_type.cpp +3 -22
  15. package/src/duckdb/src/common/exception.cpp +2 -2
  16. package/src/duckdb/src/common/serializer/enum_serializer.cpp +1172 -0
  17. package/src/duckdb/src/common/types/value.cpp +117 -93
  18. package/src/duckdb/src/common/types/vector.cpp +140 -1
  19. package/src/duckdb/src/common/types.cpp +166 -89
  20. package/src/duckdb/src/execution/operator/helper/physical_limit.cpp +3 -0
  21. package/src/duckdb/src/execution/physical_plan/plan_aggregate.cpp +5 -8
  22. package/src/duckdb/src/function/scalar/date/date_part.cpp +2 -2
  23. package/src/duckdb/src/function/scalar/date/date_trunc.cpp +2 -2
  24. package/src/duckdb/src/function/scalar/list/list_aggregates.cpp +1 -1
  25. package/src/duckdb/src/function/scalar/list/list_lambdas.cpp +4 -0
  26. package/src/duckdb/src/function/scalar/operators/arithmetic.cpp +8 -8
  27. package/src/duckdb/src/function/scalar/string/regexp/regexp_extract_all.cpp +243 -0
  28. package/src/duckdb/src/function/scalar/string/regexp/regexp_util.cpp +79 -0
  29. package/src/duckdb/src/function/scalar/string/regexp.cpp +21 -80
  30. package/src/duckdb/src/function/table/arrow_conversion.cpp +7 -1
  31. package/src/duckdb/src/function/table/table_scan.cpp +1 -1
  32. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  33. package/src/duckdb/src/include/duckdb/catalog/catalog.hpp +3 -0
  34. package/src/duckdb/src/include/duckdb/common/enums/aggregate_handling.hpp +2 -0
  35. package/src/duckdb/src/include/duckdb/common/enums/expression_type.hpp +2 -3
  36. package/src/duckdb/src/include/duckdb/common/enums/joinref_type.hpp +2 -0
  37. package/src/duckdb/src/include/duckdb/common/enums/order_type.hpp +2 -0
  38. package/src/duckdb/src/include/duckdb/common/enums/set_operation_type.hpp +2 -1
  39. package/src/duckdb/src/include/duckdb/common/exception.hpp +40 -9
  40. package/src/duckdb/src/include/duckdb/common/preserved_error.hpp +3 -0
  41. package/src/duckdb/src/include/duckdb/common/serializer/enum_serializer.hpp +113 -0
  42. package/src/duckdb/src/include/duckdb/common/serializer/format_deserializer.hpp +336 -0
  43. package/src/duckdb/src/include/duckdb/common/serializer/format_serializer.hpp +268 -0
  44. package/src/duckdb/src/include/duckdb/common/serializer/serialization_traits.hpp +126 -0
  45. package/src/duckdb/src/include/duckdb/common/string_util.hpp +12 -0
  46. package/src/duckdb/src/include/duckdb/common/types/value.hpp +2 -31
  47. package/src/duckdb/src/include/duckdb/common/types/vector.hpp +3 -0
  48. package/src/duckdb/src/include/duckdb/common/types.hpp +8 -2
  49. package/src/duckdb/src/include/duckdb/function/scalar/regexp.hpp +81 -1
  50. package/src/duckdb/src/include/duckdb/main/extension_entries.hpp +1 -0
  51. package/src/duckdb/src/include/duckdb/parser/common_table_expression_info.hpp +2 -0
  52. package/src/duckdb/src/include/duckdb/parser/expression/between_expression.hpp +3 -0
  53. package/src/duckdb/src/include/duckdb/parser/expression/bound_expression.hpp +2 -0
  54. package/src/duckdb/src/include/duckdb/parser/expression/case_expression.hpp +5 -0
  55. package/src/duckdb/src/include/duckdb/parser/expression/cast_expression.hpp +2 -0
  56. package/src/duckdb/src/include/duckdb/parser/expression/collate_expression.hpp +2 -0
  57. package/src/duckdb/src/include/duckdb/parser/expression/columnref_expression.hpp +2 -0
  58. package/src/duckdb/src/include/duckdb/parser/expression/comparison_expression.hpp +2 -0
  59. package/src/duckdb/src/include/duckdb/parser/expression/conjunction_expression.hpp +2 -0
  60. package/src/duckdb/src/include/duckdb/parser/expression/constant_expression.hpp +3 -0
  61. package/src/duckdb/src/include/duckdb/parser/expression/default_expression.hpp +1 -0
  62. package/src/duckdb/src/include/duckdb/parser/expression/function_expression.hpp +2 -0
  63. package/src/duckdb/src/include/duckdb/parser/expression/lambda_expression.hpp +2 -0
  64. package/src/duckdb/src/include/duckdb/parser/expression/operator_expression.hpp +2 -0
  65. package/src/duckdb/src/include/duckdb/parser/expression/parameter_expression.hpp +2 -0
  66. package/src/duckdb/src/include/duckdb/parser/expression/positional_reference_expression.hpp +2 -0
  67. package/src/duckdb/src/include/duckdb/parser/expression/star_expression.hpp +2 -0
  68. package/src/duckdb/src/include/duckdb/parser/expression/subquery_expression.hpp +2 -0
  69. package/src/duckdb/src/include/duckdb/parser/expression/window_expression.hpp +5 -0
  70. package/src/duckdb/src/include/duckdb/parser/parsed_data/sample_options.hpp +2 -0
  71. package/src/duckdb/src/include/duckdb/parser/parsed_expression.hpp +5 -0
  72. package/src/duckdb/src/include/duckdb/parser/query_node/recursive_cte_node.hpp +3 -0
  73. package/src/duckdb/src/include/duckdb/parser/query_node/select_node.hpp +5 -0
  74. package/src/duckdb/src/include/duckdb/parser/query_node/set_operation_node.hpp +3 -0
  75. package/src/duckdb/src/include/duckdb/parser/query_node.hpp +11 -1
  76. package/src/duckdb/src/include/duckdb/parser/result_modifier.hpp +24 -1
  77. package/src/duckdb/src/include/duckdb/parser/sql_statement.hpp +2 -1
  78. package/src/duckdb/src/include/duckdb/parser/statement/select_statement.hpp +6 -1
  79. package/src/duckdb/src/include/duckdb/parser/tableref/basetableref.hpp +4 -0
  80. package/src/duckdb/src/include/duckdb/parser/tableref/emptytableref.hpp +2 -0
  81. package/src/duckdb/src/include/duckdb/parser/tableref/expressionlistref.hpp +3 -0
  82. package/src/duckdb/src/include/duckdb/parser/tableref/joinref.hpp +3 -0
  83. package/src/duckdb/src/include/duckdb/parser/tableref/pivotref.hpp +9 -0
  84. package/src/duckdb/src/include/duckdb/parser/tableref/subqueryref.hpp +3 -0
  85. package/src/duckdb/src/include/duckdb/parser/tableref/table_function_ref.hpp +3 -0
  86. package/src/duckdb/src/include/duckdb/parser/tableref.hpp +3 -1
  87. package/src/duckdb/src/include/duckdb/storage/statistics/numeric_stats.hpp +9 -52
  88. package/src/duckdb/src/include/duckdb/storage/statistics/numeric_stats_union.hpp +62 -0
  89. package/src/duckdb/src/include/duckdb/storage/table/column_checkpoint_state.hpp +2 -1
  90. package/src/duckdb/src/include/duckdb/storage/table/column_data.hpp +6 -3
  91. package/src/duckdb/src/include/duckdb/storage/table/column_data_checkpointer.hpp +3 -2
  92. package/src/duckdb/src/include/duckdb/storage/table/column_segment.hpp +5 -3
  93. package/src/duckdb/src/include/duckdb/storage/table/persistent_table_data.hpp +4 -1
  94. package/src/duckdb/src/include/duckdb/storage/table/row_group.hpp +6 -3
  95. package/src/duckdb/src/include/duckdb/storage/table/row_group_collection.hpp +5 -3
  96. package/src/duckdb/src/include/duckdb/storage/table/row_group_segment_tree.hpp +37 -0
  97. package/src/duckdb/src/include/duckdb/storage/table/scan_state.hpp +8 -1
  98. package/src/duckdb/src/include/duckdb/storage/table/segment_base.hpp +4 -3
  99. package/src/duckdb/src/include/duckdb/storage/table/segment_tree.hpp +271 -26
  100. package/src/duckdb/src/main/extension/extension_install.cpp +7 -2
  101. package/src/duckdb/src/optimizer/deliminator.cpp +1 -1
  102. package/src/duckdb/src/optimizer/filter_combiner.cpp +1 -1
  103. package/src/duckdb/src/optimizer/join_order/join_order_optimizer.cpp +3 -3
  104. package/src/duckdb/src/optimizer/rule/move_constants.cpp +2 -2
  105. package/src/duckdb/src/optimizer/statistics/operator/propagate_filter.cpp +1 -1
  106. package/src/duckdb/src/parser/common_table_expression_info.cpp +19 -0
  107. package/src/duckdb/src/parser/expression/between_expression.cpp +17 -0
  108. package/src/duckdb/src/parser/expression/case_expression.cpp +28 -0
  109. package/src/duckdb/src/parser/expression/cast_expression.cpp +17 -0
  110. package/src/duckdb/src/parser/expression/collate_expression.cpp +16 -0
  111. package/src/duckdb/src/parser/expression/columnref_expression.cpp +15 -0
  112. package/src/duckdb/src/parser/expression/comparison_expression.cpp +16 -0
  113. package/src/duckdb/src/parser/expression/conjunction_expression.cpp +15 -0
  114. package/src/duckdb/src/parser/expression/constant_expression.cpp +14 -0
  115. package/src/duckdb/src/parser/expression/default_expression.cpp +7 -0
  116. package/src/duckdb/src/parser/expression/function_expression.cpp +35 -0
  117. package/src/duckdb/src/parser/expression/lambda_expression.cpp +16 -0
  118. package/src/duckdb/src/parser/expression/operator_expression.cpp +15 -0
  119. package/src/duckdb/src/parser/expression/parameter_expression.cpp +15 -0
  120. package/src/duckdb/src/parser/expression/positional_reference_expression.cpp +14 -0
  121. package/src/duckdb/src/parser/expression/star_expression.cpp +20 -0
  122. package/src/duckdb/src/parser/expression/subquery_expression.cpp +20 -0
  123. package/src/duckdb/src/parser/expression/window_expression.cpp +43 -0
  124. package/src/duckdb/src/parser/parsed_data/sample_options.cpp +22 -10
  125. package/src/duckdb/src/parser/parsed_expression.cpp +72 -0
  126. package/src/duckdb/src/parser/query_node/recursive_cte_node.cpp +21 -0
  127. package/src/duckdb/src/parser/query_node/select_node.cpp +31 -0
  128. package/src/duckdb/src/parser/query_node/set_operation_node.cpp +17 -0
  129. package/src/duckdb/src/parser/query_node.cpp +50 -0
  130. package/src/duckdb/src/parser/result_modifier.cpp +78 -0
  131. package/src/duckdb/src/parser/statement/select_statement.cpp +12 -0
  132. package/src/duckdb/src/parser/tableref/basetableref.cpp +21 -0
  133. package/src/duckdb/src/parser/tableref/emptytableref.cpp +4 -0
  134. package/src/duckdb/src/parser/tableref/expressionlistref.cpp +17 -0
  135. package/src/duckdb/src/parser/tableref/joinref.cpp +25 -0
  136. package/src/duckdb/src/parser/tableref/pivotref.cpp +53 -0
  137. package/src/duckdb/src/parser/tableref/subqueryref.cpp +15 -0
  138. package/src/duckdb/src/parser/tableref/table_function.cpp +17 -0
  139. package/src/duckdb/src/parser/tableref.cpp +46 -0
  140. package/src/duckdb/src/parser/transform/expression/transform_array_access.cpp +11 -0
  141. package/src/duckdb/src/parser/transform/expression/transform_bool_expr.cpp +1 -1
  142. package/src/duckdb/src/parser/transform/expression/transform_operator.cpp +1 -1
  143. package/src/duckdb/src/parser/transform/expression/transform_subquery.cpp +1 -1
  144. package/src/duckdb/src/planner/binder/expression/bind_function_expression.cpp +22 -4
  145. package/src/duckdb/src/planner/binder/expression/bind_subquery_expression.cpp +4 -0
  146. package/src/duckdb/src/planner/binder/tableref/plan_joinref.cpp +1 -1
  147. package/src/duckdb/src/planner/expression/bound_expression.cpp +4 -0
  148. package/src/duckdb/src/storage/checkpoint/table_data_reader.cpp +3 -11
  149. package/src/duckdb/src/storage/checkpoint/table_data_writer.cpp +6 -0
  150. package/src/duckdb/src/storage/checkpoint_manager.cpp +1 -0
  151. package/src/duckdb/src/storage/compression/numeric_constant.cpp +2 -2
  152. package/src/duckdb/src/storage/data_table.cpp +1 -1
  153. package/src/duckdb/src/storage/statistics/numeric_stats.cpp +145 -83
  154. package/src/duckdb/src/storage/statistics/numeric_stats_union.cpp +65 -0
  155. package/src/duckdb/src/storage/storage_info.cpp +1 -1
  156. package/src/duckdb/src/storage/table/column_checkpoint_state.cpp +1 -6
  157. package/src/duckdb/src/storage/table/column_data.cpp +29 -35
  158. package/src/duckdb/src/storage/table/column_data_checkpointer.cpp +5 -5
  159. package/src/duckdb/src/storage/table/column_segment.cpp +8 -7
  160. package/src/duckdb/src/storage/table/list_column_data.cpp +2 -1
  161. package/src/duckdb/src/storage/table/persistent_table_data.cpp +2 -1
  162. package/src/duckdb/src/storage/table/row_group.cpp +9 -9
  163. package/src/duckdb/src/storage/table/row_group_collection.cpp +82 -66
  164. package/src/duckdb/src/storage/table/scan_state.cpp +22 -3
  165. package/src/duckdb/src/storage/table/standard_column_data.cpp +1 -0
  166. package/src/duckdb/src/storage/table/struct_column_data.cpp +1 -0
  167. package/src/duckdb/src/verification/deserialized_statement_verifier.cpp +0 -1
  168. package/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp +11780 -11512
  169. package/src/duckdb/third_party/re2/re2/re2.cc +9 -0
  170. package/src/duckdb/third_party/re2/re2/re2.h +2 -0
  171. package/src/duckdb/ub_extension_json_json_functions.cpp +2 -0
  172. package/src/duckdb/ub_src_common_serializer.cpp +2 -0
  173. package/src/duckdb/ub_src_function_scalar_string_regexp.cpp +4 -0
  174. package/src/duckdb/ub_src_parser.cpp +2 -0
  175. package/src/duckdb/ub_src_storage_statistics.cpp +2 -0
  176. package/src/duckdb/ub_src_storage_table.cpp +0 -2
  177. package/src/utils.cpp +12 -0
  178. package/test/extension.test.ts +44 -26
  179. package/src/duckdb/src/storage/table/segment_tree.cpp +0 -179
@@ -566,6 +566,15 @@ static int ascii_strcasecmp(const char* a, const char* b, size_t len) {
566
566
  return 0;
567
567
  }
568
568
 
569
+ RE2::Anchor RE2::Anchored() const {
570
+ if (prog_->anchor_start()) {
571
+ if (prog_->anchor_end()) {
572
+ return Anchor::ANCHOR_BOTH;
573
+ }
574
+ return Anchor::ANCHOR_START;
575
+ }
576
+ return Anchor::UNANCHORED;
577
+ }
569
578
 
570
579
  /***** Actual matching and rewriting code *****/
571
580
 
@@ -475,6 +475,8 @@ class RE2 {
475
475
  ANCHOR_BOTH // Anchor at start and end
476
476
  };
477
477
 
478
+ Anchor Anchored() const;
479
+
478
480
  // Return the number of capturing subpatterns, or -1 if the
479
481
  // regexp wasn't valid on construction. The overall match ($0)
480
482
  // does not count: if the regexp is "(a)(b)", returns 2.
@@ -20,6 +20,8 @@
20
20
 
21
21
  #include "extension/json/json_functions/json_valid.cpp"
22
22
 
23
+ #include "extension/json/json_functions/json_serialize_sql.cpp"
24
+
23
25
  #include "extension/json/json_functions/read_json.cpp"
24
26
 
25
27
  #include "extension/json/json_functions/read_json_objects.cpp"
@@ -6,3 +6,5 @@
6
6
 
7
7
  #include "src/common/serializer/buffered_serializer.cpp"
8
8
 
9
+ #include "src/common/serializer/enum_serializer.cpp"
10
+
@@ -0,0 +1,4 @@
1
+ #include "src/function/scalar/string/regexp/regexp_util.cpp"
2
+
3
+ #include "src/function/scalar/string/regexp/regexp_extract_all.cpp"
4
+
@@ -6,6 +6,8 @@
6
6
 
7
7
  #include "src/parser/constraint.cpp"
8
8
 
9
+ #include "src/parser/common_table_expression_info.cpp"
10
+
9
11
  #include "src/parser/expression_util.cpp"
10
12
 
11
13
  #include "src/parser/keyword_helper.cpp"
@@ -8,6 +8,8 @@
8
8
 
9
9
  #include "src/storage/statistics/numeric_stats.cpp"
10
10
 
11
+ #include "src/storage/statistics/numeric_stats_union.cpp"
12
+
11
13
  #include "src/storage/statistics/segment_statistics.cpp"
12
14
 
13
15
  #include "src/storage/statistics/string_stats.cpp"
@@ -14,8 +14,6 @@
14
14
 
15
15
  #include "src/storage/table/persistent_table_data.cpp"
16
16
 
17
- #include "src/storage/table/segment_tree.cpp"
18
-
19
17
  #include "src/storage/table/row_group.cpp"
20
18
 
21
19
  #include "src/storage/table/row_group_collection.cpp"
package/src/utils.cpp CHANGED
@@ -18,6 +18,18 @@ static void SetString(Napi::Object &obj, const std::string &key, const std::stri
18
18
 
19
19
  Napi::Object Utils::CreateError(Napi::Env env, duckdb::PreservedError &error) {
20
20
  auto obj = Utils::CreateError(env, error.Message());
21
+ if (error.Type() == duckdb::ExceptionType::HTTP) {
22
+ const auto &e = error.GetError()->AsHTTPException();
23
+ obj.Set(Napi::String::New(env, "statusCode"), Napi::Number::New(env, e.GetStatusCode()));
24
+ SetString(obj, "response", e.GetResponseBody());
25
+ SetString(obj, "reason", e.GetReason());
26
+
27
+ auto headers = Napi::Object::New(env);
28
+ for (const auto &item : e.GetHeaders()) {
29
+ SetString(headers, item.first, item.second);
30
+ }
31
+ obj.Set(Napi::String::New(env, "headers"), headers);
32
+ }
21
33
 
22
34
  SetString(obj, "errorType", duckdb::Exception::ExceptionTypeToString(error.Type()));
23
35
 
@@ -1,9 +1,8 @@
1
1
  import * as duckdb from '..';
2
- import {Database, TableData} from '..';
2
+ import {Database, DuckDbError, HttpError, TableData} from '..';
3
3
  import * as fs from 'fs';
4
4
  import * as assert from 'assert';
5
5
  import * as path from 'path';
6
- import {Done} from "mocha";
7
6
 
8
7
  const extension_base_path = "../../../build/release/extension";
9
8
 
@@ -21,46 +20,63 @@ if (fs.existsSync(extension_full_path)) {
21
20
  }).filter(a => a) as string[];
22
21
  }
23
22
 
23
+ function isHTTPException(err: DuckDbError): err is HttpError {
24
+ return err.errorType === 'HTTP';
25
+ }
26
+
24
27
  // Note: test will pass on http request failing due to connection issues.
25
- const test_httpfs = async function (db: duckdb.Database, done: Done) {
26
- db.all("SELECT id, first_name, last_name FROM PARQUET_SCAN('https://raw.githubusercontent.com/cwida/duckdb/master/data/parquet-testing/userdata1.parquet') LIMIT 3;", function(err: null | Error, rows: TableData) {
28
+ const test_httpfs = async function (db: duckdb.Database) {
29
+ await new Promise<void>((resolve, reject) => db.all("SELECT id, first_name, last_name FROM PARQUET_SCAN('https://raw.githubusercontent.com/cwida/duckdb/master/data/parquet-testing/userdata1.parquet') LIMIT 3;", function (err: null | Error, rows: TableData) {
27
30
  if (err) {
28
31
  if (err.message.startsWith("Unable to connect to URL")) {
29
32
  console.warn("Warning: HTTP request failed in extension.test.js");
30
- done();
33
+ resolve();
31
34
  } else {
32
- throw err;
35
+ reject(err);
33
36
  }
34
37
  } else {
35
38
  assert.deepEqual(rows, [
36
- { id: 1, first_name: 'Amanda', last_name: 'Jordan'},
37
- { id: 2, first_name: 'Albert', last_name: 'Freeman'},
38
- { id: 3, first_name: 'Evelyn', last_name: 'Morgan'},
39
+ {id: 1, first_name: 'Amanda', last_name: 'Jordan'},
40
+ {id: 2, first_name: 'Albert', last_name: 'Freeman'},
41
+ {id: 3, first_name: 'Evelyn', last_name: 'Morgan'},
39
42
  ]);
40
- done();
43
+ resolve();
41
44
  }
42
- });
45
+ }));
46
+
47
+ await new Promise<void>((resolve) => {
48
+ db.exec("select * from read_csv_auto('https://example.com/hello.csv')", (err: DuckDbError | null) => {
49
+ assert.ok(err);
50
+ assert.ok(isHTTPException(err));
51
+ if (isHTTPException(err)) {
52
+ assert.equal(err.statusCode, 404);
53
+ assert.equal(err.reason, 'Not Found');
54
+ assert.equal(err.response, '');
55
+ assert.ok('Content-Length' in err.headers, JSON.stringify(err.headers));
56
+ }
57
+ resolve();
58
+ });
59
+ })
43
60
  };
44
61
 
45
- const test_tpch = async function (db: Database, done:Done) {
46
- db.all("CALL DBGEN(sf=0.01);", function(err: null | Error) {
62
+ const test_tpch = async function (db: Database) {
63
+ await new Promise<void>((resolve, reject) => db.all("CALL DBGEN(sf=0.01);", function (err: null | Error) {
47
64
  if (err) {
48
- throw err;
65
+ reject(err);
49
66
  }
50
- done();
51
- });
67
+ resolve();
68
+ }));
52
69
  };
53
70
 
54
- const test_extension = function(extension_name: string, db: duckdb.Database, done: Done) {
55
- switch(extension_name) {
71
+ const test_extension = async function (extension_name: string, db: duckdb.Database) {
72
+ switch (extension_name) {
56
73
  case 'httpfs.duckdb_extension':
57
- test_httpfs(db, done);
74
+ await test_httpfs(db);
58
75
  break;
59
76
  case 'tpch.duckdb_extension':
60
- test_tpch(db, done);
77
+ await test_tpch(db);
61
78
  break;
62
79
  default:
63
- done();
64
80
  break;
65
81
  }
66
82
  };
@@ -79,13 +95,15 @@ describe('Extension loading', function() {
79
95
  continue;
80
96
  }
81
97
 
82
- it(extension_name, function(done) {
83
- db.run(`LOAD '${extension_path}';`, function(err: null | Error) {
98
+ it(extension_name, async function () {
99
+ await new Promise<void>((resolve, reject) => db.run(`LOAD '${extension_path}';`, function (err: null | Error) {
84
100
  if (err) {
85
- throw err;
101
+ reject(err);
86
102
  }
87
- test_extension(extension_name, db, done);
88
- });
103
+ resolve()
104
+ }));
105
+
106
+ await test_extension(extension_name, db);
89
107
  });
90
108
  }
91
109
  });
@@ -1,179 +0,0 @@
1
- #include "duckdb/storage/table/segment_tree.hpp"
2
- #include "duckdb/common/exception.hpp"
3
- #include "duckdb/common/string_util.hpp"
4
-
5
- namespace duckdb {
6
-
7
- SegmentLock SegmentTree::Lock() {
8
- return SegmentLock(node_lock);
9
- }
10
-
11
- bool SegmentTree::IsEmpty(SegmentLock &) {
12
- return nodes.empty();
13
- }
14
-
15
- SegmentBase *SegmentTree::GetRootSegment(SegmentLock &l) {
16
- return nodes.empty() ? nullptr : nodes[0].node.get();
17
- }
18
-
19
- vector<SegmentNode> SegmentTree::MoveSegments(SegmentLock &) {
20
- return std::move(nodes);
21
- }
22
-
23
- SegmentBase *SegmentTree::GetRootSegment() {
24
- auto l = Lock();
25
- return GetRootSegment(l);
26
- }
27
-
28
- SegmentBase *SegmentTree::GetSegmentByIndex(SegmentLock &, int64_t index) {
29
- if (index < 0) {
30
- index = nodes.size() + index;
31
- if (index < 0) {
32
- return nullptr;
33
- }
34
- return nodes[index].node.get();
35
- } else {
36
- if (idx_t(index) >= nodes.size()) {
37
- return nullptr;
38
- }
39
- return nodes[index].node.get();
40
- }
41
- }
42
- SegmentBase *SegmentTree::GetSegmentByIndex(int64_t index) {
43
- auto l = Lock();
44
- return GetSegmentByIndex(l, index);
45
- }
46
-
47
- SegmentBase *SegmentTree::GetLastSegment(SegmentLock &l) {
48
- if (nodes.empty()) {
49
- return nullptr;
50
- }
51
- return nodes.back().node.get();
52
- }
53
-
54
- SegmentBase *SegmentTree::GetLastSegment() {
55
- auto l = Lock();
56
- return GetLastSegment(l);
57
- }
58
-
59
- SegmentBase *SegmentTree::GetSegment(SegmentLock &l, idx_t row_number) {
60
- return nodes[GetSegmentIndex(l, row_number)].node.get();
61
- }
62
-
63
- SegmentBase *SegmentTree::GetSegment(idx_t row_number) {
64
- auto l = Lock();
65
- return GetSegment(l, row_number);
66
- }
67
-
68
- bool SegmentTree::TryGetSegmentIndex(SegmentLock &, idx_t row_number, idx_t &result) {
69
- if (nodes.empty()) {
70
- return false;
71
- }
72
- D_ASSERT(!nodes.empty());
73
- D_ASSERT(row_number >= nodes[0].row_start);
74
- D_ASSERT(row_number < nodes.back().row_start + nodes.back().node->count);
75
- idx_t lower = 0;
76
- idx_t upper = nodes.size() - 1;
77
- // binary search to find the node
78
- while (lower <= upper) {
79
- idx_t index = (lower + upper) / 2;
80
- D_ASSERT(index < nodes.size());
81
- auto &entry = nodes[index];
82
- D_ASSERT(entry.row_start == entry.node->start);
83
- if (row_number < entry.row_start) {
84
- upper = index - 1;
85
- } else if (row_number >= entry.row_start + entry.node->count) {
86
- lower = index + 1;
87
- } else {
88
- result = index;
89
- return true;
90
- }
91
- }
92
- return false;
93
- }
94
-
95
- idx_t SegmentTree::GetSegmentIndex(SegmentLock &l, idx_t row_number) {
96
- idx_t segment_index;
97
- if (TryGetSegmentIndex(l, row_number, segment_index)) {
98
- return segment_index;
99
- }
100
- string error;
101
- error = StringUtil::Format("Attempting to find row number \"%lld\" in %lld nodes\n", row_number, nodes.size());
102
- for (idx_t i = 0; i < nodes.size(); i++) {
103
- error +=
104
- StringUtil::Format("Node %lld: Start %lld, Count %lld", i, nodes[i].row_start, nodes[i].node->count.load());
105
- }
106
- throw InternalException("Could not find node in column segment tree!\n%s%s", error, Exception::GetStackTrace());
107
- }
108
-
109
- idx_t SegmentTree::GetSegmentIndex(idx_t row_number) {
110
- auto l = Lock();
111
- return GetSegmentIndex(l, row_number);
112
- }
113
-
114
- bool SegmentTree::HasSegment(SegmentLock &, SegmentBase *segment) {
115
- for (auto &node : nodes) {
116
- if (node.node.get() == segment) {
117
- return true;
118
- }
119
- }
120
- return false;
121
- }
122
-
123
- bool SegmentTree::HasSegment(SegmentBase *segment) {
124
- auto l = Lock();
125
- return HasSegment(l, segment);
126
- }
127
-
128
- void SegmentTree::AppendSegment(SegmentLock &, unique_ptr<SegmentBase> segment) {
129
- D_ASSERT(segment);
130
- // add the node to the list of nodes
131
- if (!nodes.empty()) {
132
- nodes.back().node->next = segment.get();
133
- }
134
- SegmentNode node;
135
- node.row_start = segment->start;
136
- node.node = std::move(segment);
137
- nodes.push_back(std::move(node));
138
- }
139
-
140
- void SegmentTree::AppendSegment(unique_ptr<SegmentBase> segment) {
141
- auto l = Lock();
142
- AppendSegment(l, std::move(segment));
143
- }
144
-
145
- void SegmentTree::EraseSegments(SegmentLock &, idx_t segment_start) {
146
- if (segment_start >= nodes.size() - 1) {
147
- return;
148
- }
149
- nodes.erase(nodes.begin() + segment_start + 1, nodes.end());
150
- }
151
-
152
- void SegmentTree::Replace(SegmentLock &, SegmentTree &other) {
153
- nodes = std::move(other.nodes);
154
- }
155
-
156
- void SegmentTree::Replace(SegmentTree &other) {
157
- auto l = Lock();
158
- Replace(l, other);
159
- }
160
-
161
- void SegmentTree::Verify(SegmentLock &) {
162
- #ifdef DEBUG
163
- idx_t base_start = nodes.empty() ? 0 : nodes[0].node->start;
164
- for (idx_t i = 0; i < nodes.size(); i++) {
165
- D_ASSERT(nodes[i].row_start == nodes[i].node->start);
166
- D_ASSERT(nodes[i].node->start == base_start);
167
- base_start += nodes[i].node->count;
168
- }
169
- #endif
170
- }
171
-
172
- void SegmentTree::Verify() {
173
- #ifdef DEBUG
174
- auto l = Lock();
175
- Verify(l);
176
- #endif
177
- }
178
-
179
- } // namespace duckdb