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
10 changes: 9 additions & 1 deletion src/duckdb/extension/parquet/parquet_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ void ParquetWriter::FlushRowGroup(PreparedRowGroup &prepared) {
row_group.__isset.total_compressed_size = true;

if (encryption_config) {
auto row_group_ordinal = num_row_groups.load();
const auto row_group_ordinal = file_meta_data.row_groups.size();
if (row_group_ordinal > std::numeric_limits<int16_t>::max()) {
throw InvalidInputException("RowGroup ordinal exceeds 32767 when encryption enabled");
}
Expand All @@ -583,6 +583,14 @@ void ParquetWriter::Flush(ColumnDataCollection &buffer) {
return;
}

// "total_written" is only used for the FILE_SIZE_BYTES flag, and only when threads are writing in parallel.
// We pre-emptively increase it here to try to reduce overshooting when many threads are writing in parallel.
// However, waiting for the exact value (PrepareRowGroup) takes too long, and would cause overshoots to happen.
// So, we guess the compression ratio. We guess 3x, but this will be off depending on the data.
// "total_written" is restored to the exact number of written bytes at the end of FlushRowGroup.
// PhysicalCopyToFile should be reworked to use prepare/flush batch separately for better accuracy.
total_written += buffer.SizeInBytes() / 2;

PreparedRowGroup prepared_row_group;
PrepareRowGroup(buffer, prepared_row_group);
buffer.Reset();
Expand Down
4 changes: 3 additions & 1 deletion src/duckdb/src/function/cast/cast_function_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ int64_t CastFunctionSet::ImplicitCastCost(optional_ptr<ClientContext> context, c
old_implicit_casting = DBConfig::GetSetting<OldImplicitCastingSetting>(*config);
}
if (old_implicit_casting) {
score = 149;
// very high cost to avoid choosing this cast if any other option is available
// (it should be more costly than casting to TEMPLATE if that is available)
score = 10000000000;
}
}
return score;
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-dev241"
#define DUCKDB_PATCH_VERSION "2-dev253"
#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-dev241"
#define DUCKDB_VERSION "v1.4.2-dev253"
#endif
#ifndef DUCKDB_SOURCE_ID
#define DUCKDB_SOURCE_ID "73c0d0db15"
#define DUCKDB_SOURCE_ID "f50618b48c"
#endif
#include "duckdb/function/table/system_functions.hpp"
#include "duckdb/main/database.hpp"
Expand Down
1 change: 1 addition & 0 deletions src/duckdb/src/include/duckdb/main/extension_entries.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ static constexpr ExtensionFunctionEntry EXTENSION_FUNCTIONS[] = {
{"st_envelope", "spatial", CatalogType::SCALAR_FUNCTION_ENTRY},
{"st_envelope_agg", "spatial", CatalogType::AGGREGATE_FUNCTION_ENTRY},
{"st_equals", "spatial", CatalogType::SCALAR_FUNCTION_ENTRY},
{"st_expand", "spatial", CatalogType::SCALAR_FUNCTION_ENTRY},
{"st_extent", "spatial", CatalogType::SCALAR_FUNCTION_ENTRY},
{"st_extent_agg", "spatial", CatalogType::AGGREGATE_FUNCTION_ENTRY},
{"st_extent_approx", "spatial", CatalogType::SCALAR_FUNCTION_ENTRY},
Expand Down
29 changes: 28 additions & 1 deletion src/duckdb/src/planner/binder/statement/bind_merge_into.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,32 @@ void RewriteMergeBindings(LogicalOperator &op, const vector<ColumnBinding> &sour
op, [&](unique_ptr<Expression> *child) { RewriteMergeBindings(*child, source_bindings, new_table_index); });
}

LogicalGet &ExtractLogicalGet(LogicalOperator &op) {
reference<LogicalOperator> current_op(op);
while (current_op.get().type == LogicalOperatorType::LOGICAL_FILTER) {
current_op = *current_op.get().children[0];
}
if (current_op.get().type != LogicalOperatorType::LOGICAL_GET) {
throw InvalidInputException("BindMerge - expected to find an operator of type LOGICAL_GET but got %s",
op.ToString());
}
return current_op.get().Cast<LogicalGet>();
}

void CheckMergeAction(MergeActionCondition condition, MergeActionType action_type) {
if (condition == MergeActionCondition::WHEN_NOT_MATCHED_BY_TARGET) {
switch (action_type) {
case MergeActionType::MERGE_UPDATE:
case MergeActionType::MERGE_DELETE:
throw ParserException("WHEN NOT MATCHED (BY TARGET) cannot be combined with UPDATE or DELETE actions - as "
"there is no corresponding row in the target to update or delete.\nDid you mean to "
"use WHEN MATCHED or WHEN NOT MATCHED BY SOURCE?");
default:
break;
}
}
}

BoundStatement Binder::Bind(MergeIntoStatement &stmt) {
// bind the target table
auto target_binder = Binder::CreateBinder(context, this);
Expand Down Expand Up @@ -243,7 +269,7 @@ BoundStatement Binder::Bind(MergeIntoStatement &stmt) {
// kind of hacky, CreatePlan turns a RIGHT join into a LEFT join so the children get reversed from what we need
bool inverted = join.type == JoinType::RIGHT;
auto &source = join_ref.get().children[inverted ? 1 : 0];
auto &get = join_ref.get().children[inverted ? 0 : 1]->Cast<LogicalGet>();
auto &get = ExtractLogicalGet(*join_ref.get().children[inverted ? 0 : 1]);

auto merge_into = make_uniq<LogicalMergeInto>(table);
merge_into->table_index = GenerateTableIndex();
Expand All @@ -265,6 +291,7 @@ BoundStatement Binder::Bind(MergeIntoStatement &stmt) {
for (auto &entry : stmt.actions) {
vector<unique_ptr<BoundMergeIntoAction>> bound_actions;
for (auto &action : entry.second) {
CheckMergeAction(entry.first, action->action_type);
bound_actions.push_back(BindMergeAction(*merge_into, table, get, proj_index, projection_expressions, root,
*action, source_aliases, source_names));
}
Expand Down