duckdb 0.7.2-dev3546.0 → 0.7.2-dev3710.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 (94) hide show
  1. package/package.json +1 -1
  2. package/src/database.cpp +1 -0
  3. package/src/duckdb/extension/json/buffered_json_reader.cpp +56 -17
  4. package/src/duckdb/extension/json/include/buffered_json_reader.hpp +56 -31
  5. package/src/duckdb/extension/json/include/json_common.hpp +5 -4
  6. package/src/duckdb/extension/json/include/json_executors.hpp +13 -18
  7. package/src/duckdb/extension/json/include/json_functions.hpp +3 -0
  8. package/src/duckdb/extension/json/include/json_scan.hpp +106 -153
  9. package/src/duckdb/extension/json/include/json_transform.hpp +2 -2
  10. package/src/duckdb/extension/json/json_common.cpp +1 -1
  11. package/src/duckdb/extension/json/json_functions/copy_json.cpp +94 -38
  12. package/src/duckdb/extension/json/json_functions/json_contains.cpp +7 -8
  13. package/src/duckdb/extension/json/json_functions/json_create.cpp +7 -7
  14. package/src/duckdb/extension/json/json_functions/json_merge_patch.cpp +4 -4
  15. package/src/duckdb/extension/json/json_functions/json_serialize_sql.cpp +4 -4
  16. package/src/duckdb/extension/json/json_functions/json_structure.cpp +7 -5
  17. package/src/duckdb/extension/json/json_functions/json_transform.cpp +11 -9
  18. package/src/duckdb/extension/json/json_functions/json_valid.cpp +1 -1
  19. package/src/duckdb/extension/json/json_functions/read_json.cpp +166 -169
  20. package/src/duckdb/extension/json/json_functions/read_json_objects.cpp +37 -16
  21. package/src/duckdb/extension/json/json_functions.cpp +11 -4
  22. package/src/duckdb/extension/json/json_scan.cpp +593 -374
  23. package/src/duckdb/extension/parquet/parquet-extension.cpp +5 -0
  24. package/src/duckdb/src/common/exception.cpp +17 -0
  25. package/src/duckdb/src/common/exception_format_value.cpp +14 -0
  26. package/src/duckdb/src/common/file_system.cpp +78 -36
  27. package/src/duckdb/src/common/local_file_system.cpp +5 -16
  28. package/src/duckdb/src/common/types.cpp +1 -1
  29. package/src/duckdb/src/core_functions/scalar/list/list_lambdas.cpp +1 -1
  30. package/src/duckdb/src/execution/operator/persistent/buffered_csv_reader.cpp +12 -6
  31. package/src/duckdb/src/execution/operator/persistent/csv_reader_options.cpp +10 -0
  32. package/src/duckdb/src/execution/operator/persistent/physical_export.cpp +2 -2
  33. package/src/duckdb/src/function/pragma/pragma_queries.cpp +6 -4
  34. package/src/duckdb/src/function/table/copy_csv.cpp +66 -12
  35. package/src/duckdb/src/function/table/read_csv.cpp +16 -3
  36. package/src/duckdb/src/function/table/version/pragma_version.cpp +8 -2
  37. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/column_dependency_manager.hpp +1 -1
  38. package/src/duckdb/src/include/duckdb/catalog/catalog_search_path.hpp +1 -1
  39. package/src/duckdb/src/include/duckdb/catalog/similar_catalog_entry.hpp +1 -1
  40. package/src/duckdb/src/include/duckdb/common/exception.hpp +3 -3
  41. package/src/duckdb/src/include/duckdb/common/exception_format_value.hpp +26 -0
  42. package/src/duckdb/src/include/duckdb/common/file_system.hpp +11 -0
  43. package/src/duckdb/src/include/duckdb/common/http_state.hpp +2 -1
  44. package/src/duckdb/src/include/duckdb/common/hugeint.hpp +6 -6
  45. package/src/duckdb/src/include/duckdb/common/limits.hpp +46 -46
  46. package/src/duckdb/src/include/duckdb/common/operator/cast_operators.hpp +8 -8
  47. package/src/duckdb/src/include/duckdb/common/operator/comparison_operators.hpp +6 -6
  48. package/src/duckdb/src/include/duckdb/common/operator/convert_to_string.hpp +1 -1
  49. package/src/duckdb/src/include/duckdb/common/operator/decimal_cast_operators.hpp +2 -4
  50. package/src/duckdb/src/include/duckdb/common/operator/string_cast.hpp +1 -1
  51. package/src/duckdb/src/include/duckdb/common/operator/subtract.hpp +1 -1
  52. package/src/duckdb/src/include/duckdb/common/preserved_error.hpp +1 -1
  53. package/src/duckdb/src/include/duckdb/common/re2_regex.hpp +1 -1
  54. package/src/duckdb/src/include/duckdb/common/string_util.hpp +25 -7
  55. package/src/duckdb/src/include/duckdb/common/types/chunk_collection.hpp +10 -10
  56. package/src/duckdb/src/include/duckdb/common/types/column/column_data_collection.hpp +12 -12
  57. package/src/duckdb/src/include/duckdb/common/types/column/column_data_collection_iterators.hpp +2 -2
  58. package/src/duckdb/src/include/duckdb/common/types/value.hpp +1 -1
  59. package/src/duckdb/src/include/duckdb/common/types.hpp +2 -2
  60. package/src/duckdb/src/include/duckdb/common/winapi.hpp +1 -1
  61. package/src/duckdb/src/include/duckdb/execution/expression_executor_state.hpp +1 -1
  62. package/src/duckdb/src/include/duckdb/execution/operator/persistent/csv_reader_options.hpp +8 -3
  63. package/src/duckdb/src/include/duckdb/function/aggregate_function.hpp +10 -14
  64. package/src/duckdb/src/include/duckdb/function/table_function.hpp +1 -1
  65. package/src/duckdb/src/include/duckdb/function/udf_function.hpp +56 -50
  66. package/src/duckdb/src/include/duckdb/main/appender.hpp +2 -2
  67. package/src/duckdb/src/include/duckdb/main/client_context.hpp +2 -2
  68. package/src/duckdb/src/include/duckdb/main/client_data.hpp +3 -1
  69. package/src/duckdb/src/include/duckdb/main/connection.hpp +8 -9
  70. package/src/duckdb/src/include/duckdb/main/extension_entries.hpp +1 -0
  71. package/src/duckdb/src/include/duckdb/main/query_result.hpp +3 -3
  72. package/src/duckdb/src/include/duckdb/main/relation.hpp +6 -7
  73. package/src/duckdb/src/include/duckdb/optimizer/optimizer_extension.hpp +1 -1
  74. package/src/duckdb/src/include/duckdb/parser/column_list.hpp +7 -7
  75. package/src/duckdb/src/include/duckdb/parser/expression/function_expression.hpp +1 -1
  76. package/src/duckdb/src/include/duckdb/parser/expression/operator_expression.hpp +2 -2
  77. package/src/duckdb/src/include/duckdb/parser/keyword_helper.hpp +5 -0
  78. package/src/duckdb/src/include/duckdb/parser/parser_extension.hpp +2 -2
  79. package/src/duckdb/src/include/duckdb/parser/sql_statement.hpp +1 -1
  80. package/src/duckdb/src/include/duckdb/parser/statement/select_statement.hpp +1 -1
  81. package/src/duckdb/src/include/duckdb/planner/operator_extension.hpp +2 -2
  82. package/src/duckdb/src/include/duckdb/storage/storage_extension.hpp +2 -2
  83. package/src/duckdb/src/main/db_instance_cache.cpp +5 -3
  84. package/src/duckdb/src/main/extension/extension_install.cpp +22 -18
  85. package/src/duckdb/src/parser/expression/collate_expression.cpp +1 -1
  86. package/src/duckdb/src/parser/keyword_helper.cpp +11 -1
  87. package/src/duckdb/src/parser/query_node/select_node.cpp +1 -1
  88. package/src/duckdb/src/parser/statement/copy_statement.cpp +2 -2
  89. package/src/duckdb/src/parser/tableref.cpp +1 -1
  90. package/src/duckdb/src/planner/binder/statement/bind_copy.cpp +9 -4
  91. package/src/duckdb/src/planner/binder/tableref/bind_basetableref.cpp +1 -1
  92. package/src/duckdb/src/storage/single_file_block_manager.cpp +0 -4
  93. package/src/duckdb/src/storage/storage_manager.cpp +3 -0
  94. package/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp +5735 -5773
