Skip to content

Commit 4f82d4e

Browse files
duckdblabs-botgithub-actions[bot]
authored andcommitted
Update vendored DuckDB sources to abd077cd1e
1 parent 86e7ac2 commit 4f82d4e

9 files changed

Lines changed: 55 additions & 26 deletions

File tree

src/duckdb/extension/parquet/include/parquet_dbp_decoder.hpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class DbpDecoder {
1818
: buffer_(buffer, buffer_len),
1919
//<block size in values> <number of miniblocks in a block> <total value count> <first value>
2020
block_size_in_values(ParquetDecodeUtils::VarintDecode<uint64_t>(buffer_)),
21-
number_of_miniblocks_per_block(ParquetDecodeUtils::VarintDecode<uint64_t>(buffer_)),
21+
number_of_miniblocks_per_block(DecodeNumberOfMiniblocksPerBlock(buffer_)),
2222
number_of_values_in_a_miniblock(block_size_in_values / number_of_miniblocks_per_block),
2323
total_value_count(ParquetDecodeUtils::VarintDecode<uint64_t>(buffer_)),
2424
previous_value(ParquetDecodeUtils::ZigzagToInt(ParquetDecodeUtils::VarintDecode<uint64_t>(buffer_))),
@@ -31,7 +31,7 @@ class DbpDecoder {
3131
number_of_values_in_a_miniblock % BitpackingPrimitives::BITPACKING_ALGORITHM_GROUP_SIZE == 0)) {
3232
throw InvalidInputException("Parquet file has invalid block sizes for DELTA_BINARY_PACKED");
3333
}
34-
};
34+
}
3535

