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
6 changes: 3 additions & 3 deletions src/duckdb/extension/parquet/parquet_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1282,9 +1282,9 @@ ParquetReader::ParquetReader(ClientContext &context_p, OpenFileInfo file_p, Parq
}
} else {
metadata = std::move(metadata_p);
if (parquet_options.encryption_config) {
encryption_util = context_p.db->GetEncryptionUtil(true);
}
}
if (parquet_options.encryption_config && !encryption_util) {
encryption_util = context_p.db->GetEncryptionUtil(true);
}
InitializeSchema(context_p);
// Length-pushdown rewrites these columns to BIGINT, update the local schema
Expand Down
39 changes: 34 additions & 5 deletions src/duckdb/src/catalog/catalog_entry/duck_table_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "duckdb/function/table/table_scan.hpp"
#include "duckdb/main/database.hpp"
#include "duckdb/parser/constraints/list.hpp"
#include "duckdb/parser/expression/constant_expression.hpp"
#include "duckdb/parser/parsed_data/comment_on_column_info.hpp"
#include "duckdb/parser/parsed_expression_iterator.hpp"
#include "duckdb/planner/binder.hpp"
Expand Down Expand Up @@ -333,7 +334,7 @@ unique_ptr<CatalogEntry> DuckTableEntry::AlterEntry(ClientContext &context, Alte
}
case AlterTableType::ALTER_COLUMN_TYPE: {
auto &change_type_info = table_info.Cast<ChangeColumnTypeInfo>();
return ChangeColumnType(context, change_type_info);
return ChangeColumnType(context, change_type_info, AlterTableType::ALTER_COLUMN_TYPE);
}
case AlterTableType::FOREIGN_KEY_CONSTRAINT: {
auto &foreign_key_constraint_info = table_info.Cast<AlterForeignKeyInfo>();
Expand Down Expand Up @@ -391,6 +392,29 @@ static void RenameExpression(ParsedExpression &root_expr, RenameColumnInfo &info
});
}

// Keep struct literal defaults aligned with nested field renames.
static unique_ptr<ParsedExpression> RemapStructDefault(unique_ptr<ParsedExpression> default_value,
const LogicalType &new_type, const Value &mapping) {
vector<unique_ptr<ParsedExpression>> children;
children.push_back(std::move(default_value));
children.push_back(make_uniq<ConstantExpression>(Value(new_type)));
children.push_back(make_uniq<ConstantExpression>(mapping.Copy()));
children.push_back(make_uniq<ConstantExpression>(Value()));
return make_uniq<FunctionExpression>("remap_struct", std::move(children));
}

static const Value &GetRemapStructMapping(ChangeColumnTypeInfo &info) {
D_ASSERT(info.expression);
D_ASSERT(info.expression->GetExpressionClass() == ExpressionClass::FUNCTION);
auto &function = info.expression->Cast<FunctionExpression>();
D_ASSERT(function.FunctionName() == "remap_struct");
auto &arguments = function.GetArguments();
D_ASSERT(arguments.size() == 4);
auto &mapping = arguments[2].GetExpression();
D_ASSERT(mapping.GetExpressionClass() == ExpressionClass::CONSTANT);
return mapping.Cast<ConstantExpression>().GetValue();
}

