Skip to content

Commit

Permalink
Update vendored DuckDB sources to ebcae2f
Browse files Browse the repository at this point in the history
  • Loading branch information
duckdblabs-bot committed Sep 7, 2024
1 parent ebcae2f commit 22aee43
Show file tree
Hide file tree
Showing 26 changed files with 114 additions and 31 deletions.
1 change: 1 addition & 0 deletions src/duckdb/extension/icu/icu-datefunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ unique_ptr<FunctionData> ICUDateFunc::Bind(ClientContext &context, ScalarFunctio
void ICUDateFunc::SetTimeZone(icu::Calendar *calendar, const string_t &tz_id) {
auto tz = icu_66::TimeZone::createTimeZone(icu::UnicodeString::fromUTF8(icu::StringPiece(tz_id.GetString())));
if (*tz == icu::TimeZone::getUnknown()) {
delete tz;
throw NotImplementedException("Unknown TimeZone '%s'", tz_id.GetString());
}
calendar->adoptTimeZone(tz);
Expand Down
25 changes: 25 additions & 0 deletions src/duckdb/src/common/cgroups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ optional_idx CGroups::GetMemoryLimit(FileSystem &fs) {
}

optional_idx CGroups::GetCGroupV2MemoryLimit(FileSystem &fs) {
#ifdef DUCKDB_WASM
return optional_idx();
#else
const char *cgroup_self = "/proc/self/cgroup";
const char *memory_max = "/sys/fs/cgroup/%s/memory.max";

Expand All @@ -42,9 +45,13 @@ optional_idx CGroups::GetCGroupV2MemoryLimit(FileSystem &fs) {
}

return ReadCGroupValue(fs, memory_max_path);
#endif
}

optional_idx CGroups::GetCGroupV1MemoryLimit(FileSystem &fs) {
#ifdef DUCKDB_WASM
return optional_idx();
#else
const char *cgroup_self = "/proc/self/cgroup";
const char *memory_limit = "/sys/fs/cgroup/memory/%s/memory.limit_in_bytes";

Expand All @@ -65,9 +72,13 @@ optional_idx CGroups::GetCGroupV1MemoryLimit(FileSystem &fs) {
}

return ReadCGroupValue(fs, memory_limit_path);
#endif
}

string CGroups::ReadCGroupPath(FileSystem &fs, const char *cgroup_file) {
#ifdef DUCKDB_WASM
return "";
#else
auto handle = fs.OpenFile(cgroup_file, FileFlags::FILE_FLAGS_READ);
char buffer[1024];
auto bytes_read = fs.Read(*handle, buffer, sizeof(buffer) - 1);
Expand All @@ -81,9 +92,13 @@ string CGroups::ReadCGroupPath(FileSystem &fs, const char *cgroup_file) {
}

return "";
#endif
}

string CGroups::ReadMemoryCGroupPath(FileSystem &fs, const char *cgroup_file) {
#ifdef DUCKDB_WASM
return "";
#else
auto handle = fs.OpenFile(cgroup_file, FileFlags::FILE_FLAGS_READ);
char buffer[1024];
auto bytes_read = fs.Read(*handle, buffer, sizeof(buffer) - 1);
Expand All @@ -102,9 +117,13 @@ string CGroups::ReadMemoryCGroupPath(FileSystem &fs, const char *cgroup_file) {
}

return "";
#endif
}

optional_idx CGroups::ReadCGroupValue(FileSystem &fs, const char *file_path) {
#ifdef DUCKDB_WASM
return optional_idx();
#else
auto handle = fs.OpenFile(file_path, FileFlags::FILE_FLAGS_READ);
char buffer[100];
auto bytes_read = fs.Read(*handle, buffer, 99);
Expand All @@ -115,9 +134,14 @@ optional_idx CGroups::ReadCGroupValue(FileSystem &fs, const char *file_path) {
return optional_idx(value);
}
return optional_idx();
#endif
}

idx_t CGroups::GetCPULimit(FileSystem &fs, idx_t physical_cores) {
#ifdef DUCKDB_WASM
return physical_cores;
#else

static constexpr const char *cpu_max = "/sys/fs/cgroup/cpu.max";
static constexpr const char *cfs_quota = "/sys/fs/cgroup/cpu/cpu.cfs_quota_us";
static constexpr const char *cfs_period = "/sys/fs/cgroup/cpu/cpu.cfs_period_us";
Expand Down Expand Up @@ -159,6 +183,7 @@ idx_t CGroups::GetCPULimit(FileSystem &fs, idx_t physical_cores) {
} else {
return physical_cores;
}
#endif
}

} // namespace duckdb
14 changes: 9 additions & 5 deletions src/duckdb/src/common/tree_renderer/text_tree_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,20 @@ static bool NodeHasMultipleChildren(RenderTreeNode &node) {
}

static bool ShouldRenderWhitespace(RenderTree &root, idx_t x, idx_t y) {
idx_t found_children = 0;
for (;; x--) {
auto node = root.GetNode(x, y);
if (root.HasNode(x, y + 1)) {
found_children++;
}
if (node) {
if (NodeHasMultipleChildren(*node)) {
return true;
if (found_children < node->child_positions.size()) {
return true;
}
}
return false;
}
if (root.HasNode(x, y + 1)) {
break;
}
if (x == 0) {
break;
}
Expand Down Expand Up @@ -190,11 +193,12 @@ void TextTreeRenderer::RenderBoxContent(RenderTree &root, std::ostream &ss, idx_
if (root.HasNode(x, y + 1)) {
// node right below this one
ss << StringUtil::Repeat(config.HORIZONTAL, config.node_render_width / 2);
ss << config.RTCORNER;
if (has_child_to_the_right) {
ss << config.TMIDDLE;
// but we have another child to the right! keep rendering the line
ss << StringUtil::Repeat(config.HORIZONTAL, config.node_render_width / 2);
} else {
ss << config.RTCORNER;
if (has_adjacent_nodes) {
// only a child below this one: fill the rest with spaces
ss << StringUtil::Repeat(" ", config.node_render_width / 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,11 @@ static void ArrayFixedCombine(DataChunk &args, ExpressionState &state, Vector &r
throw InvalidInputException(
StringUtil::Format("%s: right argument can not contain NULL values", func_name));
}
const auto result_offset = i * N;

const auto lhs_data_ptr = lhs_data + left_offset;
const auto rhs_data_ptr = rhs_data + right_offset;
const auto res_data_ptr = res_data + right_offset;
const auto res_data_ptr = res_data + result_offset;

OP::Operation(lhs_data_ptr, rhs_data_ptr, res_data_ptr, N);
}
Expand Down
2 changes: 1 addition & 1 deletion src/duckdb/src/execution/index/art/art.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ bool ART::SearchLess(ARTKey &upper_bound, bool equal, idx_t max_count, unsafe_ve
it.FindMinimum(tree);

// Early-out, if the minimum value is higher than the upper bound.
if (it.current_key.GreaterThan(upper_bound, equal)) {
if (it.current_key.GreaterThan(upper_bound, equal, it.GetNestedDepth())) {
return true;
}

Expand Down
15 changes: 7 additions & 8 deletions src/duckdb/src/execution/index/art/iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,19 @@ bool IteratorKey::Contains(const ARTKey &key) const {
return true;
}

bool IteratorKey::GreaterThan(const ARTKey &key, const bool equal) const {
bool IteratorKey::GreaterThan(const ARTKey &key, const bool equal, const uint8_t nested_depth) const {
for (idx_t i = 0; i < MinValue<idx_t>(Size(), key.len); i++) {
if (key_bytes[i] > key.data[i]) {
return true;
} else if (key_bytes[i] < key.data[i]) {
return false;
}
}
if (equal) {
// Returns true, if current_key is greater than key.
return Size() > key.len;
}
// Returns true, if current_key and key match or current_key is greater than key.
return Size() >= key.len;

// Returns true, if current_key is greater than (or equal to) key.
D_ASSERT(Size() >= nested_depth);
auto this_len = Size() - nested_depth;
return equal ? this_len > key.len : this_len >= key.len;
}

//===--------------------------------------------------------------------===//
Expand All @@ -48,7 +47,7 @@ bool Iterator::Scan(const ARTKey &upper_bound, const idx_t max_count, unsafe_vec
do {
// An empty upper bound indicates that no upper bound exists.
if (!upper_bound.Empty() && status == GateStatus::GATE_NOT_SET) {
if (current_key.GreaterThan(upper_bound, equal)) {
if (current_key.GreaterThan(upper_bound, equal, nested_depth)) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ bool ColumnCountResult::AddRow(ColumnCountResult &result, idx_t buffer_pos) {
}

void ColumnCountResult::SetComment(ColumnCountResult &result, idx_t buffer_pos) {
if (result.current_column_count == 0) {
if (!result.states.WasStandard()) {
result.cur_line_starts_as_comment = true;
}
result.comment = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ void CSVSniffer::DetectDialect() {

// if no dialect candidate was found, we throw an exception
if (candidates.empty()) {
auto error = CSVError::DialectSniffingError(options, dialect_candidates.Print());
auto error = CSVError::SniffingError(options, dialect_candidates.Print());
error_handler->Error(error);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,20 @@ void CSVSniffer::DetectTypes() {
SetUserDefinedDateTimeFormat(*candidate->state_machine);
// Parse chunk and read csv with info candidate
auto &data_chunk = candidate->ParseChunk().ToChunk();
if (!candidate->error_handler->errors.empty()) {
bool break_loop = false;
for (auto &errors : candidate->error_handler->errors) {
for (auto &error : errors.second) {
if (error.type != CSVErrorType::MAXIMUM_LINE_SIZE) {
break_loop = true;
break;
}
}
}
if (break_loop) {
continue;
}
}
idx_t start_idx_detection = 0;
idx_t chunk_size = data_chunk.size();
if (chunk_size > 1 &&
Expand Down Expand Up @@ -465,6 +479,11 @@ void CSVSniffer::DetectTypes() {
}
}
}
if (!best_candidate) {
DialectCandidates dialect_candidates(options.dialect_options.state_machine_options);
auto error = CSVError::SniffingError(options, dialect_candidates.Print());
error_handler->Error(error);
}
// Assert that it's all good at this point.
D_ASSERT(best_candidate && !best_format_candidates.empty());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,12 @@ CSVError CSVError::HeaderSniffingError(const CSVReaderOptions &options, const ve
return CSVError(error.str(), SNIFFING, {});
}

CSVError CSVError::DialectSniffingError(const CSVReaderOptions &options, const string &search_space) {
CSVError CSVError::SniffingError(const CSVReaderOptions &options, const string &search_space) {
std::ostringstream error;
// 1. Which file
error << "Error when sniffing file \"" << options.file_path << "\"." << '\n';
// 2. What's the error
error << "It was not possible to automatically detect the CSV Parsing dialect" << '\n';
error << "It was not possible to automatically detect the CSV Parsing dialect/types" << '\n';

// 2. What was the search space?
error << "The search space used was:" << '\n';
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 "1-dev5272"
#define DUCKDB_PATCH_VERSION "1-dev5313"
#endif
#ifndef DUCKDB_MINOR_VERSION
#define DUCKDB_MINOR_VERSION 0
Expand All @@ -8,10 +8,10 @@
#define DUCKDB_MAJOR_VERSION 1
#endif
#ifndef DUCKDB_VERSION
#define DUCKDB_VERSION "v1.0.1-dev5272"
#define DUCKDB_VERSION "v1.0.1-dev5313"
#endif
#ifndef DUCKDB_SOURCE_ID
#define DUCKDB_SOURCE_ID "4d18b9d05c"
#define DUCKDB_SOURCE_ID "64bacde85e"
#endif
#include "duckdb/function/table/system_functions.hpp"
#include "duckdb/main/database.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class IteratorKey {
//! Returns true, if key_bytes contains all bytes of key.
bool Contains(const ARTKey &key) const;
//! Returns true, if key_bytes is greater than [or equal to] the key.
bool GreaterThan(const ARTKey &key, bool equal) const;
bool GreaterThan(const ARTKey &key, const bool equal, const uint8_t nested_depth) const;

private:
unsafe_vector<uint8_t> key_bytes;
Expand All @@ -72,6 +72,11 @@ class Iterator {
//! bound exceeds the maximum value of the ART.
bool LowerBound(const Node &node, const ARTKey &key, const bool equal, idx_t depth);

//! Returns the nested depth.
uint8_t GetNestedDepth() const {
return nested_depth;
}

private:
//! The ART.
ART &art;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CSVError {
static CSVError LineSizeError(const CSVReaderOptions &options, idx_t actual_size, LinesPerBoundary error_info,
string &csv_row, idx_t byte_position, const string &current_path);
//! Produces an error message for a dialect sniffing error.
static CSVError DialectSniffingError(const CSVReaderOptions &options, const string &search_space);
static CSVError SniffingError(const CSVReaderOptions &options, const string &search_space);
//! Produces an error message for a header sniffing error.
static CSVError HeaderSniffingError(const CSVReaderOptions &options, const vector<HeaderValue> &best_header_row,
idx_t column_count, char delimiter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ struct CSVStates {
(states[1] == CSVState::RECORD_SEPARATOR || states[1] == CSVState::CARRIAGE_RETURN);
}

inline bool WasStandard() {
return states[0] == CSVState::STANDARD;
}

inline bool EmptyLastValue() {
// It is a new row, if the previous state is not a record separator, and the current one is
return states[0] == CSVState::DELIMITER &&
Expand Down
1 change: 1 addition & 0 deletions src/duckdb/src/include/duckdb/planner/logical_operator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class LogicalOperator {
void AddChild(unique_ptr<LogicalOperator> child);
virtual idx_t EstimateCardinality(ClientContext &context);
void SetEstimatedCardinality(idx_t _estimated_cardinality);
void SetParamsEstimatedCardinality(InsertionOrderPreservingMap<string> &result) const;

virtual void Serialize(Serializer &serializer) const;
static unique_ptr<LogicalOperator> Deserialize(Deserializer &deserializer);
Expand Down
17 changes: 12 additions & 5 deletions src/duckdb/src/planner/logical_operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ vector<ColumnBinding> LogicalOperator::GetColumnBindings() {
return {ColumnBinding(0, 0)};
}

void LogicalOperator::SetParamsEstimatedCardinality(InsertionOrderPreservingMap<string> &result) const {
if (has_estimated_cardinality) {
result[RenderTreeNode::ESTIMATED_CARDINALITY] = StringUtil::Format("%llu", estimated_cardinality);
}
}

void LogicalOperator::SetEstimatedCardinality(idx_t _estimated_cardinality) {
estimated_cardinality = _estimated_cardinality;
has_estimated_cardinality = true;
}

// LCOV_EXCL_START
string LogicalOperator::ColumnBindingsToString(const vector<ColumnBinding> &bindings) {
string result = "{";
Expand Down Expand Up @@ -57,6 +68,7 @@ InsertionOrderPreservingMap<string> LogicalOperator::ParamsToString() const {
expressions_info += expressions[i]->GetName();
}
result["Expressions"] = expressions_info;
SetParamsEstimatedCardinality(result);
return result;
}

Expand Down Expand Up @@ -191,11 +203,6 @@ idx_t LogicalOperator::EstimateCardinality(ClientContext &context) {
return estimated_cardinality;
}

void LogicalOperator::SetEstimatedCardinality(idx_t _estimated_cardinality) {
estimated_cardinality = _estimated_cardinality;
has_estimated_cardinality = true;
}

void LogicalOperator::Print() {
Printer::Print(ToString());
}
Expand Down
1 change: 1 addition & 0 deletions src/duckdb/src/planner/operator/logical_aggregate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ InsertionOrderPreservingMap<string> LogicalAggregate::ParamsToString() const {
expressions_info += expressions[i]->GetName();
}
result["Expressions"] = expressions_info;
SetParamsEstimatedCardinality(result);
return result;
}

Expand Down
1 change: 1 addition & 0 deletions src/duckdb/src/planner/operator/logical_any_join.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ LogicalAnyJoin::LogicalAnyJoin(JoinType type) : LogicalJoin(type, LogicalOperato
InsertionOrderPreservingMap<string> LogicalAnyJoin::ParamsToString() const {
InsertionOrderPreservingMap<string> result;
result["Condition"] = condition->ToString();
SetParamsEstimatedCardinality(result);
return result;
}

Expand Down
2 changes: 2 additions & 0 deletions src/duckdb/src/planner/operator/logical_comparison_join.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ InsertionOrderPreservingMap<string> LogicalComparisonJoin::ParamsToString() cons
conditions_info += expr->ToString();
}
result["Conditions"] = conditions_info;
SetParamsEstimatedCardinality(result);

return result;
}

Expand Down
1 change: 1 addition & 0 deletions src/duckdb/src/planner/operator/logical_cteref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace duckdb {
InsertionOrderPreservingMap<string> LogicalCTERef::ParamsToString() const {
InsertionOrderPreservingMap<string> result;
result["CTE Index"] = StringUtil::Format("%llu", cte_index);
SetParamsEstimatedCardinality(result);
return result;
}

Expand Down
Loading

0 comments on commit 22aee43

Please sign in to comment.