Skip to content

Commit a7c9147

Browse files
Update vendored DuckDB sources to 5a115ef952
1 parent bbbddb2 commit a7c9147

File tree

355 files changed

+10810
-6501
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

355 files changed

+10810
-6501
lines changed

src/duckdb/extension/core_functions/aggregate/algebraic/avg.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,20 @@ AggregateFunction GetAverageAggregate(PhysicalType type) {
266266
}
267267
}
268268

269+
LogicalType GetAvgStateType(const AggregateFunction &function) {
270+
child_list_t<LogicalType> children;
271+
children.emplace_back("count", LogicalType::UBIGINT);
272+
children.emplace_back("value", function.arguments[0]);
273+
return LogicalType::STRUCT(std::move(children));
274+
}
275+
269276
unique_ptr<FunctionData> BindDecimalAvg(ClientContext &context, AggregateFunction &function,
270277
vector<unique_ptr<Expression>> &arguments) {
271278
auto decimal_type = arguments[0]->return_type;
272279
function = GetAverageAggregate(decimal_type.InternalType());
273280
function.name = "avg";
274281
function.arguments[0] = decimal_type;
282+
function.get_state_type = GetAvgStateType;
275283
function.SetReturnType(LogicalType::DOUBLE);
276284
return make_uniq<AverageDecimalBindData>(
277285
Hugeint::Cast<double>(Hugeint::POWERS_OF_TEN[DecimalType::GetScale(decimal_type)]));
@@ -303,12 +311,18 @@ AggregateFunctionSet AvgFun::GetFunctions() {
303311
AggregateFunction::UnaryAggregate<AvgState<hugeint_t>, dtime_tz_t, dtime_tz_t, TimeTZAverageOperation>(
304312
LogicalType::TIME_TZ, LogicalType::TIME_TZ));
305313

314+
for (auto &function : avg.functions) {
315+
function.get_state_type = GetAvgStateType;
316+
}
317+
306318
return avg;
307319
}
308320

309321
AggregateFunction FAvgFun::GetFunction() {
310-
return AggregateFunction::UnaryAggregate<KahanAvgState, double, double, KahanAverageOperation>(LogicalType::DOUBLE,
311-
LogicalType::DOUBLE);
322+
auto function = AggregateFunction::UnaryAggregate<KahanAvgState, double, double, KahanAverageOperation>(
323+
LogicalType::DOUBLE, LogicalType::DOUBLE);
324+
function.get_state_type = GetAvgStateType;
325+
return function;
312326
}
313327

314328
} // namespace duckdb

