duckdb 0.7.1-dev320.0 → 0.7.1-dev341.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "duckdb",
3
3
  "main": "./lib/duckdb.js",
4
4
  "types": "./lib/duckdb.d.ts",
5
- "version": "0.7.1-dev320.0",
5
+ "version": "0.7.1-dev341.0",
6
6
  "description": "DuckDB node.js API",
7
7
  "gypfile": true,
8
8
  "dependencies": {
@@ -137,6 +137,7 @@ void PartitionedColumnData::FlushAppendState(PartitionedColumnDataAppendState &s
137
137
  auto &partition_buffer = *state.partition_buffers[i];
138
138
  if (partition_buffer.size() > 0) {
139
139
  partitions[i]->Append(partition_buffer);
140
+ partition_buffer.Reset();
140
141
  }
141
142
  }
142
143
  }
@@ -169,6 +169,10 @@ private:
169
169
  };
170
170
 
171
171
  void WindowGlobalSinkState::ResizeGroupingData(idx_t cardinality) {
172
+ // Have we started to combine? Then just live with it.
173
+ if (grouping_data && !grouping_data->GetPartitions().empty()) {
174
+ return;
175
+ }
172
176
  // Is the average partition size too large?
173
177
  const idx_t partition_size = STANDARD_ROW_GROUPS_SIZE;
174
178
  const auto bits = grouping_data ? grouping_data->GetRadixBits() : 0;
@@ -180,31 +184,7 @@ void WindowGlobalSinkState::ResizeGroupingData(idx_t cardinality) {
180
184
  // Repartition the grouping data
181
185
  if (new_bits != bits) {
182
186
  const auto hash_col_idx = payload_types.size();
183
- auto new_grouping_data =
184
- make_unique<RadixPartitionedColumnData>(context, grouping_types, new_bits, hash_col_idx);
185
-
186
- // We have to append to a shared copy for some reason
187
- if (grouping_data) {
188
- auto new_shared = new_grouping_data->CreateShared();
189
- PartitionedColumnDataAppendState shared_append;
190
- new_shared->InitializeAppendState(shared_append);
191
-
192
- auto &partitions = grouping_data->GetPartitions();
193
- for (auto &partition : partitions) {
194
- ColumnDataScanState scanner;
195
- partition->InitializeScan(scanner);
196
-
197
- DataChunk scan_chunk;
198
- partition->InitializeScanChunk(scan_chunk);
199
- for (scan_chunk.Reset(); partition->Scan(scanner, scan_chunk); scan_chunk.Reset()) {
200
- new_shared->Append(shared_append, scan_chunk);
201
- }
202
- }
203
- new_shared->FlushAppendState(shared_append);
204
- new_grouping_data->Combine(*new_shared);
205
- }
206
-
207
- grouping_data = std::move(new_grouping_data);
187
+ grouping_data = make_unique<RadixPartitionedColumnData>(context, grouping_types, new_bits, hash_col_idx);
208
188
  }
209
189
  }
210
190
 
@@ -432,8 +412,6 @@ void WindowLocalSinkState::Sink(DataChunk &input_chunk, WindowGlobalSinkState &g
432
412
  }
433
413
 
434
414
  // OVER(...)
435
- gstate.UpdateLocalPartition(local_partition, local_append);
436
-
437
415
  payload_chunk.Reset();
438
416
  auto &hash_vector = payload_chunk.data.back();
439
417
  Hash(input_chunk, hash_vector);
@@ -442,6 +420,7 @@ void WindowLocalSinkState::Sink(DataChunk &input_chunk, WindowGlobalSinkState &g
442
420
  }
443
421
  payload_chunk.SetCardinality(input_chunk);
444
422
 
423
+ gstate.UpdateLocalPartition(local_partition, local_append);
445
424
  local_partition->Append(*local_append, payload_chunk);
446
425
  }
447
426
 
@@ -66,46 +66,94 @@ void MapConversionVerify(Vector &vector, idx_t count) {
66
66
  }
67
67
  }
68
68
 
