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
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ unique_ptr<FunctionData> CurrentSettingBind(ClientContext &context, ScalarFuncti
auto extension_name = Catalog::AutoloadExtensionByConfigName(context, key);
// If autoloader didn't throw, the config is now available
if (!context.TryGetCurrentSetting(key, val)) {
throw InternalException("Extension %s did not provide the '%s' config setting", extension_name, key);
throw InternalException("Extension %s did not provide the '%s' config setting",
extension_name.ToStdString(), key);
}
}

Expand Down
16 changes: 3 additions & 13 deletions src/duckdb/extension/parquet/include/reader/uuid_column_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,14 @@
#include "column_reader.hpp"
#include "templated_column_reader.hpp"
#include "parquet_reader.hpp"
#include "duckdb/common/types/uuid.hpp"

namespace duckdb {

struct UUIDValueConversion {
static hugeint_t ReadParquetUUID(const_data_ptr_t input) {
hugeint_t result;
result.lower = 0;
uint64_t unsigned_upper = 0;
for (idx_t i = 0; i < sizeof(uint64_t); i++) {
unsigned_upper <<= 8;
unsigned_upper += input[i];
}
for (idx_t i = sizeof(uint64_t); i < sizeof(hugeint_t); i++) {
result.lower <<= 8;
result.lower += input[i];
}
result.upper = static_cast<int64_t>(unsigned_upper ^ (uint64_t(1) << 63));
return result;
// Use the utility function from BaseUUID
return BaseUUID::FromBlob(input);
}

template <bool CHECKED>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "writer/parquet_write_stats.hpp"
#include "zstd/common/xxhash.hpp"
#include "duckdb/common/types/uhugeint.hpp"
#include "duckdb/common/types/uuid.hpp"

namespace duckdb {

Expand Down Expand Up @@ -201,16 +202,8 @@ struct ParquetUUIDOperator : public BaseParquetOperator {
template <class SRC, class TGT>
static TGT Operation(SRC input) {
TGT result;
uint64_t high_bytes = input.upper ^ (int64_t(1) << 63);
uint64_t low_bytes = input.lower;
for (idx_t i = 0; i < sizeof(uint64_t); i++) {
auto shift_count = (sizeof(uint64_t) - i - 1) * 8;
result.bytes[i] = (high_bytes >> shift_count) & 0xFF;
}
for (idx_t i = 0; i < sizeof(uint64_t); i++) {
auto shift_count = (sizeof(uint64_t) - i - 1) * 8;
result.bytes[sizeof(uint64_t) + i] = (low_bytes >> shift_count) & 0xFF;
}
// Use the utility function from BaseUUID
BaseUUID::ToBlob(input, result.bytes);
return result;
}

Expand Down
7 changes: 4 additions & 3 deletions src/duckdb/src/catalog/catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,19 +535,20 @@ bool Catalog::TryAutoLoad(ClientContext &context, const string &original_name) n
return false;
}

string Catalog::AutoloadExtensionByConfigName(ClientContext &context, const string &configuration_name) {
String Catalog::AutoloadExtensionByConfigName(ClientContext &context, const String &configuration_name) {
#ifndef DUCKDB_DISABLE_EXTENSION_LOAD
auto &dbconfig = DBConfig::GetConfig(context);
if (dbconfig.options.autoload_known_extensions) {
auto extension_name = ExtensionHelper::FindExtensionInEntries(configuration_name, EXTENSION_SETTINGS);
auto extension_name =
ExtensionHelper::FindExtensionInEntries(configuration_name.ToStdString(), EXTENSION_SETTINGS);
if (ExtensionHelper::CanAutoloadExtension(extension_name)) {
ExtensionHelper::AutoLoadExtension(context, extension_name);
return extension_name;
}
}
#endif

throw Catalog::UnrecognizedConfigurationError(context, configuration_name);
throw Catalog::UnrecognizedConfigurationError(context, configuration_name.ToStdString());
}

static bool IsAutoloadableFunction(CatalogType type) {
Expand Down
7 changes: 4 additions & 3 deletions src/duckdb/src/catalog/default/default_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,13 @@ unique_ptr<CreateMacroInfo> DefaultFunctionGenerator::CreateInternalMacroInfo(ar
make_uniq<ColumnRefExpression>(default_macro.parameters[param_idx]));
}
for (idx_t named_idx = 0; default_macro.named_parameters[named_idx].name != nullptr; named_idx++) {
auto expr_list = Parser::ParseExpressionList(default_macro.named_parameters[named_idx].default_value);
const auto &named_param = default_macro.named_parameters[named_idx];
auto expr_list = Parser::ParseExpressionList(named_param.default_value);
if (expr_list.size() != 1) {
throw InternalException("Expected a single expression");
}
function->default_parameters.insert(
make_pair(default_macro.named_parameters[named_idx].name, std::move(expr_list[0])));
function->parameters.push_back(make_uniq<ColumnRefExpression>(named_param.name));
function->default_parameters.insert(make_pair(named_param.name, std::move(expr_list[0])));
}
D_ASSERT(function->type == MacroType::SCALAR_MACRO);
bind_info->macros.push_back(std::move(function));
Expand Down
7 changes: 4 additions & 3 deletions src/duckdb/src/catalog/default/default_table_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,13 @@ DefaultTableFunctionGenerator::CreateInternalTableMacroInfo(const DefaultTableMa
function->parameters.push_back(make_uniq<ColumnRefExpression>(default_macro.parameters[param_idx]));
}
for (idx_t named_idx = 0; default_macro.named_parameters[named_idx].name != nullptr; named_idx++) {
auto expr_list = Parser::ParseExpressionList(default_macro.named_parameters[named_idx].default_value);
const auto &named_param = default_macro.named_parameters[named_idx];
auto expr_list = Parser::ParseExpressionList(named_param.default_value);
if (expr_list.size() != 1) {
throw InternalException("Expected a single expression");
}
function->default_parameters.insert(
make_pair(default_macro.named_parameters[named_idx].name, std::move(expr_list[0])));
function->parameters.push_back(make_uniq<ColumnRefExpression>(named_param.name));
function->default_parameters.insert(make_pair(named_param.name, std::move(expr_list[0])));
}

auto type = CatalogType::TABLE_MACRO_ENTRY;
Expand Down
8 changes: 4 additions & 4 deletions src/duckdb/src/common/compressed_file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ idx_t CompressedFile::GetProgress() {
return current_position;
}

int64_t CompressedFile::ReadData(QueryContext context, void *buffer, int64_t remaining) {
int64_t CompressedFile::ReadData(void *buffer, int64_t remaining) {
idx_t total_read = 0;
while (true) {
// first check if there are input bytes available in the output buffers
Expand Down Expand Up @@ -79,7 +79,7 @@ int64_t CompressedFile::ReadData(QueryContext context, void *buffer, int64_t rem
memmove(stream_data.in_buff.get(), stream_data.in_buff_start, UnsafeNumericCast<size_t>(bufrem));
stream_data.in_buff_start = stream_data.in_buff.get();
// refill the rest of input buffer
auto sz = child_handle->Read(context, stream_data.in_buff_start + bufrem,
auto sz = child_handle->Read(QueryContext(), stream_data.in_buff_start + bufrem,
stream_data.in_buf_size - UnsafeNumericCast<idx_t>(bufrem));
stream_data.in_buff_end = stream_data.in_buff_start + bufrem + sz;
if (sz <= 0) {
Expand All @@ -93,7 +93,7 @@ int64_t CompressedFile::ReadData(QueryContext context, void *buffer, int64_t rem
// empty input buffer: refill from the start
stream_data.in_buff_start = stream_data.in_buff.get();
stream_data.in_buff_end = stream_data.in_buff_start;
auto sz = child_handle->Read(context, stream_data.in_buff.get(), stream_data.in_buf_size);
auto sz = child_handle->Read(QueryContext(), stream_data.in_buff.get(), stream_data.in_buf_size);
if (sz <= 0) {
stream_wrapper.reset();
break;
Expand Down Expand Up @@ -132,7 +132,7 @@ void CompressedFile::Close() {

int64_t CompressedFileSystem::Read(FileHandle &handle, void *buffer, int64_t nr_bytes) {
auto &compressed_file = handle.Cast<CompressedFile>();
return compressed_file.ReadData(QueryContext(), buffer, nr_bytes);
return compressed_file.ReadData(buffer, nr_bytes);
}

int64_t CompressedFileSystem::Write(FileHandle &handle, void *buffer, int64_t nr_bytes) {
Expand Down
5 changes: 3 additions & 2 deletions src/duckdb/src/common/enum_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2744,6 +2744,7 @@ const StringUtil::EnumStringLiteral *GetMetricsTypeValues() {
{ static_cast<uint32_t>(MetricsType::OPERATOR_NAME), "OPERATOR_NAME" },
{ static_cast<uint32_t>(MetricsType::SYSTEM_PEAK_BUFFER_MEMORY), "SYSTEM_PEAK_BUFFER_MEMORY" },
{ static_cast<uint32_t>(MetricsType::SYSTEM_PEAK_TEMP_DIR_SIZE), "SYSTEM_PEAK_TEMP_DIR_SIZE" },
{ static_cast<uint32_t>(MetricsType::TOTAL_BYTES_READ), "TOTAL_BYTES_READ" },
{ static_cast<uint32_t>(MetricsType::ALL_OPTIMIZERS), "ALL_OPTIMIZERS" },
{ static_cast<uint32_t>(MetricsType::CUMULATIVE_OPTIMIZER_TIMING), "CUMULATIVE_OPTIMIZER_TIMING" },
{ static_cast<uint32_t>(MetricsType::PLANNER), "PLANNER" },
Expand Down Expand Up @@ -2786,12 +2787,12 @@ const StringUtil::EnumStringLiteral *GetMetricsTypeValues() {

template<>
const char* EnumUtil::ToChars<MetricsType>(MetricsType value) {
return StringUtil::EnumToString(GetMetricsTypeValues(), 52, "MetricsType", static_cast<uint32_t>(value));
return StringUtil::EnumToString(GetMetricsTypeValues(), 53, "MetricsType", static_cast<uint32_t>(value));
}

template<>
MetricsType EnumUtil::FromString<MetricsType>(const char *value) {
return static_cast<MetricsType>(StringUtil::StringToEnum(GetMetricsTypeValues(), 52, "MetricsType", value));
return static_cast<MetricsType>(StringUtil::StringToEnum(GetMetricsTypeValues(), 53, "MetricsType", value));
}

const StringUtil::EnumStringLiteral *GetMultiFileColumnMappingModeValues() {
Expand Down
9 changes: 8 additions & 1 deletion src/duckdb/src/common/exception_format_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "duckdb/common/types/hugeint.hpp"
#include "duckdb/common/types/uhugeint.hpp"
#include "duckdb/parser/keyword_helper.hpp"
#include "duckdb/common/types/string.hpp"

namespace duckdb {

Expand All @@ -27,6 +28,9 @@ ExceptionFormatValue::ExceptionFormatValue(uhugeint_t uhuge_val)
ExceptionFormatValue::ExceptionFormatValue(string str_val)
: type(ExceptionFormatValueType::FORMAT_VALUE_TYPE_STRING), str_val(std::move(str_val)) {
}
ExceptionFormatValue::ExceptionFormatValue(String str_val)
: type(ExceptionFormatValueType::FORMAT_VALUE_TYPE_STRING), str_val(str_val.ToStdString()) {
}

template <>
ExceptionFormatValue ExceptionFormatValue::CreateFormatValue(PhysicalType value) {
Expand All @@ -49,7 +53,10 @@ template <>
ExceptionFormatValue ExceptionFormatValue::CreateFormatValue(string value) {
return ExceptionFormatValue(std::move(value));
}

template <>
ExceptionFormatValue ExceptionFormatValue::CreateFormatValue(String value) {
return ExceptionFormatValue(std::move(value));
}
template <>
ExceptionFormatValue
ExceptionFormatValue::CreateFormatValue(SQLString value) { // NOLINT: templating requires us to copy value here
Expand Down
11 changes: 8 additions & 3 deletions src/duckdb/src/common/file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#include <cstdint>
#include <cstdio>
#include "duckdb/logging/file_system_logger.hpp"

#ifndef _WIN32
#include <dirent.h>
Expand Down Expand Up @@ -694,7 +693,10 @@ int64_t FileHandle::Read(void *buffer, idx_t nr_bytes) {
}

int64_t FileHandle::Read(QueryContext context, void *buffer, idx_t nr_bytes) {
// FIXME: Add profiling.
if (context.GetClientContext() != nullptr) {
context.GetClientContext()->client_data->profiler->AddBytesRead(nr_bytes);
}

return file_system.Read(*this, buffer, UnsafeNumericCast<int64_t>(nr_bytes));
}

Expand All @@ -711,7 +713,10 @@ void FileHandle::Read(void *buffer, idx_t nr_bytes, idx_t location) {
}

void FileHandle::Read(QueryContext context, void *buffer, idx_t nr_bytes, idx_t location) {
// FIXME: Add profiling.
if (context.GetClientContext() != nullptr) {
context.GetClientContext()->client_data->profiler->AddBytesRead(nr_bytes);
}

file_system.Read(*this, buffer, UnsafeNumericCast<int64_t>(nr_bytes), location);
}

Expand Down
51 changes: 51 additions & 0 deletions src/duckdb/src/common/operator/cast_operators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1501,6 +1501,22 @@ string_t CastFromUUID::Operation(hugeint_t input, Vector &vector) {
return result;
}

//===--------------------------------------------------------------------===//
// Cast From UUID To Blob
//===--------------------------------------------------------------------===//
template <>
string_t CastFromUUIDToBlob::Operation(hugeint_t input, Vector &vector) {
// UUID is 16 bytes (128 bits)
string_t result = StringVector::EmptyString(vector, 16);
auto data = result.GetDataWriteable();

// Use the utility function from BaseUUID
BaseUUID::ToBlob(input, data_ptr_cast(data));

result.Finalize();
return result;
}

//===--------------------------------------------------------------------===//
// Cast To UUID
//===--------------------------------------------------------------------===//
Expand All @@ -1509,6 +1525,41 @@ bool TryCastToUUID::Operation(string_t input, hugeint_t &result, Vector &result_
return UUID::FromString(input.GetString(), result, parameters.strict);
}

//===--------------------------------------------------------------------===//
// Cast Blob To UUID
//===--------------------------------------------------------------------===//
template <>
bool TryCastBlobToUUID::Operation(string_t input, hugeint_t &result, Vector &result_vector,
CastParameters &parameters) {
// BLOB must be exactly 16 bytes for UUID
if (input.GetSize() != 16) {
HandleCastError::AssignError("BLOB must be exactly 16 bytes to convert to UUID", parameters);
return false;
}

auto data = const_data_ptr_cast(input.GetData());

// Use the utility function from BaseUUID
result = BaseUUID::FromBlob(data);

return true;
}

template <>
bool TryCastBlobToUUID::Operation(string_t input, hugeint_t &result, bool strict) {
// BLOB must be exactly 16 bytes for UUID
if (input.GetSize() != 16) {
return false;
}

auto data = const_data_ptr_cast(input.GetData());

// Use the utility function from BaseUUID
result = BaseUUID::FromBlob(data);

return true;
}

//===--------------------------------------------------------------------===//
// Cast To Date
//===--------------------------------------------------------------------===//
Expand Down
4 changes: 4 additions & 0 deletions src/duckdb/src/common/serializer/buffered_file_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ BufferedFileReader::BufferedFileReader(FileSystem &fs, unique_ptr<FileHandle> ha
}

void BufferedFileReader::ReadData(data_ptr_t target_buffer, uint64_t read_size) {
ReadData(QueryContext(), target_buffer, read_size);
}

void BufferedFileReader::ReadData(QueryContext context, data_ptr_t target_buffer, uint64_t read_size) {
// first copy anything we can from the buffer
data_ptr_t end_ptr = target_buffer + read_size;
while (true) {
Expand Down
4 changes: 4 additions & 0 deletions src/duckdb/src/common/serializer/memory_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ void MemoryStream::WriteData(const_data_ptr_t source, idx_t write_size) {
}

void MemoryStream::ReadData(data_ptr_t destination, idx_t read_size) {
ReadData(QueryContext(), destination, read_size);
}

void MemoryStream::ReadData(QueryContext context, data_ptr_t destination, idx_t read_size) {
if (position + read_size > capacity) {
throw SerializationException("Failed to deserialize: not enough data in buffer to fulfill read request");
}
Expand Down
Loading
Loading