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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/duckdb/extension/icu/icu-datefunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ uint64_t ICUDateFunc::SetTimeNS(icu::Calendar *calendar, timestamp_tz_ns_t date)
int64_t nanos = date.value % Interval::NANOS_PER_MSEC;
if (nanos < 0) {
--millis;
nanos += Interval::MICROS_PER_MSEC;
nanos += Interval::NANOS_PER_MSEC;
}

const auto udate = UDate(millis);
Expand Down
32 changes: 21 additions & 11 deletions src/duckdb/extension/icu/icu-datesub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,20 +187,29 @@ ICUDateFunc::part_sub_t ICUDateFunc::SubtractFactory(DatePartSpecifier type) {
// MS-SQL differences can be computed using ICU by truncating both arguments
// to the desired part precision and then applying ICU subtraction/difference
struct ICUCalendarDiff : public ICUDateFunc {
template <typename T>
static int64_t DifferenceFunc(icu::Calendar *calendar, timestamp_tz_t start_date, timestamp_tz_t end_date,
part_trunc_t trunc_func, part_sub_t sub_func) {
// Truncate the two arguments. This is safe because we will stay in range
auto micros = SetTime(calendar, start_date);
static timestamp_tz_t TruncateForDiff(icu::Calendar *calendar, timestamp_tz_t date, part_trunc_t trunc_func) {
auto micros = SetTime(calendar, date);
trunc_func(calendar, micros);
start_date = GetTimeUnsafe(calendar, micros);
return GetTimeUnsafe(calendar, micros);
}

micros = SetTime(calendar, end_date);
static timestamp_tz_t TruncateForDiff(icu::Calendar *calendar, timestamp_tz_ns_t date, part_trunc_t trunc_func) {
auto nanos = SetTimeNS(calendar, date);
// Adapt TIMESTAMPTZ_NS to the existing microsecond-or-coarser date_diff path.
uint64_t micros = nanos / Interval::NANOS_PER_MICRO;
trunc_func(calendar, micros);
end_date = GetTimeUnsafe(calendar, micros);
return GetTimeUnsafe(calendar, micros);
}

template <typename T>
static int64_t DifferenceFunc(icu::Calendar *calendar, T start_date, T end_date, part_trunc_t trunc_func,
part_sub_t sub_func) {
// Truncate the two arguments. This is safe because we will stay in range
auto start_micros = TruncateForDiff(calendar, start_date, trunc_func);
auto end_micros = TruncateForDiff(calendar, end_date, trunc_func);

// Now use ICU difference
return sub_func(calendar, start_date, end_date);
return sub_func(calendar, start_micros, end_micros);
}

static part_trunc_t DiffTruncationFactory(DatePartSpecifier type) {
Expand Down Expand Up @@ -238,7 +247,7 @@ struct ICUCalendarDiff : public ICUDateFunc {
BinaryExecutor::Execute<T, T, int64_t>(
startdate_arg, enddate_arg, result, [&](T start_date, T end_date) -> optional<int64_t> {
if (start_date.IsFinite() && end_date.IsFinite()) {
return DifferenceFunc<T>(calendar, start_date, end_date, trunc_func, sub_func);
return DifferenceFunc(calendar, start_date, end_date, trunc_func, sub_func);
} else {
return nullopt;
}
Expand All @@ -252,7 +261,7 @@ struct ICUCalendarDiff : public ICUDateFunc {
const auto part = GetDatePartSpecifier(specifier.GetString());
auto trunc_func = DiffTruncationFactory(part);
auto sub_func = SubtractFactory(part);
return DifferenceFunc<T>(calendar, start_date, end_date, trunc_func, sub_func);
return DifferenceFunc(calendar, start_date, end_date, trunc_func, sub_func);
} else {
return nullopt;
}
Expand All @@ -268,6 +277,7 @@ struct ICUCalendarDiff : public ICUDateFunc {
static void AddFunctions(const Identifier &name, ExtensionLoader &loader) {
ScalarFunctionSet set {name};
set.AddFunction(GetFunction<timestamp_tz_t>(LogicalType::TIMESTAMP_TZ));
set.AddFunction(GetFunction<timestamp_tz_ns_t>(LogicalType::TIMESTAMP_TZ_NS));
set.SetArgProperties(1, ArgProperties().NonIncreasing());
set.SetArgProperties(2, ArgProperties().NonDecreasing());
loader.RegisterFunction(set);
Expand Down
18 changes: 12 additions & 6 deletions src/duckdb/src/common/row_operations/row_matcher.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "duckdb/common/vector/flat_vector.hpp"
#include "duckdb/common/vector/map_vector.hpp"
#include "duckdb/common/vector/struct_vector.hpp"
#include "duckdb/common/row_operations/row_matcher.hpp"

Expand Down Expand Up @@ -164,13 +163,13 @@ static idx_t SelectComparison(const Vector &, const Vector &, const SelectionVec
template <>
idx_t SelectComparison<Equals>(const Vector &left, const Vector &right, const SelectionVector &sel, idx_t count,
SelectionVector *true_sel, SelectionVector *false_sel) {
return VectorOperations::NestedEquals(left, right, &sel, count, true_sel, false_sel);
return VectorOperations::Equals(left, right, &sel, count, true_sel, false_sel);
}

template <>
idx_t SelectComparison<NotEquals>(const Vector &left, const Vector &right, const SelectionVector &sel, idx_t count,
SelectionVector *true_sel, SelectionVector *false_sel) {
return VectorOperations::NestedNotEquals(left, right, &sel, count, true_sel, false_sel);
return VectorOperations::NotEquals(left, right, &sel, count, true_sel, false_sel);
}

template <>
Expand Down Expand Up @@ -381,8 +380,11 @@ MatchFunction RowMatcher::GetStructMatchFunction(const LogicalType &type, const
ExpressionType child_predicate = predicate;
switch (predicate) {
case ExpressionType::COMPARE_EQUAL:
result.function = StructMatchEquality<NO_MATCH_SEL, Equals>;
child_predicate = ExpressionType::COMPARE_NOT_DISTINCT_FROM;
if (type.id() == LogicalTypeId::UNION) {
result.function = GenericNestedMatch<NO_MATCH_SEL, Equals>;
} else {
result.function = StructMatchEquality<NO_MATCH_SEL, Equals>;
}
break;
case ExpressionType::COMPARE_NOTEQUAL:
result.function = GenericNestedMatch<NO_MATCH_SEL, NotEquals>;
Expand All @@ -391,7 +393,11 @@ MatchFunction RowMatcher::GetStructMatchFunction(const LogicalType &type, const
result.function = GenericNestedMatch<NO_MATCH_SEL, DistinctFrom>;
return result;
case ExpressionType::COMPARE_NOT_DISTINCT_FROM:
result.function = StructMatchEquality<NO_MATCH_SEL, NotDistinctFrom>;
if (type.id() == LogicalTypeId::UNION) {
result.function = GenericNestedMatch<NO_MATCH_SEL, NotDistinctFrom>;
} else {
result.function = StructMatchEquality<NO_MATCH_SEL, NotDistinctFrom>;
}
break;
case ExpressionType::COMPARE_GREATERTHAN:
result.function = GenericNestedMatch<NO_MATCH_SEL, GreaterThan>;
Expand Down
10 changes: 9 additions & 1 deletion src/duckdb/src/common/types/row/tuple_data_layout.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "duckdb/common/types/row/tuple_data_layout.hpp"

#include "duckdb/planner/expression/bound_aggregate_expression.hpp"
#include "duckdb/common/sorting/sort_key.hpp"

namespace duckdb {
Expand Down Expand Up @@ -228,4 +227,13 @@ bool TupleDataLayout::IsSortKeyLayout() const {
return sort_key_type != SortKeyType::INVALID;
}

bool TupleDataLayout::HasNestedTypes() const {
for (const auto &type : types) {
if (type.IsNested()) {
return true;
}
}
return false;
}

} // namespace duckdb
Loading
Loading