69
- static void MapFunction(DataChunk &args, ExpressionState &state, Vector &result) {
70
- D_ASSERT(result.GetType().id() == LogicalTypeId::MAP);
71
-
72
- //! Otherwise if its not a constant vector, this breaks the optimizer
73
- result.SetVectorType(VectorType::CONSTANT_VECTOR);
74
- for (idx_t i = 0; i < args.ColumnCount(); i++) {
75
- if (args.data[i].GetVectorType() != VectorType::CONSTANT_VECTOR) {
76
- result.SetVectorType(VectorType::FLAT_VECTOR);
69
+ // Example:
70
+ // source: [1,2,3], expansion_factor: 4
71
+ // target (result): [1,2,3,1,2,3,1,2,3,1,2,3]
72
+ static void CreateExpandedVector(const Vector &source, Vector &target, idx_t expansion_factor) {
73
+ idx_t count = ListVector::GetListSize(source);
74
+ auto &entry = ListVector::GetEntry(source);
75
+
76
+ idx_t target_idx = 0;
77
+ for (idx_t copy = 0; copy < expansion_factor; copy++) {
78
+ for (idx_t key_idx = 0; key_idx < count; key_idx++) {
79
+ target.SetValue(target_idx, entry.GetValue(key_idx));
80
+ target_idx++;
77
81
  }
78
82
  }
83
+ D_ASSERT(target_idx == count * expansion_factor);
84
+ }
85
+
86
+ static void AlignVectorToReference(const Vector &original, const Vector &reference, idx_t tuple_count, Vector &result) {
87
+ auto original_length = ListVector::GetListSize(original);
88
+ auto new_length = ListVector::GetListSize(reference);
89
+
90
+ Vector expanded_const(ListType::GetChildType(original.GetType()), new_length);
91
+
92
+ auto expansion_factor = new_length / original_length;
93
+ if (expansion_factor != tuple_count) {
94
+ throw InvalidInputException("Error in MAP creation: key list and value list do not align. i.e. different "
95
+ "size or incompatible structure");
96
+ }
97
+ CreateExpandedVector(original, expanded_const, expansion_factor);
98
+ result.Reference(expanded_const);
99
+ }
100
+
101
+ static void MapFunction(DataChunk &args, ExpressionState &state, Vector &result) {
102
+ D_ASSERT(result.GetType().id() == LogicalTypeId::MAP);
79
103
 
80
104
  auto &key_vector = MapVector::GetKeys(result);
81
105
  auto &value_vector = MapVector::GetValues(result);
82
- auto list_data = ListVector::GetData(result);
106
+ auto result_data = ListVector::GetData(result);
83
107
 
108
+ result.SetVectorType(VectorType::CONSTANT_VECTOR);
84
109
  if (args.data.empty()) {
85
110
  ListVector::SetListSize(result, 0);
86
- list_data->offset = 0;
87
- list_data->length = 0;
111
+ result_data->offset = 0;
112
+ result_data->length = 0;
88
113
  result.Verify(args.size());
89
114
  return;
90
115
  }
91
116
 
92
- auto args_data = ListVector::GetData(args.data[0]);
117
+ bool keys_are_const = args.data[0].GetVectorType() == VectorType::CONSTANT_VECTOR;
118
+ bool values_are_const = args.data[1].GetVectorType() == VectorType::CONSTANT_VECTOR;
119
+ if (!keys_are_const || !values_are_const) {
120
+ result.SetVectorType(VectorType::FLAT_VECTOR);
121
+ }
122
+
93
123
  auto key_count = ListVector::GetListSize(args.data[0]);
94
124
  auto value_count = ListVector::GetListSize(args.data[1]);
95
- if (key_count != value_count) {
96
- throw InvalidInputException(
97
- "Error in MAP creation: key list has a different size from value list (%lld keys, %lld values)", key_count,
98
- value_count);
125
+ auto key_data = ListVector::GetData(args.data[0]);
126
+ auto value_data = ListVector::GetData(args.data[1]);
127
+ auto src_data = key_data;
128
+
129
+ if (keys_are_const && !values_are_const) {
130
+ AlignVectorToReference(args.data[0], args.data[1], args.size(), key_vector);
131
+ src_data = value_data;
132
+ } else if (values_are_const && !keys_are_const) {
133
+ AlignVectorToReference(args.data[1], args.data[0], args.size(), value_vector);
134
+ } else {
135
+ if (key_count != value_count || memcmp(key_data, value_data, args.size() * sizeof(list_entry_t)) != 0) {
136
+ throw InvalidInputException("Error in MAP creation: key list and value list do not align. i.e. different "
137
+ "size or incompatible structure");
138
+ }
99
139
  }
100
- ListVector::Reserve(result, key_count);
101
- ListVector::SetListSize(result, key_count);
102
140
 
141
+ ListVector::SetListSize(result, MaxValue(key_count, value_count));
142
+
143
+ result_data = ListVector::GetData(result);
103
144
  for (idx_t i = 0; i < args.size(); i++) {
104
- list_data[i] = args_data[i];
145
+ result_data[i] = src_data[i];
146
+ }
147
+
148
+ // check whether one of the vectors has already been referenced to an expanded vector in the case of const/non-const
149
+ // combination. If not, then referencing is still necessary
150
+ if (!(keys_are_const && !values_are_const)) {
151
+ key_vector.Reference(ListVector::GetEntry(args.data[0]));
152
+ }
153
+ if (!(values_are_const && !keys_are_const)) {
154
+ value_vector.Reference(ListVector::GetEntry(args.data[1]));
105
155
  }
106
156
 
107
- key_vector.Reference(ListVector::GetEntry(args.data[0]));
108
- value_vector.Reference(ListVector::GetEntry(args.data[1]));
109
157
  MapConversionVerify(result, args.size());
110
158
  result.Verify(args.size());
111
159
  }
@@ -1,8 +1,8 @@
1
1
  #ifndef DUCKDB_VERSION
2
- #define DUCKDB_VERSION "0.7.1-dev320"
2
+ #define DUCKDB_VERSION "0.7.1-dev341"
3
3
  #endif
4
4
  #ifndef DUCKDB_SOURCE_ID
5
- #define DUCKDB_SOURCE_ID "4a6205db95"
5
+ #define DUCKDB_SOURCE_ID "d58ab188ff"
6
6
  #endif
7
7
  #include "duckdb/function/table/system_functions.hpp"
8
8
  #include "duckdb/main/database.hpp"
@@ -54,7 +54,7 @@ BoundStatement Binder::Bind(DropStatement &stmt) {
54
54
  auto &config = DBConfig::GetConfig(context);
55
55
  // for now assume only one storage extension provides the custom drop_database impl
56
56
  for (auto &extension_entry : config.storage_extensions) {
57
- if (extension_entry.second->drop_database != nullptr) {
57
+ if (extension_entry.second->drop_database == nullptr) {
58
58
  continue;
59
59
  }
60
60
  auto &storage_extension = extension_entry.second;
@@ -64,7 +64,7 @@ BoundStatement Binder::Bind(DropStatement &stmt) {
64
64
  auto bound_drop_database_func = Bind(*drop_database_function_ref);
65
65
  result.plan = CreatePlan(*bound_drop_database_func);
66
66
  result.names = {"Success"};
67
- result.types = {LogicalType::BOOLEAN};
67
+ result.types = {LogicalType::BIGINT};
68
68
  properties.allow_stream_result = false;
69
69
  properties.return_type = StatementReturnType::NOTHING;
70
70
  return result;