unique_ptr<CatalogEntry> DuckTableEntry::RenameColumn(ClientContext &context, RenameColumnInfo &info) {
auto rename_idx = GetColumnIndex(info.old_name);
if (rename_idx.index == COLUMN_IDENTIFIER_ROW_ID) {
Expand Down Expand Up @@ -674,7 +698,7 @@ unique_ptr<CatalogEntry> DuckTableEntry::AddField(ClientContext &context, AddFie

ChangeColumnTypeInfo change_column_type(info.GetAlterEntryData(), info.column_path[0], std::move(res.new_type),
std::move(function));
return ChangeColumnType(context, change_column_type);
return ChangeColumnType(context, change_column_type, AlterTableType::ADD_FIELD);
}

void DuckTableEntry::UpdateConstraintsOnColumnDrop(const LogicalIndex &removed_index,
Expand Down Expand Up @@ -930,7 +954,7 @@ unique_ptr<CatalogEntry> DuckTableEntry::RemoveField(ClientContext &context, Rem

ChangeColumnTypeInfo change_column_type(info.GetAlterEntryData(), info.column_path[0], std::move(res.new_type),
std::move(function));
return ChangeColumnType(context, change_column_type);
return ChangeColumnType(context, change_column_type, AlterTableType::REMOVE_FIELD);
}

DroppedFieldMapping RenameFieldFromStruct(const LogicalType &type, const vector<Identifier> &column_path,
Expand Down Expand Up @@ -1024,7 +1048,7 @@ unique_ptr<CatalogEntry> DuckTableEntry::RenameField(ClientContext &context, Ren
auto function = make_uniq<FunctionExpression>("remap_struct", std::move(children));
ChangeColumnTypeInfo change_column_type(info.GetAlterEntryData(), info.column_path[0], std::move(res.new_type),
std::move(function));
return ChangeColumnType(context, change_column_type);
return ChangeColumnType(context, change_column_type, AlterTableType::RENAME_FIELD);
}

unique_ptr<CatalogEntry> DuckTableEntry::SetDefault(ClientContext &context, SetDefaultInfo &info) {
Expand Down Expand Up @@ -1112,7 +1136,8 @@ unique_ptr<CatalogEntry> DuckTableEntry::DropNotNull(ClientContext &context, Dro
return make_uniq<DuckTableEntry>(catalog, schema, *bound_create_info, storage, triggers);
}

unique_ptr<CatalogEntry> DuckTableEntry::ChangeColumnType(ClientContext &context, ChangeColumnTypeInfo &info) {
unique_ptr<CatalogEntry> DuckTableEntry::ChangeColumnType(ClientContext &context, ChangeColumnTypeInfo &info,
AlterTableType alter_table_type) {
// Bind type
auto type_binder = Binder::CreateBinder(context);
type_binder->SetSearchPath(catalog, schema.name);
Expand Down Expand Up @@ -1148,6 +1173,10 @@ unique_ptr<CatalogEntry> DuckTableEntry::ChangeColumnType(ClientContext &context
throw NotImplementedException("Changing types of generated columns is not supported yet");
}
copy.SetType(info.target_type);
if (alter_table_type == AlterTableType::RENAME_FIELD && copy.HasDefaultValue()) {
copy.SetDefaultValue(
RemapStructDefault(copy.DefaultValue().Copy(), info.target_type, GetRemapStructMapping(info)));
}
}
// TODO: check if the generated_expression breaks, only delete it if it does
if (copy.Generated() && column_dependency_manager.IsDependencyOf(col.Logical(), change_idx)) {
Expand Down
2 changes: 1 addition & 1 deletion src/duckdb/src/catalog/default/default_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static const DefaultMacro internal_macros[] = {
"(arr, sep := ',') AS case len(arr::varchar[]) when 0 then '' else list_aggr(arr::varchar[], 'string_agg', sep) "
"end"},

{DEFAULT_SCHEMA, "generate_subscripts", "(arr, dim) AS unnest(generate_series(1, array_length(arr, dim)))"},
{DEFAULT_SCHEMA, "generate_subscripts", "(arr, dim := 1) AS unnest(generate_series(1, array_length(arr, dim)))"},
{DEFAULT_SCHEMA, "fdiv", "(x, y) AS floor(x/y)"},
{DEFAULT_SCHEMA, "fmod", "(x, y) AS (x-y*floor(x/y))"},
{DEFAULT_SCHEMA, "split_part",
Expand Down
19 changes: 19 additions & 0 deletions src/duckdb/src/common/enum_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4412,6 +4412,25 @@ PipelineBroadcastExchangeConsumerMode EnumUtil::FromString<PipelineBroadcastExch
return static_cast<PipelineBroadcastExchangeConsumerMode>(StringUtil::StringToEnum(GetPipelineBroadcastExchangeConsumerModeValues(), 4, "PipelineBroadcastExchangeConsumerMode", value));
}

const StringUtil::EnumStringLiteral *GetPipelineBroadcastExchangeOrderModeValues() {
static constexpr StringUtil::EnumStringLiteral values[] {
{ static_cast<uint32_t>(PipelineBroadcastExchangeOrderMode::UNORDERED), "UNORDERED" },
{ static_cast<uint32_t>(PipelineBroadcastExchangeOrderMode::SEQUENTIAL), "SEQUENTIAL" },
{ static_cast<uint32_t>(PipelineBroadcastExchangeOrderMode::BATCH_INDEX), "BATCH_INDEX" }
};
return values;
}

template<>
const char* EnumUtil::ToChars<PipelineBroadcastExchangeOrderMode>(PipelineBroadcastExchangeOrderMode value) {
return StringUtil::EnumToString(GetPipelineBroadcastExchangeOrderModeValues(), 3, "PipelineBroadcastExchangeOrderMode", static_cast<uint32_t>(value));
}

template<>
PipelineBroadcastExchangeOrderMode EnumUtil::FromString<PipelineBroadcastExchangeOrderMode>(const char *value) {
return static_cast<PipelineBroadcastExchangeOrderMode>(StringUtil::StringToEnum(GetPipelineBroadcastExchangeOrderModeValues(), 3, "PipelineBroadcastExchangeOrderMode", value));
}

const StringUtil::EnumStringLiteral *GetPipelineInputModeValues() {
static constexpr StringUtil::EnumStringLiteral values[] {
{ static_cast<uint32_t>(PipelineInputMode::SCHEDULED_SOURCE), "SCHEDULED_SOURCE" },
Expand Down
10 changes: 8 additions & 2 deletions src/duckdb/src/execution/index/fixed_size_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,14 @@ void FixedSizeAllocator::Init(const FixedSizeAllocatorInfo &info) {
auto allocation_size = info.allocation_sizes[i];

// create the FixedSizeBuffer
buffers[buffer_id] =
make_uniq<FixedSizeBuffer>(block_manager, segment_count, allocation_size, buffer_block_pointer);
if (info.transient_block_handles) {
D_ASSERT(info.transient_block_handles->size() == info.buffer_ids.size());
buffers[buffer_id] = make_uniq<FixedSizeBuffer>(block_manager, segment_count, allocation_size,
std::move((*info.transient_block_handles)[i]));
} else {
buffers[buffer_id] =
make_uniq<FixedSizeBuffer>(block_manager, segment_count, allocation_size, buffer_block_pointer);
}
total_segment_count += segment_count;
}

Expand Down
9 changes: 9 additions & 0 deletions src/duckdb/src/execution/index/fixed_size_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ FixedSizeBuffer::FixedSizeBuffer(BlockManager &block_manager, MemoryTag memory_t
memset(buffer_handle.GetDataMutable(), 0, block_size);
}

FixedSizeBuffer::FixedSizeBuffer(BlockManager &block_manager, const idx_t segment_count, const idx_t allocation_size,
shared_ptr<BlockHandle> block_handle_p)
: block_manager(block_manager), readers(0), segment_count(segment_count), allocation_size(allocation_size),
dirty(false), vacuum(false), loaded(false), block_pointer(), block_handle(std::move(block_handle_p)) {
D_ASSERT(block_handle);
buffer_handle = block_manager.buffer_manager.Pin(block_handle);
D_ASSERT(buffer_handle.IsValid());
}

FixedSizeBuffer::FixedSizeBuffer(BlockManager &block_manager, const idx_t segment_count, const idx_t allocation_size,
const BlockPointer &block_pointer)
: block_manager(block_manager), readers(0), segment_count(segment_count), allocation_size(allocation_size),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "duckdb/parallel/base_pipeline_event.hpp"
#include "duckdb/parallel/executor_task.hpp"
#include "duckdb/storage/buffer_manager.hpp"
#include "duckdb/storage/storage_info.hpp"
#include "duckdb/logging/logger.hpp"
#include "duckdb/logging/log_type.hpp"

Expand Down Expand Up @@ -47,6 +48,10 @@ InsertionOrderPreservingMap<string> PhysicalBatchCopyToFile::ParamsToString() co
return result;
}

OperatorPartitionInfo PhysicalBatchCopyToFile::RequiredPartitionInfo() const {
return OperatorPartitionInfo::BatchIndex(batch_size.IsValid() ? batch_size : optional_idx(DEFAULT_ROW_GROUP_SIZE));
}

//===--------------------------------------------------------------------===//
// States
//===--------------------------------------------------------------------===//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "duckdb/storage/table/row_group_collection.hpp"
#include "duckdb/storage/table/scan_state.hpp"
#include "duckdb/storage/table_io_manager.hpp"
#include "duckdb/storage/storage_info.hpp"
#include "duckdb/transaction/duck_transaction.hpp"
#include "duckdb/transaction/local_storage.hpp"
#include "duckdb/common/types/column/column_data_collection.hpp"
Expand All @@ -19,16 +20,21 @@ PhysicalBatchInsert::PhysicalBatchInsert(PhysicalPlan &physical_plan, vector<Log
DuckTableEntry &table, vector<unique_ptr<BoundConstraint>> bound_constraints_p,
idx_t estimated_cardinality)
: PhysicalOperator(physical_plan, PhysicalOperatorType::BATCH_INSERT, std::move(types_p), estimated_cardinality),
insert_table(&table), insert_types(table.GetTypes()), bound_constraints(std::move(bound_constraints_p)) {
insert_table(&table), insert_types(table.GetTypes()), bound_constraints(std::move(bound_constraints_p)),
preferred_batch_size(table.GetStorage().GetRowGroupSize()) {
}

PhysicalBatchInsert::PhysicalBatchInsert(PhysicalPlan &physical_plan, LogicalOperator &op, SchemaCatalogEntry &schema,
unique_ptr<BoundCreateTableInfo> info_p, idx_t estimated_cardinality)
: PhysicalOperator(physical_plan, PhysicalOperatorType::BATCH_CREATE_TABLE_AS, op.types, estimated_cardinality),
insert_table(nullptr), schema(&schema), info(std::move(info_p)) {
insert_table(nullptr), schema(&schema), info(std::move(info_p)), preferred_batch_size(DEFAULT_ROW_GROUP_SIZE) {
PhysicalInsert::GetInsertInfo(*info, insert_types);
}

OperatorPartitionInfo PhysicalBatchInsert::RequiredPartitionInfo() const {
return OperatorPartitionInfo::BatchIndex(preferred_batch_size);
}

//===--------------------------------------------------------------------===//
// CollectionMerger
//===--------------------------------------------------------------------===//
Expand Down
Loading
Loading