Skip to content

Commit

Permalink
Update vendored DuckDB sources to 6688538
Browse files Browse the repository at this point in the history
  • Loading branch information
duckdblabs-bot committed Jan 21, 2025
1 parent 6688538 commit 02a9357
Show file tree
Hide file tree
Showing 54 changed files with 631 additions and 400 deletions.
1 change: 1 addition & 0 deletions src/duckdb/extension/core_functions/function_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ static const StaticFunctionDefinition core_functions[] = {
DUCKDB_SCALAR_FUNCTION(MapConcatFun),
DUCKDB_SCALAR_FUNCTION(MapEntriesFun),
DUCKDB_SCALAR_FUNCTION(MapExtractFun),
DUCKDB_SCALAR_FUNCTION(MapExtractValueFun),
DUCKDB_SCALAR_FUNCTION(MapFromEntriesFun),
DUCKDB_SCALAR_FUNCTION(MapKeysFun),
DUCKDB_SCALAR_FUNCTION(MapValuesFun),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ struct ElementAtFun {
static constexpr const char *Name = "element_at";
};

struct MapExtractValueFun {
static constexpr const char *Name = "map_extract_value";
static constexpr const char *Parameters = "map,key";
static constexpr const char *Description = "Returns the value for a given key or NULL if the key is not contained in the map. The type of the key provided in the second parameter must match the type of the map’s keys else an error is returned";
static constexpr const char *Example = "map_extract_value(map(['key'], ['val']), 'key')";

static ScalarFunction GetFunction();
};

struct MapFromEntriesFun {
static constexpr const char *Name = "map_from_entries";
static constexpr const char *Parameters = "map";
Expand Down
97 changes: 89 additions & 8 deletions src/duckdb/extension/core_functions/scalar/map/map_extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,36 @@

namespace duckdb {

template <bool EXTRACT_VALUE>
static unique_ptr<FunctionData> MapExtractBind(ClientContext &, ScalarFunction &bound_function,
vector<unique_ptr<Expression>> &arguments) {
if (arguments.size() != 2) {
throw BinderException("MAP_EXTRACT must have exactly two arguments");
}

auto &map_type = arguments[0]->return_type;
auto &input_type = arguments[1]->return_type;
const auto &map_type = arguments[0]->return_type;
const auto &input_type = arguments[1]->return_type;

if (map_type.id() == LogicalTypeId::SQLNULL) {
bound_function.return_type = LogicalTypeId::SQLNULL;
bound_function.return_type = EXTRACT_VALUE ? LogicalTypeId::SQLNULL : LogicalType::LIST(LogicalTypeId::SQLNULL);
return make_uniq<VariableReturnBindData>(bound_function.return_type);
}

if (map_type.id() != LogicalTypeId::MAP) {
throw BinderException("MAP_EXTRACT can only operate on MAPs");
throw BinderException("'%s' can only operate on MAPs", bound_function.name);
}
auto &value_type = MapType::ValueType(map_type);

//! Here we have to construct the List Type that will be returned
bound_function.return_type = value_type;
auto key_type = MapType::KeyType(map_type);
bound_function.return_type = EXTRACT_VALUE ? value_type : LogicalType::LIST(value_type);
const auto &key_type = MapType::KeyType(map_type);
if (key_type.id() != LogicalTypeId::SQLNULL && input_type.id() != LogicalTypeId::SQLNULL) {
bound_function.arguments[1] = MapType::KeyType(map_type);
}
return make_uniq<VariableReturnBindData>(bound_function.return_type);
}

static void MapExtractFunc(DataChunk &args, ExpressionState &state, Vector &result) {
static void MapExtractValueFunc(DataChunk &args, ExpressionState &state, Vector &result) {
const auto count = args.size();

auto &map_vec = args.data[0];
Expand Down Expand Up @@ -94,8 +95,88 @@ static void MapExtractFunc(DataChunk &args, ExpressionState &state, Vector &resu
result.Verify(count);
}

static void MapExtractListFunc(DataChunk &args, ExpressionState &state, Vector &result) {
const auto count = args.size();

auto &map_vec = args.data[0];
auto &arg_vec = args.data[1];

const auto map_is_null = map_vec.GetType().id() == LogicalTypeId::SQLNULL;
const auto arg_is_null = arg_vec.GetType().id() == LogicalTypeId::SQLNULL;

if (map_is_null || arg_is_null) {
// Short-circuit if either the map or the arg is NULL
ListVector::SetListSize(result, 0);
result.SetVectorType(VectorType::CONSTANT_VECTOR);
ConstantVector::GetData<list_entry_t>(result)[0] = {0, 0};
result.Verify(count);
return;
}

auto &key_vec = MapVector::GetKeys(map_vec);
auto &val_vec = MapVector::GetValues(map_vec);

// Collect the matching positions
Vector pos_vec(LogicalType::INTEGER, count);
ListSearchOp<true>(map_vec, key_vec, arg_vec, pos_vec, args.size());

UnifiedVectorFormat val_format;
UnifiedVectorFormat pos_format;
UnifiedVectorFormat lst_format;

val_vec.ToUnifiedFormat(ListVector::GetListSize(map_vec), val_format);
pos_vec.ToUnifiedFormat(count, pos_format);
map_vec.ToUnifiedFormat(count, lst_format);

const auto pos_data = UnifiedVectorFormat::GetData<int32_t>(pos_format);
const auto inc_list_data = ListVector::GetData(map_vec);
const auto out_list_data = ListVector::GetData(result);

idx_t offset = 0;
for (idx_t row_idx = 0; row_idx < count; row_idx++) {
const auto lst_idx = lst_format.sel->get_index(row_idx);
if (!lst_format.validity.RowIsValid(lst_idx)) {
FlatVector::SetNull(result, row_idx, true);
continue;
}

auto &inc_list = inc_list_data[lst_idx];
auto &out_list = out_list_data[row_idx];

const auto pos_idx = pos_format.sel->get_index(row_idx);
if (!pos_format.validity.RowIsValid(pos_idx)) {
// We didnt find the key in the map, so return emptyl ist
out_list.offset = offset;
out_list.length = 0;
continue;
}

// Compute the actual position of the value in the map value vector
const auto pos = inc_list.offset + UnsafeNumericCast<idx_t>(pos_data[pos_idx] - 1);
out_list.offset = offset;
out_list.length = 1;
ListVector::Append(result, val_vec, pos + 1, pos);
offset++;
}

if (args.size() == 1) {
result.SetVectorType(VectorType::CONSTANT_VECTOR);
}

result.Verify(count);
}

ScalarFunction MapExtractValueFun::GetFunction() {
ScalarFunction fun({LogicalType::ANY, LogicalType::ANY}, LogicalType::ANY, MapExtractValueFunc,
MapExtractBind<true>);
fun.varargs = LogicalType::ANY;
fun.null_handling = FunctionNullHandling::SPECIAL_HANDLING;
return fun;
}

ScalarFunction MapExtractFun::GetFunction() {
ScalarFunction fun({LogicalType::ANY, LogicalType::ANY}, LogicalType::ANY, MapExtractFunc, MapExtractBind);
ScalarFunction fun({LogicalType::ANY, LogicalType::ANY}, LogicalType::ANY, MapExtractListFunc,
MapExtractBind<false>);
fun.varargs = LogicalType::ANY;
fun.null_handling = FunctionNullHandling::SPECIAL_HANDLING;
return fun;
Expand Down
7 changes: 7 additions & 0 deletions src/duckdb/src/catalog/dependency_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ LogicalDependency::LogicalDependency(CatalogEntry &entry) {
}
}

LogicalDependency::LogicalDependency(optional_ptr<Catalog> catalog_p, CatalogEntryInfo entry_p, string catalog_str)
: entry(std::move(entry_p)), catalog(std::move(catalog_str)) {
if (catalog_p) {
catalog = catalog_p->GetName();
}
}

bool LogicalDependency::operator==(const LogicalDependency &other) const {
return other.entry.name == entry.name && other.entry.schema == entry.schema && other.entry.type == entry.type;
}
Expand Down
3 changes: 2 additions & 1 deletion src/duckdb/src/common/error_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ void ErrorData::AddErrorLocation(const string &query) {
}
{
auto entry = extra_info.find("stack_trace");
if (entry != extra_info.end()) {
if (entry != extra_info.end() && !entry->second.empty()) {
raw_message += "\n\nStack Trace:\n" + entry->second;
entry->second = "";
}
}
final_message = ConstructFinalMessage();
Expand Down
4 changes: 2 additions & 2 deletions src/duckdb/src/common/local_file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ unique_ptr<FileHandle> LocalFileSystem::OpenFile(const string &path_p, FileOpenF
}

if (opener) {
Logger::Info("duckdb.FileSystem.LocalFileSystem.OpenFile", *opener, path_p);
DUCKDB_LOG_INFO(*opener, "duckdb.FileSystem.LocalFileSystem.OpenFile", path_p);
}

flags.Verify();
Expand Down Expand Up @@ -842,7 +842,7 @@ unique_ptr<FileHandle> LocalFileSystem::OpenFile(const string &path_p, FileOpenF
flags.Verify();

if (opener) {
Logger::Info("duckdb.FileSystem.LocalFileSystem.OpenFile", *opener, path_p);
DUCKDB_LOG_INFO(*opener, "duckdb.FileSystem.LocalFileSystem.OpenFile", path_p);
}

DWORD desired_access;
Expand Down
15 changes: 11 additions & 4 deletions src/duckdb/src/execution/index/art/art.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1056,9 +1056,12 @@ void ART::VerifyLeaf(const Node &leaf, const ARTKey &key, optional_ptr<ART> dele

// Get the delete_leaf.
// All leaves in the delete ART are inlined.
auto deleted_leaf = delete_art->Lookup(delete_art->tree, key, 0);
unsafe_optional_ptr<const Node> deleted_leaf;
if (delete_art) {
deleted_leaf = delete_art->Lookup(delete_art->tree, key, 0);
}

// The leaf is inlined, and the same key does not exist in the delete ART.
// The leaf is inlined, and there is no deleted leaf with the same key.
if (leaf.GetType() == NType::LEAF_INLINED && !deleted_leaf) {
if (manager.AddHit(i, leaf.GetRowId())) {
conflict_idx = i;
Expand All @@ -1068,6 +1071,7 @@ void ART::VerifyLeaf(const Node &leaf, const ARTKey &key, optional_ptr<ART> dele

// The leaf is inlined, and the same key exists in the delete ART.
if (leaf.GetType() == NType::LEAF_INLINED && deleted_leaf) {
D_ASSERT(deleted_leaf->GetType() == NType::LEAF_INLINED);
auto deleted_row_id = deleted_leaf->GetRowId();
auto this_row_id = leaf.GetRowId();

Expand All @@ -1084,6 +1088,10 @@ void ART::VerifyLeaf(const Node &leaf, const ARTKey &key, optional_ptr<ART> dele
return;
}

// FIXME: proper foreign key + delete ART support.
// This implicitly works for foreign keys, as we do not have to consider the actual row IDs.
// We only need to know that there are conflicts (for now), as we still perform over-eager constraint checking.

// Scan the two row IDs in the leaf.
Iterator it(*this);
it.FindMinimum(leaf);
Expand All @@ -1092,14 +1100,13 @@ void ART::VerifyLeaf(const Node &leaf, const ARTKey &key, optional_ptr<ART> dele
it.Scan(empty_key, 2, row_ids, false);

if (!deleted_leaf) {
if (manager.AddHit(i, row_ids[0]) || manager.AddHit(i, row_ids[0])) {
if (manager.AddHit(i, row_ids[0]) || manager.AddHit(i, row_ids[1])) {
conflict_idx = i;
}
return;
}

auto deleted_row_id = deleted_leaf->GetRowId();

if (deleted_row_id == row_ids[0] || deleted_row_id == row_ids[1]) {
if (manager.AddMiss(i)) {
conflict_idx = i;
Expand Down
9 changes: 7 additions & 2 deletions src/duckdb/src/execution/radix_partitioned_hashtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ struct RadixHTConfig {
void SetRadixBits(const idx_t &radix_bits_p);
bool SetRadixBitsToExternal();
idx_t GetRadixBits() const;
idx_t GetExternalRadixBits() const;

private:
void SetRadixBitsInternal(idx_t radix_bits_p, bool external);
Expand Down Expand Up @@ -210,13 +211,13 @@ RadixHTGlobalSinkState::RadixHTGlobalSinkState(ClientContext &context_p, const R
auto tuples_per_block = block_alloc_size / radix_ht.GetLayout().GetRowWidth();
idx_t ht_count =
LossyNumericCast<idx_t>(static_cast<double>(config.sink_capacity) / GroupedAggregateHashTable::LOAD_FACTOR);
auto num_partitions = RadixPartitioning::NumberOfPartitions(config.GetRadixBits());
auto num_partitions = RadixPartitioning::NumberOfPartitions(config.GetExternalRadixBits());
auto count_per_partition = ht_count / num_partitions;
auto blocks_per_partition = (count_per_partition + tuples_per_block) / tuples_per_block + 1;
if (!radix_ht.GetLayout().AllConstant()) {
blocks_per_partition += 2;
}
auto ht_size = blocks_per_partition * block_alloc_size + config.sink_capacity * sizeof(ht_entry_t);
auto ht_size = num_partitions * blocks_per_partition * block_alloc_size + config.sink_capacity * sizeof(ht_entry_t);

// This really is the minimum reservation that we can do
auto num_threads = NumericCast<idx_t>(TaskScheduler::GetScheduler(context).NumberOfThreads());
Expand Down Expand Up @@ -280,6 +281,10 @@ idx_t RadixHTConfig::GetRadixBits() const {
return sink_radix_bits;
}

idx_t RadixHTConfig::GetExternalRadixBits() const {
return MAXIMUM_FINAL_SINK_RADIX_BITS;
}

void RadixHTConfig::SetRadixBitsInternal(const idx_t radix_bits_p, bool external) {
if (sink_radix_bits > radix_bits_p || sink.any_combined) {
return;
Expand Down
4 changes: 2 additions & 2 deletions src/duckdb/src/function/scalar/system/write_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ static void WriteLogValues(T &LogSource, LogLevel level, const string_t *data, c
const string &type) {
if (!type.empty()) {
for (idx_t i = 0; i < size; i++) {
Logger::Log(type.c_str(), LogSource, level, data[sel->get_index(i)]);
DUCKDB_LOG(LogSource, type.c_str(), level, data[sel->get_index(i)]);
}
} else {
for (idx_t i = 0; i < size; i++) {
Logger::Log(LogSource, level, data[sel->get_index(i)]);
DUCKDB_LOG(LogSource, type.c_str(), level, data[sel->get_index(i)]);
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/duckdb/src/function/table/table_scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ struct IndexScanLocalState : public LocalTableFunctionState {
//! The DataChunk containing all read columns.
//! This includes filter columns, which are immediately removed.
DataChunk all_columns;
//! Fetch state
ColumnFetchState fetch_state;
};

static StorageIndex TransformStorageIndex(const ColumnIndex &column_id) {
Expand Down Expand Up @@ -116,7 +118,6 @@ class DuckIndexScanState : public TableScanGlobalState {
//! Synchronize changes to the global index scan state.
mutex index_scan_lock;

ColumnFetchState fetch_state;
TableScanState table_scan_state;

public:
Expand Down Expand Up @@ -160,10 +161,10 @@ class DuckIndexScanState : public TableScanGlobalState {

if (CanRemoveFilterColumns()) {
l_state.all_columns.Reset();
storage.Fetch(tx, l_state.all_columns, column_ids, local_vector, scan_count, fetch_state);
storage.Fetch(tx, l_state.all_columns, column_ids, local_vector, scan_count, l_state.fetch_state);
output.ReferenceColumns(l_state.all_columns, projection_ids);
} else {
storage.Fetch(tx, output, column_ids, local_vector, scan_count, fetch_state);
storage.Fetch(tx, output, column_ids, local_vector, scan_count, l_state.fetch_state);
}
}

Expand Down Expand Up @@ -670,7 +671,7 @@ InsertionOrderPreservingMap<string> TableScanToString(TableFunctionToStringInput
InsertionOrderPreservingMap<string> result;
auto &bind_data = input.bind_data->Cast<TableScanBindData>();
result["Table"] = bind_data.table.name;
result["Type"] = bind_data.is_index_scan ? "Index Scan" : "Sequence Scan";
result["Type"] = bind_data.is_index_scan ? "Index Scan" : "Sequential Scan";
return result;
}

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 "4-dev4760"
#define DUCKDB_PATCH_VERSION "4-dev4815"
#endif
#ifndef DUCKDB_MINOR_VERSION
#define DUCKDB_MINOR_VERSION 1
Expand All @@ -8,10 +8,10 @@
#define DUCKDB_MAJOR_VERSION 1
#endif
#ifndef DUCKDB_VERSION
#define DUCKDB_VERSION "v1.1.4-dev4760"
#define DUCKDB_VERSION "v1.1.4-dev4815"
#endif
#ifndef DUCKDB_SOURCE_ID
#define DUCKDB_SOURCE_ID "9c133491ad"
#define DUCKDB_SOURCE_ID "8e68a3e34a"
#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/catalog/dependency_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ struct LogicalDependency {
public:
explicit LogicalDependency(CatalogEntry &entry);
LogicalDependency();
LogicalDependency(optional_ptr<Catalog> catalog, CatalogEntryInfo entry, string catalog_str);
bool operator==(const LogicalDependency &other) const;

public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ class Deserializer {
return data.Get<T>();
}

template <class T>
optional_ptr<T> TryGet() {
return data.TryGet<T>();
}

//! Unset a serialization property
template <class T>
void Unset() {
Expand Down
Loading

0 comments on commit 02a9357

Please sign in to comment.