duckdb 0.7.2-dev14.0 → 0.7.2-dev225.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 (129) hide show
  1. package/binding.gyp +2 -0
  2. package/package.json +1 -1
  3. package/src/duckdb/extension/icu/icu-extension.cpp +2 -0
  4. package/src/duckdb/extension/icu/icu-table-range.cpp +194 -0
  5. package/src/duckdb/extension/icu/include/icu-table-range.hpp +17 -0
  6. package/src/duckdb/extension/parquet/column_writer.cpp +0 -1
  7. package/src/duckdb/extension/parquet/parquet-extension.cpp +11 -2
  8. package/src/duckdb/src/catalog/catalog_entry/duck_schema_entry.cpp +4 -0
  9. package/src/duckdb/src/catalog/catalog_entry/scalar_function_catalog_entry.cpp +7 -6
  10. package/src/duckdb/src/catalog/catalog_entry/table_function_catalog_entry.cpp +20 -1
  11. package/src/duckdb/src/common/enums/statement_type.cpp +2 -0
  12. package/src/duckdb/src/common/types/bit.cpp +95 -58
  13. package/src/duckdb/src/common/types/value.cpp +149 -53
  14. package/src/duckdb/src/common/types/vector.cpp +13 -10
  15. package/src/duckdb/src/execution/operator/persistent/buffered_csv_reader.cpp +1 -1
  16. package/src/duckdb/src/function/aggregate/algebraic/avg.cpp +0 -6
  17. package/src/duckdb/src/function/aggregate/distributive/bitagg.cpp +99 -95
  18. package/src/duckdb/src/function/aggregate/distributive/bitstring_agg.cpp +261 -0
  19. package/src/duckdb/src/function/aggregate/distributive/sum.cpp +0 -3
  20. package/src/duckdb/src/function/aggregate/distributive_functions.cpp +1 -0
  21. package/src/duckdb/src/function/aggregate/sorted_aggregate_function.cpp +16 -5
  22. package/src/duckdb/src/function/cast/bit_cast.cpp +0 -2
  23. package/src/duckdb/src/function/cast/blob_cast.cpp +0 -1
  24. package/src/duckdb/src/function/scalar/bit/bitstring.cpp +99 -0
  25. package/src/duckdb/src/function/scalar/map/map_entries.cpp +61 -0
  26. package/src/duckdb/src/function/scalar/map/map_keys_values.cpp +97 -0
  27. package/src/duckdb/src/function/scalar/nested_functions.cpp +3 -0
  28. package/src/duckdb/src/function/scalar/operators/add.cpp +0 -9
  29. package/src/duckdb/src/function/scalar/operators/arithmetic.cpp +2 -14
  30. package/src/duckdb/src/function/scalar/operators/bitwise.cpp +0 -63
  31. package/src/duckdb/src/function/scalar/operators/multiply.cpp +0 -6
  32. package/src/duckdb/src/function/scalar/operators/subtract.cpp +0 -6
  33. package/src/duckdb/src/function/scalar/string_functions.cpp +1 -0
  34. package/src/duckdb/src/function/table/read_csv.cpp +9 -0
  35. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  36. package/src/duckdb/src/function/table_function.cpp +19 -0
  37. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_function_catalog_entry.hpp +6 -8
  38. package/src/duckdb/src/include/duckdb/common/constants.hpp +0 -19
  39. package/src/duckdb/src/include/duckdb/common/enums/statement_type.hpp +2 -1
  40. package/src/duckdb/src/include/duckdb/common/enums/tableref_type.hpp +2 -1
  41. package/src/duckdb/src/include/duckdb/common/types/bit.hpp +5 -1
  42. package/src/duckdb/src/include/duckdb/common/types/value.hpp +2 -8
  43. package/src/duckdb/src/include/duckdb/common/types.hpp +1 -2
  44. package/src/duckdb/src/include/duckdb/function/aggregate/distributive_functions.hpp +5 -0
  45. package/src/duckdb/src/include/duckdb/function/scalar/bit_functions.hpp +4 -0
  46. package/src/duckdb/src/include/duckdb/function/scalar/nested_functions.hpp +12 -0
  47. package/src/duckdb/src/include/duckdb/function/table_function.hpp +2 -0
  48. package/src/duckdb/src/include/duckdb/main/capi/capi_internal.hpp +2 -0
  49. package/src/duckdb/src/include/duckdb/main/config.hpp +3 -0
  50. package/src/duckdb/src/include/duckdb/main/database.hpp +1 -0
  51. package/src/duckdb/src/include/duckdb/optimizer/join_order/cardinality_estimator.hpp +2 -2
  52. package/src/duckdb/src/include/duckdb/parser/common_table_expression_info.hpp +2 -0
  53. package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_info.hpp +2 -1
  54. package/src/duckdb/src/include/duckdb/parser/parsed_data/{alter_function_info.hpp → alter_scalar_function_info.hpp} +13 -13
  55. package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_table_function_info.hpp +47 -0
  56. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_table_function_info.hpp +2 -1
  57. package/src/duckdb/src/include/duckdb/parser/query_node.hpp +2 -1
  58. package/src/duckdb/src/include/duckdb/parser/statement/multi_statement.hpp +28 -0
  59. package/src/duckdb/src/include/duckdb/parser/tableref/list.hpp +1 -0
  60. package/src/duckdb/src/include/duckdb/parser/tableref/pivotref.hpp +76 -0
  61. package/src/duckdb/src/include/duckdb/parser/tokens.hpp +2 -0
  62. package/src/duckdb/src/include/duckdb/parser/transformer.hpp +28 -0
  63. package/src/duckdb/src/include/duckdb/planner/binder.hpp +8 -0
  64. package/src/duckdb/src/include/duckdb/storage/buffer/block_handle.hpp +2 -0
  65. package/src/duckdb/src/include/duckdb/storage/buffer_manager.hpp +76 -44
  66. package/src/duckdb/src/include/duckdb/storage/statistics/base_statistics.hpp +2 -0
  67. package/src/duckdb/src/include/duckdb/storage/statistics/node_statistics.hpp +26 -0
  68. package/src/duckdb/src/include/duckdb/storage/table/list_column_data.hpp +1 -1
  69. package/src/duckdb/src/include/duckdb/storage/table/scan_state.hpp +2 -0
  70. package/src/duckdb/src/include/duckdb.h +49 -1
  71. package/src/duckdb/src/include/duckdb.hpp +0 -1
  72. package/src/duckdb/src/main/capi/pending-c.cpp +16 -3
  73. package/src/duckdb/src/main/capi/result-c.cpp +27 -1
  74. package/src/duckdb/src/main/capi/stream-c.cpp +25 -0
  75. package/src/duckdb/src/main/client_context.cpp +8 -1
  76. package/src/duckdb/src/main/database.cpp +10 -2
  77. package/src/duckdb/src/optimizer/join_order/cardinality_estimator.cpp +98 -66
  78. package/src/duckdb/src/optimizer/join_order/join_order_optimizer.cpp +16 -3
  79. package/src/duckdb/src/parser/parsed_data/alter_info.cpp +7 -3
  80. package/src/duckdb/src/parser/parsed_data/alter_scalar_function_info.cpp +56 -0
  81. package/src/duckdb/src/parser/parsed_data/alter_table_function_info.cpp +51 -0
  82. package/src/duckdb/src/parser/parsed_data/create_scalar_function_info.cpp +3 -2
  83. package/src/duckdb/src/parser/parsed_data/create_table_function_info.cpp +6 -0
  84. package/src/duckdb/src/parser/parsed_expression_iterator.cpp +8 -0
  85. package/src/duckdb/src/parser/query_node.cpp +1 -1
  86. package/src/duckdb/src/parser/statement/multi_statement.cpp +18 -0
  87. package/src/duckdb/src/parser/tableref/pivotref.cpp +296 -0
  88. package/src/duckdb/src/parser/tableref.cpp +3 -0
  89. package/src/duckdb/src/parser/transform/helpers/transform_alias.cpp +12 -6
  90. package/src/duckdb/src/parser/transform/helpers/transform_cte.cpp +24 -0
  91. package/src/duckdb/src/parser/transform/statement/transform_create_function.cpp +4 -0
  92. package/src/duckdb/src/parser/transform/statement/transform_create_view.cpp +4 -0
  93. package/src/duckdb/src/parser/transform/statement/transform_pivot_stmt.cpp +150 -0
  94. package/src/duckdb/src/parser/transform/statement/transform_select.cpp +8 -0
  95. package/src/duckdb/src/parser/transform/statement/transform_select_node.cpp +1 -1
  96. package/src/duckdb/src/parser/transform/tableref/transform_pivot.cpp +105 -0
  97. package/src/duckdb/src/parser/transform/tableref/transform_tableref.cpp +2 -0
  98. package/src/duckdb/src/parser/transformer.cpp +15 -3
  99. package/src/duckdb/src/planner/binder/query_node/bind_select_node.cpp +11 -3
  100. package/src/duckdb/src/planner/binder/statement/bind_create.cpp +1 -1
  101. package/src/duckdb/src/planner/binder/statement/bind_logical_plan.cpp +17 -0
  102. package/src/duckdb/src/planner/binder/tableref/bind_pivot.cpp +365 -0
  103. package/src/duckdb/src/planner/binder.cpp +5 -0
  104. package/src/duckdb/src/planner/pragma_handler.cpp +10 -2
  105. package/src/duckdb/src/storage/buffer_manager.cpp +44 -46
  106. package/src/duckdb/src/storage/compression/bitpacking.cpp +25 -21
  107. package/src/duckdb/src/storage/compression/fixed_size_uncompressed.cpp +41 -43
  108. package/src/duckdb/src/storage/compression/rle.cpp +17 -13
  109. package/src/duckdb/src/storage/statistics/base_statistics.cpp +3 -3
  110. package/src/duckdb/src/storage/storage_info.cpp +1 -1
  111. package/src/duckdb/src/storage/table/column_data.cpp +5 -2
  112. package/src/duckdb/src/storage/table/list_column_data.cpp +32 -47
  113. package/src/duckdb/third_party/libpg_query/include/nodes/nodes.hpp +3 -0
  114. package/src/duckdb/third_party/libpg_query/include/nodes/parsenodes.hpp +34 -1
  115. package/src/duckdb/third_party/libpg_query/include/parser/gram.hpp +1016 -530
  116. package/src/duckdb/third_party/libpg_query/include/parser/kwlist.hpp +5 -0
  117. package/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp +22697 -21987
  118. package/src/duckdb/ub_src_function_aggregate_distributive.cpp +2 -0
  119. package/src/duckdb/ub_src_function_scalar_bit.cpp +2 -0
  120. package/src/duckdb/ub_src_function_scalar_map.cpp +4 -0
  121. package/src/duckdb/ub_src_main_capi.cpp +2 -0
  122. package/src/duckdb/ub_src_parser_parsed_data.cpp +4 -2
  123. package/src/duckdb/ub_src_parser_statement.cpp +2 -0
  124. package/src/duckdb/ub_src_parser_tableref.cpp +2 -0
  125. package/src/duckdb/ub_src_parser_transform_statement.cpp +2 -0
  126. package/src/duckdb/ub_src_parser_transform_tableref.cpp +2 -0
  127. package/src/duckdb/ub_src_planner_binder_tableref.cpp +2 -0
  128. package/src/duckdb/src/include/duckdb/main/loadable_extension.hpp +0 -59
  129. package/src/duckdb/src/parser/parsed_data/alter_function_info.cpp +0 -55
