Skip to content

Commit

Permalink
chore: Update vendored sources to duckdb/duckdb@1bdf93c
Browse files Browse the repository at this point in the history
Merge pull request duckdb/duckdb#11861 from hawkfish/timetz-compare
Merge pull request duckdb/duckdb#11834 from Tishj/pyrelation_fetch_df_chunk_sync
  • Loading branch information
krlmlr committed May 5, 2024
1 parent b7fd91a commit bab7543
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/duckdb/src/core_functions/function_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ static const StaticFunctionDefinition internal_functions[] = {
DUCKDB_AGGREGATE_FUNCTION_ALIAS(SumkahanFun),
DUCKDB_SCALAR_FUNCTION(TanFun),
DUCKDB_SCALAR_FUNCTION_SET(TimeBucketFun),
DUCKDB_SCALAR_FUNCTION(TimeTZSortKeyFun),
DUCKDB_SCALAR_FUNCTION_SET(TimezoneFun),
DUCKDB_SCALAR_FUNCTION_SET(TimezoneHourFun),
DUCKDB_SCALAR_FUNCTION_SET(TimezoneMinuteFun),
Expand Down
17 changes: 17 additions & 0 deletions src/duckdb/src/core_functions/scalar/date/epoch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,21 @@ ScalarFunction ToTimestampFun::GetFunction() {
return ScalarFunction({LogicalType::DOUBLE}, LogicalType::TIMESTAMP_TZ, EpochSecFunction);
}

struct TimeTZSortKeyOperator {
template <typename INPUT_TYPE, typename RESULT_TYPE>
static RESULT_TYPE Operation(INPUT_TYPE input) {
return input.sort_key();
}
};

static void TimeTZSortKeyFunction(DataChunk &input, ExpressionState &state, Vector &result) {
D_ASSERT(input.ColumnCount() == 1);

UnaryExecutor::Execute<dtime_tz_t, uint64_t, TimeTZSortKeyOperator>(input.data[0], result, input.size());
}

ScalarFunction TimeTZSortKeyFun::GetFunction() {
return ScalarFunction({LogicalType::TIME_TZ}, LogicalType::UBIGINT, TimeTZSortKeyFunction);
}

} // namespace duckdb
6 changes: 3 additions & 3 deletions src/duckdb/src/function/table/version/pragma_version.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef DUCKDB_PATCH_VERSION
#define DUCKDB_PATCH_VERSION "3-dev413"
#define DUCKDB_PATCH_VERSION "3-dev418"
#endif
#ifndef DUCKDB_MINOR_VERSION
#define DUCKDB_MINOR_VERSION 10
Expand All @@ -8,10 +8,10 @@
#define DUCKDB_MAJOR_VERSION 0
#endif
#ifndef DUCKDB_VERSION
#define DUCKDB_VERSION "v0.10.3-dev413"
#define DUCKDB_VERSION "v0.10.3-dev418"
#endif
#ifndef DUCKDB_SOURCE_ID
#define DUCKDB_SOURCE_ID "50f9d9c095"
#define DUCKDB_SOURCE_ID "1bdf93c550"
#endif
#include "duckdb/function/table/system_functions.hpp"
#include "duckdb/main/database.hpp"
Expand Down
41 changes: 33 additions & 8 deletions src/duckdb/src/include/duckdb/common/types/datetime.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "duckdb/common/common.hpp"
#include "duckdb/common/numeric_utils.hpp"

#include <functional>

Expand Down Expand Up @@ -92,23 +93,47 @@ struct dtime_tz_t { // NOLINT
static constexpr const uint64_t OFFSET_MASK = ~uint64_t(0) >> TIME_BITS;
static constexpr const int32_t MAX_OFFSET = 16 * 60 * 60 - 1; // ±15:59:59
static constexpr const int32_t MIN_OFFSET = -MAX_OFFSET;
static constexpr const uint64_t OFFSET_MICROS = 1000000;

uint64_t bits;

// Offsets are reverse ordered e.g., 13:00:00+01 < 12:00:00+00 < 11:00:00-01
// Because we encode them as the low order bits,
// they are also biased into an unsigned integer: (-16, 16) => (32, 0)
static inline uint64_t encode_offset(int32_t offset) { // NOLINT
return uint64_t(MAX_OFFSET - offset);
}
static inline int32_t decode_offset(uint64_t bits) { // NOLINT
return MAX_OFFSET - int32_t(bits & OFFSET_MASK);
}

static inline uint64_t encode_micros(int64_t micros) { // NOLINT
return uint64_t(micros) << OFFSET_BITS;
}
static inline int64_t decode_micros(uint64_t bits) { // NOLINT
return int64_t(bits >> OFFSET_BITS);
}

dtime_tz_t() = default;

inline dtime_tz_t(dtime_t t, int32_t offset)
: bits((uint64_t(t.micros) << OFFSET_BITS) | uint64_t(MAX_OFFSET - offset)) {
inline dtime_tz_t(dtime_t t, int32_t offset) : bits(encode_micros(t.micros) | encode_offset(offset)) {
}
explicit inline dtime_tz_t(uint64_t bits_p) : bits(bits_p) {
}

inline dtime_t time() const { // NOLINT
return dtime_t(bits >> OFFSET_BITS);
return dtime_t(decode_micros(bits));
}

inline int32_t offset() const { // NOLINT
return MAX_OFFSET - int32_t(bits & OFFSET_MASK);
return decode_offset(bits);
}

// Times are compared after adjusting to offset +00:00:00, e.g., 13:01:00+01 > 12:00:00+00
// Because we encode them as the high order bits,
// they are biased by the maximum offset: (0, 24) => (0, 56)
inline uint64_t sort_key() const { // NOLINT
return bits + encode_micros((bits & OFFSET_MASK) * OFFSET_MICROS);
}

// comparison operators
Expand All @@ -119,16 +144,16 @@ struct dtime_tz_t { // NOLINT
return bits != rhs.bits;
};
inline bool operator<=(const dtime_tz_t &rhs) const {
return bits <= rhs.bits;
return sort_key() <= rhs.sort_key();
};
inline bool operator<(const dtime_tz_t &rhs) const {
return bits < rhs.bits;
return sort_key() < rhs.sort_key();
};
inline bool operator>(const dtime_tz_t &rhs) const {
return bits > rhs.bits;
return sort_key() > rhs.sort_key();
};
inline bool operator>=(const dtime_tz_t &rhs) const {
return bits >= rhs.bits;
return sort_key() >= rhs.sort_key();
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,15 @@ struct TimezoneMinuteFun {
static ScalarFunctionSet GetFunctions();
};

struct TimeTZSortKeyFun {
static constexpr const char *Name = "timetz_byte_comparable";
static constexpr const char *Parameters = "time_tz";
static constexpr const char *Description = "Converts a TIME WITH TIME ZONE to an integer sort key";
static constexpr const char *Example = "timetz_byte_comparable('18:18:16.21-07:00'::TIME_TZ)";

static ScalarFunction GetFunction();
};

struct ToCenturiesFun {
static constexpr const char *Name = "to_centuries";
static constexpr const char *Parameters = "integer";
Expand Down

0 comments on commit bab7543

Please sign in to comment.