Skip to content

Commit

Permalink
Update vendored DuckDB sources to 998d0e4
Browse files Browse the repository at this point in the history
  • Loading branch information
duckdblabs-bot committed Dec 14, 2024
1 parent 998d0e4 commit b611ab5
Show file tree
Hide file tree
Showing 91 changed files with 4,104 additions and 2,092 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct ReservoirQuantileState {
void FillReservoir(idx_t sample_size, T element) {
if (pos < sample_size) {
v[pos++] = element;
r_samp->InitializeReservoir(pos, len);
r_samp->InitializeReservoirWeights(pos, len);
} else {
D_ASSERT(r_samp->next_index_to_sample >= r_samp->num_entries_to_skip_b4_next_sample);
if (r_samp->next_index_to_sample == r_samp->num_entries_to_skip_b4_next_sample) {
Expand Down
5 changes: 5 additions & 0 deletions src/duckdb/extension/json/buffered_json_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ void BufferedJSONReader::ThrowTransformError(idx_t buf_index, idx_t line_or_obje
error_message);
}

bool BufferedJSONReader::HasThrown() {
lock_guard<mutex> guard(lock);
return thrown;
}

double BufferedJSONReader::GetProgress() const {
lock_guard<mutex> guard(lock);
if (HasFileHandle()) {
Expand Down
2 changes: 2 additions & 0 deletions src/duckdb/extension/json/include/buffered_json_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ class BufferedJSONReader {
void ThrowParseError(idx_t buf_index, idx_t line_or_object_in_buf, yyjson_read_err &err, const string &extra = "");
//! Throws a transform error that mentions the file name and line number
void ThrowTransformError(idx_t buf_index, idx_t line_or_object_in_buf, const string &error_message);
//! Whether this reader has thrown if an error has occurred
bool HasThrown();

//! Scan progress
double GetProgress() const;
Expand Down
7 changes: 5 additions & 2 deletions src/duckdb/extension/json/json_scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,8 +676,8 @@ void JSONScanLocalState::ReadAndAutoDetect(JSONScanGlobalState &gstate, Allocate

if (!bind_data.ignore_errors && bind_data.options.record_type == JSONRecordType::RECORDS &&
current_reader->GetRecordType() != JSONRecordType::RECORDS) {
throw InvalidInputException("Expected file \"%s\" to contain records, detected non-record JSON instead.",
current_reader->GetFileName());
current_reader->ThrowTransformError(buffer_index.GetIndex(), 0,
"Expected records, detected non-record JSON instead.");
}
}

Expand Down Expand Up @@ -829,6 +829,9 @@ bool JSONScanLocalState::ReconstructFirstObject(JSONScanGlobalState &gstate) {
// Spinlock until the previous batch index has also read its buffer
optional_ptr<JSONBufferHandle> previous_buffer_handle;
while (!previous_buffer_handle) {
if (current_reader->HasThrown()) {
return false;
}
previous_buffer_handle = current_reader->GetBuffer(current_buffer_handle->buffer_index - 1);
}

Expand Down
5 changes: 3 additions & 2 deletions src/duckdb/extension/parquet/column_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ idx_t ColumnReader::Read(uint64_t num_values, parquet_filter_t &filter, data_ptr

idx_t result_offset = 0;
auto to_read = num_values;
D_ASSERT(to_read <= STANDARD_VECTOR_SIZE);

while (to_read > 0) {
while (page_rows_available == 0) {
Expand All @@ -542,7 +543,7 @@ idx_t ColumnReader::Read(uint64_t num_values, parquet_filter_t &filter, data_ptr
D_ASSERT(block);
auto read_now = MinValue<idx_t>(to_read, page_rows_available);

D_ASSERT(read_now <= STANDARD_VECTOR_SIZE);
D_ASSERT(read_now + result_offset <= STANDARD_VECTOR_SIZE);

if (HasRepeats()) {
D_ASSERT(repeated_decoder);
Expand All @@ -565,7 +566,7 @@ idx_t ColumnReader::Read(uint64_t num_values, parquet_filter_t &filter, data_ptr

if (result_offset != 0 && result.GetVectorType() != VectorType::FLAT_VECTOR) {
result.Flatten(result_offset);
result.Resize(result_offset, result_offset + read_now);
result.Resize(result_offset, STANDARD_VECTOR_SIZE);
}

if (dict_decoder) {
Expand Down
4 changes: 4 additions & 0 deletions src/duckdb/src/catalog/catalog_entry/duck_table_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ unique_ptr<BaseStatistics> DuckTableEntry::GetStatistics(ClientContext &context,
return storage->GetStatistics(context, column.StorageOid());
}

unique_ptr<BlockingSample> DuckTableEntry::GetSample() {
return storage->GetSample();
}

unique_ptr<CatalogEntry> DuckTableEntry::AlterEntry(CatalogTransaction transaction, AlterInfo &info) {
if (transaction.HasContext()) {
return AlterEntry(transaction.GetContext(), info);
Expand Down
28 changes: 5 additions & 23 deletions src/duckdb/src/catalog/catalog_entry/table_catalog_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ LogicalIndex TableCatalogEntry::GetColumnIndex(string &column_name, bool if_exis
return entry;
}

unique_ptr<BlockingSample> TableCatalogEntry::GetSample() {
return nullptr;
}

bool TableCatalogEntry::ColumnExists(const string &name) const {
return columns.ColumnExists(name);
}
Expand Down Expand Up @@ -251,28 +255,6 @@ static void BindExtraColumns(TableCatalogEntry &table, LogicalGet &get, LogicalP
}
}

static bool TypeSupportsRegularUpdate(const LogicalType &type) {
switch (type.id()) {
case LogicalTypeId::LIST:
case LogicalTypeId::ARRAY:
case LogicalTypeId::MAP:
case LogicalTypeId::UNION:
// lists and maps and unions don't support updates directly
return false;
case LogicalTypeId::STRUCT: {
auto &child_types = StructType::GetChildTypes(type);
for (auto &entry : child_types) {
if (!TypeSupportsRegularUpdate(entry.second)) {
return false;
}
}
return true;
}
default:
return true;
}
}

vector<ColumnSegmentInfo> TableCatalogEntry::GetColumnSegmentInfo() {
return {};
}
Expand Down Expand Up @@ -317,7 +299,7 @@ void TableCatalogEntry::BindUpdateConstraints(Binder &binder, LogicalGet &get, L
// we also convert any updates on LIST columns into delete + insert
for (auto &col_index : update.columns) {
auto &column = GetColumns().GetColumn(col_index);
if (!TypeSupportsRegularUpdate(column.Type())) {
if (!column.Type().SupportsRegularUpdate()) {
update.update_is_del_and_insert = true;
break;
}
Expand Down
63 changes: 60 additions & 3 deletions src/duckdb/src/common/enum_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,44 @@

namespace duckdb {

const StringUtil::EnumStringLiteral *GetARTAppendModeValues() {
static constexpr StringUtil::EnumStringLiteral values[] {
{ static_cast<uint32_t>(ARTAppendMode::DEFAULT), "DEFAULT" },
{ static_cast<uint32_t>(ARTAppendMode::IGNORE_DUPLICATES), "IGNORE_DUPLICATES" },
{ static_cast<uint32_t>(ARTAppendMode::INSERT_DUPLICATES), "INSERT_DUPLICATES" }
};
return values;
}

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

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

const StringUtil::EnumStringLiteral *GetARTConflictTypeValues() {
static constexpr StringUtil::EnumStringLiteral values[] {
{ static_cast<uint32_t>(ARTConflictType::NO_CONFLICT), "NO_CONFLICT" },
{ static_cast<uint32_t>(ARTConflictType::CONSTRAINT), "CONSTRAINT" },
{ static_cast<uint32_t>(ARTConflictType::TRANSACTION), "TRANSACTION" }
};
return values;
}

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

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

const StringUtil::EnumStringLiteral *GetAccessModeValues() {
static constexpr StringUtil::EnumStringLiteral values[] {
{ static_cast<uint32_t>(AccessMode::UNDEFINED), "UNDEFINED" },
Expand Down Expand Up @@ -1426,19 +1464,20 @@ const StringUtil::EnumStringLiteral *GetExtensionABITypeValues() {
static constexpr StringUtil::EnumStringLiteral values[] {
{ static_cast<uint32_t>(ExtensionABIType::UNKNOWN), "UNKNOWN" },
{ static_cast<uint32_t>(ExtensionABIType::CPP), "CPP" },
{ static_cast<uint32_t>(ExtensionABIType::C_STRUCT), "C_STRUCT" }
{ static_cast<uint32_t>(ExtensionABIType::C_STRUCT), "C_STRUCT" },
{ static_cast<uint32_t>(ExtensionABIType::C_STRUCT_UNSTABLE), "C_STRUCT_UNSTABLE" }
};
return values;
}

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

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

const StringUtil::EnumStringLiteral *GetExtensionInstallModeValues() {
Expand Down Expand Up @@ -3086,6 +3125,24 @@ SampleType EnumUtil::FromString<SampleType>(const char *value) {
return static_cast<SampleType>(StringUtil::StringToEnum(GetSampleTypeValues(), 3, "SampleType", value));
}

const StringUtil::EnumStringLiteral *GetSamplingStateValues() {
static constexpr StringUtil::EnumStringLiteral values[] {
{ static_cast<uint32_t>(SamplingState::RANDOM), "RANDOM" },
{ static_cast<uint32_t>(SamplingState::RESERVOIR), "RESERVOIR" }
};
return values;
}

template<>
const char* EnumUtil::ToChars<SamplingState>(SamplingState value) {
return StringUtil::EnumToString(GetSamplingStateValues(), 2, "SamplingState", static_cast<uint32_t>(value));
}

template<>
SamplingState EnumUtil::FromString<SamplingState>(const char *value) {
return static_cast<SamplingState>(StringUtil::StringToEnum(GetSamplingStateValues(), 2, "SamplingState", value));
}

const StringUtil::EnumStringLiteral *GetScanTypeValues() {
static constexpr StringUtil::EnumStringLiteral values[] {
{ static_cast<uint32_t>(ScanType::TABLE), "TABLE" },
Expand Down
4 changes: 4 additions & 0 deletions src/duckdb/src/common/random_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ uint32_t RandomEngine::NextRandomInteger(uint32_t min, uint32_t max) {
return min + static_cast<uint32_t>(NextRandom() * double(max - min));
}

uint32_t RandomEngine::NextRandomInteger32(uint32_t min, uint32_t max) {
return min + static_cast<uint32_t>(NextRandom32() * double(max - min));
}

void RandomEngine::SetSeed(uint32_t seed) {
random_state->pcg.seed(seed);
}
Expand Down
18 changes: 15 additions & 3 deletions src/duckdb/src/common/tree_renderer/text_tree_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,12 @@ void TextTreeRenderer::RenderBoxContent(RenderTree &root, std::ostream &ss, idx_
for (idx_t x = 0; x < root.width; x++) {
auto node = root.GetNode(x, y);
if (node) {
SplitUpExtraInfo(node->extra_text, extra_info[x]);
SplitUpExtraInfo(node->extra_text, extra_info[x], config.max_extra_lines);
if (extra_info[x].size() > extra_height) {
extra_height = extra_info[x].size();
}
}
}
extra_height = MinValue<idx_t>(extra_height, config.max_extra_lines);
idx_t halfway_point = (extra_height + 1) / 2;
// now we render the actual node
for (idx_t render_y = 0; render_y <= extra_height; render_y++) {
Expand Down Expand Up @@ -405,7 +404,8 @@ void TextTreeRenderer::SplitStringBuffer(const string &source, vector<string> &r
}
}

void TextTreeRenderer::SplitUpExtraInfo(const InsertionOrderPreservingMap<string> &extra_info, vector<string> &result) {
void TextTreeRenderer::SplitUpExtraInfo(const InsertionOrderPreservingMap<string> &extra_info, vector<string> &result,
idx_t max_lines) {
if (extra_info.empty()) {
return;
}
Expand Down Expand Up @@ -467,6 +467,18 @@ void TextTreeRenderer::SplitUpExtraInfo(const InsertionOrderPreservingMap<string
break;
}
auto splits = StringUtil::Split(str, "\n");
if (splits.size() > max_lines) {
// truncate this entry
vector<string> truncated_splits;
for (idx_t i = 0; i < max_lines / 2; i++) {
truncated_splits.push_back(std::move(splits[i]));
}
truncated_splits.push_back("...");
for (idx_t i = splits.size() - max_lines / 2; i < splits.size(); i++) {
truncated_splits.push_back(std::move(splits[i]));
}
splits = std::move(truncated_splits);
}
for (auto &split : splits) {
SplitStringBuffer(split, result);
}
Expand Down
21 changes: 21 additions & 0 deletions src/duckdb/src/common/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,27 @@ bool LogicalType::IsComplete() const {
});
}

bool LogicalType::SupportsRegularUpdate() const {
switch (id()) {
case LogicalTypeId::LIST:
case LogicalTypeId::ARRAY:
case LogicalTypeId::MAP:
case LogicalTypeId::UNION:
return false;
case LogicalTypeId::STRUCT: {
auto &child_types = StructType::GetChildTypes(*this);
for (auto &entry : child_types) {
if (!entry.second.SupportsRegularUpdate()) {
return false;
}
}
return true;
}
default:
return true;
}
}

bool LogicalType::GetDecimalProperties(uint8_t &width, uint8_t &scale) const {
switch (id_) {
case LogicalTypeId::SQLNULL:
Expand Down
20 changes: 13 additions & 7 deletions src/duckdb/src/common/types/conflict_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,24 @@ idx_t ConflictManager::ConflictCount() const {
return conflicts.Count();
}

void ConflictManager::AddIndex(BoundIndex &index) {
matched_indexes.insert(&index);
void ConflictManager::AddIndex(BoundIndex &index, optional_ptr<BoundIndex> delete_index) {
matched_indexes.push_back(index);
matched_delete_indexes.push_back(delete_index);
matched_index_names.insert(index.name);
}

bool ConflictManager::MatchedIndex(BoundIndex &index) {
return matched_indexes.count(&index);
return matched_index_names.find(index.name) != matched_index_names.end();
}

const unordered_set<BoundIndex *> &ConflictManager::MatchedIndexes() const {
const vector<reference<BoundIndex>> &ConflictManager::MatchedIndexes() const {
return matched_indexes;
}

const vector<optional_ptr<BoundIndex>> &ConflictManager::MatchedDeleteIndexes() const {
return matched_delete_indexes;
}

void ConflictManager::Finalize() {
D_ASSERT(!finalized);
if (SingleIndexTarget()) {
Expand All @@ -246,8 +252,8 @@ void ConflictManager::Finalize() {
}
}
// Now create the row_ids Vector, aligned with the selection vector
auto &row_ids = InternalRowIds();
auto row_id_data = FlatVector::GetData<row_t>(row_ids);
auto &internal_row_ids = InternalRowIds();
auto row_id_data = FlatVector::GetData<row_t>(internal_row_ids);

for (idx_t i = 0; i < selection.Count(); i++) {
D_ASSERT(!row_id_map.empty());
Expand All @@ -260,7 +266,7 @@ void ConflictManager::Finalize() {
}

VerifyExistenceType ConflictManager::LookupType() const {
return this->lookup_type;
return lookup_type;
}

} // namespace duckdb
Loading

0 comments on commit b611ab5

Please sign in to comment.