package/binding.gyp CHANGED
@@ -57,6 +57,7 @@
57
57
  "src/duckdb/ub_src_function.cpp",
58
58
  "src/duckdb/ub_src_function_cast.cpp",
59
59
  "src/duckdb/ub_src_function_pragma.cpp",
60
+ "src/duckdb/ub_src_function_scalar_bit.cpp",
60
61
  "src/duckdb/ub_src_function_scalar_blob.cpp",
61
62
  "src/duckdb/ub_src_function_scalar_date.cpp",
62
63
  "src/duckdb/ub_src_function_scalar.cpp",
@@ -223,6 +224,7 @@
223
224
  "src/duckdb/third_party/zstd/compress/zstd_ldm.cpp",
224
225
  "src/duckdb/third_party/zstd/compress/zstd_opt.cpp",
225
226
  "src/duckdb/extension/icu/./icu-dateadd.cpp",
227
+ "src/duckdb/extension/icu/./icu-table-range.cpp",
226
228
  "src/duckdb/extension/icu/./icu-datetrunc.cpp",
227
229
  "src/duckdb/extension/icu/./icu-strptime.cpp",
228
230
  "src/duckdb/extension/icu/./icu-datefunc.cpp",
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.7.2-dev14.0",
5
+ "version": "0.7.2-dev225.0",
6
6
  "description": "DuckDB node.js API",