3636
ByteBuffer BufferPtr() const {
3737
return buffer_;
@@ -68,6 +68,15 @@ class DbpDecoder {
6868
}
6969

7070
private:
71+
static idx_t DecodeNumberOfMiniblocksPerBlock(ByteBuffer &buffer) {
72+
auto res = ParquetDecodeUtils::VarintDecode<uint64_t>(buffer);
73+
if (res == 0) {
74+
throw InvalidInputException(
75+
"Parquet file has invalid number of miniblocks per block for DELTA_BINARY_PACKED");
76+
}
77+
return res;
78+
}
79+
7180
template <typename T, bool SKIP_READ = false>
7281
void GetBatchInternal(const data_ptr_t target_values_ptr, const idx_t batch_size) {
7382
if (batch_size == 0) {

src/duckdb/extension/parquet/parquet_reader.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,9 @@ unique_ptr<ParquetColumnSchema> ParquetReader::ParseSchema(ClientContext &contex
740740
throw InvalidInputException("Root element of Parquet file must be a struct");
741741
}
742742
D_ASSERT(next_schema_idx == file_meta_data->schema.size() - 1);
743-
D_ASSERT(file_meta_data->row_groups.empty() || next_file_idx == file_meta_data->row_groups[0].columns.size());
743+
if (!file_meta_data->row_groups.empty() && next_file_idx != file_meta_data->row_groups[0].columns.size()) {
744+
throw InvalidInputException("Parquet reader: row group does not have enough columns");
745+
}
744746
if (parquet_options.file_row_number) {
745747
for (auto &column : root.children) {
746748
auto &name = column.name;

src/duckdb/src/function/table/version/pragma_version.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#ifndef DUCKDB_PATCH_VERSION
2-
#define DUCKDB_PATCH_VERSION "2-dev31"
2+
#define DUCKDB_PATCH_VERSION "2-dev54"
33
#endif
44
#ifndef DUCKDB_MINOR_VERSION
55
#define DUCKDB_MINOR_VERSION 4
@@ -8,10 +8,10 @@
88
#define DUCKDB_MAJOR_VERSION 1
99
#endif
1010
#ifndef DUCKDB_VERSION
11-
#define DUCKDB_VERSION "v1.4.2-dev31"
11+
#define DUCKDB_VERSION "v1.4.2-dev54"
1212
#endif
1313
#ifndef DUCKDB_SOURCE_ID
14-
#define DUCKDB_SOURCE_ID "46beeea72f"
14+
#define DUCKDB_SOURCE_ID "abd077cd1e"
1515
#endif
1616
#include "duckdb/function/table/system_functions.hpp"
1717
#include "duckdb/main/database.hpp"

src/duckdb/src/include/duckdb/common/sort/duckdb_pdqsort.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ applications, and to alter it and redistribute it freely, subject to the followi
2626
#include "duckdb/common/helper.hpp"
2727
#include "duckdb/common/types.hpp"
2828
#include "duckdb/common/unique_ptr.hpp"
29+
#include "duckdb/common/operator/numeric_cast.hpp"
2930

3031
#include <algorithm>
3132
#include <cstddef>

src/duckdb/src/include/duckdb/main/attached_database.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ enum class AttachedDatabaseType {
3535
class DatabaseFilePathManager;
3636

3737
struct StoredDatabasePath {
38-
StoredDatabasePath(DatabaseFilePathManager &manager, string path, const string &name);
38+
StoredDatabasePath(DatabaseManager &db_manager, DatabaseFilePathManager &manager, string path, const string &name);
3939
~StoredDatabasePath();
4040

41+
DatabaseManager &db_manager;
4142
DatabaseFilePathManager &manager;
4243
string path;
4344

src/duckdb/src/include/duckdb/main/database_file_path_manager.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,34 @@
1313
#include "duckdb/common/case_insensitive_map.hpp"
1414
#include "duckdb/common/enums/on_create_conflict.hpp"
1515
#include "duckdb/common/enums/access_mode.hpp"
16+
#include "duckdb/common/reference_map.hpp"
1617

1718
namespace duckdb {
1819
struct AttachInfo;
1920
struct AttachOptions;
21+
class DatabaseManager;
2022

2123
enum class InsertDatabasePathResult { SUCCESS, ALREADY_EXISTS };
2224

2325
struct DatabasePathInfo {
24-
explicit DatabasePathInfo(string name_p, AccessMode access_mode)
25-
: name(std::move(name_p)), access_mode(access_mode), is_attached(true) {
26-
}
26+
DatabasePathInfo(DatabaseManager &manager, string name_p, AccessMode access_mode);
2727

2828
string name;
2929
AccessMode access_mode;
30-
bool is_attached;
30+
reference_set_t<DatabaseManager> attached_databases;
3131
idx_t reference_count = 1;
3232
};
3333

3434
//! The DatabaseFilePathManager is used to ensure we only ever open a single database file once
3535
class DatabaseFilePathManager {
3636
public:
3737
idx_t ApproxDatabaseCount() const;
38-
InsertDatabasePathResult InsertDatabasePath(const string &path, const string &name, OnCreateConflict on_conflict,
39-
AttachOptions &options);
38+
InsertDatabasePathResult InsertDatabasePath(DatabaseManager &manager, const string &path, const string &name,
39+
OnCreateConflict on_conflict, AttachOptions &options);
4040
//! Erase a database path - indicating we are done with using it
4141
void EraseDatabasePath(const string &path);
4242
//! Called when a database is detached, but before it is fully finished being used
43-
void DetachDatabase(const string &path);
43+
void DetachDatabase(DatabaseManager &manager, const string &path);
4444

4545
private:
4646
//! The lock to add entries to the database path map

src/duckdb/src/main/attached_database.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@
1414

1515
namespace duckdb {
1616

17-
StoredDatabasePath::StoredDatabasePath(DatabaseFilePathManager &manager, string path_p, const string &name)
18-
: manager(manager), path(std::move(path_p)) {
17+
StoredDatabasePath::StoredDatabasePath(DatabaseManager &db_manager, DatabaseFilePathManager &manager, string path_p,
18+
const string &name)
19+
: db_manager(db_manager), manager(manager), path(std::move(path_p)) {
1920
}
2021

2122
StoredDatabasePath::~StoredDatabasePath() {
2223
manager.EraseDatabasePath(path);
2324
}
2425

2526
void StoredDatabasePath::OnDetach() {
26-
manager.DetachDatabase(path);
27+
manager.DetachDatabase(db_manager, path);
2728
}
2829

2930
//===--------------------------------------------------------------------===//

src/duckdb/src/main/database_file_path_manager.cpp

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,43 @@
55

66
namespace duckdb {
77

8+
DatabasePathInfo::DatabasePathInfo(DatabaseManager &manager, string name_p, AccessMode access_mode)
9+
: name(std::move(name_p)), access_mode(access_mode) {
10+
attached_databases.insert(manager);
11+
}
12+
813
idx_t DatabaseFilePathManager::ApproxDatabaseCount() const {
914
lock_guard<mutex> path_lock(db_paths_lock);
1015
return db_paths.size();
1116
}
1217

13-
InsertDatabasePathResult DatabaseFilePathManager::InsertDatabasePath(const string &path, const string &name,
14-
OnCreateConflict on_conflict,
18+
InsertDatabasePathResult DatabaseFilePathManager::InsertDatabasePath(DatabaseManager &manager, const string &path,
19+
const string &name, OnCreateConflict on_conflict,
1520
AttachOptions &options) {
1621
if (path.empty() || path == IN_MEMORY_PATH) {
1722
return InsertDatabasePathResult::SUCCESS;
1823
}
1924

2025
lock_guard<mutex> path_lock(db_paths_lock);
21-
auto entry = db_paths.emplace(path, DatabasePathInfo(name, options.access_mode));
26+
auto entry = db_paths.emplace(path, DatabasePathInfo(manager, name, options.access_mode));
2227
if (!entry.second) {
2328
auto &existing = entry.first->second;
29+
bool already_exists = false;
30+
bool attached_in_this_system = false;
31+
if (on_conflict == OnCreateConflict::IGNORE_ON_CONFLICT && existing.name == name) {
32+
already_exists = true;
33+
attached_in_this_system = existing.attached_databases.find(manager) != existing.attached_databases.end();
34+
}
2435
if (options.access_mode == AccessMode::READ_ONLY && existing.access_mode == AccessMode::READ_ONLY) {
36+
if (attached_in_this_system) {
37+
return InsertDatabasePathResult::ALREADY_EXISTS;
38+
}
2539
// all attaches are in read-only mode - there is no conflict, just increase the reference count
40+
existing.attached_databases.insert(manager);
2641
existing.reference_count++;
2742
} else {
28-
if (on_conflict == OnCreateConflict::IGNORE_ON_CONFLICT && existing.name == name) {
29-
if (existing.is_attached) {
43+
if (already_exists) {
44+
if (attached_in_this_system) {
3045
return InsertDatabasePathResult::ALREADY_EXISTS;
3146
}
3247
throw BinderException(
@@ -40,7 +55,7 @@ InsertDatabasePathResult DatabaseFilePathManager::InsertDatabasePath(const strin
4055
name, path, existing.name);
4156
}
4257
}
43-
options.stored_database_path = make_uniq<StoredDatabasePath>(*this, path, name);
58+
options.stored_database_path = make_uniq<StoredDatabasePath>(manager, *this, path, name);
4459
return InsertDatabasePathResult::SUCCESS;
4560
}
4661

@@ -59,14 +74,14 @@ void DatabaseFilePathManager::EraseDatabasePath(const string &path) {
5974
}
6075
}
6176

62-
void DatabaseFilePathManager::DetachDatabase(const string &path) {
77+
void DatabaseFilePathManager::DetachDatabase(DatabaseManager &manager, const string &path) {
6378
if (path.empty() || path == IN_MEMORY_PATH) {
6479
return;
6580
}
6681
lock_guard<mutex> path_lock(db_paths_lock);
6782
auto entry = db_paths.find(path);
6883
if (entry != db_paths.end()) {
69-
entry->second.is_attached = false;
84+
entry->second.attached_databases.erase(manager);
7085
}
7186
}
7287

src/duckdb/src/main/database_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ idx_t DatabaseManager::ApproxDatabaseCount() {
199199
}
200200

201201
InsertDatabasePathResult DatabaseManager::InsertDatabasePath(const AttachInfo &info, AttachOptions &options) {
202-
return path_manager->InsertDatabasePath(info.path, info.name, info.on_conflict, options);
202+
return path_manager->InsertDatabasePath(*this, info.path, info.name, info.on_conflict, options);
203203
}
204204

205205
vector<string> DatabaseManager::GetAttachedDatabasePaths() {

0 commit comments

Comments
 (0)