src/duckdb/extension/core_functions/function_list.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ static const StaticFunctionDefinition core_functions[] = {
196196
DUCKDB_SCALAR_FUNCTION_SET(GenerateSeriesFun),
197197
DUCKDB_SCALAR_FUNCTION(GetBitFun),
198198
DUCKDB_SCALAR_FUNCTION(GetCurrentTimestampFun),
199+
DUCKDB_SCALAR_FUNCTION(GetTypeFun),
199200
DUCKDB_SCALAR_FUNCTION_SET_ALIAS(GradeUpFun),
200201
DUCKDB_SCALAR_FUNCTION_SET(GreatestFun),
201202
DUCKDB_SCALAR_FUNCTION_SET(GreatestCommonDivisorFun),
@@ -266,6 +267,7 @@ static const StaticFunctionDefinition core_functions[] = {
266267
DUCKDB_SCALAR_FUNCTION_SET(MakeTimestampFun),
267268
DUCKDB_SCALAR_FUNCTION_SET(MakeTimestampMsFun),
268269
DUCKDB_SCALAR_FUNCTION_SET(MakeTimestampNsFun),
270+
DUCKDB_SCALAR_FUNCTION(MakeTypeFun),
269271
DUCKDB_SCALAR_FUNCTION_SET(MapFun),
270272
DUCKDB_SCALAR_FUNCTION(MapConcatFun),
271273
DUCKDB_SCALAR_FUNCTION(MapEntriesFun),

src/duckdb/extension/core_functions/include/core_functions/scalar/generic_functions.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,26 @@ struct TypeOfFun {
8585
static ScalarFunction GetFunction();
8686
};
8787

88+
struct GetTypeFun {
89+
static constexpr const char *Name = "get_type";
90+
static constexpr const char *Parameters = "expression";
91+
static constexpr const char *Description = "Returns the type of the result of the expression";
92+
static constexpr const char *Example = "get_type('abc')";
93+
static constexpr const char *Categories = "";
94+
95+
static ScalarFunction GetFunction();
96+
};
97+
98+
struct MakeTypeFun {
99+
static constexpr const char *Name = "make_type";
100+
static constexpr const char *Parameters = "name,...";
101+
static constexpr const char *Description = "Construct a type from its name and optional parameters";
102+
static constexpr const char *Example = "make_type('DECIMAL', 10, 2)";
103+
static constexpr const char *Categories = "";
104+
105+
static ScalarFunction GetFunction();
106+
};
107+
88108
struct CanCastImplicitlyFun {
89109
static constexpr const char *Name = "can_cast_implicitly";
90110
static constexpr const char *Parameters = "source_type,target_type";

src/duckdb/extension/core_functions/lambda_functions.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "duckdb/planner/expression/bound_function_expression.hpp"
77
#include "duckdb/planner/expression/bound_cast_expression.hpp"
8+
#include "duckdb/planner/expression/bound_lambda_expression.hpp"
89

910
namespace duckdb {
1011

src/duckdb/extension/core_functions/scalar/date/date_trunc.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,8 @@ unique_ptr<BaseStatistics> DateTruncStatistics(vector<BaseStatistics> &child_sta
517517
auto result = NumericStats::CreateEmpty(min_value.type());
518518
NumericStats::SetMin(result, min_value);
519519
NumericStats::SetMax(result, max_value);
520-
result.CopyValidity(child_stats[0]);
520+
521+
result.CombineValidity(child_stats[0], child_stats[1]);
521522
return result.ToUnique();
522523
}
523524

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#include "core_functions/scalar/generic_functions.hpp"
2+
#include "duckdb/planner/expression/bound_constant_expression.hpp"
3+
#include "duckdb/planner/expression/bound_function_expression.hpp"
4+
#include "duckdb/parser/expression/constant_expression.hpp"
5+
#include "duckdb/planner/binder.hpp"
6+
#include "duckdb/parser/expression/type_expression.hpp"
7+
#include "duckdb/execution/expression_executor.hpp"
8+
9+
namespace duckdb {
10+
11+
//----------------------------------------------------------------------------------------------------------------------
12+
// typeof function
13+
//----------------------------------------------------------------------------------------------------------------------
14+
15+
static void TypeOfFunction(DataChunk &args, ExpressionState &state, Vector &result) {
16+
Value v(args.data[0].GetType().ToString());
17+
result.Reference(v);
18+
}
19+
20+
static unique_ptr<Expression> BindTypeOfFunctionExpression(FunctionBindExpressionInput &input) {
21+
auto &return_type = input.children[0]->return_type;
22+
if (return_type.id() == LogicalTypeId::UNKNOWN || return_type.id() == LogicalTypeId::SQLNULL) {
23+
// parameter - unknown return type
24+
return nullptr;
25+
}
26+
// emit a constant expression
27+
return make_uniq<BoundConstantExpression>(Value(return_type.ToString()));
28+
}
29+
30+
ScalarFunction TypeOfFun::GetFunction() {
31+
auto fun = ScalarFunction({LogicalType::ANY}, LogicalType::VARCHAR, TypeOfFunction);
32+
fun.SetNullHandling(FunctionNullHandling::SPECIAL_HANDLING);
33+
fun.SetBindExpressionCallback(BindTypeOfFunctionExpression);
34+
return fun;
35+
}
36+
37+
//----------------------------------------------------------------------------------------------------------------------
38+
// get_type function
39+
//----------------------------------------------------------------------------------------------------------------------
40+
// This is like "typeof", except returns LogicalType::TYPE instead of VARCHAR
41+
42+
static void GetTypeFunction(DataChunk &args, ExpressionState &state, Vector &result) {
43+
auto v = Value::TYPE(args.data[0].GetType());
44+
result.Reference(v);
45+
}
46+
47+
static unique_ptr<Expression> BindGetTypeFunctionExpression(FunctionBindExpressionInput &input) {
48+
auto &return_type = input.children[0]->return_type;
49+
if (return_type.id() == LogicalTypeId::UNKNOWN || return_type.id() == LogicalTypeId::SQLNULL) {
50+
// parameter - unknown return type
51+
return nullptr;
52+
}
53+
// emit a constant expression
54+
return make_uniq<BoundConstantExpression>(Value::TYPE(return_type));
55+
}
56+
57+
ScalarFunction GetTypeFun::GetFunction() {
58+
auto fun = ScalarFunction({LogicalType::ANY}, LogicalType::VARCHAR, GetTypeFunction);
59+
fun.SetNullHandling(FunctionNullHandling::SPECIAL_HANDLING);
60+
fun.SetBindExpressionCallback(BindGetTypeFunctionExpression);
61+
return fun;
62+
}
63+
64+
//----------------------------------------------------------------------------------------------------------------------
65+
// make_type function
66+
//----------------------------------------------------------------------------------------------------------------------
67+
static void MakeTypeFunction(DataChunk &args, ExpressionState &state, Vector &result) {
68+
throw InvalidInputException("make_type function can only be used in constant expressions");
69+
}
70+
71+
static unique_ptr<Expression> BindMakeTypeFunctionExpression(FunctionBindExpressionInput &input) {
72+
vector<pair<string, Value>> args;
73+
74+
// Evaluate all arguments to constant values
75+
for (auto &child : input.children) {
76+
string name = child->alias;
77+
if (!child->IsFoldable()) {
78+
throw BinderException("make_type function arguments must be constant expressions");
79+
}
80+
auto val = ExpressionExecutor::EvaluateScalar(input.context, *child);
81+
args.emplace_back(name, val);
82+
}
83+
84+
if (args.empty()) {
85+
throw BinderException("make_type function requires at least one argument");
86+
}
87+
88+
if (args.front().second.type() != LogicalType::VARCHAR) {
89+
throw BinderException("make_type function first argument must be the type name as VARCHAR");
90+
}
91+
92+
vector<unique_ptr<ParsedExpression>> type_args;
93+
for (idx_t i = 1; i < args.size(); i++) {
94+
auto &arg = args[i];
95+
auto result = make_uniq<ConstantExpression>(arg.second);
96+
result->SetAlias(arg.first);
97+
98+
type_args.push_back(std::move(result));
99+
}
100+
101+
auto type_name = args.front().second.GetValue<string>();
102+
auto qualified_name = QualifiedName::Parse(type_name);
103+
104+
auto unbound_type = LogicalType::UNBOUND(make_uniq<TypeExpression>(qualified_name.catalog, qualified_name.schema,
105+
qualified_name.name, std::move(type_args)));
106+
107+
// Bind the unbound type
108+
auto binder = Binder::CreateBinder(input.context);
109+
binder->BindLogicalType(unbound_type);
110+
return make_uniq<BoundConstantExpression>(Value::TYPE(unbound_type));
111+
}
112+
113+
ScalarFunction MakeTypeFun::GetFunction() {
114+
auto fun = ScalarFunction({LogicalType::VARCHAR}, LogicalType::TYPE(), MakeTypeFunction);
115+
fun.SetNullHandling(FunctionNullHandling::SPECIAL_HANDLING);
116+
fun.SetBindExpressionCallback(BindMakeTypeFunctionExpression);
117+
fun.varargs = LogicalType::ANY;
118+
return fun;
119+
}
120+
121+
} // namespace duckdb

src/duckdb/extension/core_functions/scalar/generic/typeof.cpp

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/duckdb/extension/core_functions/scalar/list/list_filter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "duckdb/function/lambda_functions.hpp"
44
#include "duckdb/planner/expression/bound_cast_expression.hpp"
5+
#include "duckdb/planner/expression/bound_lambda_expression.hpp"
56

67
namespace duckdb {
78

src/duckdb/extension/core_functions/scalar/list/list_reduce.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "core_functions/scalar/list_functions.hpp"
2+
23
#include "duckdb/function/lambda_functions.hpp"
34
#include "duckdb/planner/expression/bound_cast_expression.hpp"
5+
#include "duckdb/planner/expression/bound_lambda_expression.hpp"
46

57
namespace duckdb {
68

src/duckdb/extension/core_functions/scalar/list/list_transform.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "duckdb/function/lambda_functions.hpp"
44
#include "duckdb/planner/expression/bound_cast_expression.hpp"
5+
#include "duckdb/planner/expression/bound_lambda_expression.hpp"
56

67
namespace duckdb {
78

0 commit comments

Comments
 (0)