Skip to content

Commit f286998

Browse files
duckdblabs-botgithub-actions[bot]
authored andcommitted
Update vendored DuckDB sources to b8a06e4a22
1 parent 933e76c commit f286998

File tree

11 files changed

+119
-50
lines changed

11 files changed

+119
-50
lines changed

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 "0-dev4109"
2+
#define DUCKDB_PATCH_VERSION "0-dev4124"
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.0-dev4109"
11+
#define DUCKDB_VERSION "v1.4.0-dev4124"
1212
#endif
1313
#ifndef DUCKDB_SOURCE_ID
14-
#define DUCKDB_SOURCE_ID "b3edbac851"
14+
#define DUCKDB_SOURCE_ID "b8a06e4a22"
1515
#endif
1616
#include "duckdb/function/table/system_functions.hpp"
1717
#include "duckdb/main/database.hpp"

src/duckdb/src/include/duckdb/planner/expression_binder.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ class ExpressionBinder {
193193

194194
BindResult BindUnsupportedExpression(ParsedExpression &expr, idx_t depth, const string &message);
195195

196+
optional_ptr<CatalogEntry> BindAndQualifyFunction(FunctionExpression &function, bool allow_throw);
197+
196198
protected:
197199
virtual BindResult BindGroupingFunction(OperatorExpression &op, idx_t depth);
198200
virtual BindResult BindFunction(FunctionExpression &expr, ScalarFunctionCatalogEntry &function, idx_t depth);

src/duckdb/src/include/duckdb/storage/table/row_group.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class RowGroup : public SegmentBase<RowGroup> {
164164
const vector<PhysicalIndex> &column_ids);
165165
//! Update a single column; corresponds to DataTable::UpdateColumn
166166
//! This method should only be called from the WAL
167-
void UpdateColumn(TransactionData transaction, DataChunk &updates, Vector &row_ids,
167+
void UpdateColumn(TransactionData transaction, DataChunk &updates, Vector &row_ids, idx_t offset, idx_t count,
168168
const vector<column_t> &column_path);
169169

170170
void MergeStatistics(idx_t column_idx, const BaseStatistics &other);

src/duckdb/src/include/duckdb/storage/table/row_group_collection.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ class RowGroupCollection {
151151
private:
152152
bool IsEmpty(SegmentLock &) const;
153153

154+
optional_ptr<RowGroup> NextUpdateRowGroup(row_t *ids, idx_t &pos, idx_t count) const;
155+
154156
private:
155157
//! BlockManager
156158
BlockManager &block_manager;

src/duckdb/src/main/config.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,10 @@ idx_t DBConfig::GetSystemMaxThreads(FileSystem &fs) {
539539
}
540540

541541
idx_t DBConfig::GetSystemAvailableMemory(FileSystem &fs) {
542+
// System memory detection
543+
auto memory = FileSystem::GetAvailableMemory();
544+
auto available_memory = memory.IsValid() ? memory.GetIndex() : DBConfigOptions().maximum_memory;
545+
542546
#ifdef __linux__
543547
// Check SLURM environment variables first
544548
const char *slurm_mem_per_node = getenv("SLURM_MEM_PER_NODE");
@@ -560,16 +564,12 @@ idx_t DBConfig::GetSystemAvailableMemory(FileSystem &fs) {
560564
// Check cgroup memory limit
561565
auto cgroup_memory_limit = CGroups::GetMemoryLimit(fs);
562566
if (cgroup_memory_limit.IsValid()) {
563-
return cgroup_memory_limit.GetIndex();
567+
auto cgroup_memory_limit_value = cgroup_memory_limit.GetIndex();
568+
return std::min(cgroup_memory_limit_value, available_memory);
564569
}
565570
#endif
566571

567-
// System memory detection
568-
auto memory = FileSystem::GetAvailableMemory();
569-
if (!memory.IsValid()) {
570-
return DBConfigOptions().maximum_memory;
571-
}
572-
return memory.GetIndex();
572+
return available_memory;
573573
}
574574

575575
idx_t DBConfig::ParseMemoryLimit(const string &arg) {

src/duckdb/src/main/database_manager.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,18 @@ shared_ptr<AttachedDatabase> DatabaseManager::AttachDatabase(ClientContext &cont
7070
AttachOptions &options) {
7171
auto &config = DBConfig::GetConfig(context);
7272
if (options.db_type.empty() || StringUtil::CIEquals(options.db_type, "duckdb")) {
73-
if (InsertDatabasePath(info, options) == InsertDatabasePathResult::ALREADY_EXISTS) {
74-
return nullptr;
73+
while (InsertDatabasePath(info, options) == InsertDatabasePathResult::ALREADY_EXISTS) {
74+
// database with this name and path already exists
75+
// ... but it might not be done attaching yet!
76+
// verify the database has actually finished attaching prior to returning
77+
lock_guard<mutex> guard(databases_lock);
78+
if (databases.find(info.name) != databases.end()) {
79+
// database ACTUALLY exists - return
80+
return nullptr;
81+
}
82+
if (context.interrupted) {
83+
throw InterruptException();
84+
}
7585
}
7686
}
7787
GetDatabaseType(context, info, config, options);

src/duckdb/src/planner/binder/expression/bind_columnref_expression.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ void ExpressionBinder::QualifyColumnNames(unique_ptr<ParsedExpression> &expr,
155155
case ExpressionType::FUNCTION: {
156156
// Special-handling for lambdas, which are inside function expressions.
157157
auto &function = expr->Cast<FunctionExpression>();
158+
if (!IsUnnestFunction(function.function_name)) {
159+
BindAndQualifyFunction(function, false);
160+
}
158161
if (function.IsLambdaFunction()) {
159162
return QualifyColumnNamesInLambda(function, lambda_params);
160163
}

src/duckdb/src/planner/binder/expression/bind_function_expression.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ BindResult ExpressionBinder::TryBindLambdaOrJson(FunctionExpression &function, i
6868
json_bind_result.error.RawMessage());
6969
}
7070

71-
BindResult ExpressionBinder::BindExpression(FunctionExpression &function, idx_t depth,
72-
unique_ptr<ParsedExpression> &expr_ptr) {
71+
optional_ptr<CatalogEntry> ExpressionBinder::BindAndQualifyFunction(FunctionExpression &function, bool allow_throw) {
72+
D_ASSERT(!IsUnnestFunction(function.function_name));
7373
// lookup the function in the catalog
7474
QueryErrorContext error_context(function.GetQueryLocation());
7575
binder.BindSchemaOrCatalog(function.catalog, function.schema);
@@ -82,6 +82,9 @@ BindResult ExpressionBinder::BindExpression(FunctionExpression &function, idx_t
8282
auto table_func =
8383
GetCatalogEntry(function.catalog, function.schema, table_function_lookup, OnEntryNotFound::RETURN_NULL);
8484
if (table_func) {
85+
if (!allow_throw) {
86+
return func;
87+
}
8588
throw BinderException(function,
8689
"Function \"%s\" is a table function but it was used as a scalar function. This "
8790
"function has to be called in a FROM clause (similar to a table).",
@@ -105,6 +108,9 @@ BindResult ExpressionBinder::BindExpression(FunctionExpression &function, idx_t
105108
if (error.HasError()) {
106109
// could not find the column - try to qualify the alias
107110
if (!QualifyColumnAlias(*colref)) {
111+
if (!allow_throw) {
112+
return func;
113+
}
108114
// no alias found either - throw
109115
error.Throw();
110116
}
@@ -118,11 +124,19 @@ BindResult ExpressionBinder::BindExpression(FunctionExpression &function, idx_t
118124
}
119125
// rebind the function
120126
if (!func) {
121-
func =
122-
GetCatalogEntry(function.catalog, function.schema, function_lookup, OnEntryNotFound::THROW_EXCEPTION);
127+
const auto on_entry_not_found =
128+
allow_throw ? OnEntryNotFound::THROW_EXCEPTION : OnEntryNotFound::RETURN_NULL;
129+
func = GetCatalogEntry(function.catalog, function.schema, function_lookup, on_entry_not_found);
123130
}
124131
}
125132

133+
return func;
134+
}
135+
136+
BindResult ExpressionBinder::BindExpression(FunctionExpression &function, idx_t depth,
137+
unique_ptr<ParsedExpression> &expr_ptr) {
138+
auto func = BindAndQualifyFunction(function, true);
139+
126140
if (func->type != CatalogType::AGGREGATE_FUNCTION_ENTRY &&
127141
(function.distinct || function.filter || !function.order_bys->orders.empty())) {
128142
throw InvalidInputException("Function \"%s\" is a %s. \"DISTINCT\", \"FILTER\", and \"ORDER BY\" are only "

src/duckdb/src/planner/binder/statement/bind_drop.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,34 @@ BoundStatement Binder::Bind(DropStatement &stmt) {
4040
// mark catalog as accessed
4141
properties.RegisterDBRead(*catalog, context);
4242
}
43-
EntryLookupInfo entry_lookup(stmt.info->type, stmt.info->name);
44-
auto entry =
45-
Catalog::GetEntry(context, stmt.info->catalog, stmt.info->schema, entry_lookup, stmt.info->if_not_found);
43+
optional_ptr<CatalogEntry> entry;
44+
if (stmt.info->type == CatalogType::MACRO_ENTRY) {
45+
// We also support "DROP MACRO" (instead of "DROP MACRO TABLE") for table macros
46+
// First try to drop a scalar macro
47+
EntryLookupInfo macro_entry_lookup(stmt.info->type, stmt.info->name);
48+
entry = Catalog::GetEntry(context, stmt.info->catalog, stmt.info->schema, macro_entry_lookup,
49+
OnEntryNotFound::RETURN_NULL);
50+
if (!entry) {
51+
// Unable to find a scalar macro, try to drop a table macro
52+
EntryLookupInfo table_macro_entry_lookup(CatalogType::TABLE_MACRO_ENTRY, stmt.info->name);
53+
entry = Catalog::GetEntry(context, stmt.info->catalog, stmt.info->schema, table_macro_entry_lookup,
54+
OnEntryNotFound::RETURN_NULL);
55+
if (entry) {
56+
// Change type to table macro so future lookups get the correct one
57+
stmt.info->type = CatalogType::TABLE_MACRO_ENTRY;
58+
}
59+
}
60+
61+
if (!entry) {
62+
// Unable to find table macro, try again with original OnEntryNotFound to ensure we throw if necessary
63+
entry = Catalog::GetEntry(context, stmt.info->catalog, stmt.info->schema, macro_entry_lookup,
64+
stmt.info->if_not_found);
65+
}
66+
} else {
67+
EntryLookupInfo entry_lookup(stmt.info->type, stmt.info->name);
68+
entry = Catalog::GetEntry(context, stmt.info->catalog, stmt.info->schema, entry_lookup,
69+
stmt.info->if_not_found);
70+
}
4671
if (!entry) {
4772
break;
4873
}

src/duckdb/src/storage/table/row_group.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -881,15 +881,21 @@ void RowGroup::Update(TransactionData transaction, DataChunk &update_chunk, row_
881881
}
882882
}
883883

884-
void RowGroup::UpdateColumn(TransactionData transaction, DataChunk &updates, Vector &row_ids,
884+
void RowGroup::UpdateColumn(TransactionData transaction, DataChunk &updates, Vector &row_ids, idx_t offset, idx_t count,
885885
const vector<column_t> &column_path) {
886886
D_ASSERT(updates.ColumnCount() == 1);
887887
auto ids = FlatVector::GetData<row_t>(row_ids);
888888

889889
auto primary_column_idx = column_path[0];
890890
D_ASSERT(primary_column_idx < columns.size());
891891
auto &col_data = GetColumn(primary_column_idx);
892-
col_data.UpdateColumn(transaction, column_path, updates.data[0], ids, updates.size(), 1);
892+
if (offset > 0) {
893+
Vector sliced_vector(updates.data[0], offset, offset + count);
894+
sliced_vector.Flatten(count);
895+
col_data.UpdateColumn(transaction, column_path, sliced_vector, ids + offset, count, 1);
896+
} else {
897+
col_data.UpdateColumn(transaction, column_path, updates.data[0], ids, count, 1);
898+
}
893899
MergeStatistics(primary_column_idx, *col_data.GetUpdateStatistics());
894900
}
895901

0 commit comments

Comments
 (0)