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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ set(DUCKDB_SRC_FILES
src/duckdb/extension/json/json_scan.cpp
src/duckdb/extension/json/json_serializer.cpp
src/duckdb/extension/json/serialize_json.cpp
src/duckdb/extension/loader/static_extension_autoregister.cpp
src/duckdb/extension/parquet/column_reader.cpp
src/duckdb/extension/parquet/column_writer.cpp
src/duckdb/extension/parquet/parquet_column_schema.cpp
Expand All @@ -159,6 +160,7 @@ set(DUCKDB_SRC_FILES
src/duckdb/extension/parquet/parquet_statistics.cpp
src/duckdb/extension/parquet/parquet_timestamp.cpp
src/duckdb/extension/parquet/parquet_writer.cpp
src/duckdb/extension/parquet/reader/variant/parquet_variant_shredding.cpp
src/duckdb/extension/parquet/serialize_parquet.cpp
src/duckdb/extension/parquet/zstd_file_system.cpp
src/duckdb/generated_extension_loader_package_build.cpp
Expand Down Expand Up @@ -225,6 +227,7 @@ set(DUCKDB_SRC_FILES
src/duckdb/src/main/extension/extension_load.cpp
src/duckdb/src/main/extension/extension_loader.cpp
src/duckdb/src/main/extension/extension_repository_manager.cpp
src/duckdb/src/main/extension/linked_extension_registry.cpp
src/duckdb/src/optimizer/matcher/expression_matcher.cpp
src/duckdb/third_party/brotli/common/constants.cpp
src/duckdb/third_party/brotli/common/context.cpp
Expand Down Expand Up @@ -371,7 +374,6 @@ set(DUCKDB_SRC_FILES
src/duckdb/ub_extension_json_json_functions.cpp
src/duckdb/ub_extension_parquet_decoder.cpp
src/duckdb/ub_extension_parquet_reader.cpp
src/duckdb/ub_extension_parquet_reader_variant.cpp
src/duckdb/ub_extension_parquet_writer.cpp
src/duckdb/ub_extension_parquet_writer_variant.cpp
src/duckdb/ub_src_catalog.cpp
Expand Down Expand Up @@ -701,6 +703,11 @@ target_compile_definitions(duckdb_java PRIVATE
-DDUCKDB_EXTENSION_AUTOLOAD_DEFAULT
-DDUCKDB_EXTENSION_AUTOINSTALL_DEFAULT)

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_definitions(duckdb_java PRIVATE
-DD_ASSERT_IS_ENABLED)
endif()

if(JEMALLOC_ENABLED)
target_compile_definitions(duckdb_java PRIVATE
-DDUCKDB_ENABLE_JEMALLOC)
Expand Down
5 changes: 5 additions & 0 deletions CMakeLists.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ target_compile_definitions(duckdb_java PRIVATE
-DDUCKDB_EXTENSION_AUTOLOAD_DEFAULT
-DDUCKDB_EXTENSION_AUTOINSTALL_DEFAULT)

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_definitions(duckdb_java PRIVATE
-DD_ASSERT_IS_ENABLED)
endif()

if(JEMALLOC_ENABLED)
target_compile_definitions(duckdb_java PRIVATE
-DDUCKDB_ENABLE_JEMALLOC)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static AggregateFunction NameArgParameter(AggregateFunction fun) {
}

template <class OP>
AggregateFunction GetBitfieldUnaryAggregate(LogicalType type) {
AggregateFunction GetBitfieldUnaryAggregate(const LogicalType &type) {
switch (type.id()) {
case LogicalTypeId::TINYINT:
return NameArgParameter(AggregateFunction::UnaryAggregate<BitState<uint8_t>, int8_t, int8_t, OP>(type, type));
Expand Down Expand Up @@ -111,7 +111,9 @@ struct BitwiseOperation {
};

template <class OP>
struct NumericBitwiseOperation : public BitwiseOperation, public ClusteredStateCopy {
struct NumericBitwiseOperation // NOLINT(bugprone-crtp-constructor-accessibility)
: public BitwiseOperation,
public ClusteredStateCopy {
template <class INPUT_TYPE, class STATE>
static void UpdateClusteredLocal(STATE &local, const INPUT_TYPE &input) {
if (!local.is_set) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ struct ClusteredSumOperation : public ClusteredSumStateCopy<BASE> {
static void ExecuteFlatI64HugeintSum(const INPUT_TYPE *vals, const ClusteredAggr &clustered,
const SelectionVector *isel, const sel_t *cluster_iter) {
idx_t pos = 0;
for (idx_t r = 0; r < clustered.n_group_runs; r++) {
auto &state = *reinterpret_cast<STATE_TYPE *>(clustered.group_runs[r].state);
const auto *run_sel = clustered.group_runs[r].sel;
const idx_t run_count = clustered.group_runs[r].count;
for (auto &run : clustered.runs()) {
auto &state = *reinterpret_cast<STATE_TYPE *>(run.state);
const auto *run_sel = run.sel;
const idx_t run_count = run.count;
if (run_count == 0) {
continue;
}
Expand Down Expand Up @@ -144,10 +144,10 @@ struct ClusteredSumOperation : public ClusteredSumStateCopy<BASE> {
input.ToUnifiedFormat(idata);
const auto *dict_sel = idata.sel->data();
auto &validity = idata.validity;
for (idx_t r = 0; r < clustered.n_group_runs; r++) {
auto &state = *reinterpret_cast<STATE_TYPE *>(clustered.group_runs[r].state);
const auto *run_sel = clustered.group_runs[r].sel;
const idx_t run_count = clustered.group_runs[r].count;
for (auto &run : clustered.runs()) {
auto &state = *reinterpret_cast<STATE_TYPE *>(run.state);
const auto *run_sel = run.sel;
const idx_t run_count = run.count;
int64_t local64 = 0;
if (run_sel) {
for (idx_t k = 0; k < run_count; k++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct ApproxTopKValue {
//! Allocated data
char *dataptr = nullptr;
uint32_t size = 0;
uint32_t capacity = 0;
idx_t capacity = 0;
};

struct InternalApproxTopKState {
Expand Down Expand Up @@ -94,7 +94,7 @@ struct InternalApproxTopKState {
value.size = UnsafeNumericCast<uint32_t>(input.str.GetSize());
if (value.size > value.capacity) {
// need to re-allocate for this value
value.capacity = UnsafeNumericCast<uint32_t>(NextPowerOfTwo(value.size));
value.capacity = NextPowerOfTwo(value.size);
value.dataptr = char_ptr_cast(allocator.Allocate(value.capacity));
}
// copy over the data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,9 @@ unique_ptr<FunctionData> ApproxQuantileDecimalDeserialize(Deserializer &deserial
auto bind_data = ApproximateQuantileBindData::Deserialize(deserializer, function);
auto &return_type = deserializer.Get<const LogicalType &>();
if (return_type.id() == LogicalTypeId::LIST) {
function.ReplaceImplementation(ApproxQuantileDecimalListFunction(function.GetArguments()[0]));
ReplaceApproxQuantileDecimal(function, ApproxQuantileDecimalListFunction(function.GetArguments()[0]));
} else {
function.ReplaceImplementation(ApproxQuantileDecimalFunction(function.GetArguments()[0]));
ReplaceApproxQuantileDecimal(function, ApproxQuantileDecimalFunction(function.GetArguments()[0]));
}
return bind_data;
}
Expand Down
11 changes: 6 additions & 5 deletions src/duckdb/extension/core_functions/aggregate/holistic/mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ struct ModeStandard {
return Equals::Operation(left, right);
}

static T *Update(T *mode, uint32_t &, const T &key, AggregateInputData &) {
static T *Update(T *mode, idx_t &, const T &key, AggregateInputData &) {
if (!mode) {
mode = new T(key);
}
Expand Down Expand Up @@ -156,7 +156,7 @@ struct ModeString {
return Equals::Operation(left, right);
}

static string_t *Update(string_t *mode, uint32_t &alloc_size, const string_t &key,
static string_t *Update(string_t *mode, idx_t &alloc_size, const string_t &key,
AggregateInputData &aggr_input_data) {
if (key.IsInlined()) {
if (!mode) {
Expand All @@ -168,14 +168,14 @@ struct ModeString {
}

// non-inlined string, need to allocate space for it somehow
const auto len = UnsafeNumericCast<uint32_t>(key.GetSize());
const auto len = key.GetSize();
char *ptr;
if (mode && alloc_size >= len) {
// this fits into the current arena allocation - reuse it
ptr = mode->GetDataWriteable();
} else {
// round up so repeatedly growing keys don't churn through a new arena allocation every time
alloc_size = UnsafeNumericCast<uint32_t>(NextPowerOfTwo(len));
alloc_size = NextPowerOfTwo(len);
ptr = char_ptr_cast(aggr_input_data.allocator.Allocate(alloc_size));
if (!mode) {
mode = new string_t(nullptr, 0);
Expand All @@ -197,7 +197,8 @@ struct ModeState {
SubFrames prevs;
Counts *frequency_map = nullptr;
KEY_TYPE *mode = nullptr;
uint32_t mode_alloc_size = 0;
//! Must be wide enough for NextPowerOfTwo(MAX_STRING_SIZE), which does not fit in a uint32_t
idx_t mode_alloc_size = 0;
size_t nonzero = 0;
bool valid = false;
size_t count = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ namespace duckdb {

namespace {

//! The quantile defaults to the median
constexpr double DEFAULT_QUANTILE = 0.5;
constexpr int32_t DEFAULT_SAMPLE_SIZE = 8192;

template <typename T>
struct ReservoirQuantileState {
T *v;
Expand Down Expand Up @@ -312,8 +316,6 @@ double CheckReservoirQuantile(const Value &quantile_val) {
//! Binds the quantile parameter and the sample size into the bind data. They stay part of the expression tree, and
//! the aggregate is handed them along with the input - the update callbacks only consume the leading input argument
unique_ptr<FunctionData> BindReservoirQuantile(BindAggregateFunctionInput &input) {
auto &arguments = input.GetArguments();
D_ASSERT(arguments.size() >= 2);
Value quantile_val = input.GetConstant(1);
vector<double> quantiles;
if (quantile_val.type().id() != LogicalTypeId::LIST) {
Expand All @@ -324,19 +326,13 @@ unique_ptr<FunctionData> BindReservoirQuantile(BindAggregateFunctionInput &input
}
}

idx_t sample_size = 8192ULL;

if (arguments.size() == 3) {
auto sample_size_val = input.GetNonNullConstant(2);
auto sample_size_int = sample_size_val.GetValue<int32_t>();

if (sample_size_val.IsNull() || sample_size_int <= 0) {
throw BinderException("Size of the RESERVOIR_QUANTILE sample must be bigger than 0");
}
sample_size = NumericCast<idx_t>(sample_size_int);
auto sample_size_val = input.GetNonNullConstant(2);
auto sample_size = sample_size_val.GetValue<int32_t>();
if (sample_size <= 0) {
throw BinderException("Size of the RESERVOIR_QUANTILE sample must be bigger than 0");
}

return make_uniq<ReservoirQuantileBindData>(quantiles, sample_size);
return make_uniq<ReservoirQuantileBindData>(quantiles, NumericCast<idx_t>(sample_size));
}

static unique_ptr<FunctionData> DeserializeReservoirQuantileDecimal(Deserializer &deserializer,
Expand Down Expand Up @@ -421,7 +417,7 @@ AggregateFunction GetReservoirQuantileAggregate(PhysicalType type) {
fun.SetDeserializeCallback(ReservoirQuantileBindData::Deserialize);
// temporarily push an argument so we can bind the actual quantile
fun.GetSignature().GetParameter(0).SetName("x");
fun.GetSignature().AddParameter("quantile", LogicalType::DOUBLE);
fun.GetSignature().AddParameter("quantile", LogicalType::DOUBLE, Value::DOUBLE(DEFAULT_QUANTILE));
return fun;
}

Expand All @@ -438,18 +434,14 @@ AggregateFunction GetReservoirQuantileListAggregate(const LogicalType &type) {
}

void DefineReservoirQuantile(AggregateFunctionSet &set, const LogicalType &type) {
// Four versions: type, scalar/list[, count]
// Two versions: type, scalar/list
auto fun = GetReservoirQuantileAggregate(type.InternalType());
fun.GetSignature().AddParameter("sample_size", LogicalType::INTEGER, Value::INTEGER(DEFAULT_SAMPLE_SIZE));
set.AddFunction(fun);

fun.GetSignature().AddParameter("sample_size", LogicalType::INTEGER);
set.AddFunction(fun);

// List variants
// List variant
fun = GetReservoirQuantileListAggregate(type);
set.AddFunction(fun);

fun.GetSignature().AddParameter("sample_size", LogicalType::INTEGER);
fun.GetSignature().AddParameter("sample_size", LogicalType::INTEGER, Value::INTEGER(DEFAULT_SAMPLE_SIZE));
set.AddFunction(fun);
}

Expand All @@ -462,11 +454,12 @@ void GetReservoirQuantileDecimalFunction(AggregateFunctionSet &set, const vector
fun.SetDeserializeCallback(DeserializeReservoirQuantileDecimal);

fun.GetSignature().GetParameter(0).SetName("x");
fun.GetSignature().AddParameter("quantile", arguments[1]);

set.AddFunction(fun);

fun.GetSignature().AddParameter("sample_size", LogicalType::INTEGER);
if (arguments[1].id() == LogicalTypeId::LIST) {
fun.GetSignature().AddParameter("quantile", arguments[1]);
} else {
fun.GetSignature().AddParameter("quantile", arguments[1], Value::DOUBLE(DEFAULT_QUANTILE));
}
fun.GetSignature().AddParameter("sample_size", LogicalType::INTEGER, Value::INTEGER(DEFAULT_SAMPLE_SIZE));
set.AddFunction(fun);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ AggregateFunction VariantGroupObjectFun::GetFunction() {
AggregateFunction::StateSize<VariantObjAggState>,
AggregateFunction::StateInitialize<VariantObjAggState, VariantObjFun>, VariantObjUpdate,
ListCombineFunction<VariantObjFun>, VariantObjFinalize, VariantObjClusterUpdate);
function.GetSignature().GetParameter(0).SetName("key");
function.GetSignature().GetParameter(1).SetName("value");
function.SetStructStateExport(VariantObjStateLayout);
return function;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct ApproxCountDistinctFun {

struct ArgMinFun {
static constexpr const char *Name = "arg_min";
static constexpr const char *Parameters = "arg,val";
static constexpr const char *Parameters = "arg,val,N";
static constexpr const char *Description = "Finds the row with the minimum val. Calculates the non-NULL arg expression at that row.";
static constexpr const char *Example = "arg_min(A, B)";
static constexpr const char *Categories = "";
Expand Down Expand Up @@ -69,7 +69,7 @@ struct ArgMinNullsLastFun {

struct ArgMaxFun {
static constexpr const char *Name = "arg_max";
static constexpr const char *Parameters = "arg,val";
static constexpr const char *Parameters = "arg,val,N";
static constexpr const char *Description = "Finds the row with the maximum val. Calculates the non-NULL arg expression at that row.";
static constexpr const char *Example = "arg_max(A, B)";
static constexpr const char *Categories = "";
Expand Down Expand Up @@ -141,7 +141,7 @@ struct BitXorFun {

struct BitstringAggFun {
static constexpr const char *Name = "bitstring_agg";
static constexpr const char *Parameters = "arg";
static constexpr const char *Parameters = "arg,min,max";
static constexpr const char *Description = "Returns a bitstring with bits set for each distinct value.";
static constexpr const char *Example = "bitstring_agg(A)";
static constexpr const char *Categories = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct ModeFun {

struct QuantileDiscFun {
static constexpr const char *Name = "quantile_disc";
static constexpr const char *Parameters = "x,pos";
static constexpr const char *Parameters = "x,quantile";
static constexpr const char *Description = "Returns the exact quantile number between 0 and 1 . If pos is a LIST of FLOATs, then the result is a LIST of the corresponding exact quantiles.";
static constexpr const char *Example = "quantile_disc(x, 0.5)";
static constexpr const char *Categories = "";
Expand All @@ -73,7 +73,7 @@ struct QuantileFun {

struct QuantileContFun {
static constexpr const char *Name = "quantile_cont";
static constexpr const char *Parameters = "x,pos";
static constexpr const char *Parameters = "x,quantile";
static constexpr const char *Description = "Returns the interpolated quantile number between 0 and 1 . If pos is a LIST of FLOATs, then the result is a LIST of the corresponding interpolated quantiles. ";
static constexpr const char *Example = "quantile_cont(x, 0.5)";
static constexpr const char *Categories = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace duckdb {

struct HistogramFun {
static constexpr const char *Name = "histogram";
static constexpr const char *Parameters = "arg";
static constexpr const char *Parameters = "arg,bins";
static constexpr const char *Description = "Returns a LIST of STRUCTs with the fields bucket and count.";
static constexpr const char *Example = "histogram(A)";
static constexpr const char *Categories = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace duckdb {

struct AgeFun {
static constexpr const char *Name = "age";
static constexpr const char *Parameters = "timestamp,timestamp";
static constexpr const char *Parameters = "timestamp1,timestamp2";
static constexpr const char *Description = "Subtract arguments, resulting in the time difference between the two timestamps";
static constexpr const char *Example = "age(TIMESTAMP '2001-04-10', TIMESTAMP '1992-09-20')";
static constexpr const char *Categories = "";
Expand Down Expand Up @@ -53,7 +53,7 @@ struct DatediffFun {

struct DatePartFun {
static constexpr const char *Name = "date_part";
static constexpr const char *Parameters = "ts";
static constexpr const char *Parameters = "part,ts";
static constexpr const char *Description = "Get subfield (equivalent to extract)";
static constexpr const char *Example = "date_part('minute', TIMESTAMP '1992-09-20 20:38:40')";
static constexpr const char *Categories = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct SleepMsFun {

struct IndexKeyFun {
static constexpr const char *Name = "index_key";
static constexpr const char *Parameters = "path,name,[key_column_1,key_column_2,...]";
static constexpr const char *Parameters = "path,name,...";
static constexpr const char *Description = "Generate index keys for a named index on a table (specified by a path struct with required 'table' and optional 'catalog'/'schema' fields) from key column arguments. Currently only supports ART indexes.";
static constexpr const char *Example = "index_key({'schema': 'main', 'table': 'tbl3'}, 'tbl3_idx', key1, key2, key3)";
static constexpr const char *Categories = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct HashFun {

struct LeastFun {
static constexpr const char *Name = "least";
static constexpr const char *Parameters = "arg1,arg2,...";
static constexpr const char *Parameters = "arg1,...";
static constexpr const char *Description = "Returns the smallest value. For strings lexicographical ordering is used. Note that uppercase characters are considered “smaller” than lowercase characters, and collations are not supported.";
static constexpr const char *Example = "least(42, 84)\002least('abc', 'bcd', 'cde', 'EFG')";
static constexpr const char *Categories = "string,numeric,date,timestamp,aggregate";
Expand All @@ -57,7 +57,7 @@ struct LeastFun {

struct GreatestFun {
static constexpr const char *Name = "greatest";
static constexpr const char *Parameters = "arg1,arg2,...";
static constexpr const char *Parameters = "arg1,...";
static constexpr const char *Description = "Returns the largest value. For strings lexicographical ordering is used. Note that lowercase characters are considered “larger” than uppercase characters and collations are not supported.";
static constexpr const char *Example = "greatest(42, 84)\002greatest('abc', 'bcd', 'cde', 'EFG')";
static constexpr const char *Categories = "string,numeric,date,timestamp,aggregate";
Expand Down
Loading
Loading