Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions src/duckdb/src/common/arrow/arrow_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,25 @@ int ResultArrowArrayStreamWrapper::MyStreamGetNext(struct ArrowArrayStream *stre
my_stream->column_types = result.types;
my_stream->column_names = result.names;
}
idx_t result_count;
ErrorData error;
if (!ArrowUtil::TryFetchChunk(scan_state, result.client_properties, my_stream->batch_size, out, result_count, error,
my_stream->extension_types)) {
D_ASSERT(error.HasError());
my_stream->last_error = error;

try {
idx_t result_count;
ErrorData error;
if (!ArrowUtil::TryFetchChunk(scan_state, result.client_properties, my_stream->batch_size, out, result_count,
error, my_stream->extension_types)) {
D_ASSERT(error.HasError());
my_stream->last_error = error;
return -1;
}
if (result_count == 0) {
// Nothing to output
out->release = nullptr;
}
} catch (std::exception &e) {
my_stream->last_error = ErrorData(e);
return -1;
}
if (result_count == 0) {
// Nothing to output
out->release = nullptr;
}

return 0;
}

Expand Down
1 change: 1 addition & 0 deletions src/duckdb/src/common/bignum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ string_t BignumIntermediate::Add(Vector &result_vector, const BignumIntermediate
auto target_data = target.GetDataWriteable();
Bignum::SetHeader(target_data, 1, false);
target_data[Bignum::BIGNUM_HEADER_SIZE] = 0;
target.SetSizeAndFinalize(1 + Bignum::BIGNUM_HEADER_SIZE, result_size);
return target;

} else if (is_absolute_bigger == SMALLER) {
Expand Down
4 changes: 2 additions & 2 deletions src/duckdb/src/common/box_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1915,8 +1915,8 @@ void BoxRendererImplementation::ComputeRenderWidths(vector<RenderDataCollection>

// check if we shortened any columns that would be rendered and if we can expand them
// we only expand columns in the ".mode rows", and only if we haven't hidden any columns
if (shortened_columns && config.render_mode == RenderMode::ROWS && row_count + 5 < config.max_rows &&
pruned_columns.empty()) {
if (shortened_columns && config.render_mode == RenderMode::ROWS && row_count > 0 &&
row_count + 5 < config.max_rows && pruned_columns.empty()) {
max_rows_per_row = MaxValue<idx_t>(1, config.max_rows <= 5 ? 0 : (config.max_rows - 5) / row_count);
if (max_rows_per_row > 1) {
// we can expand rows - check if we should expand any rows
Expand Down
7 changes: 3 additions & 4 deletions src/duckdb/src/common/enum_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,20 +383,19 @@ const StringUtil::EnumStringLiteral *GetAllowParserOverrideValues() {
static constexpr StringUtil::EnumStringLiteral values[] {
{ static_cast<uint32_t>(AllowParserOverride::DEFAULT_OVERRIDE), "DEFAULT" },
{ static_cast<uint32_t>(AllowParserOverride::FALLBACK_OVERRIDE), "FALLBACK" },
{ static_cast<uint32_t>(AllowParserOverride::STRICT_OVERRIDE), "STRICT" },
{ static_cast<uint32_t>(AllowParserOverride::STRICT_WHEN_SUPPORTED), "STRICT_WHEN_SUPPORTED" }
{ static_cast<uint32_t>(AllowParserOverride::STRICT_OVERRIDE), "STRICT" }
};
return values;
}

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

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

const StringUtil::EnumStringLiteral *GetAlterDatabaseTypeValues() {
Expand Down
1 change: 1 addition & 0 deletions src/duckdb/src/common/error_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ void ErrorData::AddErrorLocation(const string &query) {
auto entry = extra_info.find("position");
if (entry != extra_info.end()) {
raw_message = QueryErrorContext::Format(query, raw_message, std::stoull(entry->second));
extra_info.erase(entry);
}
}
{
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 "2-dev118"
#define DUCKDB_PATCH_VERSION "2-dev189"
#endif
#ifndef DUCKDB_MINOR_VERSION
#define DUCKDB_MINOR_VERSION 5
Expand All @@ -8,10 +8,10 @@
#define DUCKDB_MAJOR_VERSION 1
#endif
#ifndef DUCKDB_VERSION
#define DUCKDB_VERSION "v1.5.2-dev118"
#define DUCKDB_VERSION "v1.5.2-dev189"
#endif
#ifndef DUCKDB_SOURCE_ID
#define DUCKDB_SOURCE_ID "c23c958a93"
#define DUCKDB_SOURCE_ID "4d195b9091"
#endif
#include "duckdb/function/table/system_functions.hpp"
#include "duckdb/main/database.hpp"
Expand Down
9 changes: 7 additions & 2 deletions src/duckdb/src/include/duckdb/common/arrow/arrow_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,16 @@ struct ArrowBuffer {

private:
void ReserveInternal(idx_t bytes) {
data_ptr_t new_ptr;
if (dataptr) {
dataptr = data_ptr_cast(realloc(dataptr, bytes));
new_ptr = data_ptr_cast(realloc(dataptr, bytes));
} else {
dataptr = data_ptr_cast(malloc(bytes));
new_ptr = data_ptr_cast(malloc(bytes));
}
if (!new_ptr) {
throw OutOfMemoryException("ArrowBuffer: failed to allocate %llu bytes", bytes);
}
dataptr = new_ptr;
capacity = bytes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@

namespace duckdb {

enum class AllowParserOverride : uint8_t {
DEFAULT_OVERRIDE,
FALLBACK_OVERRIDE,
STRICT_OVERRIDE,
STRICT_WHEN_SUPPORTED
};
enum class AllowParserOverride : uint8_t { DEFAULT_OVERRIDE, FALLBACK_OVERRIDE, STRICT_OVERRIDE };

} // namespace duckdb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "duckdb/common/enums/order_type.hpp"
#include "duckdb/function/aggregate_function.hpp"
#include "duckdb/function/create_sort_key.hpp"
#include <new>

namespace duckdb {

Expand Down Expand Up @@ -180,9 +181,8 @@ class BinaryAggregateHeap {

void Initialize(ArenaAllocator &allocator, const idx_t capacity_p) {
capacity = capacity_p;
auto ptr = allocator.AllocateAligned(capacity * sizeof(STORAGE_TYPE));
memset(ptr, 0, capacity * sizeof(STORAGE_TYPE));
heap = reinterpret_cast<STORAGE_TYPE *>(ptr);
allocated_capacity = 0;
heap = nullptr;
size = 0;
}

Expand All @@ -201,6 +201,9 @@ class BinaryAggregateHeap {

// If the heap is not full, insert the value into a new slot
if (size < capacity) {
if (size == allocated_capacity) {
Grow(allocator);
}
heap[size].first.Assign(allocator, key);
heap[size].second.Assign(allocator, value);
size++;
Expand Down Expand Up @@ -233,13 +236,33 @@ class BinaryAggregateHeap {
}

private:
void Grow(ArenaAllocator &allocator) {
D_ASSERT(allocated_capacity < capacity);
const auto old_allocated_capacity = allocated_capacity;
if (allocated_capacity == 0) {
allocated_capacity = 1;
} else if (allocated_capacity > capacity / 2) {
allocated_capacity = capacity;
} else {
allocated_capacity *= 2;
}

const auto old_size = old_allocated_capacity * sizeof(STORAGE_TYPE);
const auto new_size = allocated_capacity * sizeof(STORAGE_TYPE);
auto ptr = heap ? allocator.ReallocateAligned(reinterpret_cast<data_ptr_t>(heap), old_size, new_size)
: allocator.AllocateAligned(new_size);
memset(ptr + old_size, 0, new_size - old_size);
heap = reinterpret_cast<STORAGE_TYPE *>(ptr);
}

static bool Compare(const STORAGE_TYPE &left, const STORAGE_TYPE &right) {
return K_COMPARATOR::Operation(left.first.value, right.first.value);
}

idx_t capacity;
STORAGE_TYPE *heap;
idx_t size;
idx_t capacity = 0;
idx_t allocated_capacity = 0;
STORAGE_TYPE *heap = nullptr;
idx_t size = 0;
};

enum class ArgMinMaxNullHandling { IGNORE_ANY_NULL, HANDLE_ARG_NULL, HANDLE_ANY_NULL };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class TopNWindowElimination : public BaseColumnPruner {

vector<unique_ptr<Expression>> GenerateAggregatePayload(const vector<ColumnBinding> &bindings,
const LogicalWindow &window, map<idx_t, idx_t> &group_idxs);
vector<ColumnBinding> TraverseProjectionBindings(const std::vector<ColumnBinding> &old_bindings,
reference<LogicalOperator> &op);
bool TraverseProjectionBindings(const vector<ColumnBinding> &old_bindings, reference<LogicalOperator> &op,
vector<ColumnBinding> &new_bindings);
unique_ptr<Expression> CreateAggregateExpression(vector<unique_ptr<Expression>> aggregate_params, bool requires_arg,
const TopNWindowEliminationParameters &params) const;
unique_ptr<Expression> CreateRowNumberGenerator(unique_ptr<Expression> aggregate_column_ref) const;
Expand Down
2 changes: 2 additions & 0 deletions src/duckdb/src/include/duckdb/parser/tableref/pivotref.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ struct PivotColumn {

void Serialize(Serializer &serializer) const;
static PivotColumn Deserialize(Deserializer &source);

vector<PivotColumnEntry> GetEntriesForSerialization(Serializer &serializer) const;
};

//! Represents a PIVOT or UNPIVOT expression
Expand Down
18 changes: 13 additions & 5 deletions src/duckdb/src/optimizer/topn_window_elimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ unique_ptr<LogicalOperator> TopNWindowElimination::OptimizeInternal(unique_ptr<L

// Get bindings and types from filter to use in top-most operator later
const auto topmost_bindings = filter.GetColumnBindings();
auto new_bindings = TraverseProjectionBindings(topmost_bindings, child);
vector<ColumnBinding> new_bindings;
if (!TraverseProjectionBindings(topmost_bindings, child, new_bindings)) {
return op;
}

D_ASSERT(child.get().type == LogicalOperatorType::LOGICAL_WINDOW);
auto &window = child.get().Cast<LogicalWindow>();
Expand Down Expand Up @@ -647,9 +650,10 @@ vector<unique_ptr<Expression>> TopNWindowElimination::GenerateAggregatePayload(c
return aggregate_args;
}

vector<ColumnBinding> TopNWindowElimination::TraverseProjectionBindings(const std::vector<ColumnBinding> &old_bindings,
reference<LogicalOperator> &op) {
auto new_bindings = old_bindings;
bool TopNWindowElimination::TraverseProjectionBindings(const vector<ColumnBinding> &old_bindings,
reference<LogicalOperator> &op,
vector<ColumnBinding> &new_bindings) {
new_bindings = old_bindings;

// Traverse child projections to retrieve projections on window output
while (op.get().type == LogicalOperatorType::LOGICAL_PROJECTION) {
Expand All @@ -659,13 +663,17 @@ vector<ColumnBinding> TopNWindowElimination::TraverseProjectionBindings(const st
auto &new_binding = new_bindings[i];
D_ASSERT(new_binding.table_index == projection.table_index);
VisitExpression(&projection.expressions[new_binding.column_index]);
if (column_references.size() != 1) {
column_references.clear();
return false;
}
new_binding = column_references.begin()->first;
column_references.clear();
}
op = *op.get().children[0];
}

return new_bindings;
return true;
}

void TopNWindowElimination::UpdateTopmostBindings(const idx_t window_idx, const unique_ptr<LogicalOperator> &op,
Expand Down
48 changes: 0 additions & 48 deletions src/duckdb/src/parser/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,6 @@ void Parser::ThrowParserOverrideError(ParserOverrideResult &result) {
result.error.RawMessage());
}
if (result.type == ParserExtensionResultType::DISPLAY_EXTENSION_ERROR) {
if (result.error.Type() == ExceptionType::NOT_IMPLEMENTED) {
throw NotImplementedException("Parser override has not yet implemented this "
"transformer rule.\nOriginal error: %s",
result.error.RawMessage());
}
if (result.error.Type() == ExceptionType::PARSER) {
result.error.Throw();
}
result.error.Throw();
}
}
Expand Down Expand Up @@ -256,46 +248,6 @@ void Parser::ParseQuery(const string &query) {
}
if (options.parser_override_setting == AllowParserOverride::STRICT_OVERRIDE) {
ThrowParserOverrideError(result);
}
if (options.parser_override_setting == AllowParserOverride::STRICT_WHEN_SUPPORTED) {
auto statement = GetStatement(query);
if (!statement) {
break;
}
bool is_supported = false;
switch (statement->type) {
case StatementType::ANALYZE_STATEMENT:
case StatementType::VACUUM_STATEMENT:
case StatementType::CALL_STATEMENT:
case StatementType::MERGE_INTO_STATEMENT:
case StatementType::TRANSACTION_STATEMENT:
case StatementType::VARIABLE_SET_STATEMENT:
case StatementType::LOAD_STATEMENT:
case StatementType::EXPLAIN_STATEMENT:
case StatementType::PREPARE_STATEMENT:
case StatementType::ATTACH_STATEMENT:
case StatementType::SELECT_STATEMENT:
case StatementType::DETACH_STATEMENT:
case StatementType::DELETE_STATEMENT:
case StatementType::DROP_STATEMENT:
case StatementType::ALTER_STATEMENT:
case StatementType::PRAGMA_STATEMENT:
case StatementType::INSERT_STATEMENT:
case StatementType::UPDATE_STATEMENT:
case StatementType::COPY_DATABASE_STATEMENT:
case StatementType::CREATE_STATEMENT:
case StatementType::COPY_STATEMENT:
case StatementType::SET_STATEMENT: {
is_supported = true;
break;
}
default:
is_supported = false;
break;
}
if (is_supported) {
ThrowParserOverrideError(result);
}
} else if (options.parser_override_setting == AllowParserOverride::FALLBACK_OVERRIDE) {
continue;
}
Expand Down
Loading
Loading