Skip to content

Commit

Permalink
Update vendored DuckDB sources to 582658a
Browse files Browse the repository at this point in the history
  • Loading branch information
duckdblabs-bot committed Nov 28, 2024
1 parent 582658a commit 2507f4e
Show file tree
Hide file tree
Showing 24 changed files with 411 additions and 80 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "duckdb/catalog/catalog_entry/scalar_function_catalog_entry.hpp"
#include "duckdb/common/vector.hpp"
#include "duckdb/parser/parsed_data/alter_scalar_function_info.hpp"

namespace duckdb {
Expand Down Expand Up @@ -26,12 +27,9 @@ unique_ptr<CatalogEntry> ScalarFunctionCatalogEntry::AlterEntry(CatalogTransacti
}
CreateScalarFunctionInfo new_info(std::move(new_set));
new_info.internal = internal;
new_info.description =
add_overloads.new_overloads->description.empty() ? description : add_overloads.new_overloads->description;
new_info.parameter_names = add_overloads.new_overloads->parameter_names.empty()
? parameter_names
: add_overloads.new_overloads->parameter_names;
new_info.example = add_overloads.new_overloads->example.empty() ? example : add_overloads.new_overloads->example;
new_info.descriptions = descriptions;
new_info.descriptions.insert(new_info.descriptions.end(), add_overloads.new_overloads->descriptions.begin(),
add_overloads.new_overloads->descriptions.end());
return make_uniq<ScalarFunctionCatalogEntry>(catalog, schema, new_info);
}

Expand Down
63 changes: 53 additions & 10 deletions src/duckdb/src/common/string_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "duckdb/common/exception.hpp"
#include "duckdb/common/pair.hpp"
#include "duckdb/common/stack.hpp"
#include "duckdb/common/to_string.hpp"
#include "duckdb/common/helper.hpp"
#include "duckdb/common/exception/parser_exception.hpp"
Expand All @@ -16,6 +17,7 @@
#include <stdarg.h>
#include <string.h>
#include <random>
#include <stack>

#include "yyjson.hpp"

Expand Down Expand Up @@ -47,6 +49,10 @@ optional_idx StringUtil::Find(const string &haystack, const string &needle) {
return optional_idx(index);
}

bool StringUtil::Contains(const string &haystack, const char &needle_char) {
return (haystack.find(needle_char) != string::npos);
}