@@ -133,6 +133,23 @@ void ExtensionHelper::InstallExtension(ClientContext &context, const string &ext
133
133
  InstallExtensionInternal(config, &client_config, fs, local_path, extension, force_install);
134
134
  }
135
135
 
136
+ unsafe_array_ptr<data_t> ReadExtensionFileFromDisk(FileSystem &fs, const string &path, idx_t &file_size) {
137
+ auto source_file = fs.OpenFile(path, FileFlags::FILE_FLAGS_READ);
138
+ file_size = source_file->GetFileSize();
139
+ auto in_buffer = make_unsafe_array<data_t>(file_size);
140
+ source_file->Read(in_buffer.get(), file_size);
141
+ source_file->Close();
142
+ return in_buffer;
143
+ }
144
+
145
+ void WriteExtensionFileToDisk(FileSystem &fs, const string &path, void *data, idx_t data_size) {
146
+ auto target_file = fs.OpenFile(path, FileFlags::FILE_FLAGS_WRITE | FileFlags::FILE_FLAGS_APPEND |
147
+ FileFlags::FILE_FLAGS_FILE_CREATE_NEW);
148
+ target_file->Write(data, data_size);
149
+ target_file->Close();
150
+ target_file.reset();
151
+ }
152
+
136
153
  void ExtensionHelper::InstallExtensionInternal(DBConfig &config, ClientConfig *client_config, FileSystem &fs,
137
154
  const string &local_path, const string &extension, bool force_install) {
138
155
  if (!config.options.enable_external_access) {
@@ -152,18 +169,9 @@ void ExtensionHelper::InstallExtensionInternal(DBConfig &config, ClientConfig *c
152
169
  }
153
170
  auto is_http_url = StringUtil::Contains(extension, "http://");
154
171
  if (fs.FileExists(extension)) {
155
-
156
- std::ifstream in(extension, std::ios::binary);
157
- if (in.bad()) {
158
- throw IOException("Failed to read extension from \"%s\"", extension);
159
- }
160
- std::ofstream out(temp_path, std::ios::binary);
161
- out << in.rdbuf();
162
- if (out.bad()) {
163
- throw IOException("Failed to write extension to \"%s\"", temp_path);
164
- }
165
- in.close();
166
- out.close();
172
+ idx_t file_size;
173
+ auto in_buffer = ReadExtensionFileFromDisk(fs, extension, file_size);
174
+ WriteExtensionFileToDisk(fs, temp_path, in_buffer.get(), file_size);
167
175
 
168
176
  fs.MoveFile(temp_path, local_extension_path);
169
177
  return;
@@ -225,12 +233,8 @@ void ExtensionHelper::InstallExtensionInternal(DBConfig &config, ClientConfig *c
225
233
  }
226
234
  }
227
235
  auto decompressed_body = GZipFileSystem::UncompressGZIPString(res->body);
228
- std::ofstream out(temp_path, std::ios::binary);
229
- out.write(decompressed_body.data(), decompressed_body.size());
230
- if (out.bad()) {
231
- throw IOException("Failed to write extension to %s", temp_path);
232
- }
233
- out.close();
236
+
237
+ WriteExtensionFileToDisk(fs, temp_path, (void *)decompressed_body.data(), decompressed_body.size());
234
238
  fs.MoveFile(temp_path, local_extension_path);
235
239
  #endif
236
240
  }
@@ -15,7 +15,7 @@ CollateExpression::CollateExpression(string collation_p, unique_ptr<ParsedExpres
15
15
  }
16
16
 
17
17
  string CollateExpression::ToString() const {
18
- return child->ToString() + " COLLATE " + KeywordHelper::WriteOptionallyQuoted(collation);
18
+ return StringUtil::Format("%s COLLATE %s", child->ToString(), SQLIdentifier(collation));
19
19
  }
20
20
 
21
21
  bool CollateExpression::Equal(const CollateExpression *a, const CollateExpression *b) {
@@ -29,11 +29,21 @@ bool KeywordHelper::RequiresQuotes(const string &text, bool allow_caps) {
29
29
  return IsKeyword(text);
30
30
  }
31
31
 
32
+ string KeywordHelper::EscapeQuotes(const string &text, char quote) {
33
+ return StringUtil::Replace(text, string(1, quote), string(2, quote));
34
+ }
35
+
36
+ string KeywordHelper::WriteQuoted(const string &text, char quote) {
37
+ // 1. Escapes all occurences of 'quote' by doubling them (escape in SQL)
38
+ // 2. Adds quotes around the string
39
+ return string(1, quote) + EscapeQuotes(text) + string(1, quote);
40
+ }
41
+
32
42
  string KeywordHelper::WriteOptionallyQuoted(const string &text, char quote, bool allow_caps) {
33
43
  if (!RequiresQuotes(text, allow_caps)) {
34
44
  return text;
35
45
  }
36
- return string(1, quote) + StringUtil::Replace(text, string(1, quote), string(2, quote)) + string(1, quote);
46
+ return WriteQuoted(text, quote);
37
47
  }
38
48
 
39
49
  } // namespace duckdb
@@ -39,7 +39,7 @@ string SelectNode::ToString() const {
39
39
  }
40
40
  result += select_list[i]->ToString();
41
41
  if (!select_list[i]->alias.empty()) {
42
- result += " AS " + KeywordHelper::WriteOptionallyQuoted(select_list[i]->alias);
42
+ result += StringUtil::Format(" AS %s", SQLIdentifier(select_list[i]->alias));
43
43
  }
44
44
  }