7
7
  "gypfile": true,
8
8
  "dependencies": {
@@ -13,6 +13,7 @@
13
13
  #include "include/icu-datesub.hpp"
14
14
  #include "include/icu-datetrunc.hpp"
15
15
  #include "include/icu-makedate.hpp"
16
+ #include "include/icu-table-range.hpp"
16
17
  #include "include/icu-strptime.hpp"
17
18
  #include "include/icu-timebucket.hpp"
18
19
  #include "include/icu-timezone.hpp"
@@ -266,6 +267,7 @@ void ICUExtension::Load(DuckDB &db) {
266
267
  RegisterICUDateSubFunctions(*con.context);
267
268
  RegisterICUDateTruncFunctions(*con.context);
268
269
  RegisterICUMakeDateFunctions(*con.context);
270
+ RegisterICUTableRangeFunctions(*con.context);
269
271
  RegisterICUStrptimeFunctions(*con.context);
270
272
  RegisterICUTimeBucketFunctions(*con.context);
271
273
  RegisterICUTimeZoneFunctions(*con.context);
@@ -0,0 +1,194 @@
1
+ #include "duckdb/common/exception.hpp"
2
+ #include "duckdb/common/types/interval.hpp"
3
+ #include "duckdb/common/types/timestamp.hpp"
4
+ #include "duckdb/function/function_set.hpp"
5
+ #include "duckdb/function/table_function.hpp"
6
+ #include "duckdb/parser/parsed_data/create_table_function_info.hpp"
7
+ #include "include/icu-datefunc.hpp"
8
+ #include "unicode/calendar.h"
9
+
10
+ namespace duckdb {
11
+
12
+ struct ICUTableRange {
13
+ using CalendarPtr = unique_ptr<icu::Calendar>;
14
+
15
+ struct BindData : public TableFunctionData {
16
+ explicit BindData(const BindData &other)
17
+ : tz_setting(other.tz_setting), cal_setting(other.cal_setting), calendar(other.calendar->clone()),
18
+ start(other.start), end(other.end), increment(other.increment), inclusive_bound(other.inclusive_bound),
19
+ greater_than_check(other.greater_than_check) {
20
+ }
21
+
22
+ BindData(ClientContext &context) {
23
+ Value tz_value;
24
+ if (context.TryGetCurrentSetting("TimeZone", tz_value)) {
25
+ tz_setting = tz_value.ToString();
26
+ }
27
+ auto tz = icu::TimeZone::createTimeZone(icu::UnicodeString::fromUTF8(icu::StringPiece(tz_setting)));
28
+
29
+ string cal_id("@calendar=");
30
+ Value cal_value;
31
+ if (context.TryGetCurrentSetting("Calendar", cal_value)) {
32
+ cal_setting = cal_value.ToString();
33
+ cal_id += cal_setting;
34
+ } else {
35
+ cal_id += "gregorian";
36
+ }
37
+
38
+ icu::Locale locale(cal_id.c_str());
39
+
40
+ UErrorCode success = U_ZERO_ERROR;
41
+ calendar.reset(icu::Calendar::createInstance(tz, locale, success));
42
+ if (U_FAILURE(success)) {
43
+ throw Exception("Unable to create ICU calendar.");
44
+ }
45
+ }
46
+
47
+ string tz_setting;
48
+ string cal_setting;
49
+ CalendarPtr calendar;
50
+
51
+ timestamp_t start;
52
+ timestamp_t end;
53
+ interval_t increment;
54
+ bool inclusive_bound;
55
+ bool greater_than_check;
56
+
57
+ bool Equals(const FunctionData &other_p) const {
58
+ auto &other = (const BindData &)other_p;
59
+ return other.start == start && other.end == end && other.increment == increment &&
60
+ other.inclusive_bound == inclusive_bound && other.greater_than_check == greater_than_check &&
61
+ *calendar == *other.calendar;
62
+ }
63
+
64
+ unique_ptr<FunctionData> Copy() const {
65
+ return make_unique<BindData>(*this);
66
+ }
67
+
68
+ bool Finished(timestamp_t current_value) {
69
+ if (greater_than_check) {
70
+ if (inclusive_bound) {
71
+ return current_value > end;
72
+ } else {
73
+ return current_value >= end;
74
+ }
75
+ } else {
76
+ if (inclusive_bound) {
77
+ return current_value < end;
78
+ } else {
79
+ return current_value <= end;
80
+ }
81
+ }
82
+ }
83
+ };
84
+
85
+ template <bool GENERATE_SERIES>
86
+ static unique_ptr<FunctionData> Bind(ClientContext &context, TableFunctionBindInput &input,
87
+ vector<LogicalType> &return_types, vector<string> &names) {
88
+ auto result = make_unique<BindData>(context);
89
+
90
+ auto &inputs = input.inputs;
91
+ D_ASSERT(inputs.size() == 3);
92
+ result->start = inputs[0].GetValue<timestamp_t>();
93
+ result->end = inputs[1].GetValue<timestamp_t>();
94
+ result->increment = inputs[2].GetValue<interval_t>();
95
+
96
+ // Infinities either cause errors or infinite loops, so just ban them
97
+ if (!Timestamp::IsFinite(result->start) || !Timestamp::IsFinite(result->end)) {
98
+ throw BinderException("RANGE with infinite bounds is not supported");
99
+ }
100
+
101
+ if (result->increment.months == 0 && result->increment.days == 0 && result->increment.micros == 0) {
102
+ throw BinderException("interval cannot be 0!");
103
+ }
104
+ // all elements should point in the same direction
105
+ if (result->increment.months > 0 || result->increment.days > 0 || result->increment.micros > 0) {
106
+ if (result->increment.months < 0 || result->increment.days < 0 || result->increment.micros < 0) {
107
+ throw BinderException("RANGE with composite interval that has mixed signs is not supported");
108
+ }
109
+ result->greater_than_check = true;
110
+ if (result->start > result->end) {
111
+ throw BinderException(
112
+ "start is bigger than end, but increment is positive: cannot generate infinite series");
113
+ }
114
+ } else {
115
+ result->greater_than_check = false;
116
+ if (result->start < result->end) {
117
+ throw BinderException(
118
+ "start is smaller than end, but increment is negative: cannot generate infinite series");
119
+ }
120
+ }
121
+ return_types.push_back(inputs[0].type());
122
+ if (GENERATE_SERIES) {
123
+ // generate_series has inclusive bounds on the RHS
124
+ result->inclusive_bound = true;
125
+ names.emplace_back("generate_series");
126
+ } else {
127
+ result->inclusive_bound = false;
128
+ names.emplace_back("range");
129
+ }
130
+ return std::move(result);
131
+ }
132
+
133
+ struct State : public GlobalTableFunctionState {
134
+ explicit State(timestamp_t start_p) : current_state(start_p) {
135
+ }
136
+
137
+ timestamp_t current_state;
138
+ bool finished = false;
139
+ };
140
+
141
+ static unique_ptr<GlobalTableFunctionState> Init(ClientContext &context, TableFunctionInitInput &input) {
142
+ auto &bind_data = (BindData &)*input.bind_data;
143
+ return make_unique<State>(bind_data.start);
144
+ }
145
+
146
+ static void ICUTableRangeFunction(ClientContext &context, TableFunctionInput &data_p, DataChunk &output) {
147
+ auto &bind_data = (BindData &)*data_p.bind_data;
148
+ CalendarPtr calendar_ptr(bind_data.calendar->clone());
149
+ auto calendar = calendar_ptr.get();
150
+ auto &state = (State &)*data_p.global_state;
151
+ if (state.finished) {
152
+ return;
153
+ }
154
+
155
+ idx_t size = 0;
156
+ auto data = FlatVector::GetData<timestamp_t>(output.data[0]);
157
+ while (true) {
158
+ data[size++] = state.current_state;
159
+ state.current_state = ICUDateFunc::Add(calendar, state.current_state, bind_data.increment);
160
+ if (bind_data.Finished(state.current_state)) {
161
+ state.finished = true;
162
+ break;
163
+ }
164
+ if (size >= STANDARD_VECTOR_SIZE) {
165
+ break;
166
+ }
167
+ }
168
+ output.SetCardinality(size);
169
+ }
170
+
171
+ static void AddICUTableRangeFunction(ClientContext &context) {
172
+ auto &catalog = Catalog::GetSystemCatalog(context);
173
+
174
+ TableFunctionSet range("range");
175
+ range.AddFunction(TableFunction({LogicalType::TIMESTAMP_TZ, LogicalType::TIMESTAMP_TZ, LogicalType::INTERVAL},
176
+ ICUTableRangeFunction, Bind<false>, Init));
177
+ CreateTableFunctionInfo range_func_info(range);
178
+ catalog.AddFunction(context, &range_func_info);
179
+
180
+ // generate_series: similar to range, but inclusive instead of exclusive bounds on the RHS
181
+ TableFunctionSet generate_series("generate_series");
182
+ generate_series.AddFunction(
183
+ TableFunction({LogicalType::TIMESTAMP_TZ, LogicalType::TIMESTAMP_TZ, LogicalType::INTERVAL},
184
+ ICUTableRangeFunction, Bind<true>, Init));
185
+ CreateTableFunctionInfo generate_series_func_info(generate_series);
186
+ catalog.AddFunction(context, &generate_series_func_info);
187
+ }
188
+ };
189
+
190
+ void RegisterICUTableRangeFunctions(ClientContext &context) {
191
+ ICUTableRange::AddICUTableRangeFunction(context);
192
+ }
193
+
194
+ } // namespace duckdb
@@ -0,0 +1,17 @@
1
+ //===----------------------------------------------------------------------===//
2
+ // DuckDB
3
+ //
4
+ // icu-table-range.hpp
5
+ //
6
+ //
7
+ //===----------------------------------------------------------------------===//
8
+
9
+ #pragma once
10
+
11
+ #include "duckdb.hpp"
12
+
13
+ namespace duckdb {
14
+
15
+ void RegisterICUTableRangeFunctions(ClientContext &context);
16
+
17
+ } // namespace duckdb
@@ -1994,7 +1994,6 @@ unique_ptr<ColumnWriter> ColumnWriter::CreateWriterRecursive(vector<duckdb_parqu
1994
1994
  max_define, can_have_nulls);
1995
1995
  }
1996
1996
  case LogicalTypeId::BLOB:
1997
- case LogicalTypeId::BIT:
1998
1997
  case LogicalTypeId::VARCHAR:
1999
1998
  return make_unique<StringColumnWriter>(writer, schema_idx, std::move(schema_path), max_repeat, max_define,
2000
1999
  can_have_nulls);
@@ -368,7 +368,10 @@ public:
368
368
  if (!config.options.enable_external_access) {
369
369
  throw PermissionException("Scanning Parquet files is disabled through configuration");
370
370
  }
371
- auto file_name = input.inputs[0].GetValue<string>();
371
+ if (input.inputs[0].IsNull()) {
372
+ throw ParserException("Parquet reader cannot take NULL list as parameter");
373
+ }
374
+ auto file_name = StringValue::Get(input.inputs[0]);
372
375
  ParquetOptions parquet_options(context);
373
376
  for (auto &kv : input.named_parameters) {
374
377
  auto loption = StringUtil::Lower(kv.first);
@@ -395,10 +398,16 @@ public:
395
398
  if (!config.options.enable_external_access) {
396
399
  throw PermissionException("Scanning Parquet files is disabled through configuration");
397
400
  }
401
+ if (input.inputs[0].IsNull()) {
402
+ throw ParserException("Parquet reader cannot take NULL list as parameter");
403
+ }
398
404
  FileSystem &fs = FileSystem::GetFileSystem(context);
399
405
  vector<string> files;
400
406
  for (auto &val : ListValue::GetChildren(input.inputs[0])) {
401
- auto glob_files = ParquetGlob(fs, val.ToString(), context);
407
+ if (val.IsNull()) {
408
+ throw ParserException("Parquet reader cannot take NULL input as parameter");
409
+ }
410
+ auto glob_files = ParquetGlob(fs, StringValue::Get(val), context);
402
411
  files.insert(files.end(), glob_files.begin(), glob_files.end());
403
412
  }
404
413
  if (files.empty()) {
@@ -145,6 +145,10 @@ CatalogEntry *DuckSchemaEntry::CreateFunction(CatalogTransaction transaction, Cr
145
145
  function = make_unique_base<StandardEntry, ScalarFunctionCatalogEntry>(catalog, this,
146
146
  (CreateScalarFunctionInfo *)info);
147
147
  break;
148
+ case CatalogType::TABLE_FUNCTION_ENTRY:
149
+ function =
150
+ make_unique_base<StandardEntry, TableFunctionCatalogEntry>(catalog, this, (CreateTableFunctionInfo *)info);
151
+ break;
148
152
  case CatalogType::MACRO_ENTRY:
149
153
  // create a macro function
150
154
  function = make_unique_base<StandardEntry, ScalarMacroCatalogEntry>(catalog, this, (CreateMacroInfo *)info);
@@ -1,5 +1,5 @@
1
1
  #include "duckdb/catalog/catalog_entry/scalar_function_catalog_entry.hpp"
2
- #include "duckdb/parser/parsed_data/alter_function_info.hpp"
2
+ #include "duckdb/parser/parsed_data/alter_scalar_function_info.hpp"
3
3
 
4
4
  namespace duckdb {
5
5
 
@@ -9,14 +9,15 @@ ScalarFunctionCatalogEntry::ScalarFunctionCatalogEntry(Catalog *catalog, SchemaC
9
9
  }
10
10
 
11
11
  unique_ptr<CatalogEntry> ScalarFunctionCatalogEntry::AlterEntry(ClientContext &context, AlterInfo *info) {
12
- if (info->type != AlterType::ALTER_FUNCTION) {
12
+ if (info->type != AlterType::ALTER_SCALAR_FUNCTION) {
13
13
  throw InternalException("Attempting to alter ScalarFunctionCatalogEntry with unsupported alter type");
14
14
  }
15
- auto &function_info = (AlterFunctionInfo &)*info;
16
- if (function_info.alter_function_type != AlterFunctionType::ADD_FUNCTION_OVERLOADS) {
17
- throw InternalException("Attempting to alter ScalarFunctionCatalogEntry with unsupported alter function type");
15
+ auto &function_info = (AlterScalarFunctionInfo &)*info;
16
+ if (function_info.alter_scalar_function_type != AlterScalarFunctionType::ADD_FUNCTION_OVERLOADS) {
17
+ throw InternalException(
18
+ "Attempting to alter ScalarFunctionCatalogEntry with unsupported alter scalar function type");
18
19
  }
19
- auto &add_overloads = (AddFunctionOverloadInfo &)function_info;
20
+ auto &add_overloads = (AddScalarFunctionOverloadInfo &)function_info;
20
21
 
21
22
  ScalarFunctionSet new_set = functions;
22
23
  if (!new_set.MergeFunctionSet(add_overloads.new_overloads)) {
@@ -1,5 +1,5 @@
1
1
  #include "duckdb/catalog/catalog_entry/table_function_catalog_entry.hpp"
2
- #include "duckdb/parser/parsed_data/create_table_function_info.hpp"
2
+ #include "duckdb/parser/parsed_data/alter_table_function_info.hpp"
3
3
 
4
4
  namespace duckdb {
5
5
 
@@ -10,4 +10,23 @@ TableFunctionCatalogEntry::TableFunctionCatalogEntry(Catalog *catalog, SchemaCat
10
10
  D_ASSERT(this->functions.Size() > 0);
11
11
  }
12
12
 
13
+ unique_ptr<CatalogEntry> TableFunctionCatalogEntry::AlterEntry(ClientContext &context, AlterInfo *info) {
14
+ if (info->type != AlterType::ALTER_TABLE_FUNCTION) {
15
+ throw InternalException("Attempting to alter TableFunctionCatalogEntry with unsupported alter type");
16
+ }
17
+ auto &function_info = (AlterTableFunctionInfo &)*info;
18
+ if (function_info.alter_table_function_type != AlterTableFunctionType::ADD_FUNCTION_OVERLOADS) {
19
+ throw InternalException(
20
+ "Attempting to alter TableFunctionCatalogEntry with unsupported alter table function type");
21
+ }
22
+ auto &add_overloads = (AddTableFunctionOverloadInfo &)function_info;
23
+
24
+ TableFunctionSet new_set = functions;
25
+ if (!new_set.MergeFunctionSet(add_overloads.new_overloads)) {
26
+ throw BinderException("Failed to add new function overloads to function \"%s\": function already exists", name);
27
+ }
28
+ CreateTableFunctionInfo new_info(std::move(new_set));
29
+ return make_unique<TableFunctionCatalogEntry>(catalog, schema, &new_info);
30
+ }
31
+
13
32
  } // namespace duckdb
@@ -59,6 +59,8 @@ string StatementTypeToString(StatementType type) {
59
59
  return "ATTACH";
60
60
  case StatementType::DETACH_STATEMENT:
61
61
  return "DETACH";
62
+ case StatementType::MULTI_STATEMENT:
63
+ return "MULTI";
62
64
  case StatementType::INVALID_STATEMENT:
63
65
  break;
64
66
  }
@@ -4,66 +4,35 @@
4
4
 
5
5
  namespace duckdb {
6
6
 
7
- void Bit::SetEmptyBitString(string_t &target, string_t &input) {
8
- char *res_buf = target.GetDataWriteable();
9
- const char *buf = input.GetDataUnsafe();
10
- memset(res_buf, 0, input.GetSize());
11
- res_buf[0] = buf[0];
7
+ // **** helper functions ****
8
+ static char ComputePadding(idx_t len) {
9
+ return (8 - (len % 8)) % 8;
12
10
  }
13
11
 
14
- idx_t Bit::BitLength(string_t bits) {
15
- return ((bits.GetSize() - 1) * 8) - GetPadding(bits);
12
+ idx_t Bit::ComputeBitstringLen(idx_t len) {
13
+ len = len % 8 ? (len / 8) + 1 : len / 8;
14
+ return ++len; // additional first byte to store info on zero padding
16
15
  }
17
16
 
18
- idx_t Bit::OctetLength(string_t bits) {
19
- return bits.GetSize() - 1;
17
+ inline idx_t Bit::GetPadding(const string_t &bit_string) {
18
+ auto data = (const_data_ptr_t)bit_string.GetDataUnsafe();
19
+ return data[0];
20
20
  }
21
21
 
22
- idx_t Bit::BitCount(string_t bits) {
23
- idx_t count = 0;
24
- const char *buf = bits.GetDataUnsafe();
25
- for (idx_t byte_idx = 1; byte_idx < OctetLength(bits) + 1; byte_idx++) {
26
- for (idx_t bit_idx = 0; bit_idx < 8; bit_idx++) {
27
- count += (buf[byte_idx] & (1 << bit_idx)) ? 1 : 0;
28
- }
29
- }
30
- return count;
22
+ void Bit::SetEmptyBitString(string_t &target, string_t &input) {
23
+ char *res_buf = target.GetDataWriteable();
24
+ const char *buf = input.GetDataUnsafe();
25
+ memset(res_buf, 0, input.GetSize());
26
+ res_buf[0] = buf[0];
31
27
  }
32
28
 
33
- idx_t Bit::BitPosition(string_t substring, string_t bits) {
34
- const char *buf = bits.GetDataUnsafe();
35
- auto len = bits.GetSize();
36
- auto substr_len = BitLength(substring);
37
- idx_t substr_idx = 0;
38
-
39
- for (idx_t bit_idx = GetPadding(bits); bit_idx < 8; bit_idx++) {
40
- idx_t bit = buf[1] & (1 << (7 - bit_idx)) ? 1 : 0;
41
- if (bit == GetBit(substring, substr_idx)) {
42
- substr_idx++;
43
- if (substr_idx == substr_len) {
44
- return (bit_idx - GetPadding(bits)) - substr_len + 2;
45
- }
46
- } else {
47
- substr_idx = 0;
48
- }
49
- }
50
-
51
- for (idx_t byte_idx = 2; byte_idx < len; byte_idx++) {
52
- for (idx_t bit_idx = 0; bit_idx < 8; bit_idx++) {
53
- idx_t bit = buf[byte_idx] & (1 << (7 - bit_idx)) ? 1 : 0;
54
- if (bit == GetBit(substring, substr_idx)) {
55
- substr_idx++;
56
- if (substr_idx == substr_len) {
57
- return (((byte_idx - 1) * 8) + bit_idx - GetPadding(bits)) - substr_len + 2;
58
- }
59
- } else {
60
- substr_idx = 0;
61
- }
62
- }
63
- }
64
- return 0;
29
+ void Bit::SetEmptyBitString(string_t &target, idx_t len) {
30
+ char *res_buf = target.GetDataWriteable();
31
+ memset(res_buf, 0, target.GetSize());
32
+ res_buf[0] = ComputePadding(len);
65
33
  }
66
34
 
35
+ // **** casting functions ****
67
36
  void Bit::ToString(string_t bits, char *output) {
68
37
  auto data = (const_data_ptr_t)bits.GetDataUnsafe();
69
38
  auto len = bits.GetSize();
@@ -101,8 +70,12 @@ bool Bit::TryGetBitStringSize(string_t str, idx_t &str_len, string *error_messag
101
70
  return false;
102
71
  }
103
72
  }
104
- str_len = str_len % 8 ? (str_len / 8) + 1 : str_len / 8;
105
- str_len++; // additional first byte to store info on zero padding
73
+ if (str_len == 0) {
74
+ string error = "Cannot cast empty string to BIT";
75
+ HandleCastError::AssignError(error, error_message);
76
+ return false;
77
+ }
78
+ str_len = ComputeBitstringLen(str_len);
106
79
  return true;
107
80
  }
108
81
 
@@ -151,6 +124,75 @@ string Bit::ToBit(string_t str) {
151
124
  return string(buffer.get(), bit_len);
152
125
  }
153
126
 
127
+ // **** scalar functions ****
128
+ void Bit::BitString(const string_t &input, const idx_t &len, string_t &result) {
129
+ char *res_buf = result.GetDataWriteable();
130
+ const char *buf = input.GetDataUnsafe();
131
+
132
+ res_buf[0] = ComputePadding(len);
133
+ for (idx_t i = 0; i < Bit::BitLength(result); i++) {
134
+ if (i < len - input.GetSize()) {
135
+ Bit::SetBit(result, i, 0);
136
+ } else {
137
+ idx_t bit = buf[i - (len - input.GetSize())] == '1' ? 1 : 0;
138
+ Bit::SetBit(result, i, bit);
139
+ }
140
+ }
141
+ }
142
+
143
+ idx_t Bit::BitLength(string_t bits) {
144
+ return ((bits.GetSize() - 1) * 8) - GetPadding(bits);
145
+ }
146
+
147
+ idx_t Bit::OctetLength(string_t bits) {
148
+ return bits.GetSize() - 1;
149
+ }
150
+
151
+ idx_t Bit::BitCount(string_t bits) {
152
+ idx_t count = 0;
153
+ const char *buf = bits.GetDataUnsafe();
154
+ for (idx_t byte_idx = 1; byte_idx < OctetLength(bits) + 1; byte_idx++) {
155
+ for (idx_t bit_idx = 0; bit_idx < 8; bit_idx++) {
156
+ count += (buf[byte_idx] & (1 << bit_idx)) ? 1 : 0;
157
+ }
158
+ }
159
+ return count;
160
+ }
161
+
162
+ idx_t Bit::BitPosition(string_t substring, string_t bits) {
163
+ const char *buf = bits.GetDataUnsafe();
164
+ auto len = bits.GetSize();
165
+ auto substr_len = BitLength(substring);
166
+ idx_t substr_idx = 0;
167
+
168
+ for (idx_t bit_idx = GetPadding(bits); bit_idx < 8; bit_idx++) {
169
+ idx_t bit = buf[1] & (1 << (7 - bit_idx)) ? 1 : 0;
170
+ if (bit == GetBit(substring, substr_idx)) {
171
+ substr_idx++;
172
+ if (substr_idx == substr_len) {
173
+ return (bit_idx - GetPadding(bits)) - substr_len + 2;
174
+ }
175
+ } else {
176
+ substr_idx = 0;
177
+ }
178
+ }
179
+
180
+ for (idx_t byte_idx = 2; byte_idx < len; byte_idx++) {
181
+ for (idx_t bit_idx = 0; bit_idx < 8; bit_idx++) {
182
+ idx_t bit = buf[byte_idx] & (1 << (7 - bit_idx)) ? 1 : 0;
183
+ if (bit == GetBit(substring, substr_idx)) {
184
+ substr_idx++;
185
+ if (substr_idx == substr_len) {
186
+ return (((byte_idx - 1) * 8) + bit_idx - GetPadding(bits)) - substr_len + 2;
187
+ }
188
+ } else {
189
+ substr_idx = 0;
190
+ }
191
+ }
192
+ }
193
+ return 0;
194
+ }
195
+
154
196
  idx_t Bit::GetBit(string_t bit_string, idx_t n) {
155
197
  const char *buf = bit_string.GetDataUnsafe();
156
198
  n += GetPadding(bit_string);
@@ -187,12 +229,7 @@ void Bit::SetBit(string_t &bit_string, idx_t n, idx_t new_value) {
187
229
  }
188
230
  }
189
231
 
190
- inline idx_t Bit::GetPadding(const string_t &bit_string) {
191
- auto data = (const_data_ptr_t)bit_string.GetDataUnsafe();
192
- return data[0];
193
- }
194
-
195
- // **** BITWISE OPERATORS ****
232
+ // **** BITWISE operators ****
196
233
  void Bit::RightShift(const string_t &bit_string, const idx_t &shift, string_t &result) {
197
234
  char *res_buf = result.GetDataWriteable();
198
235
  const char *buf = bit_string.GetDataUnsafe();