duckdb 0.6.2-dev2085.0 → 0.6.2-dev2091.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.6.2-dev2085.0",
5
+ "version": "0.6.2-dev2091.0",
6
6
  "description": "DuckDB node.js API",
7
7
  "gypfile": true,
8
8
  "dependencies": {
@@ -211,6 +211,19 @@ void ParquetWriter::SetSchemaProperties(const LogicalType &duckdb_type,
211
211
  }
212
212
  }
213
213
 
214
+ void VerifyUniqueNames(const vector<string> &names) {
215
+ #ifdef DEBUG
216
+ unordered_set<string> name_set;
217
+ name_set.reserve(names.size());
218
+ for (auto &column : names) {
219
+ auto res = name_set.insert(column);
220
+ D_ASSERT(res.second == true);
221
+ }
222
+ // If there would be duplicates, these sizes would differ
223
+ D_ASSERT(name_set.size() == names.size());
224
+ #endif
225
+ }
226
+
214
227
  ParquetWriter::ParquetWriter(FileSystem &fs, string file_name_p, FileOpener *file_opener_p, vector<LogicalType> types_p,
215
228
  vector<string> names_p, CompressionCodec::type codec)
216
229
  : file_name(std::move(file_name_p)), sql_types(std::move(types_p)), column_names(std::move(names_p)), codec(codec) {
@@ -237,10 +250,13 @@ ParquetWriter::ParquetWriter(FileSystem &fs, string file_name_p, FileOpener *fil
237
250
  file_meta_data.schema[0].repetition_type = duckdb_parquet::format::FieldRepetitionType::REQUIRED;
238
251
  file_meta_data.schema[0].__isset.repetition_type = true;
239
252
 
253
+ auto &unique_names = column_names;
254
+ VerifyUniqueNames(unique_names);
255
+
240
256
  vector<string> schema_path;
241
257
  for (idx_t i = 0; i < sql_types.size(); i++) {
242
258
  column_writers.push_back(ColumnWriter::CreateWriterRecursive(file_meta_data.schema, *this, sql_types[i],
243
- column_names[i], schema_path));
259
+ unique_names[i], schema_path));
244
260
  }
245
261
  }
246
262
 
@@ -1,8 +1,8 @@
1
1
  #ifndef DUCKDB_VERSION
2
- #define DUCKDB_VERSION "0.6.2-dev2085"
2
+ #define DUCKDB_VERSION "0.6.2-dev2091"
3
3
  #endif
4
4
  #ifndef DUCKDB_SOURCE_ID
5
- #define DUCKDB_SOURCE_ID "a038924fb3"
5
+ #define DUCKDB_SOURCE_ID "4d9705ca54"
6
6
  #endif
7
7
  #include "duckdb/function/table/system_functions.hpp"
8
8
  #include "duckdb/main/database.hpp"
@@ -33,6 +33,34 @@ static vector<idx_t> ColumnListToIndices(const vector<bool> &vec) {
33
33
  return ret;
34
34
  }
35
35
 
36
+ vector<string> GetUniqueNames(const vector<string> &original_names) {
37
+ unordered_set<string> name_set;
38
+ vector<string> unique_names;
39
+ unique_names.reserve(original_names.size());
40
+
41
+ for (auto &name : original_names) {
42
+ auto insert_result = name_set.insert(name);
43
+ if (insert_result.second == false) {
44
+ // Could not be inserted, name already exists
45
+ idx_t index = 1;
46
+ string postfixed_name;
47
+ while (true) {
48
+ postfixed_name = StringUtil::Format("%s:%d", name, index);
49
+ auto res = name_set.insert(postfixed_name);
50
+ if (!res.second) {
51
+ index++;
52
+ continue;
53
+ }
54
+ break;
55
+ }
56
+ unique_names.push_back(postfixed_name);
57
+ } else {
58
+ unique_names.push_back(name);
59
+ }
60
+ }
61
+ return unique_names;
62
+ }
63
+
36
64
  BoundStatement Binder::BindCopyTo(CopyStatement &stmt) {
37
65
  // COPY TO a file
38
66
  auto &config = DBConfig::GetConfig(context);
@@ -99,8 +127,10 @@ BoundStatement Binder::BindCopyTo(CopyStatement &stmt) {
99
127
  use_tmp_file = is_file_and_exists && !per_thread_output && partition_cols.empty() && !is_stdout;
100
128
  }
101
129
 
130
+ auto unique_column_names = GetUniqueNames(select_node.names);
131
+
102
132
  auto function_data =
103
- copy_function->function.copy_to_bind(context, *stmt.info, select_node.names, select_node.types);
133
+ copy_function->function.copy_to_bind(context, *stmt.info, unique_column_names, select_node.types);
104
134
  // now create the copy information
105
135
  auto copy = make_unique<LogicalCopyToFile>(copy_function->function, std::move(function_data));
106
136
  copy->file_path = stmt.info->file_path;
@@ -110,7 +140,8 @@ BoundStatement Binder::BindCopyTo(CopyStatement &stmt) {
110
140
  copy->per_thread_output = per_thread_output;
111
141
  copy->partition_output = !partition_cols.empty();
112
142
  copy->partition_columns = std::move(partition_cols);
113
- copy->names = select_node.names;
143
+
144
+ copy->names = unique_column_names;
114
145
  copy->expected_types = select_node.types;
115
146
 
116
147
  copy->AddChild(std::move(select_node.plan));