Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/duckdb/extension/parquet/include/parquet_dbp_decoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DbpDecoder {
: buffer_(buffer, buffer_len),
//<block size in values> <number of miniblocks in a block> <total value count> <first value>
block_size_in_values(ParquetDecodeUtils::VarintDecode<uint64_t>(buffer_)),
number_of_miniblocks_per_block(ParquetDecodeUtils::VarintDecode<uint64_t>(buffer_)),
number_of_miniblocks_per_block(DecodeNumberOfMiniblocksPerBlock(buffer_)),
number_of_values_in_a_miniblock(block_size_in_values / number_of_miniblocks_per_block),
total_value_count(ParquetDecodeUtils::VarintDecode<uint64_t>(buffer_)),
previous_value(ParquetDecodeUtils::ZigzagToInt(ParquetDecodeUtils::VarintDecode<uint64_t>(buffer_))),
Expand All @@ -31,7 +31,7 @@ class DbpDecoder {
number_of_values_in_a_miniblock % BitpackingPrimitives::BITPACKING_ALGORITHM_GROUP_SIZE == 0)) {
throw InvalidInputException("Parquet file has invalid block sizes for DELTA_BINARY_PACKED");
}
};
}

ByteBuffer BufferPtr() const {
return buffer_;
Expand Down Expand Up @@ -68,6 +68,15 @@ class DbpDecoder {
}

private:
static idx_t DecodeNumberOfMiniblocksPerBlock(ByteBuffer &buffer) {
auto res = ParquetDecodeUtils::VarintDecode<uint64_t>(buffer);
if (res == 0) {
throw InvalidInputException(
"Parquet file has invalid number of miniblocks per block for DELTA_BINARY_PACKED");
}
return res;
}

template <typename T, bool SKIP_READ = false>
void GetBatchInternal(const data_ptr_t target_values_ptr, const idx_t batch_size) {
if (batch_size == 0) {
Expand Down
4 changes: 3 additions & 1 deletion src/duckdb/extension/parquet/parquet_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,9 @@ unique_ptr<ParquetColumnSchema> ParquetReader::ParseSchema(ClientContext &contex
throw InvalidInputException("Root element of Parquet file must be a struct");
}
D_ASSERT(next_schema_idx == file_meta_data->schema.size() - 1);
D_ASSERT(file_meta_data->row_groups.empty() || next_file_idx == file_meta_data->row_groups[0].columns.size());
if (!file_meta_data->row_groups.empty() && next_file_idx != file_meta_data->row_groups[0].columns.size()) {
throw InvalidInputException("Parquet reader: row group does not have enough columns");
}
if (parquet_options.file_row_number) {
for (auto &column : root.children) {
auto &name = column.name;
Expand Down
6 changes: 3 additions & 3 deletions src/duckdb/src/function/table/version/pragma_version.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef DUCKDB_PATCH_VERSION
#define DUCKDB_PATCH_VERSION "2-dev31"
#define DUCKDB_PATCH_VERSION "2-dev54"
#endif
#ifndef DUCKDB_MINOR_VERSION
#define DUCKDB_MINOR_VERSION 4
Expand All @@ -8,10 +8,10 @@
#define DUCKDB_MAJOR_VERSION 1
#endif
#ifndef DUCKDB_VERSION
#define DUCKDB_VERSION "v1.4.2-dev31"
#define DUCKDB_VERSION "v1.4.2-dev54"
#endif
#ifndef DUCKDB_SOURCE_ID
#define DUCKDB_SOURCE_ID "46beeea72f"
#define DUCKDB_SOURCE_ID "abd077cd1e"
#endif
#include "duckdb/function/table/system_functions.hpp"
#include "duckdb/main/database.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ applications, and to alter it and redistribute it freely, subject to the followi
#include "duckdb/common/helper.hpp"
#include "duckdb/common/types.hpp"
#include "duckdb/common/unique_ptr.hpp"
#include "duckdb/common/operator/numeric_cast.hpp"

#include <algorithm>
#include <cstddef>
Expand Down
3 changes: 2 additions & 1 deletion src/duckdb/src/include/duckdb/main/attached_database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ enum class AttachedDatabaseType {
class DatabaseFilePathManager;

struct StoredDatabasePath {
StoredDatabasePath(DatabaseFilePathManager &manager, string path, const string &name);
StoredDatabasePath(DatabaseManager &db_manager, DatabaseFilePathManager &manager, string path, const string &name);
~StoredDatabasePath();

DatabaseManager &db_manager;
DatabaseFilePathManager &manager;
string path;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,34 @@
#include "duckdb/common/case_insensitive_map.hpp"
#include "duckdb/common/enums/on_create_conflict.hpp"
#include "duckdb/common/enums/access_mode.hpp"
#include "duckdb/common/reference_map.hpp"

namespace duckdb {
struct AttachInfo;
struct AttachOptions;
class DatabaseManager;

enum class InsertDatabasePathResult { SUCCESS, ALREADY_EXISTS };

struct DatabasePathInfo {
explicit DatabasePathInfo(string name_p, AccessMode access_mode)
: name(std::move(name_p)), access_mode(access_mode), is_attached(true) {
}
DatabasePathInfo(DatabaseManager &manager, string name_p, AccessMode access_mode);

string name;
AccessMode access_mode;
bool is_attached;
reference_set_t<DatabaseManager> attached_databases;
idx_t reference_count = 1;
};

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

private:
//! The lock to add entries to the database path map
Expand Down
7 changes: 4 additions & 3 deletions src/duckdb/src/main/attached_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@

namespace duckdb {

StoredDatabasePath::StoredDatabasePath(DatabaseFilePathManager &manager, string path_p, const string &name)
: manager(manager), path(std::move(path_p)) {
StoredDatabasePath::StoredDatabasePath(DatabaseManager &db_manager, DatabaseFilePathManager &manager, string path_p,
const string &name)
: db_manager(db_manager), manager(manager), path(std::move(path_p)) {
}

StoredDatabasePath::~StoredDatabasePath() {
manager.EraseDatabasePath(path);
}

void StoredDatabasePath::OnDetach() {
manager.DetachDatabase(path);
manager.DetachDatabase(db_manager, path);
}

//===--------------------------------------------------------------------===//
Expand Down
31 changes: 23 additions & 8 deletions src/duckdb/src/main/database_file_path_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,43 @@

namespace duckdb {

DatabasePathInfo::DatabasePathInfo(DatabaseManager &manager, string name_p, AccessMode access_mode)
: name(std::move(name_p)), access_mode(access_mode) {
attached_databases.insert(manager);
}

idx_t DatabaseFilePathManager::ApproxDatabaseCount() const {
lock_guard<mutex> path_lock(db_paths_lock);
return db_paths.size();
}

InsertDatabasePathResult DatabaseFilePathManager::InsertDatabasePath(const string &path, const string &name,
OnCreateConflict on_conflict,
InsertDatabasePathResult DatabaseFilePathManager::InsertDatabasePath(DatabaseManager &manager, const string &path,
const string &name, OnCreateConflict on_conflict,
AttachOptions &options) {
if (path.empty() || path == IN_MEMORY_PATH) {
return InsertDatabasePathResult::SUCCESS;
}

lock_guard<mutex> path_lock(db_paths_lock);
auto entry = db_paths.emplace(path, DatabasePathInfo(name, options.access_mode));
auto entry = db_paths.emplace(path, DatabasePathInfo(manager, name, options.access_mode));
if (!entry.second) {
auto &existing = entry.first->second;
bool already_exists = false;
bool attached_in_this_system = false;
if (on_conflict == OnCreateConflict::IGNORE_ON_CONFLICT && existing.name == name) {
already_exists = true;
attached_in_this_system = existing.attached_databases.find(manager) != existing.attached_databases.end();
}
if (options.access_mode == AccessMode::READ_ONLY && existing.access_mode == AccessMode::READ_ONLY) {
if (attached_in_this_system) {
return InsertDatabasePathResult::ALREADY_EXISTS;
}
// all attaches are in read-only mode - there is no conflict, just increase the reference count
existing.attached_databases.insert(manager);
existing.reference_count++;
} else {
if (on_conflict == OnCreateConflict::IGNORE_ON_CONFLICT && existing.name == name) {
if (existing.is_attached) {
if (already_exists) {
if (attached_in_this_system) {
return InsertDatabasePathResult::ALREADY_EXISTS;
}
throw BinderException(
Expand All @@ -40,7 +55,7 @@ InsertDatabasePathResult DatabaseFilePathManager::InsertDatabasePath(const strin
name, path, existing.name);
}
}
options.stored_database_path = make_uniq<StoredDatabasePath>(*this, path, name);
options.stored_database_path = make_uniq<StoredDatabasePath>(manager, *this, path, name);
return InsertDatabasePathResult::SUCCESS;
}

Expand All @@ -59,14 +74,14 @@ void DatabaseFilePathManager::EraseDatabasePath(const string &path) {
}
}

void DatabaseFilePathManager::DetachDatabase(const string &path) {
void DatabaseFilePathManager::DetachDatabase(DatabaseManager &manager, const string &path) {
if (path.empty() || path == IN_MEMORY_PATH) {
return;
}
lock_guard<mutex> path_lock(db_paths_lock);
auto entry = db_paths.find(path);
if (entry != db_paths.end()) {
entry->second.is_attached = false;
entry->second.attached_databases.erase(manager);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/duckdb/src/main/database_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ idx_t DatabaseManager::ApproxDatabaseCount() {
}

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

vector<string> DatabaseManager::GetAttachedDatabasePaths() {
Expand Down