void StringUtil::LTrim(string &str) {
auto it = str.begin();
while (it != str.end() && CharacterIsSpace(*it)) {
Expand Down Expand Up @@ -95,16 +101,6 @@ string StringUtil::Repeat(const string &str, idx_t n) {
return (os.str());
}

vector<string> StringUtil::Split(const string &str, char delimiter) {
std::stringstream ss(str);
vector<string> lines;
string temp;
while (getline(ss, temp, delimiter)) {
lines.push_back(temp);
}
return (lines);
}

namespace string_util_internal {

inline void SkipSpaces(const string &str, idx_t &index) {
Expand Down Expand Up @@ -164,6 +160,43 @@ vector<string> StringUtil::SplitWithQuote(const string &str, char delimiter, cha
return entries;
}

vector<string> StringUtil::SplitWithParentheses(const string &str, char delimiter, char par_open, char par_close) {
vector<string> result;
string current;
stack<char> parentheses;

for (size_t i = 0; i < str.size(); ++i) {
char ch = str[i];

// stack to keep track if we are within parentheses
if (ch == par_open) {
parentheses.push(ch);
}
if (ch == par_close) {
if (!parentheses.empty()) {
parentheses.pop();
} else {
throw InternalException("Incongruent parentheses in string: '%s'", str);
}
}
// split if not within parentheses
if (parentheses.empty() && ch == delimiter) {
result.push_back(current);
current.clear();
} else {
current += ch;
}
}
// Add the last segment
if (!current.empty()) {
result.push_back(current);
}
if (!parentheses.empty()) {
throw InternalException("Incongruent parentheses in string: '%s'", str);
}
return result;
}

string StringUtil::Join(const vector<string> &input, const string &separator) {
return StringUtil::Join(input, input.size(), separator, [](const string &s) { return s; });
}
Expand Down Expand Up @@ -299,6 +332,16 @@ idx_t StringUtil::CIFind(vector<string> &vector, const string &search_string) {
return DConstants::INVALID_INDEX;
}

vector<string> StringUtil::Split(const string &str, char delimiter) {
std::stringstream ss(str);
vector<string> lines;
string temp;
while (getline(ss, temp, delimiter)) {
lines.push_back(temp);
}
return (lines);
}

vector<string> StringUtil::Split(const string &input, const string &split) {
vector<string> splits;

Expand Down
1 change: 1 addition & 0 deletions src/duckdb/src/common/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ string LogicalTypeIdToString(LogicalTypeId type) {

constexpr const LogicalTypeId LogicalType::INVALID;
constexpr const LogicalTypeId LogicalType::SQLNULL;
constexpr const LogicalTypeId LogicalType::UNKNOWN;
constexpr const LogicalTypeId LogicalType::BOOLEAN;
constexpr const LogicalTypeId LogicalType::TINYINT;
constexpr const LogicalTypeId LogicalType::UTINYINT;
Expand Down
34 changes: 31 additions & 3 deletions src/duckdb/src/common/types/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -739,16 +739,37 @@ Value Value::STRUCT(child_list_t<Value> values) {
return Value::STRUCT(LogicalType::STRUCT(child_types), std::move(struct_values));
}

void MapKeyCheck(unordered_set<hash_t> &unique_keys, const Value &key) {
// NULL key check.
if (key.IsNull()) {
MapVector::EvalMapInvalidReason(MapInvalidReason::NULL_KEY);
}

// Duplicate key check.
auto key_hash = key.Hash();
if (unique_keys.find(key_hash) != unique_keys.end()) {
MapVector::EvalMapInvalidReason(MapInvalidReason::DUPLICATE_KEY);
}
unique_keys.insert(key_hash);
}

Value Value::MAP(const LogicalType &child_type, vector<Value> values) { // NOLINT
vector<Value> map_keys;
vector<Value> map_values;
unordered_set<hash_t> unique_keys;

for (auto &val : values) {
D_ASSERT(val.type().InternalType() == PhysicalType::STRUCT);
auto &children = StructValue::GetChildren(val);
D_ASSERT(children.size() == 2);
map_keys.push_back(children[0]);

auto &key = children[0];
MapKeyCheck(unique_keys, key);

map_keys.push_back(key);
map_values.push_back(children[1]);
}

auto &key_type = StructType::GetChildType(child_type, 0);
auto &value_type = StructType::GetChildType(child_type, 1);
return Value::MAP(key_type, value_type, std::move(map_keys), std::move(map_values));
Expand All @@ -760,13 +781,20 @@ Value Value::MAP(const LogicalType &key_type, const LogicalType &value_type, vec

result.type_ = LogicalType::MAP(key_type, value_type);
result.is_null = false;
unordered_set<hash_t> unique_keys;

for (idx_t i = 0; i < keys.size(); i++) {
child_list_t<Value> new_children;
new_children.reserve(2);
new_children.push_back(std::make_pair("key", keys[i].DefaultCastAs(key_type)));

auto key = keys[i].DefaultCastAs(key_type);
MapKeyCheck(unique_keys, key);

new_children.push_back(std::make_pair("key", key));
new_children.push_back(std::make_pair("value", values[i].DefaultCastAs(value_type)));
values[i] = Value::STRUCT(std::move(new_children));
}

result.value_info_ = make_shared_ptr<NestedValueInfo>(std::move(values));
return result;
}
Expand Down Expand Up @@ -1514,7 +1542,7 @@ hash_t Value::Hash() const {
return 0;
}
Vector input(*this);
Vector result(LogicalType::HASH);
Vector result(LogicalType::HASH, 1);
VectorOperations::Hash(input, result, 1);

auto data = FlatVector::GetData<hash_t>(result);
Expand Down
5 changes: 3 additions & 2 deletions src/duckdb/src/execution/operator/join/physical_hash_join.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,9 +600,10 @@ void JoinFilterPushdownInfo::PushInFilter(const JoinFilterPushdownFilter &info,
}
vector<Value> in_list(unique_ht_values.begin(), unique_ht_values.end());

// generating the OR filter only makes sense if the range is not dense
// generating the OR filter only makes sense if the range is
// not dense and that the range does not contain NULL
// i.e. if we have the values [0, 1, 2, 3, 4] - the min/max is fully equivalent to the OR filter
if (FilterCombiner::IsDenseRange(in_list)) {
if (FilterCombiner::ContainsNull(in_list) || FilterCombiner::IsDenseRange(in_list)) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/duckdb/src/execution/window_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2146,10 +2146,10 @@ void WindowNthValueExecutor::EvaluateInternal(WindowExecutorGlobalState &gstate,
}
// Returns value evaluated at the row that is the n'th row of the window frame (counting from 1);
// returns NULL if there is no such row.
if (nth_col.CellIsNull(row_idx)) {
if (nth_col.CellIsNull(i)) {
FlatVector::SetNull(result, i, true);
} else {
auto n_param = nth_col.GetCell<int64_t>(row_idx);
auto n_param = nth_col.GetCell<int64_t>(i);
if (n_param < 1) {
FlatVector::SetNull(result, i, true);
} else {
Expand Down
58 changes: 55 additions & 3 deletions src/duckdb/src/function/register_function_list.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,67 @@
#include "duckdb/catalog/default/default_types.hpp"
#include "duckdb/common/string_util.hpp"
#include "duckdb/function/function_list.hpp"
#include "duckdb/parser/parsed_data/create_aggregate_function_info.hpp"
#include "duckdb/parser/parsed_data/create_scalar_function_info.hpp"

namespace duckdb {

static void FillFunctionParameters(FunctionDescription &function_description, const char *function_name,
vector<string> &parameters, vector<string> &descriptions, vector<string> &examples) {
for (string &parameter : parameters) {
vector<string> parameter_name_type = StringUtil::Split(parameter, "::");
if (parameter_name_type.size() == 1) {
function_description.parameter_names.push_back(std::move(parameter_name_type[0]));
function_description.parameter_types.push_back(LogicalType::ANY);
} else if (parameter_name_type.size() == 2) {
function_description.parameter_names.push_back(std::move(parameter_name_type[0]));
function_description.parameter_types.push_back(DBConfig::ParseLogicalType(parameter_name_type[1]));
} else {
throw InternalException("Ill formed function variant for function '%s'", function_name);
}
}
}

template <class T>
void FillFunctionDescriptions(const StaticFunctionDefinition &function, T &info) {
vector<string> variants = StringUtil::Split(function.parameters, '\1');
vector<string> descriptions = StringUtil::Split(function.description, '\1');
vector<string> examples = StringUtil::Split(function.example, '\1');

// add single variant for functions that take no arguments
if (variants.empty()) {
variants.push_back("");
}

for (idx_t variant_index = 0; variant_index < variants.size(); variant_index++) {
FunctionDescription function_description;
// parameter_names and parameter_types
vector<string> parameters = StringUtil::SplitWithParentheses(variants[variant_index], ',');
FillFunctionParameters(function_description, function.name, parameters, descriptions, examples);
// description
if (descriptions.size() == variants.size()) {
function_description.description = descriptions[variant_index];
} else if (descriptions.size() == 1) {
function_description.description = descriptions[0];
} else if (!descriptions.empty()) {
throw InternalException("Incorrect number of function descriptions for function '%s'", function.name);
}
// examples
if (examples.size() == variants.size()) {
function_description.examples = StringUtil::Split(examples[variant_index], '\2');
} else if (examples.size() == 1) {
function_description.examples = StringUtil::Split(examples[0], '\2');
} else if (!examples.empty()) {
throw InternalException("Incorrect number of function examples for function '%s'", function.name);
}
info.descriptions.push_back(std::move(function_description));
}
}

template <class T>
static void FillExtraInfo(const StaticFunctionDefinition &function, T &info) {
info.internal = true;
info.description = function.description;
info.parameter_names = StringUtil::Split(function.parameters, ",");
info.example = function.example;
FillFunctionDescriptions(function, info);
}

static void RegisterFunctionList(Catalog &catalog, CatalogTransaction transaction,
Expand Down
2 changes: 1 addition & 1 deletion src/duckdb/src/function/scalar/operator/arithmetic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ ScalarFunction AddFunction::GetFunction(const LogicalType &left_type, const Logi
break;
}
// LCOV_EXCL_START
throw NotImplementedException("AddFun for types %s, %s", EnumUtil::ToString(left_type.id()),
throw NotImplementedException("AddFunction for types %s, %s", EnumUtil::ToString(left_type.id()),
EnumUtil::ToString(right_type.id()));
// LCOV_EXCL_STOP
}
Expand Down
Loading

0 comments on commit 2507f4e

Please sign in to comment.