duckdb 0.9.1-dev69.0 → 0.9.1-dev86.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.9.1-dev69.0",
5
+ "version": "0.9.1-dev86.0",
6
6
  "description": "DuckDB node.js API",
7
7
  "gypfile": true,
8
8
  "dependencies": {
@@ -87,11 +87,24 @@ static bool ListEntriesEqual(Vector &keys, Vector &values, idx_t count) {
87
87
  return true;
88
88
  }
89
89
 
90
+ static list_entry_t *GetBiggestList(Vector &key, Vector &value, idx_t &size) {
91
+ auto key_size = ListVector::GetListSize(key);
92
+ auto value_size = ListVector::GetListSize(value);
93
+ if (key_size > value_size) {
94
+ size = key_size;
95
+ return ListVector::GetData(key);
96
+ }
97
+ size = value_size;
98
+ return ListVector::GetData(value);
99
+ }
100
+
90
101
  static void MapFunction(DataChunk &args, ExpressionState &state, Vector &result) {
91
102
  D_ASSERT(result.GetType().id() == LogicalTypeId::MAP);
92
103
 
93
- auto &key_vector = MapVector::GetKeys(result);
94
- auto &value_vector = MapVector::GetValues(result);
104
+ auto count = args.size();
105
+
106
+ auto &map_key_vector = MapVector::GetKeys(result);
107
+ auto &map_value_vector = MapVector::GetValues(result);
95
108
  auto result_data = ListVector::GetData(result);
96
109
 
97
110
  result.SetVectorType(VectorType::CONSTANT_VECTOR);
@@ -99,52 +112,73 @@ static void MapFunction(DataChunk &args, ExpressionState &state, Vector &result)
99
112
  ListVector::SetListSize(result, 0);
100
113
  result_data->offset = 0;
101
114
  result_data->length = 0;
102
- result.Verify(args.size());
115
+ result.Verify(count);
103
116
  return;
104
117
  }
105
118
 
106
- bool keys_are_const = args.data[0].GetVectorType() == VectorType::CONSTANT_VECTOR;
107
- bool values_are_const = args.data[1].GetVectorType() == VectorType::CONSTANT_VECTOR;
108
- if (!keys_are_const || !values_are_const) {
109
- result.SetVectorType(VectorType::FLAT_VECTOR);
119
+ D_ASSERT(args.ColumnCount() == 2);
120
+ auto &key_vector = args.data[0];
121
+ auto &value_vector = args.data[1];
122
+
123
+ if (args.AllConstant()) {
124
+ auto key_data = ListVector::GetData(key_vector);
125
+ auto value_data = ListVector::GetData(value_vector);
126
+ auto key_entry = key_data[0];
127
+ auto value_entry = value_data[0];
128
+ if (key_entry != value_entry) {
129
+ throw BinderException("Key and value list sizes don't match");
130
+ }
131
+ result_data[0] = key_entry;
132
+ ListVector::SetListSize(result, ListVector::GetListSize(key_vector));
133
+ map_key_vector.Reference(ListVector::GetEntry(key_vector));
134
+ map_value_vector.Reference(ListVector::GetEntry(value_vector));
135
+ MapVector::MapConversionVerify(result, count);
136
+ result.Verify(count);
137
+ return;
110
138
  }
111
139
 
112
- auto key_count = ListVector::GetListSize(args.data[0]);
113
- auto value_count = ListVector::GetListSize(args.data[1]);
114
- auto key_data = ListVector::GetData(args.data[0]);
115
- auto value_data = ListVector::GetData(args.data[1]);
116
- auto src_data = key_data;
117
-
118
- if (keys_are_const && !values_are_const) {
119
- AlignVectorToReference(args.data[0], args.data[1], args.size(), key_vector);
120
- src_data = value_data;
121
- } else if (values_are_const && !keys_are_const) {
122
- AlignVectorToReference(args.data[1], args.data[0], args.size(), value_vector);
140
+ result.SetVectorType(VectorType::FLAT_VECTOR);
141
+
142
+ if (key_vector.GetVectorType() == VectorType::CONSTANT_VECTOR) {
143
+ D_ASSERT(value_vector.GetVectorType() != VectorType::CONSTANT_VECTOR);
144
+ Vector expanded_const(ListType::GetChildType(key_vector.GetType()), count);
145
+ AlignVectorToReference(key_vector, value_vector, count, expanded_const);
146
+ map_key_vector.Reference(expanded_const);
147
+
148
+ value_vector.Flatten(count);
149
+ map_value_vector.Reference(ListVector::GetEntry(value_vector));
150
+ } else if (value_vector.GetVectorType() == VectorType::CONSTANT_VECTOR) {
151
+ D_ASSERT(key_vector.GetVectorType() != VectorType::CONSTANT_VECTOR);
152
+ Vector expanded_const(ListType::GetChildType(value_vector.GetType()), count);
153
+ AlignVectorToReference(value_vector, key_vector, count, expanded_const);
154
+ map_value_vector.Reference(expanded_const);
155
+
156
+ key_vector.Flatten(count);
157
+ map_key_vector.Reference(ListVector::GetEntry(key_vector));
123
158
  } else {
124
- if (!ListEntriesEqual(args.data[0], args.data[1], args.size())) {
159
+ key_vector.Flatten(count);
160
+ value_vector.Flatten(count);
161
+
162
+ if (!ListEntriesEqual(key_vector, value_vector, count)) {
125
163
  throw InvalidInputException("Error in MAP creation: key list and value list do not align. i.e. different "
126
164
  "size or incompatible structure");
127
165
  }
166
+
167
+ map_value_vector.Reference(ListVector::GetEntry(value_vector));
168
+ map_key_vector.Reference(ListVector::GetEntry(key_vector));
128
169
  }
129
170
 
130
- ListVector::SetListSize(result, MaxValue(key_count, value_count));
171
+ idx_t list_size;
172
+ auto src_data = GetBiggestList(key_vector, value_vector, list_size);
173
+ ListVector::SetListSize(result, list_size);
131
174
 
132
175
  result_data = ListVector::GetData(result);
133
- for (idx_t i = 0; i < args.size(); i++) {
176
+ for (idx_t i = 0; i < count; i++) {
134
177
  result_data[i] = src_data[i];
135
178
  }
136
179
 
137
- // check whether one of the vectors has already been referenced to an expanded vector in the case of const/non-const
138
- // combination. If not, then referencing is still necessary
139
- if (!(keys_are_const && !values_are_const)) {
140
- key_vector.Reference(ListVector::GetEntry(args.data[0]));
141
- }
142
- if (!(values_are_const && !keys_are_const)) {
143
- value_vector.Reference(ListVector::GetEntry(args.data[1]));
144
- }
145
-
146
- MapVector::MapConversionVerify(result, args.size());
147
- result.Verify(args.size());
180
+ MapVector::MapConversionVerify(result, count);
181
+ result.Verify(count);
148
182
  }
149
183
 
150
184
  static unique_ptr<FunctionData> MapBind(ClientContext &context, ScalarFunction &bound_function,
@@ -1,8 +1,8 @@
1
1
  #ifndef DUCKDB_VERSION
2
- #define DUCKDB_VERSION "v0.9.1-dev69"
2
+ #define DUCKDB_VERSION "v0.9.1-dev86"
3
3
  #endif
4
4
  #ifndef DUCKDB_SOURCE_ID
5
- #define DUCKDB_SOURCE_ID "5ba1abd81a"
5
+ #define DUCKDB_SOURCE_ID "c0dfff9198"
6
6
  #endif
7
7
  #include "duckdb/function/table/system_functions.hpp"
8
8
  #include "duckdb/main/database.hpp"
@@ -196,6 +196,9 @@ string ExtensionHelper::AddExtensionInstallHintToErrorMsg(ClientContext &context
196
196
  }
197
197
 
198
198
  bool ExtensionHelper::TryAutoLoadExtension(ClientContext &context, const string &extension_name) noexcept {
199
+ if (context.db->ExtensionIsLoaded(extension_name)) {
200
+ return true;
201
+ }
199
202
  auto &dbconfig = DBConfig::GetConfig(context);
200
203
  try {
201
204
  if (dbconfig.options.autoinstall_known_extensions) {
@@ -211,6 +214,10 @@ bool ExtensionHelper::TryAutoLoadExtension(ClientContext &context, const string
211
214
  }
212
215
 
213
216
  void ExtensionHelper::AutoLoadExtension(ClientContext &context, const string &extension_name) {
217
+ if (context.db->ExtensionIsLoaded(extension_name)) {
218
+ // Avoid downloading again
219
+ return;
220
+ }
214
221
  auto &dbconfig = DBConfig::GetConfig(context);
215
222
  try {
216
223
  #ifndef DUCKDB_WASM