45
45
  if (from_table && from_table->type != TableReferenceType::EMPTY) {
@@ -86,7 +86,7 @@ string CopyStatement::ToString() const {
86
86
  D_ASSERT(!select_statement);
87
87
  result += TablePart(*info);
88
88
  result += " FROM";
89
- result += StringUtil::Format(" '%s'", info->file_path);
89
+ result += StringUtil::Format(" %s", SQLString(info->file_path));
90
90
  result += CopyOptionsToString(info->format, info->options);
91
91
  } else {
92
92
  if (select_statement) {
@@ -96,7 +96,7 @@ string CopyStatement::ToString() const {
96
96
  result += TablePart(*info);
97
97
  }
98
98
  result += " TO ";
99
- result += StringUtil::Format("'%s'", info->file_path);
99
+ result += StringUtil::Format("%s", SQLString(info->file_path));
100
100
  result += CopyOptionsToString(info->format, info->options);
101
101
  }
102
102
  return result;
@@ -16,7 +16,7 @@ string TableRef::BaseToString(string result) const {
16
16
 
17
17
  string TableRef::BaseToString(string result, const vector<string> &column_name_alias) const {
18
18
  if (!alias.empty()) {
19
- result += " AS " + KeywordHelper::WriteOptionallyQuoted(alias);
19
+ result += StringUtil::Format(" AS %s", SQLIdentifier(alias));
20
20
  }
21
21
  if (!column_name_alias.empty()) {
22
22
  D_ASSERT(!alias.empty());
@@ -129,10 +129,15 @@ BoundStatement Binder::BindCopyTo(CopyStatement &stmt) {
129
129
  if (per_thread_output && !partition_cols.empty()) {
130
130
  throw NotImplementedException("Can't combine PER_THREAD_OUTPUT and PARTITION_BY for COPY");
131
131
  }
132
- bool is_file_and_exists = config.file_system->FileExists(stmt.info->file_path);
133
- bool is_stdout = stmt.info->file_path == "/dev/stdout";
134
- if (!user_set_use_tmp_file) {
135
- use_tmp_file = is_file_and_exists && !per_thread_output && partition_cols.empty() && !is_stdout;
132
+ bool is_remote_file = config.file_system->IsRemoteFile(stmt.info->file_path);
133
+ if (is_remote_file) {
134
+ use_tmp_file = false;
135
+ } else {
136
+ bool is_file_and_exists = config.file_system->FileExists(stmt.info->file_path);
137
+ bool is_stdout = stmt.info->file_path == "/dev/stdout";
138
+ if (!user_set_use_tmp_file) {
139
+ use_tmp_file = is_file_and_exists && !per_thread_output && partition_cols.empty() && !is_stdout;
140
+ }
136
141
  }
137
142
 
138
143
  auto unique_column_names = GetUniqueNames(select_node.names);
@@ -94,7 +94,7 @@ unique_ptr<BoundTableRef> Binder::Bind(BaseTableRef &ref) {
94
94
  for (auto &scan : config.replacement_scans) {
95
95
  auto replacement_function = scan.function(context, table_name, scan.data.get());
96
96
  if (replacement_function) {
97
- replacement_function->alias = ref.alias.empty() ? ref.table_name : ref.alias;
97
+ replacement_function->alias = ref.alias.empty() ? replacement_function->alias : ref.alias;
98
98
  if (replacement_function->type == TableReferenceType::TABLE_FUNCTION) {
99
99
  auto &table_function = replacement_function->Cast<TableFunctionRef>();
100
100
  table_function.column_name_alias = ref.column_name_alias;
@@ -241,10 +241,6 @@ void SingleFileBlockManager::Initialize(DatabaseHeader &header) {
241
241
  }
242
242
 
243
243
  void SingleFileBlockManager::LoadFreeList() {
244
- if (options.read_only) {
245
- // no need to load free list for read only db
246
- return;
247
- }
248
244
  if (free_list_id == INVALID_BLOCK) {
249
245
  // no free list
250
246
  return;
@@ -19,6 +19,9 @@ StorageManager::StorageManager(AttachedDatabase &db, string path_p, bool read_on
19
19
  : db(db), path(std::move(path_p)), read_only(read_only) {
20
20
  if (path.empty()) {
21
21
  path = ":memory:";
22
+ } else {
23
+ auto &fs = FileSystem::Get(db);
24
+ this->path = fs.ExpandPath(path);
22
25
  }
23
26
  }
24
27