Skip to content

Commit

Permalink
Update vendored sources to duckdb/duckdb@d5c4422
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Sep 9, 2023
1 parent e1d67b2 commit 9017eb9
Show file tree
Hide file tree
Showing 66 changed files with 1,848 additions and 1,555 deletions.
20 changes: 20 additions & 0 deletions src/duckdb/src/catalog/catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,26 @@ void FindMinimalQualification(ClientContext &context, const string &catalog_name
qualify_schema = true;
}

bool Catalog::TryAutoLoad(ClientContext &context, const string &extension_name) noexcept {
if (context.db->ExtensionIsLoaded(extension_name)) {
return true;
}
#ifndef DUCKDB_DISABLE_EXTENSION_LOAD
auto &dbconfig = DBConfig::GetConfig(context);
if (!dbconfig.options.autoload_known_extensions) {
return false;
}
try {
if (ExtensionHelper::CanAutoloadExtension(extension_name)) {
return ExtensionHelper::TryAutoLoadExtension(context, extension_name);
}
} catch (...) {
return false;
}
#endif
return false;
}

void Catalog::AutoloadExtensionByConfigName(ClientContext &context, const string &configuration_name) {
#ifndef DUCKDB_DISABLE_EXTENSION_LOAD
auto &dbconfig = DBConfig::GetConfig(context);
Expand Down
5 changes: 5 additions & 0 deletions src/duckdb/src/catalog/catalog_entry/duck_index_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ string DuckIndexEntry::GetTableName() const {
return info->table;
}

void DuckIndexEntry::CommitDrop() {
D_ASSERT(info && index);
index->CommitDrop();
}

} // namespace duckdb
3 changes: 3 additions & 0 deletions src/duckdb/src/common/arrow/arrow_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ void SetArrowFormat(DuckDBArrowSchemaHolder &root_holder, ArrowSchema &child, co
case LogicalTypeId::DATE:
child.format = "tdD";
break;
#ifdef DUCKDB_WASM
case LogicalTypeId::TIME_TZ:
#endif
case LogicalTypeId::TIME:
child.format = "ttu";
break;
Expand Down
2 changes: 1 addition & 1 deletion src/duckdb/src/common/radix_partitioning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct RadixPartitioningConstants {
};

template <class OP, class RETURN_TYPE, typename... ARGS>
RETURN_TYPE RadixBitsSwitch(idx_t radix_bits, ARGS &&...args) {
RETURN_TYPE RadixBitsSwitch(idx_t radix_bits, ARGS &&... args) {
D_ASSERT(radix_bits <= RadixPartitioning::MAX_RADIX_BITS);
switch (radix_bits) {
case 0:
Expand Down
6 changes: 5 additions & 1 deletion src/duckdb/src/common/sort/partition_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,11 @@ bool PartitionGlobalMergeState::TryPrepareNextStage() {

switch (stage) {
case PartitionSortStage::INIT:
total_tasks = num_threads;
// If the partitions are unordered, don't scan in parallel
// because it produces non-deterministic orderings.
// This can theoretically happen with ORDER BY,
// but that is something the query should be explicit about.
total_tasks = sink.orders.size() > sink.partitions.size() ? num_threads : 1;
stage = PartitionSortStage::SCAN;
return true;

Expand Down
2 changes: 1 addition & 1 deletion src/duckdb/src/core_functions/aggregate/holistic/mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ struct ModeFunction {
state.frequency_map = new typename STATE::Counts;
}
const double tau = .25;
if (state.nonzero <= tau * state.frequency_map->size()) {
if (state.nonzero <= tau * state.frequency_map->size() || prev.end <= frame.start || frame.end <= prev.start) {
state.Reset();
// for f ∈ F do
for (auto f = frame.start; f < frame.end; ++f) {
Expand Down
7 changes: 7 additions & 0 deletions src/duckdb/src/core_functions/function_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ static StaticFunctionDefinition internal_functions[] = {
DUCKDB_SCALAR_FUNCTION(FactorialOperatorFun),
DUCKDB_SCALAR_FUNCTION_SET(BitwiseAndFun),
DUCKDB_SCALAR_FUNCTION(PowOperatorFun),
DUCKDB_SCALAR_FUNCTION_SET_ALIAS(ListInnerProductFunAlias),
DUCKDB_SCALAR_FUNCTION_SET_ALIAS(ListDistanceFunAlias),
DUCKDB_SCALAR_FUNCTION_SET(LeftShiftFun),
DUCKDB_SCALAR_FUNCTION_SET_ALIAS(ListCosineSimilarityFunAlias),
DUCKDB_SCALAR_FUNCTION_SET(RightShiftFun),
DUCKDB_SCALAR_FUNCTION_SET(AbsOperatorFun),
DUCKDB_SCALAR_FUNCTION_ALIAS(PowOperatorFunAlias),
Expand Down Expand Up @@ -197,8 +200,12 @@ static StaticFunctionDefinition internal_functions[] = {
DUCKDB_SCALAR_FUNCTION_ALIAS(ListAggrFun),
DUCKDB_SCALAR_FUNCTION(ListAggregateFun),
DUCKDB_SCALAR_FUNCTION_ALIAS(ListApplyFun),
DUCKDB_SCALAR_FUNCTION_SET(ListCosineSimilarityFun),
DUCKDB_SCALAR_FUNCTION_SET(ListDistanceFun),
DUCKDB_SCALAR_FUNCTION(ListDistinctFun),
DUCKDB_SCALAR_FUNCTION_SET_ALIAS(ListDotProductFun),
DUCKDB_SCALAR_FUNCTION(ListFilterFun),
DUCKDB_SCALAR_FUNCTION_SET(ListInnerProductFun),
DUCKDB_SCALAR_FUNCTION_ALIAS(ListPackFun),
DUCKDB_SCALAR_FUNCTION_SET(ListReverseSortFun),
DUCKDB_SCALAR_FUNCTION_SET(ListSliceFun),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#include "duckdb/core_functions/scalar/list_functions.hpp"
#include <cmath>
#include <algorithm>

namespace duckdb {

template <class NUMERIC_TYPE>
static void ListCosineSimilarity(DataChunk &args, ExpressionState &, Vector &result) {
D_ASSERT(args.ColumnCount() == 2);

auto count = args.size();
auto &left = args.data[0];
auto &right = args.data[1];
auto left_count = ListVector::GetListSize(left);
auto right_count = ListVector::GetListSize(right);

auto &left_child = ListVector::GetEntry(left);
auto &right_child = ListVector::GetEntry(right);

D_ASSERT(left_child.GetVectorType() == VectorType::FLAT_VECTOR);
D_ASSERT(right_child.GetVectorType() == VectorType::FLAT_VECTOR);

if (!FlatVector::Validity(left_child).CheckAllValid(left_count)) {
throw InvalidInputException("list_cosine_similarity: left argument can not contain NULL values");
}

if (!FlatVector::Validity(right_child).CheckAllValid(right_count)) {
throw InvalidInputException("list_cosine_similarity: right argument can not contain NULL values");
}

auto left_data = FlatVector::GetData<NUMERIC_TYPE>(left_child);
auto right_data = FlatVector::GetData<NUMERIC_TYPE>(right_child);

BinaryExecutor::Execute<list_entry_t, list_entry_t, NUMERIC_TYPE>(
left, right, result, count, [&](list_entry_t left, list_entry_t right) {
if (left.length != right.length) {
throw InvalidInputException(StringUtil::Format(
"list_cosine_similarity: list dimensions must be equal, got left length %d and right length %d",
left.length, right.length));
}

auto dimensions = left.length;

NUMERIC_TYPE distance = 0;
NUMERIC_TYPE norm_l = 0;
NUMERIC_TYPE norm_r = 0;

auto l_ptr = left_data + left.offset;
auto r_ptr = right_data + right.offset;
for (idx_t i = 0; i < dimensions; i++) {
auto x = *l_ptr++;
auto y = *r_ptr++;
distance += x * y;
norm_l += x * x;
norm_r += y * y;
}

auto similarity = distance / (std::sqrt(norm_l) * std::sqrt(norm_r));

// clamp to [-1, 1] to avoid floating point errors
return std::max(static_cast<NUMERIC_TYPE>(-1), std::min(similarity, static_cast<NUMERIC_TYPE>(1)));
});

if (args.AllConstant()) {
result.SetVectorType(VectorType::CONSTANT_VECTOR);
}
}

ScalarFunctionSet ListCosineSimilarityFun::GetFunctions() {
ScalarFunctionSet set("list_cosine_similarity");
set.AddFunction(ScalarFunction({LogicalType::LIST(LogicalType::FLOAT), LogicalType::LIST(LogicalType::FLOAT)},
LogicalType::FLOAT, ListCosineSimilarity<float>));
set.AddFunction(ScalarFunction({LogicalType::LIST(LogicalType::DOUBLE), LogicalType::LIST(LogicalType::DOUBLE)},
LogicalType::DOUBLE, ListCosineSimilarity<double>));
return set;
}

} // namespace duckdb
72 changes: 72 additions & 0 deletions src/duckdb/src/core_functions/scalar/list/list_distance.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include "duckdb/core_functions/scalar/list_functions.hpp"
#include <cmath>

namespace duckdb {

template <class NUMERIC_TYPE>
static void ListDistance(DataChunk &args, ExpressionState &, Vector &result) {
D_ASSERT(args.ColumnCount() == 2);

auto count = args.size();
auto &left = args.data[0];
auto &right = args.data[1];
auto left_count = ListVector::GetListSize(left);
auto right_count = ListVector::GetListSize(right);

auto &left_child = ListVector::GetEntry(left);
auto &right_child = ListVector::GetEntry(right);

D_ASSERT(left_child.GetVectorType() == VectorType::FLAT_VECTOR);
D_ASSERT(right_child.GetVectorType() == VectorType::FLAT_VECTOR);

if (!FlatVector::Validity(left_child).CheckAllValid(left_count)) {
throw InvalidInputException("list_distance: left argument can not contain NULL values");
}

if (!FlatVector::Validity(right_child).CheckAllValid(right_count)) {
throw InvalidInputException("list_distance: right argument can not contain NULL values");
}

auto left_data = FlatVector::GetData<NUMERIC_TYPE>(left_child);
auto right_data = FlatVector::GetData<NUMERIC_TYPE>(right_child);

BinaryExecutor::Execute<list_entry_t, list_entry_t, NUMERIC_TYPE>(
left, right, result, count, [&](list_entry_t left, list_entry_t right) {
if (left.length != right.length) {
throw InvalidInputException(StringUtil::Format(
"list_distance: list dimensions must be equal, got left length %d and right length %d", left.length,
right.length));
}

auto dimensions = left.length;

NUMERIC_TYPE distance = 0;

auto l_ptr = left_data + left.offset;
auto r_ptr = right_data + right.offset;

for (idx_t i = 0; i < dimensions; i++) {
auto x = *l_ptr++;
auto y = *r_ptr++;
auto diff = x - y;
distance += diff * diff;
}

return std::sqrt(distance);
});

if (args.AllConstant()) {
result.SetVectorType(VectorType::CONSTANT_VECTOR);
}
}

ScalarFunctionSet ListDistanceFun::GetFunctions() {
ScalarFunctionSet set("list_distance");
set.AddFunction(ScalarFunction({LogicalType::LIST(LogicalType::FLOAT), LogicalType::LIST(LogicalType::FLOAT)},
LogicalType::FLOAT, ListDistance<float>));
set.AddFunction(ScalarFunction({LogicalType::LIST(LogicalType::DOUBLE), LogicalType::LIST(LogicalType::DOUBLE)},
LogicalType::DOUBLE, ListDistance<double>));
return set;
}

} // namespace duckdb
70 changes: 70 additions & 0 deletions src/duckdb/src/core_functions/scalar/list/list_inner_product.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include "duckdb/core_functions/scalar/list_functions.hpp"

namespace duckdb {

template <class NUMERIC_TYPE>
static void ListInnerProduct(DataChunk &args, ExpressionState &, Vector &result) {
D_ASSERT(args.ColumnCount() == 2);

auto count = args.size();
auto &left = args.data[0];
auto &right = args.data[1];
auto left_count = ListVector::GetListSize(left);
auto right_count = ListVector::GetListSize(right);

auto &left_child = ListVector::GetEntry(left);
auto &right_child = ListVector::GetEntry(right);

D_ASSERT(left_child.GetVectorType() == VectorType::FLAT_VECTOR);
D_ASSERT(right_child.GetVectorType() == VectorType::FLAT_VECTOR);

if (!FlatVector::Validity(left_child).CheckAllValid(left_count)) {
throw InvalidInputException("list_inner_product: left argument can not contain NULL values");
}

if (!FlatVector::Validity(right_child).CheckAllValid(right_count)) {
throw InvalidInputException("list_inner_product: right argument can not contain NULL values");
}

auto left_data = FlatVector::GetData<NUMERIC_TYPE>(left_child);
auto right_data = FlatVector::GetData<NUMERIC_TYPE>(right_child);

BinaryExecutor::Execute<list_entry_t, list_entry_t, NUMERIC_TYPE>(
left, right, result, count, [&](list_entry_t left, list_entry_t right) {
if (left.length != right.length) {
throw InvalidInputException(StringUtil::Format(
"list_inner_product: list dimensions must be equal, got left length %d and right length %d",
left.length, right.length));
}

auto dimensions = left.length;

NUMERIC_TYPE distance = 0;

auto l_ptr = left_data + left.offset;
auto r_ptr = right_data + right.offset;

for (idx_t i = 0; i < dimensions; i++) {
auto x = *l_ptr++;
auto y = *r_ptr++;
distance += x * y;
}

return distance;
});

if (args.AllConstant()) {
result.SetVectorType(VectorType::CONSTANT_VECTOR);
}
}

ScalarFunctionSet ListInnerProductFun::GetFunctions() {
ScalarFunctionSet set("list_inner_product");
set.AddFunction(ScalarFunction({LogicalType::LIST(LogicalType::FLOAT), LogicalType::LIST(LogicalType::FLOAT)},
LogicalType::FLOAT, ListInnerProduct<float>));
set.AddFunction(ScalarFunction({LogicalType::LIST(LogicalType::DOUBLE), LogicalType::LIST(LogicalType::DOUBLE)},
LogicalType::DOUBLE, ListInnerProduct<double>));
return set;
}

} // namespace duckdb
Loading

0 comments on commit 9017eb9

Please sign in to comment.