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
17 changes: 12 additions & 5 deletions src/duckdb/src/catalog/catalog_search_path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,15 @@ void CatalogSearchPath::Set(CatalogSearchEntry new_value, CatalogSetPathType set
Set(std::move(new_paths), set_type);
}

const vector<CatalogSearchEntry> &CatalogSearchPath::Get() const {
return paths;
vector<CatalogSearchEntry> CatalogSearchPath::Get() const {
vector<CatalogSearchEntry> res;
for (auto &path : paths) {
if (path.schema.empty()) {
continue;
}
res.emplace_back(path);
}
return res;
}

string CatalogSearchPath::GetDefaultSchema(const string &catalog) const {
Expand Down Expand Up @@ -248,7 +255,7 @@ vector<string> CatalogSearchPath::GetCatalogsForSchema(const string &schema) con
catalogs.push_back(SYSTEM_CATALOG);
} else {
for (auto &path : paths) {
if (StringUtil::CIEquals(path.schema, schema)) {
if (StringUtil::CIEquals(path.schema, schema) || path.schema.empty()) {
catalogs.push_back(path.catalog);
}
}
Expand All @@ -259,16 +266,16 @@ vector<string> CatalogSearchPath::GetCatalogsForSchema(const string &schema) con
vector<string> CatalogSearchPath::GetSchemasForCatalog(const string &catalog) const {
vector<string> schemas;
for (auto &path : paths) {
if (StringUtil::CIEquals(path.catalog, catalog)) {
if (!path.schema.empty() && StringUtil::CIEquals(path.catalog, catalog)) {
schemas.push_back(path.schema);
}
}
return schemas;
}

const CatalogSearchEntry &CatalogSearchPath::GetDefault() const {
const auto &paths = Get();
D_ASSERT(paths.size() >= 2);
D_ASSERT(!paths[1].schema.empty());
return paths[1];
}

Expand Down
31 changes: 31 additions & 0 deletions src/duckdb/src/common/adbc/adbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "duckdb/common/adbc/single_batch_array_stream.hpp"
#include "duckdb/function/table/arrow.hpp"
#include "duckdb/common/adbc/wrappers.hpp"
#include <algorithm>
#include <cstring>
#include <stdlib.h>
#include <string.h>

Expand Down Expand Up @@ -862,6 +864,22 @@ AdbcStatusCode StatementExecuteQuery(struct AdbcStatement *statement, struct Arr
if (has_stream && to_table) {
return IngestToTableFromBoundStream(wrapper, error);
}

if (!wrapper->statement) {
if (out) {
out->private_data = nullptr;
out->get_schema = nullptr;
out->get_next = nullptr;
out->release = nullptr;
out->get_last_error = nullptr;
}

if (rows_affected) {
*rows_affected = 0;
}
return ADBC_STATUS_OK;
}

auto stream_wrapper = static_cast<DuckDBAdbcStreamWrapper *>(malloc(sizeof(DuckDBAdbcStreamWrapper)));
if (has_stream) {
// A stream was bound to the statement, use that to bind parameters
Expand Down Expand Up @@ -987,6 +1005,12 @@ AdbcStatusCode StatementSetSqlQuery(struct AdbcStatement *statement, const char
return ADBC_STATUS_INVALID_ARGUMENT;
}

auto query_len = strlen(query);
if (std::all_of(query, query + query_len, duckdb::StringUtil::CharacterIsSpace)) {
SetError(error, "No statements found");
return ADBC_STATUS_INVALID_ARGUMENT;
}

auto wrapper = static_cast<DuckDBAdbcStatementWrapper *>(statement->private_data);
if (wrapper->ingestion_stream.release) {
// Release any resources currently held by the ingestion stream before we overwrite it
Expand All @@ -1006,6 +1030,13 @@ AdbcStatusCode StatementSetSqlQuery(struct AdbcStatement *statement, const char
duckdb_destroy_extracted(&extracted_statements);
return ADBC_STATUS_INTERNAL;
}

if (extract_statements_size == 0) {
// Query is non-empty, but there are no actual statements.
duckdb_destroy_extracted(&extracted_statements);
return ADBC_STATUS_OK;
}

// Now lets loop over the statements, and execute every one
for (idx_t i = 0; i < extract_statements_size - 1; i++) {
duckdb_prepared_statement statement_internal = nullptr;
Expand Down
5 changes: 3 additions & 2 deletions src/duckdb/src/function/scalar/create_sort_key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,9 @@ void FinalizeSortData(Vector &result, idx_t size, const SortKeyLengthInfo &key_l
auto result_data = FlatVector::GetData<string_t>(result);
// call Finalize on the result
for (idx_t r = 0; r < size; r++) {
result_data[r].SetSizeAndFinalize(offsets[r],
key_lengths.variable_lengths[r] + key_lengths.constant_length);
const auto offset = static_cast<uint32_t>(offsets[r]);
const auto allocated_size = key_lengths.variable_lengths[r] + key_lengths.constant_length;
result_data[r].SetSizeAndFinalize(offset, allocated_size);
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ static void ConstantOrNullFunction(DataChunk &args, ExpressionState &state, Vect
// there are null values: need to merge them into the result
result.Flatten(args.size());
auto &result_mask = FlatVector::Validity(result);
result_mask.EnsureWritable();
result_mask.Combine(input_mask, args.size());
}
break;
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-dev67"
#define DUCKDB_PATCH_VERSION "4-dev100"
#endif
#ifndef DUCKDB_MINOR_VERSION
#define DUCKDB_MINOR_VERSION 4
Expand All @@ -8,10 +8,10 @@
#define DUCKDB_MAJOR_VERSION 1
#endif
#ifndef DUCKDB_VERSION
#define DUCKDB_VERSION "v1.4.4-dev67"
#define DUCKDB_VERSION "v1.4.4-dev100"
#endif
#ifndef DUCKDB_SOURCE_ID
#define DUCKDB_SOURCE_ID "5a334c23da"
#define DUCKDB_SOURCE_ID "30bc6df28d"
#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 @@ -48,7 +48,7 @@ class CatalogSearchPath {
DUCKDB_API void Set(vector<CatalogSearchEntry> new_paths, CatalogSetPathType set_type);
DUCKDB_API void Reset();

DUCKDB_API const vector<CatalogSearchEntry> &Get() const;
DUCKDB_API vector<CatalogSearchEntry> Get() const;
const vector<CatalogSearchEntry> &GetSetPaths() const {
return set_paths;
}
Expand Down
63 changes: 32 additions & 31 deletions src/duckdb/src/include/duckdb/common/operator/numeric_cast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
//
//===----------------------------------------------------------------------===//

//! NOTE: This file should not be included directly.
//! NOTE: When included directly, this file produces 'unused static method' warnings/errors.
//! NOTE: The methods in this file should be used through the TryCast:: methods defined in 'cast_operators.hpp'.

#pragma once

#include "duckdb/common/operator/cast_operators.hpp"
Expand All @@ -19,55 +23,52 @@

namespace duckdb {

//! Note: this should not be included directly, when these methods are required
//! They should be used through the TryCast:: methods defined in 'cast_operators.hpp'
//! This file produces 'unused static method' warnings/errors when included

template <class SRC, class DST>
static bool TryCastWithOverflowCheck(SRC value, DST &result) {
if (!Value::IsFinite<SRC>(value)) {
return false;
}

// SRC and DST do not have the same sign.
if (NumericLimits<SRC>::IsSigned() != NumericLimits<DST>::IsSigned()) {
// SRC is signed.
if (NumericLimits<SRC>::IsSigned()) {
// signed to unsigned conversion
if (NumericLimits<SRC>::Digits() > NumericLimits<DST>::Digits()) {
if (value < 0 || value > (SRC)NumericLimits<DST>::Maximum()) {
if (value < 0 || value > static_cast<SRC>(NumericLimits<DST>::Maximum())) {
return false;
}
} else {
if (value < 0) {
return false;
}
}
result = (DST)value;
result = static_cast<DST>(value);
return true;
} else {
// unsigned to signed conversion
if (NumericLimits<SRC>::Digits() >= NumericLimits<DST>::Digits()) {
if (value <= (SRC)NumericLimits<DST>::Maximum()) {
result = (DST)value;
return true;
}
return false;
} else {
result = (DST)value;
}

// SRC is unsigned.
if (NumericLimits<SRC>::Digits() >= NumericLimits<DST>::Digits()) {
if (value <= static_cast<SRC>(NumericLimits<DST>::Maximum())) {
result = static_cast<DST>(value);
return true;
}
return false;
}
} else {
// same sign conversion
if (NumericLimits<DST>::Digits() >= NumericLimits<SRC>::Digits()) {
result = (DST)value;
return true;
} else {
if (value < SRC(NumericLimits<DST>::Minimum()) || value > SRC(NumericLimits<DST>::Maximum())) {
return false;
}
result = (DST)value;
return true;
}
result = static_cast<DST>(value);
return true;
}

// SRC and DST have the same sign.
if (NumericLimits<DST>::Digits() >= NumericLimits<SRC>::Digits()) {
result = static_cast<DST>(value);
return true;
}

if (value < SRC(NumericLimits<DST>::Minimum()) || value > SRC(NumericLimits<DST>::Maximum())) {
return false;
}
result = static_cast<DST>(value);
return true;
}

template <class SRC, class T>
Expand Down Expand Up @@ -594,14 +595,14 @@ struct NumericTryCastToBit {

struct NumericTryCast {
template <class SRC, class DST>
static inline bool Operation(SRC input, DST &result, bool strict = false) {
static bool Operation(SRC input, DST &result, bool strict = false) {
return TryCastWithOverflowCheck(input, result);
}
};

struct NumericCast {
template <class SRC, class DST>
static inline DST Operation(SRC input) {
static DST Operation(SRC input) {
DST result;
if (!NumericTryCast::Operation(input, result)) {
throw InvalidInputException(CastExceptionText<SRC, DST>(input));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ class BlockIteratorState<BlockIteratorStateType::IN_MEMORY>
return GetValueAtIndex<T>(block_idx, tuple_idx);
}

void SetKeepPinned(const bool &) {
static void SetKeepPinned(const bool &) {
// NOP
}

void SetPinPayload(const bool &) {
static void SetPinPayload(const bool &) {
// NOP
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class TableDataWriter {
public:
void WriteTableData(Serializer &metadata_serializer);

virtual void WriteUnchangedTable(MetaBlockPointer pointer, idx_t total_rows) = 0;
virtual void WriteUnchangedTable(MetaBlockPointer pointer, const vector<MetaBlockPointer> &metadata_pointers,
idx_t total_rows) = 0;
virtual void FinalizeTable(const TableStatistics &global_stats, DataTableInfo &info, RowGroupCollection &collection,
Serializer &serializer) = 0;
virtual unique_ptr<RowGroupWriter> GetRowGroupWriter(RowGroup &row_group) = 0;
Expand All @@ -54,7 +55,8 @@ class SingleFileTableDataWriter : public TableDataWriter {
MetadataWriter &table_data_writer);

public:
void WriteUnchangedTable(MetaBlockPointer pointer, idx_t total_rows) override;
void WriteUnchangedTable(MetaBlockPointer pointer, const vector<MetaBlockPointer> &metadata_pointers,
idx_t total_rows) override;
void FinalizeTable(const TableStatistics &global_stats, DataTableInfo &info, RowGroupCollection &collection,
Serializer &serializer) override;
unique_ptr<RowGroupWriter> GetRowGroupWriter(RowGroup &row_group) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class InMemoryTableDataWriter : public TableDataWriter {
InMemoryTableDataWriter(InMemoryCheckpointer &checkpoint_manager, TableCatalogEntry &table);

public:
void WriteUnchangedTable(MetaBlockPointer pointer, idx_t total_rows) override;
void WriteUnchangedTable(MetaBlockPointer pointer, const vector<MetaBlockPointer> &metadata_pointers,
idx_t total_rows) override;
void FinalizeTable(const TableStatistics &global_stats, DataTableInfo &info, RowGroupCollection &collection,
Serializer &serializer) override;
unique_ptr<RowGroupWriter> GetRowGroupWriter(RowGroup &row_group) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class PersistentTableData {
~PersistentTableData();

MetaBlockPointer base_table_pointer;
vector<MetaBlockPointer> read_metadata_pointers;
TableStatistics table_stats;
idx_t total_rows;
idx_t row_group_count;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class RowGroupCollection {
void Initialize(PersistentCollectionData &data);
void Initialize(PersistentTableData &data);
void InitializeEmpty();
void FinalizeCheckpoint(MetaBlockPointer pointer);
void FinalizeCheckpoint(MetaBlockPointer pointer, const vector<MetaBlockPointer> &existing_pointers);

bool IsEmpty() const;

Expand Down Expand Up @@ -175,6 +175,8 @@ class RowGroupCollection {
atomic<idx_t> allocation_size;
//! Root metadata pointer, if the collection is loaded from disk
MetaBlockPointer metadata_pointer;
//! Other metadata pointers
vector<MetaBlockPointer> metadata_pointers;
//! Whether or not we need to append a new row group prior to appending
bool requires_new_row_group;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class RowGroupSegmentTree : public SegmentTree<RowGroup, true> {
explicit RowGroupSegmentTree(RowGroupCollection &collection);
~RowGroupSegmentTree() override;

void Initialize(PersistentTableData &data);
void Initialize(PersistentTableData &data, optional_ptr<vector<MetaBlockPointer>> read_pointers = nullptr);

MetaBlockPointer GetRootPointer() const {
return root_pointer;
Expand Down
Loading