Skip to content

Commit a6cb922

Browse files
committed
vendor: Update vendored sources to duckdb/duckdb@cd9b4ef
MultiFileReader: simplify constant handling, and allow virtual columns returned by the multi file reader to be constant (duckdb/duckdb#17149)
1 parent fab901e commit a6cb922

File tree

5 files changed

+31
-34
lines changed

5 files changed

+31
-34
lines changed

src/duckdb/src/common/multi_file/multi_file_column_mapper.cpp

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,11 @@ ResultColumnMapping MultiFileColumnMapper::CreateColumnMappingByMapper(const Col
425425
auto expr =
426426
multi_file_reader.GetVirtualColumnExpression(context, reader_data, local_columns, global_column_id,
427427
virtual_column_type, local_idx, global_column_reference);
428+
if (expr && expr->type == ExpressionType::VALUE_CONSTANT) {
429+
// the column is constant after all - handle it
430+
expressions.push_back(std::move(expr));
431+
continue;
432+
}
428433
if (!global_column_reference) {
429434
auto is_reference = expr->type == ExpressionType::BOUND_REF;
430435
expressions.push_back(std::move(expr));
@@ -626,6 +631,23 @@ static bool EvaluateFilterAgainstConstant(TableFilter &filter, const Value &cons
626631
}
627632
}
628633

634+
Value MultiFileColumnMapper::GetConstantValue(idx_t global_index) {
635+
auto global_column_id = global_column_ids[global_index].GetPrimaryIndex();
636+
auto &expr = reader_data.expressions[global_index];
637+
if (expr->type == ExpressionType::VALUE_CONSTANT) {
638+
return expr->Cast<BoundConstantExpression>().value;
639+
}
640+
for (idx_t i = 0; i < reader_data.constant_map.size(); i++) {
641+
auto &constant_map_entry = reader_data.constant_map[MultiFileConstantMapIndex(i)];
642+
if (constant_map_entry.column_idx.GetIndex() == global_index) {
643+
return constant_map_entry.value;
644+
}
645+
}
646+
auto &global_column = global_columns[global_column_id];
647+
throw InternalException("Column '%s' is not present in the file, but no constant_map entry exists for it!",
648+
global_column.name);
649+
}
650+
629651
ReaderInitializeType
630652
MultiFileColumnMapper::EvaluateConstantFilters(ResultColumnMapping &mapping,
631653
map<idx_t, reference<TableFilter>> &remaining_filters) {
@@ -645,36 +667,7 @@ MultiFileColumnMapper::EvaluateConstantFilters(ResultColumnMapping &mapping,
645667
}
646668

647669
//! FIXME: this does not check for filters against struct fields that are not present in the file
648-
auto global_column_id = global_column_ids[global_index].GetPrimaryIndex();
649-
Value constant_value;
650-
auto virtual_it = virtual_columns.find(global_column_id);
651-
if (virtual_it != virtual_columns.end()) {
652-
auto &virtual_column = virtual_it->second;
653-
if (virtual_column.name == "filename") {
654-
constant_value = Value(reader_data.reader->GetFileName());
655-
} else if (global_column_id == MultiFileReader::COLUMN_IDENTIFIER_FILE_INDEX) {
656-
constant_value = Value::UBIGINT(reader_data.reader->file_list_idx.GetIndex());
657-
} else {
658-
throw InternalException("Unrecognized virtual column found: %s", virtual_column.name);
659-
}
660-
} else {
661-
bool has_constant = false;
662-
for (idx_t i = 0; i < reader_data.constant_map.size(); i++) {
663-
auto &constant_map_entry = reader_data.constant_map[MultiFileConstantMapIndex(i)];
664-
if (constant_map_entry.column_idx.GetIndex() == global_index) {
665-
has_constant = true;
666-
constant_value = constant_map_entry.value;
667-
break;
668-
}
669-
}
670-
if (!has_constant) {
671-
auto &global_column = global_columns[global_column_id];
672-
throw InternalException(
673-
"Column '%s' is not present in the file, but no constant_map entry exists for it!",
674-
global_column.name);
675-
}
676-
}
677-
670+
auto constant_value = GetConstantValue(global_index);
678671
if (!EvaluateFilterAgainstConstant(*global_filter, constant_value)) {
679672
return ReaderInitializeType::SKIP_READING_FILE;
680673
}

src/duckdb/src/common/multi_file/multi_file_reader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ constexpr column_t MultiFileReader::COLUMN_IDENTIFIER_FILE_INDEX;
2222
constexpr int32_t MultiFileReader::ORDINAL_FIELD_ID;
2323
constexpr int32_t MultiFileReader::FILENAME_FIELD_ID;
2424
constexpr int32_t MultiFileReader::ROW_ID_FIELD_ID;
25+
constexpr int32_t MultiFileReader::LAST_UPDATED_SEQUENCE_NUMBER_ID;
2526

2627
MultiFileReaderGlobalState::~MultiFileReaderGlobalState() {
2728
}

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-dev2575"
2+
#define DUCKDB_PATCH_VERSION "0-dev2577"
33
#endif
44
#ifndef DUCKDB_MINOR_VERSION
55
#define DUCKDB_MINOR_VERSION 3
@@ -8,10 +8,10 @@
88
#define DUCKDB_MAJOR_VERSION 1
99
#endif
1010
#ifndef DUCKDB_VERSION
11-
#define DUCKDB_VERSION "v1.3.0-dev2575"
11+
#define DUCKDB_VERSION "v1.3.0-dev2577"
1212
#endif
1313
#ifndef DUCKDB_SOURCE_ID
14-
#define DUCKDB_SOURCE_ID "453acf2e75"
14+
#define DUCKDB_SOURCE_ID "cd9b4eff85"
1515
#endif
1616
#include "duckdb/function/table/system_functions.hpp"
1717
#include "duckdb/main/database.hpp"

src/duckdb/src/include/duckdb/common/multi_file/multi_file_column_mapper.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class MultiFileColumnMapper {
3434
unique_ptr<TableFilterSet> CreateFilters(map<idx_t, reference<TableFilter>> &filters, ResultColumnMapping &mapping);
3535
ReaderInitializeType EvaluateConstantFilters(ResultColumnMapping &mapping,
3636
map<idx_t, reference<TableFilter>> &remaining_filters);
37+
Value GetConstantValue(idx_t global_index);
3738

3839
private:
3940
ClientContext &context;

src/duckdb/src/include/duckdb/common/multi_file/multi_file_reader.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ struct MultiFileReader {
3939
static constexpr int32_t ORDINAL_FIELD_ID = 2147483645;
4040
// Reserved field id used for the "_pos" field according to the iceberg spec (used for file_row_number)
4141
static constexpr int32_t FILENAME_FIELD_ID = 2147483646;
42-
// Reserved field id used for the "_row_id" field according to the iceberg spec (used for file_row_number)
42+
// Reserved field id used for the "_row_id" field according to the iceberg spec
4343
static constexpr int32_t ROW_ID_FIELD_ID = 2147483540;
44+
// Reserved field id used for the "_last_updated_sequence_number" field according to the iceberg spec
45+
static constexpr int32_t LAST_UPDATED_SEQUENCE_NUMBER_ID = 2147483539;
4446

4547
public:
4648
virtual ~MultiFileReader();

0 commit comments

Comments
 (0)