Skip to content

Commit fda3834

Browse files
committed
add vendor 1.2.0
1 parent 45e5a92 commit fda3834

File tree

66 files changed

+532
-393
lines changed

Some content is hidden

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

66 files changed

+532
-393
lines changed

CMakeLists.txt

+1-1
Large diffs are not rendered by default.

src/duckdb/extension/core_functions/function_list.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ static const StaticFunctionDefinition core_functions[] = {
136136
DUCKDB_AGGREGATE_FUNCTION(CovarPopFun),
137137
DUCKDB_AGGREGATE_FUNCTION(CovarSampFun),
138138
DUCKDB_SCALAR_FUNCTION(CurrentDatabaseFun),
139-
DUCKDB_SCALAR_FUNCTION(CurrentDateFun),
140139
DUCKDB_SCALAR_FUNCTION(CurrentQueryFun),
141140
DUCKDB_SCALAR_FUNCTION(CurrentSchemaFun),
142141
DUCKDB_SCALAR_FUNCTION(CurrentSchemasFun),
@@ -193,7 +192,6 @@ static const StaticFunctionDefinition core_functions[] = {
193192
DUCKDB_SCALAR_FUNCTION_ALIAS(GenRandomUuidFun),
194193
DUCKDB_SCALAR_FUNCTION_SET(GenerateSeriesFun),
195194
DUCKDB_SCALAR_FUNCTION(GetBitFun),
196-
DUCKDB_SCALAR_FUNCTION(CurrentTimeFun),
197195
DUCKDB_SCALAR_FUNCTION(GetCurrentTimestampFun),
198196
DUCKDB_SCALAR_FUNCTION_SET_ALIAS(GradeUpFun),
199197
DUCKDB_SCALAR_FUNCTION_SET(GreatestFun),
@@ -371,7 +369,6 @@ static const StaticFunctionDefinition core_functions[] = {
371369
DUCKDB_SCALAR_FUNCTION(ToTimestampFun),
372370
DUCKDB_SCALAR_FUNCTION(ToWeeksFun),
373371
DUCKDB_SCALAR_FUNCTION(ToYearsFun),
374-
DUCKDB_SCALAR_FUNCTION_ALIAS(TodayFun),
375372
DUCKDB_SCALAR_FUNCTION_ALIAS(TransactionTimestampFun),
376373
DUCKDB_SCALAR_FUNCTION(TranslateFun),
377374
DUCKDB_SCALAR_FUNCTION_SET(TrimFun),

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

-24
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,6 @@ struct CenturyFun {
3333
static ScalarFunctionSet GetFunctions();
3434
};
3535

36-
struct CurrentDateFun {
37-
static constexpr const char *Name = "current_date";
38-
static constexpr const char *Parameters = "";
39-
static constexpr const char *Description = "Returns the current date";
40-
static constexpr const char *Example = "current_date()";
41-
42-
static ScalarFunction GetFunction();
43-
};
44-
45-
struct TodayFun {
46-
using ALIAS = CurrentDateFun;
47-
48-
static constexpr const char *Name = "today";
49-
};
50-
5136
struct DateDiffFun {
5237
static constexpr const char *Name = "date_diff";
5338
static constexpr const char *Parameters = "part,startdate,enddate";
@@ -198,15 +183,6 @@ struct EpochNsFun {
198183
static ScalarFunctionSet GetFunctions();
199184
};
200185

201-
struct CurrentTimeFun {
202-
static constexpr const char *Name = "get_current_time";
203-
static constexpr const char *Parameters = "";
204-
static constexpr const char *Description = "Returns the current time";
205-
static constexpr const char *Example = "get_current_time()";
206-
207-
static ScalarFunction GetFunction();
208-
};
209-
210186
struct EraFun {
211187
static constexpr const char *Name = "era";
212188
static constexpr const char *Parameters = "ts";

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

-37
Original file line numberDiff line numberDiff line change
@@ -27,41 +27,4 @@ ScalarFunction GetCurrentTimestampFun::GetFunction() {
2727
return current_timestamp;
2828
}
2929

30-
static unique_ptr<Expression> CurrentTimeExpr(FunctionBindExpressionInput &input) {
31-
auto timestamp = GetCurrentTimestampFun::GetFunction();
32-
timestamp.name = GetCurrentTimestampFun::Name;
33-
34-
vector<unique_ptr<Expression>> args;
35-
36-
auto func = make_uniq_base<Expression, BoundFunctionExpression>(LogicalType::TIMESTAMP_TZ, timestamp,
37-
std::move(args), nullptr);
38-
39-
return BoundCastExpression::AddCastToType(input.context, std::move(func), LogicalType::TIME_TZ);
40-
}
41-
42-
static unique_ptr<Expression> CurrentDateExpr(FunctionBindExpressionInput &input) {
43-
auto timestamp = GetCurrentTimestampFun::GetFunction();
44-
timestamp.name = GetCurrentTimestampFun::Name;
45-
46-
vector<unique_ptr<Expression>> args;
47-
48-
auto func = make_uniq_base<Expression, BoundFunctionExpression>(LogicalType::TIMESTAMP_TZ, timestamp,
49-
std::move(args), nullptr);
50-
return BoundCastExpression::AddCastToType(input.context, std::move(func), LogicalType::DATE);
51-
}
52-
53-
ScalarFunction CurrentTimeFun::GetFunction() {
54-
ScalarFunction current_time({}, LogicalType::TIME_TZ, nullptr);
55-
current_time.bind_expression = CurrentTimeExpr;
56-
current_time.stability = FunctionStability::CONSISTENT_WITHIN_QUERY;
57-
return current_time;
58-
}
59-
60-
ScalarFunction CurrentDateFun::GetFunction() {
61-
ScalarFunction current_date({}, LogicalType::DATE, nullptr);
62-
current_date.bind_expression = CurrentDateExpr;
63-
current_date.stability = FunctionStability::CONSISTENT_WITHIN_QUERY;
64-
return current_date;
65-
}
66-
6730
} // namespace duckdb
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include "include/icu-dateadd.hpp"
2+
3+
#include "duckdb/main/extension_util.hpp"
4+
#include "duckdb/common/types/time.hpp"
5+
#include "duckdb/common/types/timestamp.hpp"
6+
#include "duckdb/parser/parsed_data/create_scalar_function_info.hpp"
7+
#include "duckdb/planner/expression/bound_function_expression.hpp"
8+
#include "duckdb/transaction/meta_transaction.hpp"
9+
#include "include/icu-current.hpp"
10+
#include "include/icu-casts.hpp"
11+
12+
namespace duckdb {
13+
14+
static timestamp_t GetTransactionTimestamp(ExpressionState &state) {
15+
return MetaTransaction::Get(state.GetContext()).start_timestamp;
16+
}
17+
18+
static void CurrentTimeFunction(DataChunk &input, ExpressionState &state, Vector &result) {
19+
D_ASSERT(input.ColumnCount() == 0);
20+
auto instant = GetTransactionTimestamp(state);
21+
ICUDateFunc::BindData data(state.GetContext());
22+
23+
dtime_tz_t result_time(dtime_t(0), 0);
24+
ICUToTimeTZ::ToTimeTZ(data.calendar.get(), instant, result_time);
25+
auto val = Value::TIMETZ(result_time);
26+
result.Reference(val);
27+
}
28+
29+
static void CurrentDateFunction(DataChunk &input, ExpressionState &state, Vector &result) {
30+
D_ASSERT(input.ColumnCount() == 0);
31+
auto instant = GetTransactionTimestamp(state);
32+
33+
auto val = Value::DATE(ICUMakeDate::ToDate(state.GetContext(), instant));
34+
result.Reference(val);
35+
}
36+
37+
ScalarFunction GetCurrentTimeFun() {
38+
ScalarFunction current_time({}, LogicalType::TIME_TZ, CurrentTimeFunction);
39+
current_time.stability = FunctionStability::CONSISTENT_WITHIN_QUERY;
40+
return current_time;
41+
}
42+
43+
ScalarFunction GetCurrentDateFun() {
44+
ScalarFunction current_date({}, LogicalType::DATE, CurrentDateFunction);
45+
current_date.stability = FunctionStability::CONSISTENT_WITHIN_QUERY;
46+
return current_date;
47+
}
48+
49+
void RegisterICUCurrentFunctions(DatabaseInstance &db) {
50+
// temporal + interval
51+
ScalarFunctionSet current_time("get_current_time");
52+
current_time.AddFunction(GetCurrentTimeFun());
53+
ExtensionUtil::RegisterFunction(db, current_time);
54+
55+
ScalarFunctionSet current_date("current_date");
56+
current_date.AddFunction(GetCurrentDateFun());
57+
ExtensionUtil::RegisterFunction(db, current_date);
58+
59+
current_date.name = "today";
60+
ExtensionUtil::RegisterFunction(db, current_date);
61+
}
62+
63+
} // namespace duckdb

src/duckdb/extension/icu/icu-makedate.cpp

+43-39
Original file line numberDiff line numberDiff line change
@@ -9,62 +9,66 @@
99
#include "duckdb/function/cast/cast_function_set.hpp"
1010
#include "duckdb/main/extension_util.hpp"
1111
#include "duckdb/parser/parsed_data/create_scalar_function_info.hpp"
12+
#include "include/icu-casts.hpp"
1213
#include "include/icu-datefunc.hpp"
1314
#include "include/icu-datetrunc.hpp"
1415

1516
#include <cmath>
1617

1718
namespace duckdb {
1819

19-
struct ICUMakeDate : public ICUDateFunc {
20-
static inline date_t Operation(icu::Calendar *calendar, timestamp_t instant) {
21-
if (!Timestamp::IsFinite(instant)) {
22-
return Timestamp::GetDate(instant);
23-
}
24-
25-
// Extract the time zone parts
26-
SetTime(calendar, instant);
27-
const auto era = ExtractField(calendar, UCAL_ERA);
28-
const auto year = ExtractField(calendar, UCAL_YEAR);
29-
const auto mm = ExtractField(calendar, UCAL_MONTH) + 1;
30-
const auto dd = ExtractField(calendar, UCAL_DATE);
31-
32-
const auto yyyy = era ? year : (-year + 1);
33-
date_t result;
34-
if (!Date::TryFromDate(yyyy, mm, dd, result)) {
35-
throw ConversionException("Unable to convert TIMESTAMPTZ to DATE");
36-
}
20+
date_t ICUMakeDate::Operation(icu::Calendar *calendar, timestamp_t instant) {
21+
if (!Timestamp::IsFinite(instant)) {
22+
return Timestamp::GetDate(instant);
23+
}
3724

38-
return result;
25+
// Extract the time zone parts
26+
SetTime(calendar, instant);
27+
const auto era = ExtractField(calendar, UCAL_ERA);
28+
const auto year = ExtractField(calendar, UCAL_YEAR);
29+
const auto mm = ExtractField(calendar, UCAL_MONTH) + 1;
30+
const auto dd = ExtractField(calendar, UCAL_DATE);
31+
32+
const auto yyyy = era ? year : (-year + 1);
33+
date_t result;
34+
if (!Date::TryFromDate(yyyy, mm, dd, result)) {
35+
throw ConversionException("Unable to convert TIMESTAMPTZ to DATE");
3936
}
4037

41-
static bool CastToDate(Vector &source, Vector &result, idx_t count, CastParameters &parameters) {
42-
auto &cast_data = parameters.cast_data->Cast<CastData>();
43-
auto &info = cast_data.info->Cast<BindData>();
44-
CalendarPtr calendar(info.calendar->clone());
38+
return result;
39+
}
4540

46-
UnaryExecutor::Execute<timestamp_t, date_t>(
47-
source, result, count, [&](timestamp_t input) { return Operation(calendar.get(), input); });
48-
return true;
49-
}
41+
date_t ICUMakeDate::ToDate(ClientContext &context, timestamp_t instant) {
42+
ICUDateFunc::BindData data(context);
43+
return Operation(data.calendar.get(), instant);
44+
}
5045

51-
static BoundCastInfo BindCastToDate(BindCastInput &input, const LogicalType &source, const LogicalType &target) {
52-
if (!input.context) {
53-
throw InternalException("Missing context for TIMESTAMPTZ to DATE cast.");
54-
}
46+
bool ICUMakeDate::CastToDate(Vector &source, Vector &result, idx_t count, CastParameters &parameters) {
47+
auto &cast_data = parameters.cast_data->Cast<CastData>();
48+
auto &info = cast_data.info->Cast<BindData>();
49+
CalendarPtr calendar(info.calendar->clone());
5550

56-
auto cast_data = make_uniq<CastData>(make_uniq<BindData>(*input.context));
51+
UnaryExecutor::Execute<timestamp_t, date_t>(source, result, count,
52+
[&](timestamp_t input) { return Operation(calendar.get(), input); });
53+
return true;
54+
}
5755

58-
return BoundCastInfo(CastToDate, std::move(cast_data));
56+
BoundCastInfo ICUMakeDate::BindCastToDate(BindCastInput &input, const LogicalType &source, const LogicalType &target) {
57+
if (!input.context) {
58+
throw InternalException("Missing context for TIMESTAMPTZ to DATE cast.");
5959
}
6060

61-
static void AddCasts(DatabaseInstance &db) {
62-
auto &config = DBConfig::GetConfig(db);
63-
auto &casts = config.GetCastFunctions();
61+
auto cast_data = make_uniq<CastData>(make_uniq<BindData>(*input.context));
6462

65-
casts.RegisterCastFunction(LogicalType::TIMESTAMP_TZ, LogicalType::DATE, BindCastToDate);
66-
}
67-
};
63+
return BoundCastInfo(CastToDate, std::move(cast_data));
64+
}
65+
66+
void ICUMakeDate::AddCasts(DatabaseInstance &db) {
67+
auto &config = DBConfig::GetConfig(db);
68+
auto &casts = config.GetCastFunctions();
69+
70+
casts.RegisterCastFunction(LogicalType::TIMESTAMP_TZ, LogicalType::DATE, BindCastToDate);
71+
}
6872

6973
struct ICUMakeTimestampTZFunc : public ICUDateFunc {
7074
template <typename T>

0 commit comments

Comments
 (0)