duckdb 0.6.1-dev19.0 → 0.6.1-dev30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/duckdb.cpp +13 -0
- package/src/duckdb.hpp +1175 -1032
- package/src/parquet-amalgamation.cpp +36731 -36731
package/src/duckdb.hpp
CHANGED
|
@@ -11,8 +11,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
|
11
11
|
#pragma once
|
|
12
12
|
#define DUCKDB_AMALGAMATION 1
|
|
13
13
|
#define DUCKDB_AMALGAMATION_EXTENDED 1
|
|
14
|
-
#define DUCKDB_SOURCE_ID "
|
|
15
|
-
#define DUCKDB_VERSION "v0.6.1-
|
|
14
|
+
#define DUCKDB_SOURCE_ID "7f70cbe4c6"
|
|
15
|
+
#define DUCKDB_VERSION "v0.6.1-dev30"
|
|
16
16
|
//===----------------------------------------------------------------------===//
|
|
17
17
|
// DuckDB
|
|
18
18
|
//
|
|
@@ -677,124 +677,6 @@ class Value;
|
|
|
677
677
|
class TypeCatalogEntry;
|
|
678
678
|
class Vector;
|
|
679
679
|
class ClientContext;
|
|
680
|
-
//! Type used to represent dates (days since 1970-01-01)
|
|
681
|
-
struct date_t { // NOLINT
|
|
682
|
-
int32_t days;
|
|
683
|
-
|
|
684
|
-
date_t() = default;
|
|
685
|
-
explicit inline date_t(int32_t days_p) : days(days_p) {}
|
|
686
|
-
|
|
687
|
-
// explicit conversion
|
|
688
|
-
explicit inline operator int32_t() const {return days;}
|
|
689
|
-
|
|
690
|
-
// comparison operators
|
|
691
|
-
inline bool operator==(const date_t &rhs) const {return days == rhs.days;};
|
|
692
|
-
inline bool operator!=(const date_t &rhs) const {return days != rhs.days;};
|
|
693
|
-
inline bool operator<=(const date_t &rhs) const {return days <= rhs.days;};
|
|
694
|
-
inline bool operator<(const date_t &rhs) const {return days < rhs.days;};
|
|
695
|
-
inline bool operator>(const date_t &rhs) const {return days > rhs.days;};
|
|
696
|
-
inline bool operator>=(const date_t &rhs) const {return days >= rhs.days;};
|
|
697
|
-
|
|
698
|
-
// arithmetic operators
|
|
699
|
-
inline date_t operator+(const int32_t &days) const {return date_t(this->days + days);};
|
|
700
|
-
inline date_t operator-(const int32_t &days) const {return date_t(this->days - days);};
|
|
701
|
-
|
|
702
|
-
// in-place operators
|
|
703
|
-
inline date_t &operator+=(const int32_t &days) {this->days += days; return *this;};
|
|
704
|
-
inline date_t &operator-=(const int32_t &days) {this->days -= days; return *this;};
|
|
705
|
-
|
|
706
|
-
// special values
|
|
707
|
-
static inline date_t infinity() {return date_t(std::numeric_limits<int32_t>::max()); } // NOLINT
|
|
708
|
-
static inline date_t ninfinity() {return date_t(-std::numeric_limits<int32_t>::max()); } // NOLINT
|
|
709
|
-
static inline date_t epoch() {return date_t(0); } // NOLINT
|
|
710
|
-
};
|
|
711
|
-
|
|
712
|
-
//! Type used to represent time (microseconds)
|
|
713
|
-
struct dtime_t { // NOLINT
|
|
714
|
-
int64_t micros;
|
|
715
|
-
|
|
716
|
-
dtime_t() = default;
|
|
717
|
-
explicit inline dtime_t(int64_t micros_p) : micros(micros_p) {}
|
|
718
|
-
inline dtime_t& operator=(int64_t micros_p) {micros = micros_p; return *this;}
|
|
719
|
-
|
|
720
|
-
// explicit conversion
|
|
721
|
-
explicit inline operator int64_t() const {return micros;}
|
|
722
|
-
explicit inline operator double() const {return micros;}
|
|
723
|
-
|
|
724
|
-
// comparison operators
|
|
725
|
-
inline bool operator==(const dtime_t &rhs) const {return micros == rhs.micros;};
|
|
726
|
-
inline bool operator!=(const dtime_t &rhs) const {return micros != rhs.micros;};
|
|
727
|
-
inline bool operator<=(const dtime_t &rhs) const {return micros <= rhs.micros;};
|
|
728
|
-
inline bool operator<(const dtime_t &rhs) const {return micros < rhs.micros;};
|
|
729
|
-
inline bool operator>(const dtime_t &rhs) const {return micros > rhs.micros;};
|
|
730
|
-
inline bool operator>=(const dtime_t &rhs) const {return micros >= rhs.micros;};
|
|
731
|
-
|
|
732
|
-
// arithmetic operators
|
|
733
|
-
inline dtime_t operator+(const int64_t µs) const {return dtime_t(this->micros + micros);};
|
|
734
|
-
inline dtime_t operator+(const double µs) const {return dtime_t(this->micros + int64_t(micros));};
|
|
735
|
-
inline dtime_t operator-(const int64_t µs) const {return dtime_t(this->micros - micros);};
|
|
736
|
-
inline dtime_t operator*(const idx_t &copies) const {return dtime_t(this->micros * copies);};
|
|
737
|
-
inline dtime_t operator/(const idx_t &copies) const {return dtime_t(this->micros / copies);};
|
|
738
|
-
inline int64_t operator-(const dtime_t &other) const {return this->micros - other.micros;};
|
|
739
|
-
|
|
740
|
-
// in-place operators
|
|
741
|
-
inline dtime_t &operator+=(const int64_t µs) {this->micros += micros; return *this;};
|
|
742
|
-
inline dtime_t &operator-=(const int64_t µs) {this->micros -= micros; return *this;};
|
|
743
|
-
inline dtime_t &operator+=(const dtime_t &other) {this->micros += other.micros; return *this;};
|
|
744
|
-
|
|
745
|
-
// special values
|
|
746
|
-
static inline dtime_t allballs() {return dtime_t(0); } // NOLINT
|
|
747
|
-
};
|
|
748
|
-
|
|
749
|
-
struct dtime_tz_t : public dtime_t {};
|
|
750
|
-
|
|
751
|
-
//! Type used to represent timestamps (seconds,microseconds,milliseconds or nanoseconds since 1970-01-01)
|
|
752
|
-
struct timestamp_t { // NOLINT
|
|
753
|
-
int64_t value;
|
|
754
|
-
|
|
755
|
-
timestamp_t() = default;
|
|
756
|
-
explicit inline timestamp_t(int64_t value_p) : value(value_p) {}
|
|
757
|
-
inline timestamp_t& operator=(int64_t value_p) {value = value_p; return *this;}
|
|
758
|
-
|
|
759
|
-
// explicit conversion
|
|
760
|
-
explicit inline operator int64_t() const {return value;}
|
|
761
|
-
|
|
762
|
-
// comparison operators
|
|
763
|
-
inline bool operator==(const timestamp_t &rhs) const {return value == rhs.value;};
|
|
764
|
-
inline bool operator!=(const timestamp_t &rhs) const {return value != rhs.value;};
|
|
765
|
-
inline bool operator<=(const timestamp_t &rhs) const {return value <= rhs.value;};
|
|
766
|
-
inline bool operator<(const timestamp_t &rhs) const {return value < rhs.value;};
|
|
767
|
-
inline bool operator>(const timestamp_t &rhs) const {return value > rhs.value;};
|
|
768
|
-
inline bool operator>=(const timestamp_t &rhs) const {return value >= rhs.value;};
|
|
769
|
-
|
|
770
|
-
// arithmetic operators
|
|
771
|
-
inline timestamp_t operator+(const double &value) const {return timestamp_t(this->value + int64_t(value));};
|
|
772
|
-
inline int64_t operator-(const timestamp_t &other) const {return this->value - other.value;};
|
|
773
|
-
|
|
774
|
-
// in-place operators
|
|
775
|
-
inline timestamp_t &operator+=(const int64_t &value) {this->value += value; return *this;};
|
|
776
|
-
inline timestamp_t &operator-=(const int64_t &value) {this->value -= value; return *this;};
|
|
777
|
-
|
|
778
|
-
// special values
|
|
779
|
-
static inline timestamp_t infinity() {return timestamp_t(std::numeric_limits<int64_t>::max()); } // NOLINT
|
|
780
|
-
static inline timestamp_t ninfinity() {return timestamp_t(-std::numeric_limits<int64_t>::max()); } // NOLINT
|
|
781
|
-
static inline timestamp_t epoch() {return timestamp_t(0); } // NOLINT
|
|
782
|
-
};
|
|
783
|
-
|
|
784
|
-
struct timestamp_tz_t : public timestamp_t {};
|
|
785
|
-
struct timestamp_ns_t : public timestamp_t {};
|
|
786
|
-
struct timestamp_ms_t : public timestamp_t {};
|
|
787
|
-
struct timestamp_sec_t : public timestamp_t {};
|
|
788
|
-
|
|
789
|
-
struct interval_t {
|
|
790
|
-
int32_t months;
|
|
791
|
-
int32_t days;
|
|
792
|
-
int64_t micros;
|
|
793
|
-
|
|
794
|
-
inline bool operator==(const interval_t &rhs) const {
|
|
795
|
-
return this->days == rhs.days && this->months == rhs.months && this->micros == rhs.micros;
|
|
796
|
-
}
|
|
797
|
-
};
|
|
798
680
|
|
|
799
681
|
struct hugeint_t {
|
|
800
682
|
public:
|
|
@@ -1249,65 +1131,12 @@ struct AggregateStateType {
|
|
|
1249
1131
|
DUCKDB_API static const aggregate_state_t &GetStateType(const LogicalType &type);
|
|
1250
1132
|
};
|
|
1251
1133
|
|
|
1252
|
-
|
|
1253
1134
|
DUCKDB_API string LogicalTypeIdToString(LogicalTypeId type);
|
|
1254
1135
|
|
|
1255
1136
|
DUCKDB_API LogicalTypeId TransformStringToLogicalTypeId(const string &str);
|
|
1256
1137
|
|
|
1257
1138
|
DUCKDB_API LogicalType TransformStringToLogicalType(const string &str);
|
|
1258
1139
|
|
|
1259
|
-
//! Returns the PhysicalType for the given type
|
|
1260
|
-
template <class T>
|
|
1261
|
-
PhysicalType GetTypeId() {
|
|
1262
|
-
if (std::is_same<T, bool>()) {
|
|
1263
|
-
return PhysicalType::BOOL;
|
|
1264
|
-
} else if (std::is_same<T, int8_t>()) {
|
|
1265
|
-
return PhysicalType::INT8;
|
|
1266
|
-
} else if (std::is_same<T, int16_t>()) {
|
|
1267
|
-
return PhysicalType::INT16;
|
|
1268
|
-
} else if (std::is_same<T, int32_t>()) {
|
|
1269
|
-
return PhysicalType::INT32;
|
|
1270
|
-
} else if (std::is_same<T, int64_t>()) {
|
|
1271
|
-
return PhysicalType::INT64;
|
|
1272
|
-
} else if (std::is_same<T, uint8_t>()) {
|
|
1273
|
-
return PhysicalType::UINT8;
|
|
1274
|
-
} else if (std::is_same<T, uint16_t>()) {
|
|
1275
|
-
return PhysicalType::UINT16;
|
|
1276
|
-
} else if (std::is_same<T, uint32_t>()) {
|
|
1277
|
-
return PhysicalType::UINT32;
|
|
1278
|
-
} else if (std::is_same<T, uint64_t>()) {
|
|
1279
|
-
return PhysicalType::UINT64;
|
|
1280
|
-
} else if (std::is_same<T, hugeint_t>()) {
|
|
1281
|
-
return PhysicalType::INT128;
|
|
1282
|
-
} else if (std::is_same<T, date_t>()) {
|
|
1283
|
-
return PhysicalType::INT32;
|
|
1284
|
-
} else if (std::is_same<T, dtime_t>()) {
|
|
1285
|
-
return PhysicalType::INT64;
|
|
1286
|
-
} else if (std::is_same<T, timestamp_t>()) {
|
|
1287
|
-
return PhysicalType::INT64;
|
|
1288
|
-
} else if (std::is_same<T, float>()) {
|
|
1289
|
-
return PhysicalType::FLOAT;
|
|
1290
|
-
} else if (std::is_same<T, double>()) {
|
|
1291
|
-
return PhysicalType::DOUBLE;
|
|
1292
|
-
} else if (std::is_same<T, const char *>() || std::is_same<T, char *>() || std::is_same<T, string_t>()) {
|
|
1293
|
-
return PhysicalType::VARCHAR;
|
|
1294
|
-
} else if (std::is_same<T, interval_t>()) {
|
|
1295
|
-
return PhysicalType::INTERVAL;
|
|
1296
|
-
} else {
|
|
1297
|
-
return PhysicalType::INVALID;
|
|
1298
|
-
}
|
|
1299
|
-
}
|
|
1300
|
-
|
|
1301
|
-
template<class T>
|
|
1302
|
-
bool TypeIsNumber() {
|
|
1303
|
-
return std::is_integral<T>() || std::is_floating_point<T>() || std::is_same<T, hugeint_t>();
|
|
1304
|
-
}
|
|
1305
|
-
|
|
1306
|
-
template <class T>
|
|
1307
|
-
bool IsValidType() {
|
|
1308
|
-
return GetTypeId<T>() != PhysicalType::INVALID;
|
|
1309
|
-
}
|
|
1310
|
-
|
|
1311
1140
|
//! The PhysicalType used by the row identifiers column
|
|
1312
1141
|
extern const PhysicalType ROW_TYPE;
|
|
1313
1142
|
|
|
@@ -1318,11 +1147,6 @@ bool TypeIsIntegral(PhysicalType type);
|
|
|
1318
1147
|
bool TypeIsNumeric(PhysicalType type);
|
|
1319
1148
|
bool TypeIsInteger(PhysicalType type);
|
|
1320
1149
|
|
|
1321
|
-
template <class T>
|
|
1322
|
-
bool IsIntegerType() {
|
|
1323
|
-
return TypeIsIntegral(GetTypeId<T>());
|
|
1324
|
-
}
|
|
1325
|
-
|
|
1326
1150
|
bool ApproxEqual(float l, float r);
|
|
1327
1151
|
bool ApproxEqual(double l, double r);
|
|
1328
1152
|
|
|
@@ -1337,87 +1161,6 @@ struct aggregate_state_t {
|
|
|
1337
1161
|
|
|
1338
1162
|
} // namespace duckdb
|
|
1339
1163
|
|
|
1340
|
-
namespace std {
|
|
1341
|
-
|
|
1342
|
-
//! Date
|
|
1343
|
-
template <>
|
|
1344
|
-
struct hash<duckdb::date_t>
|
|
1345
|
-
{
|
|
1346
|
-
std::size_t operator()(const duckdb::date_t& k) const
|
|
1347
|
-
{
|
|
1348
|
-
using std::hash;
|
|
1349
|
-
return hash<int32_t>()((int32_t)k);
|
|
1350
|
-
}
|
|
1351
|
-
};
|
|
1352
|
-
|
|
1353
|
-
//! Time
|
|
1354
|
-
template <>
|
|
1355
|
-
struct hash<duckdb::dtime_t>
|
|
1356
|
-
{
|
|
1357
|
-
std::size_t operator()(const duckdb::dtime_t& k) const
|
|
1358
|
-
{
|
|
1359
|
-
using std::hash;
|
|
1360
|
-
return hash<int64_t>()((int64_t)k);
|
|
1361
|
-
}
|
|
1362
|
-
};
|
|
1363
|
-
template <>
|
|
1364
|
-
struct hash<duckdb::dtime_tz_t>
|
|
1365
|
-
{
|
|
1366
|
-
std::size_t operator()(const duckdb::dtime_tz_t& k) const
|
|
1367
|
-
{
|
|
1368
|
-
using std::hash;
|
|
1369
|
-
return hash<int64_t>()((int64_t)k);
|
|
1370
|
-
}
|
|
1371
|
-
};
|
|
1372
|
-
|
|
1373
|
-
//! Timestamp
|
|
1374
|
-
template <>
|
|
1375
|
-
struct hash<duckdb::timestamp_t>
|
|
1376
|
-
{
|
|
1377
|
-
std::size_t operator()(const duckdb::timestamp_t& k) const
|
|
1378
|
-
{
|
|
1379
|
-
using std::hash;
|
|
1380
|
-
return hash<int64_t>()((int64_t)k);
|
|
1381
|
-
}
|
|
1382
|
-
};
|
|
1383
|
-
template <>
|
|
1384
|
-
struct hash<duckdb::timestamp_ms_t>
|
|
1385
|
-
{
|
|
1386
|
-
std::size_t operator()(const duckdb::timestamp_ms_t& k) const
|
|
1387
|
-
{
|
|
1388
|
-
using std::hash;
|
|
1389
|
-
return hash<int64_t>()((int64_t)k);
|
|
1390
|
-
}
|
|
1391
|
-
};
|
|
1392
|
-
template <>
|
|
1393
|
-
struct hash<duckdb::timestamp_ns_t>
|
|
1394
|
-
{
|
|
1395
|
-
std::size_t operator()(const duckdb::timestamp_ns_t& k) const
|
|
1396
|
-
{
|
|
1397
|
-
using std::hash;
|
|
1398
|
-
return hash<int64_t>()((int64_t)k);
|
|
1399
|
-
}
|
|
1400
|
-
};
|
|
1401
|
-
template <>
|
|
1402
|
-
struct hash<duckdb::timestamp_sec_t>
|
|
1403
|
-
{
|
|
1404
|
-
std::size_t operator()(const duckdb::timestamp_sec_t& k) const
|
|
1405
|
-
{
|
|
1406
|
-
using std::hash;
|
|
1407
|
-
return hash<int64_t>()((int64_t)k);
|
|
1408
|
-
}
|
|
1409
|
-
};
|
|
1410
|
-
template <>
|
|
1411
|
-
struct hash<duckdb::timestamp_tz_t>
|
|
1412
|
-
{
|
|
1413
|
-
std::size_t operator()(const duckdb::timestamp_tz_t& k) const
|
|
1414
|
-
{
|
|
1415
|
-
using std::hash;
|
|
1416
|
-
return hash<int64_t>()((int64_t)k);
|
|
1417
|
-
}
|
|
1418
|
-
};
|
|
1419
|
-
}
|
|
1420
|
-
|
|
1421
1164
|
|
|
1422
1165
|
namespace duckdb {
|
|
1423
1166
|
|
|
@@ -2949,82 +2692,1003 @@ public:
|
|
|
2949
2692
|
|
|
2950
2693
|
|
|
2951
2694
|
|
|
2695
|
+
//===----------------------------------------------------------------------===//
|
|
2696
|
+
// DuckDB
|
|
2697
|
+
//
|
|
2698
|
+
// duckdb/common/types/timestamp.hpp
|
|
2699
|
+
//
|
|
2700
|
+
//
|
|
2701
|
+
//===----------------------------------------------------------------------===//
|
|
2952
2702
|
|
|
2953
|
-
namespace duckdb {
|
|
2954
2703
|
|
|
2955
|
-
class CastFunctionSet;
|
|
2956
|
-
class Deserializer;
|
|
2957
|
-
class Serializer;
|
|
2958
|
-
struct GetCastFunctionInput;
|
|
2959
2704
|
|
|
2960
|
-
//! The Value object holds a single arbitrary value of any type that can be
|
|
2961
|
-
//! stored in the database.
|
|
2962
|
-
class Value {
|
|
2963
|
-
friend struct StringValue;
|
|
2964
|
-
friend struct StructValue;
|
|
2965
|
-
friend struct ListValue;
|
|
2966
|
-
friend struct UnionValue;
|
|
2967
2705
|
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
//! Create a FLOAT value
|
|
2976
|
-
DUCKDB_API Value(float val); // NOLINT: Allow implicit conversion from `float`
|
|
2977
|
-
//! Create a DOUBLE value
|
|
2978
|
-
DUCKDB_API Value(double val); // NOLINT: Allow implicit conversion from `double`
|
|
2979
|
-
//! Create a VARCHAR value
|
|
2980
|
-
DUCKDB_API Value(const char *val); // NOLINT: Allow implicit conversion from `const char *`
|
|
2981
|
-
//! Create a NULL value
|
|
2982
|
-
DUCKDB_API Value(std::nullptr_t val); // NOLINT: Allow implicit conversion from `nullptr_t`
|
|
2983
|
-
//! Create a VARCHAR value
|
|
2984
|
-
DUCKDB_API Value(string_t val); // NOLINT: Allow implicit conversion from `string_t`
|
|
2985
|
-
//! Create a VARCHAR value
|
|
2986
|
-
DUCKDB_API Value(string val); // NOLINT: Allow implicit conversion from `string`
|
|
2987
|
-
//! Copy constructor
|
|
2988
|
-
DUCKDB_API Value(const Value &other);
|
|
2989
|
-
//! Move constructor
|
|
2990
|
-
DUCKDB_API Value(Value &&other) noexcept;
|
|
2991
|
-
//! Destructor
|
|
2992
|
-
DUCKDB_API ~Value();
|
|
2706
|
+
//===----------------------------------------------------------------------===//
|
|
2707
|
+
// DuckDB
|
|
2708
|
+
//
|
|
2709
|
+
// duckdb/common/limits.hpp
|
|
2710
|
+
//
|
|
2711
|
+
//
|
|
2712
|
+
//===----------------------------------------------------------------------===//
|
|
2993
2713
|
|
|
2994
|
-
// copy assignment
|
|
2995
|
-
DUCKDB_API Value &operator=(const Value &other);
|
|
2996
|
-
// move assignment
|
|
2997
|
-
DUCKDB_API Value &operator=(Value &&other) noexcept;
|
|
2998
2714
|
|
|
2999
|
-
|
|
3000
|
-
|
|
2715
|
+
|
|
2716
|
+
|
|
2717
|
+
|
|
2718
|
+
namespace duckdb {
|
|
2719
|
+
|
|
2720
|
+
template <class T>
|
|
2721
|
+
struct NumericLimits {
|
|
2722
|
+
DUCKDB_API static T Minimum();
|
|
2723
|
+
DUCKDB_API static T Maximum();
|
|
2724
|
+
DUCKDB_API static bool IsSigned();
|
|
2725
|
+
DUCKDB_API static idx_t Digits();
|
|
2726
|
+
};
|
|
2727
|
+
|
|
2728
|
+
template <>
|
|
2729
|
+
struct NumericLimits<int8_t> {
|
|
2730
|
+
DUCKDB_API static int8_t Minimum();
|
|
2731
|
+
DUCKDB_API static int8_t Maximum();
|
|
2732
|
+
DUCKDB_API static bool IsSigned() {
|
|
2733
|
+
return true;
|
|
3001
2734
|
}
|
|
3002
|
-
|
|
3003
|
-
return
|
|
2735
|
+
DUCKDB_API static idx_t Digits() {
|
|
2736
|
+
return 3;
|
|
3004
2737
|
}
|
|
3005
|
-
|
|
3006
|
-
|
|
2738
|
+
};
|
|
2739
|
+
template <>
|
|
2740
|
+
struct NumericLimits<int16_t> {
|
|
2741
|
+
DUCKDB_API static int16_t Minimum();
|
|
2742
|
+
DUCKDB_API static int16_t Maximum();
|
|
2743
|
+
DUCKDB_API static bool IsSigned() {
|
|
2744
|
+
return true;
|
|
3007
2745
|
}
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
DUCKDB_API static
|
|
3015
|
-
DUCKDB_API static
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
DUCKDB_API static
|
|
3027
|
-
|
|
2746
|
+
DUCKDB_API static idx_t Digits() {
|
|
2747
|
+
return 5;
|
|
2748
|
+
}
|
|
2749
|
+
};
|
|
2750
|
+
template <>
|
|
2751
|
+
struct NumericLimits<int32_t> {
|
|
2752
|
+
DUCKDB_API static int32_t Minimum();
|
|
2753
|
+
DUCKDB_API static int32_t Maximum();
|
|
2754
|
+
DUCKDB_API static bool IsSigned() {
|
|
2755
|
+
return true;
|
|
2756
|
+
}
|
|
2757
|
+
DUCKDB_API static idx_t Digits() {
|
|
2758
|
+
return 10;
|
|
2759
|
+
}
|
|
2760
|
+
};
|
|
2761
|
+
template <>
|
|
2762
|
+
struct NumericLimits<int64_t> {
|
|
2763
|
+
DUCKDB_API static int64_t Minimum();
|
|
2764
|
+
DUCKDB_API static int64_t Maximum();
|
|
2765
|
+
DUCKDB_API static bool IsSigned() {
|
|
2766
|
+
return true;
|
|
2767
|
+
}
|
|
2768
|
+
DUCKDB_API static idx_t Digits() {
|
|
2769
|
+
return 19;
|
|
2770
|
+
}
|
|
2771
|
+
};
|
|
2772
|
+
template <>
|
|
2773
|
+
struct NumericLimits<hugeint_t> {
|
|
2774
|
+
DUCKDB_API static hugeint_t Minimum();
|
|
2775
|
+
DUCKDB_API static hugeint_t Maximum();
|
|
2776
|
+
DUCKDB_API static bool IsSigned() {
|
|
2777
|
+
return true;
|
|
2778
|
+
}
|
|
2779
|
+
DUCKDB_API static idx_t Digits() {
|
|
2780
|
+
return 39;
|
|
2781
|
+
}
|
|
2782
|
+
};
|
|
2783
|
+
template <>
|
|
2784
|
+
struct NumericLimits<uint8_t> {
|
|
2785
|
+
DUCKDB_API static uint8_t Minimum();
|
|
2786
|
+
DUCKDB_API static uint8_t Maximum();
|
|
2787
|
+
DUCKDB_API static bool IsSigned() {
|
|
2788
|
+
return false;
|
|
2789
|
+
}
|
|
2790
|
+
DUCKDB_API static idx_t Digits() {
|
|
2791
|
+
return 3;
|
|
2792
|
+
}
|
|
2793
|
+
};
|
|
2794
|
+
template <>
|
|
2795
|
+
struct NumericLimits<uint16_t> {
|
|
2796
|
+
DUCKDB_API static uint16_t Minimum();
|
|
2797
|
+
DUCKDB_API static uint16_t Maximum();
|
|
2798
|
+
DUCKDB_API static bool IsSigned() {
|
|
2799
|
+
return false;
|
|
2800
|
+
}
|
|
2801
|
+
DUCKDB_API static idx_t Digits() {
|
|
2802
|
+
return 5;
|
|
2803
|
+
}
|
|
2804
|
+
};
|
|
2805
|
+
template <>
|
|
2806
|
+
struct NumericLimits<uint32_t> {
|
|
2807
|
+
DUCKDB_API static uint32_t Minimum();
|
|
2808
|
+
DUCKDB_API static uint32_t Maximum();
|
|
2809
|
+
DUCKDB_API static bool IsSigned() {
|
|
2810
|
+
return false;
|
|
2811
|
+
}
|
|
2812
|
+
DUCKDB_API static idx_t Digits() {
|
|
2813
|
+
return 10;
|
|
2814
|
+
}
|
|
2815
|
+
};
|
|
2816
|
+
template <>
|
|
2817
|
+
struct NumericLimits<uint64_t> {
|
|
2818
|
+
DUCKDB_API static uint64_t Minimum();
|
|
2819
|
+
DUCKDB_API static uint64_t Maximum();
|
|
2820
|
+
DUCKDB_API static bool IsSigned() {
|
|
2821
|
+
return false;
|
|
2822
|
+
}
|
|
2823
|
+
DUCKDB_API static idx_t Digits() {
|
|
2824
|
+
return 20;
|
|
2825
|
+
}
|
|
2826
|
+
};
|
|
2827
|
+
template <>
|
|
2828
|
+
struct NumericLimits<float> {
|
|
2829
|
+
DUCKDB_API static float Minimum();
|
|
2830
|
+
DUCKDB_API static float Maximum();
|
|
2831
|
+
DUCKDB_API static bool IsSigned() {
|
|
2832
|
+
return true;
|
|
2833
|
+
}
|
|
2834
|
+
DUCKDB_API static idx_t Digits() {
|
|
2835
|
+
return 127;
|
|
2836
|
+
}
|
|
2837
|
+
};
|
|
2838
|
+
template <>
|
|
2839
|
+
struct NumericLimits<double> {
|
|
2840
|
+
DUCKDB_API static double Minimum();
|
|
2841
|
+
DUCKDB_API static double Maximum();
|
|
2842
|
+
DUCKDB_API static bool IsSigned() {
|
|
2843
|
+
return true;
|
|
2844
|
+
}
|
|
2845
|
+
DUCKDB_API static idx_t Digits() {
|
|
2846
|
+
return 250;
|
|
2847
|
+
}
|
|
2848
|
+
};
|
|
2849
|
+
|
|
2850
|
+
} // namespace duckdb
|
|
2851
|
+
|
|
2852
|
+
|
|
2853
|
+
|
|
2854
|
+
|
|
2855
|
+
#include <functional>
|
|
2856
|
+
|
|
2857
|
+
namespace duckdb {
|
|
2858
|
+
|
|
2859
|
+
struct date_t;
|
|
2860
|
+
struct dtime_t;
|
|
2861
|
+
|
|
2862
|
+
//! Type used to represent timestamps (seconds,microseconds,milliseconds or nanoseconds since 1970-01-01)
|
|
2863
|
+
struct timestamp_t { // NOLINT
|
|
2864
|
+
int64_t value;
|
|
2865
|
+
|
|
2866
|
+
timestamp_t() = default;
|
|
2867
|
+
explicit inline timestamp_t(int64_t value_p) : value(value_p) {
|
|
2868
|
+
}
|
|
2869
|
+
inline timestamp_t &operator=(int64_t value_p) {
|
|
2870
|
+
value = value_p;
|
|
2871
|
+
return *this;
|
|
2872
|
+
}
|
|
2873
|
+
|
|
2874
|
+
// explicit conversion
|
|
2875
|
+
explicit inline operator int64_t() const {
|
|
2876
|
+
return value;
|
|
2877
|
+
}
|
|
2878
|
+
|
|
2879
|
+
// comparison operators
|
|
2880
|
+
inline bool operator==(const timestamp_t &rhs) const {
|
|
2881
|
+
return value == rhs.value;
|
|
2882
|
+
};
|
|
2883
|
+
inline bool operator!=(const timestamp_t &rhs) const {
|
|
2884
|
+
return value != rhs.value;
|
|
2885
|
+
};
|
|
2886
|
+
inline bool operator<=(const timestamp_t &rhs) const {
|
|
2887
|
+
return value <= rhs.value;
|
|
2888
|
+
};
|
|
2889
|
+
inline bool operator<(const timestamp_t &rhs) const {
|
|
2890
|
+
return value < rhs.value;
|
|
2891
|
+
};
|
|
2892
|
+
inline bool operator>(const timestamp_t &rhs) const {
|
|
2893
|
+
return value > rhs.value;
|
|
2894
|
+
};
|
|
2895
|
+
inline bool operator>=(const timestamp_t &rhs) const {
|
|
2896
|
+
return value >= rhs.value;
|
|
2897
|
+
};
|
|
2898
|
+
|
|
2899
|
+
// arithmetic operators
|
|
2900
|
+
inline timestamp_t operator+(const double &value) const {
|
|
2901
|
+
return timestamp_t(this->value + int64_t(value));
|
|
2902
|
+
};
|
|
2903
|
+
inline int64_t operator-(const timestamp_t &other) const {
|
|
2904
|
+
return this->value - other.value;
|
|
2905
|
+
};
|
|
2906
|
+
|
|
2907
|
+
// in-place operators
|
|
2908
|
+
inline timestamp_t &operator+=(const int64_t &value) {
|
|
2909
|
+
this->value += value;
|
|
2910
|
+
return *this;
|
|
2911
|
+
};
|
|
2912
|
+
inline timestamp_t &operator-=(const int64_t &value) {
|
|
2913
|
+
this->value -= value;
|
|
2914
|
+
return *this;
|
|
2915
|
+
};
|
|
2916
|
+
|
|
2917
|
+
// special values
|
|
2918
|
+
static timestamp_t infinity() {
|
|
2919
|
+
return timestamp_t(NumericLimits<int64_t>::Maximum());
|
|
2920
|
+
} // NOLINT
|
|
2921
|
+
static timestamp_t ninfinity() {
|
|
2922
|
+
return timestamp_t(-NumericLimits<int64_t>::Maximum());
|
|
2923
|
+
} // NOLINT
|
|
2924
|
+
static inline timestamp_t epoch() {
|
|
2925
|
+
return timestamp_t(0);
|
|
2926
|
+
} // NOLINT
|
|
2927
|
+
};
|
|
2928
|
+
|
|
2929
|
+
struct timestamp_tz_t : public timestamp_t {};
|
|
2930
|
+
struct timestamp_ns_t : public timestamp_t {};
|
|
2931
|
+
struct timestamp_ms_t : public timestamp_t {};
|
|
2932
|
+
struct timestamp_sec_t : public timestamp_t {};
|
|
2933
|
+
|
|
2934
|
+
//! The Timestamp class is a static class that holds helper functions for the Timestamp
|
|
2935
|
+
//! type.
|
|
2936
|
+
class Timestamp {
|
|
2937
|
+
public:
|
|
2938
|
+
// min timestamp is 290308-12-22 (BC)
|
|
2939
|
+
constexpr static const int32_t MIN_YEAR = -290308;
|
|
2940
|
+
constexpr static const int32_t MIN_MONTH = 12;
|
|
2941
|
+
constexpr static const int32_t MIN_DAY = 22;
|
|
2942
|
+
|
|
2943
|
+
public:
|
|
2944
|
+
//! Convert a string in the format "YYYY-MM-DD hh:mm:ss[.f][-+TH[:tm]]" to a timestamp object
|
|
2945
|
+
DUCKDB_API static timestamp_t FromString(const string &str);
|
|
2946
|
+
//! Convert a string where the offset can also be a time zone string: / [A_Za-z0-9/_]+/
|
|
2947
|
+
//! If has_offset is true, then the result is an instant that was offset from UTC
|
|
2948
|
+
//! If the tz is not empty, the result is still an instant, but the parts can be extracted and applied to the TZ
|
|
2949
|
+
DUCKDB_API static bool TryConvertTimestampTZ(const char *str, idx_t len, timestamp_t &result, bool &has_offset,
|
|
2950
|
+
string_t &tz);
|
|
2951
|
+
DUCKDB_API static bool TryConvertTimestamp(const char *str, idx_t len, timestamp_t &result);
|
|
2952
|
+
DUCKDB_API static timestamp_t FromCString(const char *str, idx_t len);
|
|
2953
|
+
//! Convert a date object to a string in the format "YYYY-MM-DD hh:mm:ss"
|
|
2954
|
+
DUCKDB_API static string ToString(timestamp_t timestamp);
|
|
2955
|
+
|
|
2956
|
+
DUCKDB_API static date_t GetDate(timestamp_t timestamp);
|
|
2957
|
+
|
|
2958
|
+
DUCKDB_API static dtime_t GetTime(timestamp_t timestamp);
|
|
2959
|
+
//! Create a Timestamp object from a specified (date, time) combination
|
|
2960
|
+
DUCKDB_API static timestamp_t FromDatetime(date_t date, dtime_t time);
|
|
2961
|
+
DUCKDB_API static bool TryFromDatetime(date_t date, dtime_t time, timestamp_t &result);
|
|
2962
|
+
|
|
2963
|
+
//! Is the timestamp finite or infinite?
|
|
2964
|
+
static inline bool IsFinite(timestamp_t timestamp) {
|
|
2965
|
+
return timestamp != timestamp_t::infinity() && timestamp != timestamp_t::ninfinity();
|
|
2966
|
+
}
|
|
2967
|
+
|
|
2968
|
+
//! Extract the date and time from a given timestamp object
|
|
2969
|
+
DUCKDB_API static void Convert(timestamp_t date, date_t &out_date, dtime_t &out_time);
|
|
2970
|
+
//! Returns current timestamp
|
|
2971
|
+
DUCKDB_API static timestamp_t GetCurrentTimestamp();
|
|
2972
|
+
|
|
2973
|
+
//! Convert the epoch (in sec) to a timestamp
|
|
2974
|
+
DUCKDB_API static timestamp_t FromEpochSeconds(int64_t ms);
|
|
2975
|
+
//! Convert the epoch (in ms) to a timestamp
|
|
2976
|
+
DUCKDB_API static timestamp_t FromEpochMs(int64_t ms);
|
|
2977
|
+
//! Convert the epoch (in microseconds) to a timestamp
|
|
2978
|
+
DUCKDB_API static timestamp_t FromEpochMicroSeconds(int64_t micros);
|
|
2979
|
+
//! Convert the epoch (in nanoseconds) to a timestamp
|
|
2980
|
+
DUCKDB_API static timestamp_t FromEpochNanoSeconds(int64_t micros);
|
|
2981
|
+
|
|
2982
|
+
//! Convert the epoch (in seconds) to a timestamp
|
|
2983
|
+
DUCKDB_API static int64_t GetEpochSeconds(timestamp_t timestamp);
|
|
2984
|
+
//! Convert the epoch (in ms) to a timestamp
|
|
2985
|
+
DUCKDB_API static int64_t GetEpochMs(timestamp_t timestamp);
|
|
2986
|
+
//! Convert a timestamp to epoch (in microseconds)
|
|
2987
|
+
DUCKDB_API static int64_t GetEpochMicroSeconds(timestamp_t timestamp);
|
|
2988
|
+
//! Convert a timestamp to epoch (in nanoseconds)
|
|
2989
|
+
DUCKDB_API static int64_t GetEpochNanoSeconds(timestamp_t timestamp);
|
|
2990
|
+
|
|
2991
|
+
DUCKDB_API static bool TryParseUTCOffset(const char *str, idx_t &pos, idx_t len, int &hour_offset,
|
|
2992
|
+
int &minute_offset);
|
|
2993
|
+
|
|
2994
|
+
DUCKDB_API static string ConversionError(const string &str);
|
|
2995
|
+
DUCKDB_API static string ConversionError(string_t str);
|
|
2996
|
+
};
|
|
2997
|
+
|
|
2998
|
+
} // namespace duckdb
|
|
2999
|
+
|
|
3000
|
+
namespace std {
|
|
3001
|
+
|
|
3002
|
+
//! Timestamp
|
|
3003
|
+
template <>
|
|
3004
|
+
struct hash<duckdb::timestamp_t> {
|
|
3005
|
+
std::size_t operator()(const duckdb::timestamp_t &k) const {
|
|
3006
|
+
using std::hash;
|
|
3007
|
+
return hash<int64_t>()((int64_t)k);
|
|
3008
|
+
}
|
|
3009
|
+
};
|
|
3010
|
+
template <>
|
|
3011
|
+
struct hash<duckdb::timestamp_ms_t> {
|
|
3012
|
+
std::size_t operator()(const duckdb::timestamp_ms_t &k) const {
|
|
3013
|
+
using std::hash;
|
|
3014
|
+
return hash<int64_t>()((int64_t)k);
|
|
3015
|
+
}
|
|
3016
|
+
};
|
|
3017
|
+
template <>
|
|
3018
|
+
struct hash<duckdb::timestamp_ns_t> {
|
|
3019
|
+
std::size_t operator()(const duckdb::timestamp_ns_t &k) const {
|
|
3020
|
+
using std::hash;
|
|
3021
|
+
return hash<int64_t>()((int64_t)k);
|
|
3022
|
+
}
|
|
3023
|
+
};
|
|
3024
|
+
template <>
|
|
3025
|
+
struct hash<duckdb::timestamp_sec_t> {
|
|
3026
|
+
std::size_t operator()(const duckdb::timestamp_sec_t &k) const {
|
|
3027
|
+
using std::hash;
|
|
3028
|
+
return hash<int64_t>()((int64_t)k);
|
|
3029
|
+
}
|
|
3030
|
+
};
|
|
3031
|
+
template <>
|
|
3032
|
+
struct hash<duckdb::timestamp_tz_t> {
|
|
3033
|
+
std::size_t operator()(const duckdb::timestamp_tz_t &k) const {
|
|
3034
|
+
using std::hash;
|
|
3035
|
+
return hash<int64_t>()((int64_t)k);
|
|
3036
|
+
}
|
|
3037
|
+
};
|
|
3038
|
+
} // namespace std
|
|
3039
|
+
|
|
3040
|
+
//===----------------------------------------------------------------------===//
|
|
3041
|
+
// DuckDB
|
|
3042
|
+
//
|
|
3043
|
+
// duckdb/common/types/date.hpp
|
|
3044
|
+
//
|
|
3045
|
+
//
|
|
3046
|
+
//===----------------------------------------------------------------------===//
|
|
3047
|
+
|
|
3048
|
+
|
|
3049
|
+
|
|
3050
|
+
|
|
3051
|
+
|
|
3052
|
+
|
|
3053
|
+
//===----------------------------------------------------------------------===//
|
|
3054
|
+
// DuckDB
|
|
3055
|
+
//
|
|
3056
|
+
// duckdb/common/types/string_type.hpp
|
|
3057
|
+
//
|
|
3058
|
+
//
|
|
3059
|
+
//===----------------------------------------------------------------------===//
|
|
3060
|
+
|
|
3061
|
+
|
|
3062
|
+
|
|
3063
|
+
|
|
3064
|
+
|
|
3065
|
+
|
|
3066
|
+
#include <cstring>
|
|
3067
|
+
|
|
3068
|
+
namespace duckdb {
|
|
3069
|
+
|
|
3070
|
+
struct string_t {
|
|
3071
|
+
friend struct StringComparisonOperators;
|
|
3072
|
+
friend class StringSegment;
|
|
3073
|
+
|
|
3074
|
+
public:
|
|
3075
|
+
static constexpr idx_t PREFIX_BYTES = 4 * sizeof(char);
|
|
3076
|
+
static constexpr idx_t INLINE_BYTES = 12 * sizeof(char);
|
|
3077
|
+
static constexpr idx_t HEADER_SIZE = sizeof(uint32_t) + PREFIX_BYTES;
|
|
3078
|
+
#ifndef DUCKDB_DEBUG_NO_INLINE
|
|
3079
|
+
static constexpr idx_t PREFIX_LENGTH = PREFIX_BYTES;
|
|
3080
|
+
static constexpr idx_t INLINE_LENGTH = INLINE_BYTES;
|
|
3081
|
+
#else
|
|
3082
|
+
static constexpr idx_t PREFIX_LENGTH = 0;
|
|
3083
|
+
static constexpr idx_t INLINE_LENGTH = 0;
|
|
3084
|
+
#endif
|
|
3085
|
+
|
|
3086
|
+
string_t() = default;
|
|
3087
|
+
explicit string_t(uint32_t len) {
|
|
3088
|
+
value.inlined.length = len;
|
|
3089
|
+
}
|
|
3090
|
+
string_t(const char *data, uint32_t len) {
|
|
3091
|
+
value.inlined.length = len;
|
|
3092
|
+
D_ASSERT(data || GetSize() == 0);
|
|
3093
|
+
if (IsInlined()) {
|
|
3094
|
+
// zero initialize the prefix first
|
|
3095
|
+
// this makes sure that strings with length smaller than 4 still have an equal prefix
|
|
3096
|
+
memset(value.inlined.inlined, 0, INLINE_BYTES);
|
|
3097
|
+
if (GetSize() == 0) {
|
|
3098
|
+
return;
|
|
3099
|
+
}
|
|
3100
|
+
// small string: inlined
|
|
3101
|
+
memcpy(value.inlined.inlined, data, GetSize());
|
|
3102
|
+
} else {
|
|
3103
|
+
// large string: store pointer
|
|
3104
|
+
#ifndef DUCKDB_DEBUG_NO_INLINE
|
|
3105
|
+
memcpy(value.pointer.prefix, data, PREFIX_LENGTH);
|
|
3106
|
+
#else
|
|
3107
|
+
memset(value.pointer.prefix, 0, PREFIX_BYTES);
|
|
3108
|
+
#endif
|
|
3109
|
+
value.pointer.ptr = (char *)data;
|
|
3110
|
+
}
|
|
3111
|
+
}
|
|
3112
|
+
string_t(const char *data) : string_t(data, strlen(data)) { // NOLINT: Allow implicit conversion from `const char*`
|
|
3113
|
+
}
|
|
3114
|
+
string_t(const string &value)
|
|
3115
|
+
: string_t(value.c_str(), value.size()) { // NOLINT: Allow implicit conversion from `const char*`
|
|
3116
|
+
}
|
|
3117
|
+
|
|
3118
|
+
bool IsInlined() const {
|
|
3119
|
+
return GetSize() <= INLINE_LENGTH;
|
|
3120
|
+
}
|
|
3121
|
+
|
|
3122
|
+
//! this is unsafe since the string will not be terminated at the end
|
|
3123
|
+
const char *GetDataUnsafe() const {
|
|
3124
|
+
return IsInlined() ? (const char *)value.inlined.inlined : value.pointer.ptr;
|
|
3125
|
+
}
|
|
3126
|
+
|
|
3127
|
+
char *GetDataWriteable() const {
|
|
3128
|
+
return IsInlined() ? (char *)value.inlined.inlined : value.pointer.ptr;
|
|
3129
|
+
}
|
|
3130
|
+
|
|
3131
|
+
const char *GetPrefix() const {
|
|
3132
|
+
return value.pointer.prefix;
|
|
3133
|
+
}
|
|
3134
|
+
|
|
3135
|
+
idx_t GetSize() const {
|
|
3136
|
+
return value.inlined.length;
|
|
3137
|
+
}
|
|
3138
|
+
|
|
3139
|
+
string GetString() const {
|
|
3140
|
+
return string(GetDataUnsafe(), GetSize());
|
|
3141
|
+
}
|
|
3142
|
+
|
|
3143
|
+
explicit operator string() const {
|
|
3144
|
+
return GetString();
|
|
3145
|
+
}
|
|
3146
|
+
|
|
3147
|
+
void Finalize() {
|
|
3148
|
+
// set trailing NULL byte
|
|
3149
|
+
if (GetSize() <= INLINE_LENGTH) {
|
|
3150
|
+
// fill prefix with zeros if the length is smaller than the prefix length
|
|
3151
|
+
for (idx_t i = GetSize(); i < INLINE_BYTES; i++) {
|
|
3152
|
+
value.inlined.inlined[i] = '\0';
|
|
3153
|
+
}
|
|
3154
|
+
} else {
|
|
3155
|
+
// copy the data into the prefix
|
|
3156
|
+
#ifndef DUCKDB_DEBUG_NO_INLINE
|
|
3157
|
+
auto dataptr = (char *)GetDataUnsafe();
|
|
3158
|
+
memcpy(value.pointer.prefix, dataptr, PREFIX_LENGTH);
|
|
3159
|
+
#else
|
|
3160
|
+
memset(value.pointer.prefix, 0, PREFIX_BYTES);
|
|
3161
|
+
#endif
|
|
3162
|
+
}
|
|
3163
|
+
}
|
|
3164
|
+
|
|
3165
|
+
void Verify() const;
|
|
3166
|
+
void VerifyNull() const;
|
|
3167
|
+
bool operator<(const string_t &r) const {
|
|
3168
|
+
auto this_str = this->GetString();
|
|
3169
|
+
auto r_str = r.GetString();
|
|
3170
|
+
return this_str < r_str;
|
|
3171
|
+
}
|
|
3172
|
+
|
|
3173
|
+
private:
|
|
3174
|
+
union {
|
|
3175
|
+
struct {
|
|
3176
|
+
uint32_t length;
|
|
3177
|
+
char prefix[4];
|
|
3178
|
+
char *ptr;
|
|
3179
|
+
} pointer;
|
|
3180
|
+
struct {
|
|
3181
|
+
uint32_t length;
|
|
3182
|
+
char inlined[12];
|
|
3183
|
+
} inlined;
|
|
3184
|
+
} value;
|
|
3185
|
+
};
|
|
3186
|
+
|
|
3187
|
+
} // namespace duckdb
|
|
3188
|
+
|
|
3189
|
+
|
|
3190
|
+
|
|
3191
|
+
#include <functional>
|
|
3192
|
+
|
|
3193
|
+
namespace duckdb {
|
|
3194
|
+
|
|
3195
|
+
struct timestamp_t;
|
|
3196
|
+
|
|
3197
|
+
//! Type used to represent dates (days since 1970-01-01)
|
|
3198
|
+
struct date_t { // NOLINT
|
|
3199
|
+
int32_t days;
|
|
3200
|
+
|
|
3201
|
+
date_t() = default;
|
|
3202
|
+
explicit inline date_t(int32_t days_p) : days(days_p) {
|
|
3203
|
+
}
|
|
3204
|
+
|
|
3205
|
+
// explicit conversion
|
|
3206
|
+
explicit inline operator int32_t() const {
|
|
3207
|
+
return days;
|
|
3208
|
+
}
|
|
3209
|
+
|
|
3210
|
+
// comparison operators
|
|
3211
|
+
inline bool operator==(const date_t &rhs) const {
|
|
3212
|
+
return days == rhs.days;
|
|
3213
|
+
};
|
|
3214
|
+
inline bool operator!=(const date_t &rhs) const {
|
|
3215
|
+
return days != rhs.days;
|
|
3216
|
+
};
|
|
3217
|
+
inline bool operator<=(const date_t &rhs) const {
|
|
3218
|
+
return days <= rhs.days;
|
|
3219
|
+
};
|
|
3220
|
+
inline bool operator<(const date_t &rhs) const {
|
|
3221
|
+
return days < rhs.days;
|
|
3222
|
+
};
|
|
3223
|
+
inline bool operator>(const date_t &rhs) const {
|
|
3224
|
+
return days > rhs.days;
|
|
3225
|
+
};
|
|
3226
|
+
inline bool operator>=(const date_t &rhs) const {
|
|
3227
|
+
return days >= rhs.days;
|
|
3228
|
+
};
|
|
3229
|
+
|
|
3230
|
+
// arithmetic operators
|
|
3231
|
+
inline date_t operator+(const int32_t &days) const {
|
|
3232
|
+
return date_t(this->days + days);
|
|
3233
|
+
};
|
|
3234
|
+
inline date_t operator-(const int32_t &days) const {
|
|
3235
|
+
return date_t(this->days - days);
|
|
3236
|
+
};
|
|
3237
|
+
|
|
3238
|
+
// in-place operators
|
|
3239
|
+
inline date_t &operator+=(const int32_t &days) {
|
|
3240
|
+
this->days += days;
|
|
3241
|
+
return *this;
|
|
3242
|
+
};
|
|
3243
|
+
inline date_t &operator-=(const int32_t &days) {
|
|
3244
|
+
this->days -= days;
|
|
3245
|
+
return *this;
|
|
3246
|
+
};
|
|
3247
|
+
|
|
3248
|
+
// special values
|
|
3249
|
+
static inline date_t infinity() {
|
|
3250
|
+
return date_t(NumericLimits<int32_t>::Maximum());
|
|
3251
|
+
} // NOLINT
|
|
3252
|
+
static inline date_t ninfinity() {
|
|
3253
|
+
return date_t(-NumericLimits<int32_t>::Maximum());
|
|
3254
|
+
} // NOLINT
|
|
3255
|
+
static inline date_t epoch() {
|
|
3256
|
+
return date_t(0);
|
|
3257
|
+
} // NOLINT
|
|
3258
|
+
};
|
|
3259
|
+
|
|
3260
|
+
//! The Date class is a static class that holds helper functions for the Date type.
|
|
3261
|
+
class Date {
|
|
3262
|
+
public:
|
|
3263
|
+
static const char *PINF; // NOLINT
|
|
3264
|
+
static const char *NINF; // NOLINT
|
|
3265
|
+
static const char *EPOCH; // NOLINT
|
|
3266
|
+
|
|
3267
|
+
static const string_t MONTH_NAMES[12];
|
|
3268
|
+
static const string_t MONTH_NAMES_ABBREVIATED[12];
|
|
3269
|
+
static const string_t DAY_NAMES[7];
|
|
3270
|
+
static const string_t DAY_NAMES_ABBREVIATED[7];
|
|
3271
|
+
static const int32_t NORMAL_DAYS[13];
|
|
3272
|
+
static const int32_t CUMULATIVE_DAYS[13];
|
|
3273
|
+
static const int32_t LEAP_DAYS[13];
|
|
3274
|
+
static const int32_t CUMULATIVE_LEAP_DAYS[13];
|
|
3275
|
+
static const int32_t CUMULATIVE_YEAR_DAYS[401];
|
|
3276
|
+
static const int8_t MONTH_PER_DAY_OF_YEAR[365];
|
|
3277
|
+
static const int8_t LEAP_MONTH_PER_DAY_OF_YEAR[366];
|
|
3278
|
+
|
|
3279
|
+
// min date is 5877642-06-25 (BC) (-2^31+2)
|
|
3280
|
+
constexpr static const int32_t DATE_MIN_YEAR = -5877641;
|
|
3281
|
+
constexpr static const int32_t DATE_MIN_MONTH = 6;
|
|
3282
|
+
constexpr static const int32_t DATE_MIN_DAY = 25;
|
|
3283
|
+
// max date is 5881580-07-10 (2^31-2)
|
|
3284
|
+
constexpr static const int32_t DATE_MAX_YEAR = 5881580;
|
|
3285
|
+
constexpr static const int32_t DATE_MAX_MONTH = 7;
|
|
3286
|
+
constexpr static const int32_t DATE_MAX_DAY = 10;
|
|
3287
|
+
constexpr static const int32_t EPOCH_YEAR = 1970;
|
|
3288
|
+
|
|
3289
|
+
constexpr static const int32_t YEAR_INTERVAL = 400;
|
|
3290
|
+
constexpr static const int32_t DAYS_PER_YEAR_INTERVAL = 146097;
|
|
3291
|
+
|
|
3292
|
+
public:
|
|
3293
|
+
//! Convert a string in the format "YYYY-MM-DD" to a date object
|
|
3294
|
+
DUCKDB_API static date_t FromString(const string &str, bool strict = false);
|
|
3295
|
+
//! Convert a string in the format "YYYY-MM-DD" to a date object
|
|
3296
|
+
DUCKDB_API static date_t FromCString(const char *str, idx_t len, bool strict = false);
|
|
3297
|
+
//! Convert a date object to a string in the format "YYYY-MM-DD"
|
|
3298
|
+
DUCKDB_API static string ToString(date_t date);
|
|
3299
|
+
//! Try to convert text in a buffer to a date; returns true if parsing was successful
|
|
3300
|
+
//! If the date was a "special" value, the special flag will be set.
|
|
3301
|
+
DUCKDB_API static bool TryConvertDate(const char *buf, idx_t len, idx_t &pos, date_t &result, bool &special,
|
|
3302
|
+
bool strict = false);
|
|
3303
|
+
|
|
3304
|
+
//! Create a string "YYYY-MM-DD" from a specified (year, month, day)
|
|
3305
|
+
//! combination
|
|
3306
|
+
DUCKDB_API static string Format(int32_t year, int32_t month, int32_t day);
|
|
3307
|
+
|
|
3308
|
+
//! Extract the year, month and day from a given date object
|
|
3309
|
+
DUCKDB_API static void Convert(date_t date, int32_t &out_year, int32_t &out_month, int32_t &out_day);
|
|
3310
|
+
//! Create a Date object from a specified (year, month, day) combination
|
|
3311
|
+
DUCKDB_API static date_t FromDate(int32_t year, int32_t month, int32_t day);
|
|
3312
|
+
DUCKDB_API static bool TryFromDate(int32_t year, int32_t month, int32_t day, date_t &result);
|
|
3313
|
+
|
|
3314
|
+
//! Returns true if (year) is a leap year, and false otherwise
|
|
3315
|
+
DUCKDB_API static bool IsLeapYear(int32_t year);
|
|
3316
|
+
|
|
3317
|
+
//! Returns true if the specified (year, month, day) combination is a valid
|
|
3318
|
+
//! date
|
|
3319
|
+
DUCKDB_API static bool IsValid(int32_t year, int32_t month, int32_t day);
|
|
3320
|
+
|
|
3321
|
+
//! Returns true if the specified date is finite
|
|
3322
|
+
static inline bool IsFinite(date_t date) {
|
|
3323
|
+
return date != date_t::infinity() && date != date_t::ninfinity();
|
|
3324
|
+
}
|
|
3325
|
+
|
|
3326
|
+
//! The max number of days in a month of a given year
|
|
3327
|
+
DUCKDB_API static int32_t MonthDays(int32_t year, int32_t month);
|
|
3328
|
+
|
|
3329
|
+
//! Extract the epoch from the date (seconds since 1970-01-01)
|
|
3330
|
+
DUCKDB_API static int64_t Epoch(date_t date);
|
|
3331
|
+
//! Extract the epoch from the date (nanoseconds since 1970-01-01)
|
|
3332
|
+
DUCKDB_API static int64_t EpochNanoseconds(date_t date);
|
|
3333
|
+
//! Extract the epoch from the date (microseconds since 1970-01-01)
|
|
3334
|
+
DUCKDB_API static int64_t EpochMicroseconds(date_t date);
|
|
3335
|
+
//! Convert the epoch (seconds since 1970-01-01) to a date_t
|
|
3336
|
+
DUCKDB_API static date_t EpochToDate(int64_t epoch);
|
|
3337
|
+
|
|
3338
|
+
//! Extract the number of days since epoch (days since 1970-01-01)
|
|
3339
|
+
DUCKDB_API static int32_t EpochDays(date_t date);
|
|
3340
|
+
//! Convert the epoch number of days to a date_t
|
|
3341
|
+
DUCKDB_API static date_t EpochDaysToDate(int32_t epoch);
|
|
3342
|
+
|
|
3343
|
+
//! Extract year of a date entry
|
|
3344
|
+
DUCKDB_API static int32_t ExtractYear(date_t date);
|
|
3345
|
+
//! Extract year of a date entry, but optimized to first try the last year found
|
|
3346
|
+
DUCKDB_API static int32_t ExtractYear(date_t date, int32_t *last_year);
|
|
3347
|
+
DUCKDB_API static int32_t ExtractYear(timestamp_t ts, int32_t *last_year);
|
|
3348
|
+
//! Extract month of a date entry
|
|
3349
|
+
DUCKDB_API static int32_t ExtractMonth(date_t date);
|
|
3350
|
+
//! Extract day of a date entry
|
|
3351
|
+
DUCKDB_API static int32_t ExtractDay(date_t date);
|
|
3352
|
+
//! Extract the day of the week (1-7)
|
|
3353
|
+
DUCKDB_API static int32_t ExtractISODayOfTheWeek(date_t date);
|
|
3354
|
+
//! Extract the day of the year
|
|
3355
|
+
DUCKDB_API static int32_t ExtractDayOfTheYear(date_t date);
|
|
3356
|
+
//! Extract the ISO week number
|
|
3357
|
+
//! ISO weeks start on Monday and the first week of a year
|
|
3358
|
+
//! contains January 4 of that year.
|
|
3359
|
+
//! In the ISO week-numbering system, it is possible for early-January dates
|
|
3360
|
+
//! to be part of the 52nd or 53rd week of the previous year.
|
|
3361
|
+
DUCKDB_API static void ExtractISOYearWeek(date_t date, int32_t &year, int32_t &week);
|
|
3362
|
+
DUCKDB_API static int32_t ExtractISOWeekNumber(date_t date);
|
|
3363
|
+
DUCKDB_API static int32_t ExtractISOYearNumber(date_t date);
|
|
3364
|
+
//! Extract the week number as Python handles it.
|
|
3365
|
+
//! Either Monday or Sunday is the first day of the week,
|
|
3366
|
+
//! and any date before the first Monday/Sunday returns week 0
|
|
3367
|
+
//! This is a bit more consistent because week numbers in a year are always incrementing
|
|
3368
|
+
DUCKDB_API static int32_t ExtractWeekNumberRegular(date_t date, bool monday_first = true);
|
|
3369
|
+
//! Returns the date of the monday of the current week.
|
|
3370
|
+
DUCKDB_API static date_t GetMondayOfCurrentWeek(date_t date);
|
|
3371
|
+
|
|
3372
|
+
//! Helper function to parse two digits from a string (e.g. "30" -> 30, "03" -> 3, "3" -> 3)
|
|
3373
|
+
DUCKDB_API static bool ParseDoubleDigit(const char *buf, idx_t len, idx_t &pos, int32_t &result);
|
|
3374
|
+
|
|
3375
|
+
DUCKDB_API static string ConversionError(const string &str);
|
|
3376
|
+
DUCKDB_API static string ConversionError(string_t str);
|
|
3377
|
+
|
|
3378
|
+
private:
|
|
3379
|
+
static void ExtractYearOffset(int32_t &n, int32_t &year, int32_t &year_offset);
|
|
3380
|
+
};
|
|
3381
|
+
|
|
3382
|
+
} // namespace duckdb
|
|
3383
|
+
|
|
3384
|
+
namespace std {
|
|
3385
|
+
|
|
3386
|
+
//! Date
|
|
3387
|
+
template <>
|
|
3388
|
+
struct hash<duckdb::date_t> {
|
|
3389
|
+
std::size_t operator()(const duckdb::date_t &k) const {
|
|
3390
|
+
using std::hash;
|
|
3391
|
+
return hash<int32_t>()((int32_t)k);
|
|
3392
|
+
}
|
|
3393
|
+
};
|
|
3394
|
+
} // namespace std
|
|
3395
|
+
|
|
3396
|
+
|
|
3397
|
+
|
|
3398
|
+
|
|
3399
|
+
|
|
3400
|
+
#include <functional>
|
|
3401
|
+
|
|
3402
|
+
namespace duckdb {
|
|
3403
|
+
|
|
3404
|
+
//! Type used to represent time (microseconds)
|
|
3405
|
+
struct dtime_t { // NOLINT
|
|
3406
|
+
int64_t micros;
|
|
3407
|
+
|
|
3408
|
+
dtime_t() = default;
|
|
3409
|
+
explicit inline dtime_t(int64_t micros_p) : micros(micros_p) {
|
|
3410
|
+
}
|
|
3411
|
+
inline dtime_t &operator=(int64_t micros_p) {
|
|
3412
|
+
micros = micros_p;
|
|
3413
|
+
return *this;
|
|
3414
|
+
}
|
|
3415
|
+
|
|
3416
|
+
// explicit conversion
|
|
3417
|
+
explicit inline operator int64_t() const {
|
|
3418
|
+
return micros;
|
|
3419
|
+
}
|
|
3420
|
+
explicit inline operator double() const {
|
|
3421
|
+
return micros;
|
|
3422
|
+
}
|
|
3423
|
+
|
|
3424
|
+
// comparison operators
|
|
3425
|
+
inline bool operator==(const dtime_t &rhs) const {
|
|
3426
|
+
return micros == rhs.micros;
|
|
3427
|
+
};
|
|
3428
|
+
inline bool operator!=(const dtime_t &rhs) const {
|
|
3429
|
+
return micros != rhs.micros;
|
|
3430
|
+
};
|
|
3431
|
+
inline bool operator<=(const dtime_t &rhs) const {
|
|
3432
|
+
return micros <= rhs.micros;
|
|
3433
|
+
};
|
|
3434
|
+
inline bool operator<(const dtime_t &rhs) const {
|
|
3435
|
+
return micros < rhs.micros;
|
|
3436
|
+
};
|
|
3437
|
+
inline bool operator>(const dtime_t &rhs) const {
|
|
3438
|
+
return micros > rhs.micros;
|
|
3439
|
+
};
|
|
3440
|
+
inline bool operator>=(const dtime_t &rhs) const {
|
|
3441
|
+
return micros >= rhs.micros;
|
|
3442
|
+
};
|
|
3443
|
+
|
|
3444
|
+
// arithmetic operators
|
|
3445
|
+
inline dtime_t operator+(const int64_t µs) const {
|
|
3446
|
+
return dtime_t(this->micros + micros);
|
|
3447
|
+
};
|
|
3448
|
+
inline dtime_t operator+(const double µs) const {
|
|
3449
|
+
return dtime_t(this->micros + int64_t(micros));
|
|
3450
|
+
};
|
|
3451
|
+
inline dtime_t operator-(const int64_t µs) const {
|
|
3452
|
+
return dtime_t(this->micros - micros);
|
|
3453
|
+
};
|
|
3454
|
+
inline dtime_t operator*(const idx_t &copies) const {
|
|
3455
|
+
return dtime_t(this->micros * copies);
|
|
3456
|
+
};
|
|
3457
|
+
inline dtime_t operator/(const idx_t &copies) const {
|
|
3458
|
+
return dtime_t(this->micros / copies);
|
|
3459
|
+
};
|
|
3460
|
+
inline int64_t operator-(const dtime_t &other) const {
|
|
3461
|
+
return this->micros - other.micros;
|
|
3462
|
+
};
|
|
3463
|
+
|
|
3464
|
+
// in-place operators
|
|
3465
|
+
inline dtime_t &operator+=(const int64_t µs) {
|
|
3466
|
+
this->micros += micros;
|
|
3467
|
+
return *this;
|
|
3468
|
+
};
|
|
3469
|
+
inline dtime_t &operator-=(const int64_t µs) {
|
|
3470
|
+
this->micros -= micros;
|
|
3471
|
+
return *this;
|
|
3472
|
+
};
|
|
3473
|
+
inline dtime_t &operator+=(const dtime_t &other) {
|
|
3474
|
+
this->micros += other.micros;
|
|
3475
|
+
return *this;
|
|
3476
|
+
};
|
|
3477
|
+
|
|
3478
|
+
// special values
|
|
3479
|
+
static inline dtime_t allballs() {
|
|
3480
|
+
return dtime_t(0);
|
|
3481
|
+
} // NOLINT
|
|
3482
|
+
};
|
|
3483
|
+
|
|
3484
|
+
struct dtime_tz_t : public dtime_t {};
|
|
3485
|
+
|
|
3486
|
+
} // namespace duckdb
|
|
3487
|
+
|
|
3488
|
+
namespace std {
|
|
3489
|
+
|
|
3490
|
+
//! Time
|
|
3491
|
+
template <>
|
|
3492
|
+
struct hash<duckdb::dtime_t> {
|
|
3493
|
+
std::size_t operator()(const duckdb::dtime_t &k) const {
|
|
3494
|
+
using std::hash;
|
|
3495
|
+
return hash<int64_t>()((int64_t)k);
|
|
3496
|
+
}
|
|
3497
|
+
};
|
|
3498
|
+
template <>
|
|
3499
|
+
struct hash<duckdb::dtime_tz_t> {
|
|
3500
|
+
std::size_t operator()(const duckdb::dtime_tz_t &k) const {
|
|
3501
|
+
using std::hash;
|
|
3502
|
+
return hash<int64_t>()((int64_t)k);
|
|
3503
|
+
}
|
|
3504
|
+
};
|
|
3505
|
+
} // namespace std
|
|
3506
|
+
|
|
3507
|
+
//===----------------------------------------------------------------------===//
|
|
3508
|
+
// DuckDB
|
|
3509
|
+
//
|
|
3510
|
+
// duckdb/common/types/interval.hpp
|
|
3511
|
+
//
|
|
3512
|
+
//
|
|
3513
|
+
//===----------------------------------------------------------------------===//
|
|
3514
|
+
|
|
3515
|
+
|
|
3516
|
+
|
|
3517
|
+
|
|
3518
|
+
|
|
3519
|
+
namespace duckdb {
|
|
3520
|
+
|
|
3521
|
+
struct dtime_t;
|
|
3522
|
+
struct date_t;
|
|
3523
|
+
struct timestamp_t;
|
|
3524
|
+
|
|
3525
|
+
struct interval_t {
|
|
3526
|
+
int32_t months;
|
|
3527
|
+
int32_t days;
|
|
3528
|
+
int64_t micros;
|
|
3529
|
+
|
|
3530
|
+
inline bool operator==(const interval_t &rhs) const {
|
|
3531
|
+
return this->days == rhs.days && this->months == rhs.months && this->micros == rhs.micros;
|
|
3532
|
+
}
|
|
3533
|
+
};
|
|
3534
|
+
|
|
3535
|
+
//! The Interval class is a static class that holds helper functions for the Interval
|
|
3536
|
+
//! type.
|
|
3537
|
+
class Interval {
|
|
3538
|
+
public:
|
|
3539
|
+
static constexpr const int32_t MONTHS_PER_MILLENIUM = 12000;
|
|
3540
|
+
static constexpr const int32_t MONTHS_PER_CENTURY = 1200;
|
|
3541
|
+
static constexpr const int32_t MONTHS_PER_DECADE = 120;
|
|
3542
|
+
static constexpr const int32_t MONTHS_PER_YEAR = 12;
|
|
3543
|
+
static constexpr const int32_t MONTHS_PER_QUARTER = 3;
|
|
3544
|
+
static constexpr const int32_t DAYS_PER_WEEK = 7;
|
|
3545
|
+
//! only used for interval comparison/ordering purposes, in which case a month counts as 30 days
|
|
3546
|
+
static constexpr const int64_t DAYS_PER_MONTH = 30;
|
|
3547
|
+
static constexpr const int64_t DAYS_PER_YEAR = 365;
|
|
3548
|
+
static constexpr const int64_t MSECS_PER_SEC = 1000;
|
|
3549
|
+
static constexpr const int32_t SECS_PER_MINUTE = 60;
|
|
3550
|
+
static constexpr const int32_t MINS_PER_HOUR = 60;
|
|
3551
|
+
static constexpr const int32_t HOURS_PER_DAY = 24;
|
|
3552
|
+
static constexpr const int32_t SECS_PER_HOUR = SECS_PER_MINUTE * MINS_PER_HOUR;
|
|
3553
|
+
static constexpr const int32_t SECS_PER_DAY = SECS_PER_HOUR * HOURS_PER_DAY;
|
|
3554
|
+
static constexpr const int32_t SECS_PER_WEEK = SECS_PER_DAY * DAYS_PER_WEEK;
|
|
3555
|
+
|
|
3556
|
+
static constexpr const int64_t MICROS_PER_MSEC = 1000;
|
|
3557
|
+
static constexpr const int64_t MICROS_PER_SEC = MICROS_PER_MSEC * MSECS_PER_SEC;
|
|
3558
|
+
static constexpr const int64_t MICROS_PER_MINUTE = MICROS_PER_SEC * SECS_PER_MINUTE;
|
|
3559
|
+
static constexpr const int64_t MICROS_PER_HOUR = MICROS_PER_MINUTE * MINS_PER_HOUR;
|
|
3560
|
+
static constexpr const int64_t MICROS_PER_DAY = MICROS_PER_HOUR * HOURS_PER_DAY;
|
|
3561
|
+
static constexpr const int64_t MICROS_PER_WEEK = MICROS_PER_DAY * DAYS_PER_WEEK;
|
|
3562
|
+
static constexpr const int64_t MICROS_PER_MONTH = MICROS_PER_DAY * DAYS_PER_MONTH;
|
|
3563
|
+
|
|
3564
|
+
static constexpr const int64_t NANOS_PER_MICRO = 1000;
|
|
3565
|
+
static constexpr const int64_t NANOS_PER_MSEC = NANOS_PER_MICRO * MICROS_PER_MSEC;
|
|
3566
|
+
static constexpr const int64_t NANOS_PER_SEC = NANOS_PER_MSEC * MSECS_PER_SEC;
|
|
3567
|
+
static constexpr const int64_t NANOS_PER_MINUTE = NANOS_PER_SEC * SECS_PER_MINUTE;
|
|
3568
|
+
static constexpr const int64_t NANOS_PER_HOUR = NANOS_PER_MINUTE * MINS_PER_HOUR;
|
|
3569
|
+
static constexpr const int64_t NANOS_PER_DAY = NANOS_PER_HOUR * HOURS_PER_DAY;
|
|
3570
|
+
static constexpr const int64_t NANOS_PER_WEEK = NANOS_PER_DAY * DAYS_PER_WEEK;
|
|
3571
|
+
|
|
3572
|
+
public:
|
|
3573
|
+
//! Convert a string to an interval object
|
|
3574
|
+
static bool FromString(const string &str, interval_t &result);
|
|
3575
|
+
//! Convert a string to an interval object
|
|
3576
|
+
static bool FromCString(const char *str, idx_t len, interval_t &result, string *error_message, bool strict);
|
|
3577
|
+
//! Convert an interval object to a string
|
|
3578
|
+
static string ToString(const interval_t &val);
|
|
3579
|
+
|
|
3580
|
+
//! Convert milliseconds to a normalised interval
|
|
3581
|
+
DUCKDB_API static interval_t FromMicro(int64_t micros);
|
|
3582
|
+
|
|
3583
|
+
//! Get Interval in milliseconds
|
|
3584
|
+
static int64_t GetMilli(const interval_t &val);
|
|
3585
|
+
|
|
3586
|
+
//! Get Interval in microseconds
|
|
3587
|
+
static int64_t GetMicro(const interval_t &val);
|
|
3588
|
+
|
|
3589
|
+
//! Get Interval in Nanoseconds
|
|
3590
|
+
static int64_t GetNanoseconds(const interval_t &val);
|
|
3591
|
+
|
|
3592
|
+
//! Returns the age between two timestamps (including 30 day months)
|
|
3593
|
+
static interval_t GetAge(timestamp_t timestamp_1, timestamp_t timestamp_2);
|
|
3594
|
+
|
|
3595
|
+
//! Returns the exact difference between two timestamps (days and seconds)
|
|
3596
|
+
static interval_t GetDifference(timestamp_t timestamp_1, timestamp_t timestamp_2);
|
|
3597
|
+
|
|
3598
|
+
//! Returns the inverted interval
|
|
3599
|
+
static interval_t Invert(interval_t interval);
|
|
3600
|
+
|
|
3601
|
+
//! Add an interval to a date
|
|
3602
|
+
static date_t Add(date_t left, interval_t right);
|
|
3603
|
+
//! Add an interval to a timestamp
|
|
3604
|
+
static timestamp_t Add(timestamp_t left, interval_t right);
|
|
3605
|
+
//! Add an interval to a time. In case the time overflows or underflows, modify the date by the overflow.
|
|
3606
|
+
//! For example if we go from 23:00 to 02:00, we add a day to the date
|
|
3607
|
+
static dtime_t Add(dtime_t left, interval_t right, date_t &date);
|
|
3608
|
+
|
|
3609
|
+
//! Comparison operators
|
|
3610
|
+
static bool Equals(interval_t left, interval_t right);
|
|
3611
|
+
static bool GreaterThan(interval_t left, interval_t right);
|
|
3612
|
+
static bool GreaterThanEquals(interval_t left, interval_t right);
|
|
3613
|
+
};
|
|
3614
|
+
} // namespace duckdb
|
|
3615
|
+
|
|
3616
|
+
|
|
3617
|
+
namespace duckdb {
|
|
3618
|
+
|
|
3619
|
+
class CastFunctionSet;
|
|
3620
|
+
class Deserializer;
|
|
3621
|
+
class Serializer;
|
|
3622
|
+
struct GetCastFunctionInput;
|
|
3623
|
+
|
|
3624
|
+
//! The Value object holds a single arbitrary value of any type that can be
|
|
3625
|
+
//! stored in the database.
|
|
3626
|
+
class Value {
|
|
3627
|
+
friend struct StringValue;
|
|
3628
|
+
friend struct StructValue;
|
|
3629
|
+
friend struct ListValue;
|
|
3630
|
+
friend struct UnionValue;
|
|
3631
|
+
|
|
3632
|
+
public:
|
|
3633
|
+
//! Create an empty NULL value of the specified type
|
|
3634
|
+
DUCKDB_API explicit Value(LogicalType type = LogicalType::SQLNULL);
|
|
3635
|
+
//! Create an INTEGER value
|
|
3636
|
+
DUCKDB_API Value(int32_t val); // NOLINT: Allow implicit conversion from `int32_t`
|
|
3637
|
+
//! Create a BIGINT value
|
|
3638
|
+
DUCKDB_API Value(int64_t val); // NOLINT: Allow implicit conversion from `int64_t`
|
|
3639
|
+
//! Create a FLOAT value
|
|
3640
|
+
DUCKDB_API Value(float val); // NOLINT: Allow implicit conversion from `float`
|
|
3641
|
+
//! Create a DOUBLE value
|
|
3642
|
+
DUCKDB_API Value(double val); // NOLINT: Allow implicit conversion from `double`
|
|
3643
|
+
//! Create a VARCHAR value
|
|
3644
|
+
DUCKDB_API Value(const char *val); // NOLINT: Allow implicit conversion from `const char *`
|
|
3645
|
+
//! Create a NULL value
|
|
3646
|
+
DUCKDB_API Value(std::nullptr_t val); // NOLINT: Allow implicit conversion from `nullptr_t`
|
|
3647
|
+
//! Create a VARCHAR value
|
|
3648
|
+
DUCKDB_API Value(string_t val); // NOLINT: Allow implicit conversion from `string_t`
|
|
3649
|
+
//! Create a VARCHAR value
|
|
3650
|
+
DUCKDB_API Value(string val); // NOLINT: Allow implicit conversion from `string`
|
|
3651
|
+
//! Copy constructor
|
|
3652
|
+
DUCKDB_API Value(const Value &other);
|
|
3653
|
+
//! Move constructor
|
|
3654
|
+
DUCKDB_API Value(Value &&other) noexcept;
|
|
3655
|
+
//! Destructor
|
|
3656
|
+
DUCKDB_API ~Value();
|
|
3657
|
+
|
|
3658
|
+
// copy assignment
|
|
3659
|
+
DUCKDB_API Value &operator=(const Value &other);
|
|
3660
|
+
// move assignment
|
|
3661
|
+
DUCKDB_API Value &operator=(Value &&other) noexcept;
|
|
3662
|
+
|
|
3663
|
+
inline LogicalType &type() {
|
|
3664
|
+
return type_;
|
|
3665
|
+
}
|
|
3666
|
+
inline const LogicalType &type() const {
|
|
3667
|
+
return type_;
|
|
3668
|
+
}
|
|
3669
|
+
inline bool IsNull() const {
|
|
3670
|
+
return is_null;
|
|
3671
|
+
}
|
|
3672
|
+
|
|
3673
|
+
//! Create the lowest possible value of a given type (numeric only)
|
|
3674
|
+
DUCKDB_API static Value MinimumValue(const LogicalType &type);
|
|
3675
|
+
//! Create the highest possible value of a given type (numeric only)
|
|
3676
|
+
DUCKDB_API static Value MaximumValue(const LogicalType &type);
|
|
3677
|
+
//! Create a Numeric value of the specified type with the specified value
|
|
3678
|
+
DUCKDB_API static Value Numeric(const LogicalType &type, int64_t value);
|
|
3679
|
+
DUCKDB_API static Value Numeric(const LogicalType &type, hugeint_t value);
|
|
3680
|
+
|
|
3681
|
+
//! Create a tinyint Value from a specified value
|
|
3682
|
+
DUCKDB_API static Value BOOLEAN(int8_t value);
|
|
3683
|
+
//! Create a tinyint Value from a specified value
|
|
3684
|
+
DUCKDB_API static Value TINYINT(int8_t value);
|
|
3685
|
+
//! Create a smallint Value from a specified value
|
|
3686
|
+
DUCKDB_API static Value SMALLINT(int16_t value);
|
|
3687
|
+
//! Create an integer Value from a specified value
|
|
3688
|
+
DUCKDB_API static Value INTEGER(int32_t value);
|
|
3689
|
+
//! Create a bigint Value from a specified value
|
|
3690
|
+
DUCKDB_API static Value BIGINT(int64_t value);
|
|
3691
|
+
//! Create an unsigned tinyint Value from a specified value
|
|
3028
3692
|
DUCKDB_API static Value UTINYINT(uint8_t value);
|
|
3029
3693
|
//! Create an unsigned smallint Value from a specified value
|
|
3030
3694
|
DUCKDB_API static Value USMALLINT(uint16_t value);
|
|
@@ -3728,177 +4392,42 @@ private:
|
|
|
3728
4392
|
ArenaChunk *tail;
|
|
3729
4393
|
};
|
|
3730
4394
|
|
|
3731
|
-
} // namespace duckdb
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
namespace duckdb {
|
|
3735
|
-
//! A string heap is the owner of a set of strings, strings can be inserted into
|
|
3736
|
-
//! it On every insert, a pointer to the inserted string is returned The
|
|
3737
|
-
//! returned pointer will remain valid until the StringHeap is destroyed
|
|
3738
|
-
class StringHeap {
|
|
3739
|
-
public:
|
|
3740
|
-
StringHeap();
|
|
3741
|
-
|
|
3742
|
-
void Destroy();
|
|
3743
|
-
void Move(StringHeap &other);
|
|
3744
|
-
|
|
3745
|
-
//! Add a string to the string heap, returns a pointer to the string
|
|
3746
|
-
string_t AddString(const char *data, idx_t len);
|
|
3747
|
-
//! Add a string to the string heap, returns a pointer to the string
|
|
3748
|
-
string_t AddString(const char *data);
|
|
3749
|
-
//! Add a string to the string heap, returns a pointer to the string
|
|
3750
|
-
string_t AddString(const string &data);
|
|
3751
|
-
//! Add a string to the string heap, returns a pointer to the string
|
|
3752
|
-
string_t AddString(const string_t &data);
|
|
3753
|
-
//! Add a blob to the string heap; blobs can be non-valid UTF8
|
|
3754
|
-
string_t AddBlob(const string_t &data);
|
|
3755
|
-
//! Add a blob to the string heap; blobs can be non-valid UTF8
|
|
3756
|
-
string_t AddBlob(const char *data, idx_t len);
|
|
3757
|
-
//! Allocates space for an empty string of size "len" on the heap
|
|
3758
|
-
string_t EmptyString(idx_t len);
|
|
3759
|
-
|
|
3760
|
-
private:
|
|
3761
|
-
ArenaAllocator allocator;
|
|
3762
|
-
};
|
|
3763
|
-
|
|
3764
|
-
} // namespace duckdb
|
|
3765
|
-
|
|
3766
|
-
//===----------------------------------------------------------------------===//
|
|
3767
|
-
// DuckDB
|
|
3768
|
-
//
|
|
3769
|
-
// duckdb/common/types/string_type.hpp
|
|
3770
|
-
//
|
|
3771
|
-
//
|
|
3772
|
-
//===----------------------------------------------------------------------===//
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
#include <cstring>
|
|
3780
|
-
|
|
3781
|
-
namespace duckdb {
|
|
3782
|
-
|
|
3783
|
-
struct string_t {
|
|
3784
|
-
friend struct StringComparisonOperators;
|
|
3785
|
-
friend class StringSegment;
|
|
3786
|
-
|
|
3787
|
-
public:
|
|
3788
|
-
static constexpr idx_t PREFIX_BYTES = 4 * sizeof(char);
|
|
3789
|
-
static constexpr idx_t INLINE_BYTES = 12 * sizeof(char);
|
|
3790
|
-
static constexpr idx_t HEADER_SIZE = sizeof(uint32_t) + PREFIX_BYTES;
|
|
3791
|
-
#ifndef DUCKDB_DEBUG_NO_INLINE
|
|
3792
|
-
static constexpr idx_t PREFIX_LENGTH = PREFIX_BYTES;
|
|
3793
|
-
static constexpr idx_t INLINE_LENGTH = INLINE_BYTES;
|
|
3794
|
-
#else
|
|
3795
|
-
static constexpr idx_t PREFIX_LENGTH = 0;
|
|
3796
|
-
static constexpr idx_t INLINE_LENGTH = 0;
|
|
3797
|
-
#endif
|
|
3798
|
-
|
|
3799
|
-
string_t() = default;
|
|
3800
|
-
explicit string_t(uint32_t len) {
|
|
3801
|
-
value.inlined.length = len;
|
|
3802
|
-
}
|
|
3803
|
-
string_t(const char *data, uint32_t len) {
|
|
3804
|
-
value.inlined.length = len;
|
|
3805
|
-
D_ASSERT(data || GetSize() == 0);
|
|
3806
|
-
if (IsInlined()) {
|
|
3807
|
-
// zero initialize the prefix first
|
|
3808
|
-
// this makes sure that strings with length smaller than 4 still have an equal prefix
|
|
3809
|
-
memset(value.inlined.inlined, 0, INLINE_BYTES);
|
|
3810
|
-
if (GetSize() == 0) {
|
|
3811
|
-
return;
|
|
3812
|
-
}
|
|
3813
|
-
// small string: inlined
|
|
3814
|
-
memcpy(value.inlined.inlined, data, GetSize());
|
|
3815
|
-
} else {
|
|
3816
|
-
// large string: store pointer
|
|
3817
|
-
#ifndef DUCKDB_DEBUG_NO_INLINE
|
|
3818
|
-
memcpy(value.pointer.prefix, data, PREFIX_LENGTH);
|
|
3819
|
-
#else
|
|
3820
|
-
memset(value.pointer.prefix, 0, PREFIX_BYTES);
|
|
3821
|
-
#endif
|
|
3822
|
-
value.pointer.ptr = (char *)data;
|
|
3823
|
-
}
|
|
3824
|
-
}
|
|
3825
|
-
string_t(const char *data) : string_t(data, strlen(data)) { // NOLINT: Allow implicit conversion from `const char*`
|
|
3826
|
-
}
|
|
3827
|
-
string_t(const string &value)
|
|
3828
|
-
: string_t(value.c_str(), value.size()) { // NOLINT: Allow implicit conversion from `const char*`
|
|
3829
|
-
}
|
|
3830
|
-
|
|
3831
|
-
bool IsInlined() const {
|
|
3832
|
-
return GetSize() <= INLINE_LENGTH;
|
|
3833
|
-
}
|
|
3834
|
-
|
|
3835
|
-
//! this is unsafe since the string will not be terminated at the end
|
|
3836
|
-
const char *GetDataUnsafe() const {
|
|
3837
|
-
return IsInlined() ? (const char *)value.inlined.inlined : value.pointer.ptr;
|
|
3838
|
-
}
|
|
3839
|
-
|
|
3840
|
-
char *GetDataWriteable() const {
|
|
3841
|
-
return IsInlined() ? (char *)value.inlined.inlined : value.pointer.ptr;
|
|
3842
|
-
}
|
|
3843
|
-
|
|
3844
|
-
const char *GetPrefix() const {
|
|
3845
|
-
return value.pointer.prefix;
|
|
3846
|
-
}
|
|
3847
|
-
|
|
3848
|
-
idx_t GetSize() const {
|
|
3849
|
-
return value.inlined.length;
|
|
3850
|
-
}
|
|
3851
|
-
|
|
3852
|
-
string GetString() const {
|
|
3853
|
-
return string(GetDataUnsafe(), GetSize());
|
|
3854
|
-
}
|
|
4395
|
+
} // namespace duckdb
|
|
3855
4396
|
|
|
3856
|
-
explicit operator string() const {
|
|
3857
|
-
return GetString();
|
|
3858
|
-
}
|
|
3859
4397
|
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
} else {
|
|
3868
|
-
// copy the data into the prefix
|
|
3869
|
-
#ifndef DUCKDB_DEBUG_NO_INLINE
|
|
3870
|
-
auto dataptr = (char *)GetDataUnsafe();
|
|
3871
|
-
memcpy(value.pointer.prefix, dataptr, PREFIX_LENGTH);
|
|
3872
|
-
#else
|
|
3873
|
-
memset(value.pointer.prefix, 0, PREFIX_BYTES);
|
|
3874
|
-
#endif
|
|
3875
|
-
}
|
|
3876
|
-
}
|
|
4398
|
+
namespace duckdb {
|
|
4399
|
+
//! A string heap is the owner of a set of strings, strings can be inserted into
|
|
4400
|
+
//! it On every insert, a pointer to the inserted string is returned The
|
|
4401
|
+
//! returned pointer will remain valid until the StringHeap is destroyed
|
|
4402
|
+
class StringHeap {
|
|
4403
|
+
public:
|
|
4404
|
+
StringHeap();
|
|
3877
4405
|
|
|
3878
|
-
void
|
|
3879
|
-
void
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
4406
|
+
void Destroy();
|
|
4407
|
+
void Move(StringHeap &other);
|
|
4408
|
+
|
|
4409
|
+
//! Add a string to the string heap, returns a pointer to the string
|
|
4410
|
+
string_t AddString(const char *data, idx_t len);
|
|
4411
|
+
//! Add a string to the string heap, returns a pointer to the string
|
|
4412
|
+
string_t AddString(const char *data);
|
|
4413
|
+
//! Add a string to the string heap, returns a pointer to the string
|
|
4414
|
+
string_t AddString(const string &data);
|
|
4415
|
+
//! Add a string to the string heap, returns a pointer to the string
|
|
4416
|
+
string_t AddString(const string_t &data);
|
|
4417
|
+
//! Add a blob to the string heap; blobs can be non-valid UTF8
|
|
4418
|
+
string_t AddBlob(const string_t &data);
|
|
4419
|
+
//! Add a blob to the string heap; blobs can be non-valid UTF8
|
|
4420
|
+
string_t AddBlob(const char *data, idx_t len);
|
|
4421
|
+
//! Allocates space for an empty string of size "len" on the heap
|
|
4422
|
+
string_t EmptyString(idx_t len);
|
|
3885
4423
|
|
|
3886
4424
|
private:
|
|
3887
|
-
|
|
3888
|
-
struct {
|
|
3889
|
-
uint32_t length;
|
|
3890
|
-
char prefix[4];
|
|
3891
|
-
char *ptr;
|
|
3892
|
-
} pointer;
|
|
3893
|
-
struct {
|
|
3894
|
-
uint32_t length;
|
|
3895
|
-
char inlined[12];
|
|
3896
|
-
} inlined;
|
|
3897
|
-
} value;
|
|
4425
|
+
ArenaAllocator allocator;
|
|
3898
4426
|
};
|
|
3899
4427
|
|
|
3900
4428
|
} // namespace duckdb
|
|
3901
4429
|
|
|
4430
|
+
|
|
3902
4431
|
//===----------------------------------------------------------------------===//
|
|
3903
4432
|
// DuckDB
|
|
3904
4433
|
//
|
|
@@ -7455,221 +7984,145 @@ struct ExpressionState {
|
|
|
7455
7984
|
public:
|
|
7456
7985
|
void AddChild(Expression *expr);
|
|
7457
7986
|
void Finalize();
|
|
7458
|
-
Allocator &GetAllocator();
|
|
7459
|
-
bool HasContext();
|
|
7460
|
-
ClientContext &GetContext();
|
|
7461
|
-
|
|
7462
|
-
void Verify(ExpressionExecutorState &root);
|
|
7463
|
-
};
|
|
7464
|
-
|
|
7465
|
-
struct ExecuteFunctionState : public ExpressionState {
|
|
7466
|
-
ExecuteFunctionState(const Expression &expr, ExpressionExecutorState &root);
|
|
7467
|
-
~ExecuteFunctionState();
|
|
7468
|
-
|
|
7469
|
-
unique_ptr<FunctionLocalState> local_state;
|
|
7470
|
-
|
|
7471
|
-
public:
|
|
7472
|
-
static FunctionLocalState *GetFunctionState(ExpressionState &state) {
|
|
7473
|
-
return ((ExecuteFunctionState &)state).local_state.get();
|
|
7474
|
-
}
|
|
7475
|
-
};
|
|
7476
|
-
|
|
7477
|
-
struct ExpressionExecutorState {
|
|
7478
|
-
explicit ExpressionExecutorState(const string &name);
|
|
7479
|
-
|
|
7480
|
-
unique_ptr<ExpressionState> root_state;
|
|
7481
|
-
ExpressionExecutor *executor = nullptr;
|
|
7482
|
-
CycleCounter profiler;
|
|
7483
|
-
string name;
|
|
7484
|
-
|
|
7485
|
-
void Verify();
|
|
7486
|
-
};
|
|
7487
|
-
|
|
7488
|
-
} // namespace duckdb
|
|
7489
|
-
|
|
7490
|
-
|
|
7491
|
-
//===----------------------------------------------------------------------===//
|
|
7492
|
-
// DuckDB
|
|
7493
|
-
//
|
|
7494
|
-
// duckdb/storage/statistics/base_statistics.hpp
|
|
7495
|
-
//
|
|
7496
|
-
//
|
|
7497
|
-
//===----------------------------------------------------------------------===//
|
|
7498
|
-
|
|
7499
|
-
|
|
7500
|
-
|
|
7501
|
-
|
|
7502
|
-
|
|
7503
|
-
//===----------------------------------------------------------------------===//
|
|
7504
|
-
// DuckDB
|
|
7505
|
-
//
|
|
7506
|
-
// duckdb/common/operator/comparison_operators.hpp
|
|
7507
|
-
//
|
|
7508
|
-
//
|
|
7509
|
-
//===----------------------------------------------------------------------===//
|
|
7510
|
-
|
|
7511
|
-
|
|
7512
|
-
|
|
7513
|
-
|
|
7514
|
-
|
|
7515
|
-
//===----------------------------------------------------------------------===//
|
|
7516
|
-
// DuckDB
|
|
7517
|
-
//
|
|
7518
|
-
// duckdb/common/types/hugeint.hpp
|
|
7519
|
-
//
|
|
7520
|
-
//
|
|
7521
|
-
//===----------------------------------------------------------------------===//
|
|
7522
|
-
|
|
7523
|
-
|
|
7524
|
-
|
|
7525
|
-
|
|
7526
|
-
//===----------------------------------------------------------------------===//
|
|
7527
|
-
// DuckDB
|
|
7528
|
-
//
|
|
7529
|
-
// duckdb/common/limits.hpp
|
|
7530
|
-
//
|
|
7531
|
-
//
|
|
7532
|
-
//===----------------------------------------------------------------------===//
|
|
7533
|
-
|
|
7534
|
-
|
|
7535
|
-
|
|
7536
|
-
|
|
7537
|
-
|
|
7538
|
-
namespace duckdb {
|
|
7539
|
-
|
|
7540
|
-
template <class T>
|
|
7541
|
-
struct NumericLimits {
|
|
7542
|
-
DUCKDB_API static T Minimum();
|
|
7543
|
-
DUCKDB_API static T Maximum();
|
|
7544
|
-
DUCKDB_API static bool IsSigned();
|
|
7545
|
-
DUCKDB_API static idx_t Digits();
|
|
7546
|
-
};
|
|
7547
|
-
|
|
7548
|
-
template <>
|
|
7549
|
-
struct NumericLimits<int8_t> {
|
|
7550
|
-
DUCKDB_API static int8_t Minimum();
|
|
7551
|
-
DUCKDB_API static int8_t Maximum();
|
|
7552
|
-
DUCKDB_API static bool IsSigned() {
|
|
7553
|
-
return true;
|
|
7554
|
-
}
|
|
7555
|
-
DUCKDB_API static idx_t Digits() {
|
|
7556
|
-
return 3;
|
|
7557
|
-
}
|
|
7558
|
-
};
|
|
7559
|
-
template <>
|
|
7560
|
-
struct NumericLimits<int16_t> {
|
|
7561
|
-
DUCKDB_API static int16_t Minimum();
|
|
7562
|
-
DUCKDB_API static int16_t Maximum();
|
|
7563
|
-
DUCKDB_API static bool IsSigned() {
|
|
7564
|
-
return true;
|
|
7565
|
-
}
|
|
7566
|
-
DUCKDB_API static idx_t Digits() {
|
|
7567
|
-
return 5;
|
|
7568
|
-
}
|
|
7569
|
-
};
|
|
7570
|
-
template <>
|
|
7571
|
-
struct NumericLimits<int32_t> {
|
|
7572
|
-
DUCKDB_API static int32_t Minimum();
|
|
7573
|
-
DUCKDB_API static int32_t Maximum();
|
|
7574
|
-
DUCKDB_API static bool IsSigned() {
|
|
7575
|
-
return true;
|
|
7576
|
-
}
|
|
7577
|
-
DUCKDB_API static idx_t Digits() {
|
|
7578
|
-
return 10;
|
|
7579
|
-
}
|
|
7580
|
-
};
|
|
7581
|
-
template <>
|
|
7582
|
-
struct NumericLimits<int64_t> {
|
|
7583
|
-
DUCKDB_API static int64_t Minimum();
|
|
7584
|
-
DUCKDB_API static int64_t Maximum();
|
|
7585
|
-
DUCKDB_API static bool IsSigned() {
|
|
7586
|
-
return true;
|
|
7587
|
-
}
|
|
7588
|
-
DUCKDB_API static idx_t Digits() {
|
|
7589
|
-
return 19;
|
|
7590
|
-
}
|
|
7591
|
-
};
|
|
7592
|
-
template <>
|
|
7593
|
-
struct NumericLimits<hugeint_t> {
|
|
7594
|
-
DUCKDB_API static hugeint_t Minimum();
|
|
7595
|
-
DUCKDB_API static hugeint_t Maximum();
|
|
7596
|
-
DUCKDB_API static bool IsSigned() {
|
|
7597
|
-
return true;
|
|
7598
|
-
}
|
|
7599
|
-
DUCKDB_API static idx_t Digits() {
|
|
7600
|
-
return 39;
|
|
7601
|
-
}
|
|
7602
|
-
};
|
|
7603
|
-
template <>
|
|
7604
|
-
struct NumericLimits<uint8_t> {
|
|
7605
|
-
DUCKDB_API static uint8_t Minimum();
|
|
7606
|
-
DUCKDB_API static uint8_t Maximum();
|
|
7607
|
-
DUCKDB_API static bool IsSigned() {
|
|
7608
|
-
return false;
|
|
7609
|
-
}
|
|
7610
|
-
DUCKDB_API static idx_t Digits() {
|
|
7611
|
-
return 3;
|
|
7612
|
-
}
|
|
7613
|
-
};
|
|
7614
|
-
template <>
|
|
7615
|
-
struct NumericLimits<uint16_t> {
|
|
7616
|
-
DUCKDB_API static uint16_t Minimum();
|
|
7617
|
-
DUCKDB_API static uint16_t Maximum();
|
|
7618
|
-
DUCKDB_API static bool IsSigned() {
|
|
7619
|
-
return false;
|
|
7620
|
-
}
|
|
7621
|
-
DUCKDB_API static idx_t Digits() {
|
|
7622
|
-
return 5;
|
|
7623
|
-
}
|
|
7624
|
-
};
|
|
7625
|
-
template <>
|
|
7626
|
-
struct NumericLimits<uint32_t> {
|
|
7627
|
-
DUCKDB_API static uint32_t Minimum();
|
|
7628
|
-
DUCKDB_API static uint32_t Maximum();
|
|
7629
|
-
DUCKDB_API static bool IsSigned() {
|
|
7630
|
-
return false;
|
|
7631
|
-
}
|
|
7632
|
-
DUCKDB_API static idx_t Digits() {
|
|
7633
|
-
return 10;
|
|
7634
|
-
}
|
|
7635
|
-
};
|
|
7636
|
-
template <>
|
|
7637
|
-
struct NumericLimits<uint64_t> {
|
|
7638
|
-
DUCKDB_API static uint64_t Minimum();
|
|
7639
|
-
DUCKDB_API static uint64_t Maximum();
|
|
7640
|
-
DUCKDB_API static bool IsSigned() {
|
|
7641
|
-
return false;
|
|
7642
|
-
}
|
|
7643
|
-
DUCKDB_API static idx_t Digits() {
|
|
7644
|
-
return 20;
|
|
7645
|
-
}
|
|
7987
|
+
Allocator &GetAllocator();
|
|
7988
|
+
bool HasContext();
|
|
7989
|
+
ClientContext &GetContext();
|
|
7990
|
+
|
|
7991
|
+
void Verify(ExpressionExecutorState &root);
|
|
7646
7992
|
};
|
|
7647
|
-
|
|
7648
|
-
struct
|
|
7649
|
-
|
|
7650
|
-
|
|
7651
|
-
|
|
7652
|
-
|
|
7653
|
-
|
|
7654
|
-
|
|
7655
|
-
|
|
7993
|
+
|
|
7994
|
+
struct ExecuteFunctionState : public ExpressionState {
|
|
7995
|
+
ExecuteFunctionState(const Expression &expr, ExpressionExecutorState &root);
|
|
7996
|
+
~ExecuteFunctionState();
|
|
7997
|
+
|
|
7998
|
+
unique_ptr<FunctionLocalState> local_state;
|
|
7999
|
+
|
|
8000
|
+
public:
|
|
8001
|
+
static FunctionLocalState *GetFunctionState(ExpressionState &state) {
|
|
8002
|
+
return ((ExecuteFunctionState &)state).local_state.get();
|
|
7656
8003
|
}
|
|
7657
8004
|
};
|
|
7658
|
-
|
|
7659
|
-
struct
|
|
7660
|
-
|
|
7661
|
-
|
|
7662
|
-
|
|
7663
|
-
|
|
7664
|
-
|
|
7665
|
-
|
|
7666
|
-
|
|
7667
|
-
|
|
8005
|
+
|
|
8006
|
+
struct ExpressionExecutorState {
|
|
8007
|
+
explicit ExpressionExecutorState(const string &name);
|
|
8008
|
+
|
|
8009
|
+
unique_ptr<ExpressionState> root_state;
|
|
8010
|
+
ExpressionExecutor *executor = nullptr;
|
|
8011
|
+
CycleCounter profiler;
|
|
8012
|
+
string name;
|
|
8013
|
+
|
|
8014
|
+
void Verify();
|
|
7668
8015
|
};
|
|
7669
8016
|
|
|
7670
8017
|
} // namespace duckdb
|
|
7671
8018
|
|
|
7672
8019
|
|
|
8020
|
+
//===----------------------------------------------------------------------===//
|
|
8021
|
+
// DuckDB
|
|
8022
|
+
//
|
|
8023
|
+
// duckdb/storage/statistics/base_statistics.hpp
|
|
8024
|
+
//
|
|
8025
|
+
//
|
|
8026
|
+
//===----------------------------------------------------------------------===//
|
|
8027
|
+
|
|
8028
|
+
|
|
8029
|
+
|
|
8030
|
+
|
|
8031
|
+
|
|
8032
|
+
//===----------------------------------------------------------------------===//
|
|
8033
|
+
// DuckDB
|
|
8034
|
+
//
|
|
8035
|
+
// duckdb/common/operator/comparison_operators.hpp
|
|
8036
|
+
//
|
|
8037
|
+
//
|
|
8038
|
+
//===----------------------------------------------------------------------===//
|
|
8039
|
+
|
|
8040
|
+
|
|
8041
|
+
|
|
8042
|
+
|
|
8043
|
+
|
|
8044
|
+
//===----------------------------------------------------------------------===//
|
|
8045
|
+
// DuckDB
|
|
8046
|
+
//
|
|
8047
|
+
// duckdb/common/types/hugeint.hpp
|
|
8048
|
+
//
|
|
8049
|
+
//
|
|
8050
|
+
//===----------------------------------------------------------------------===//
|
|
8051
|
+
|
|
8052
|
+
|
|
8053
|
+
|
|
8054
|
+
|
|
8055
|
+
|
|
8056
|
+
|
|
8057
|
+
|
|
8058
|
+
|
|
8059
|
+
|
|
8060
|
+
|
|
8061
|
+
|
|
8062
|
+
|
|
8063
|
+
namespace duckdb {
|
|
8064
|
+
|
|
8065
|
+
//! Returns the PhysicalType for the given type
|
|
8066
|
+
template <class T>
|
|
8067
|
+
PhysicalType GetTypeId() {
|
|
8068
|
+
if (std::is_same<T, bool>()) {
|
|
8069
|
+
return PhysicalType::BOOL;
|
|
8070
|
+
} else if (std::is_same<T, int8_t>()) {
|
|
8071
|
+
return PhysicalType::INT8;
|
|
8072
|
+
} else if (std::is_same<T, int16_t>()) {
|
|
8073
|
+
return PhysicalType::INT16;
|
|
8074
|
+
} else if (std::is_same<T, int32_t>()) {
|
|
8075
|
+
return PhysicalType::INT32;
|
|
8076
|
+
} else if (std::is_same<T, int64_t>()) {
|
|
8077
|
+
return PhysicalType::INT64;
|
|
8078
|
+
} else if (std::is_same<T, uint8_t>()) {
|
|
8079
|
+
return PhysicalType::UINT8;
|
|
8080
|
+
} else if (std::is_same<T, uint16_t>()) {
|
|
8081
|
+
return PhysicalType::UINT16;
|
|
8082
|
+
} else if (std::is_same<T, uint32_t>()) {
|
|
8083
|
+
return PhysicalType::UINT32;
|
|
8084
|
+
} else if (std::is_same<T, uint64_t>()) {
|
|
8085
|
+
return PhysicalType::UINT64;
|
|
8086
|
+
} else if (std::is_same<T, hugeint_t>()) {
|
|
8087
|
+
return PhysicalType::INT128;
|
|
8088
|
+
} else if (std::is_same<T, date_t>()) {
|
|
8089
|
+
return PhysicalType::INT32;
|
|
8090
|
+
} else if (std::is_same<T, dtime_t>()) {
|
|
8091
|
+
return PhysicalType::INT64;
|
|
8092
|
+
} else if (std::is_same<T, timestamp_t>()) {
|
|
8093
|
+
return PhysicalType::INT64;
|
|
8094
|
+
} else if (std::is_same<T, float>()) {
|
|
8095
|
+
return PhysicalType::FLOAT;
|
|
8096
|
+
} else if (std::is_same<T, double>()) {
|
|
8097
|
+
return PhysicalType::DOUBLE;
|
|
8098
|
+
} else if (std::is_same<T, const char *>() || std::is_same<T, char *>() || std::is_same<T, string_t>()) {
|
|
8099
|
+
return PhysicalType::VARCHAR;
|
|
8100
|
+
} else if (std::is_same<T, interval_t>()) {
|
|
8101
|
+
return PhysicalType::INTERVAL;
|
|
8102
|
+
} else {
|
|
8103
|
+
return PhysicalType::INVALID;
|
|
8104
|
+
}
|
|
8105
|
+
}
|
|
8106
|
+
|
|
8107
|
+
template <class T>
|
|
8108
|
+
bool TypeIsNumber() {
|
|
8109
|
+
return std::is_integral<T>() || std::is_floating_point<T>() || std::is_same<T, hugeint_t>();
|
|
8110
|
+
}
|
|
8111
|
+
|
|
8112
|
+
template <class T>
|
|
8113
|
+
bool IsValidType() {
|
|
8114
|
+
return GetTypeId<T>() != PhysicalType::INVALID;
|
|
8115
|
+
}
|
|
8116
|
+
|
|
8117
|
+
template <class T>
|
|
8118
|
+
bool IsIntegerType() {
|
|
8119
|
+
return TypeIsIntegral(GetTypeId<T>());
|
|
8120
|
+
}
|
|
8121
|
+
|
|
8122
|
+
} // namespace duckdb
|
|
8123
|
+
|
|
8124
|
+
|
|
8125
|
+
|
|
7673
8126
|
|
|
7674
8127
|
namespace duckdb {
|
|
7675
8128
|
|
|
@@ -7792,130 +8245,36 @@ DUCKDB_API bool Hugeint::TryCast(hugeint_t input, float &result);
|
|
|
7792
8245
|
template <>
|
|
7793
8246
|
DUCKDB_API bool Hugeint::TryCast(hugeint_t input, double &result);
|
|
7794
8247
|
template <>
|
|
7795
|
-
DUCKDB_API bool Hugeint::TryCast(hugeint_t input, long double &result);
|
|
7796
|
-
|
|
7797
|
-
template <>
|
|
7798
|
-
bool Hugeint::TryConvert(int8_t value, hugeint_t &result);
|
|
7799
|
-
template <>
|
|
7800
|
-
bool Hugeint::TryConvert(int16_t value, hugeint_t &result);
|
|
7801
|
-
template <>
|
|
7802
|
-
bool Hugeint::TryConvert(int32_t value, hugeint_t &result);
|
|
7803
|
-
template <>
|
|
7804
|
-
bool Hugeint::TryConvert(int64_t value, hugeint_t &result);
|
|
7805
|
-
template <>
|
|
7806
|
-
bool Hugeint::TryConvert(uint8_t value, hugeint_t &result);
|
|
7807
|
-
template <>
|
|
7808
|
-
bool Hugeint::TryConvert(uint16_t value, hugeint_t &result);
|
|
7809
|
-
template <>
|
|
7810
|
-
bool Hugeint::TryConvert(uint32_t value, hugeint_t &result);
|
|
7811
|
-
template <>
|
|
7812
|
-
bool Hugeint::TryConvert(uint64_t value, hugeint_t &result);
|
|
7813
|
-
template <>
|
|
7814
|
-
bool Hugeint::TryConvert(float value, hugeint_t &result);
|
|
7815
|
-
template <>
|
|
7816
|
-
bool Hugeint::TryConvert(double value, hugeint_t &result);
|
|
7817
|
-
template <>
|
|
7818
|
-
bool Hugeint::TryConvert(long double value, hugeint_t &result);
|
|
7819
|
-
|
|
7820
|
-
} // namespace duckdb
|
|
7821
|
-
|
|
7822
|
-
//===----------------------------------------------------------------------===//
|
|
7823
|
-
// DuckDB
|
|
7824
|
-
//
|
|
7825
|
-
// duckdb/common/types/interval.hpp
|
|
7826
|
-
//
|
|
7827
|
-
//
|
|
7828
|
-
//===----------------------------------------------------------------------===//
|
|
7829
|
-
|
|
7830
|
-
|
|
7831
|
-
|
|
7832
|
-
|
|
7833
|
-
|
|
7834
|
-
namespace duckdb {
|
|
7835
|
-
|
|
7836
|
-
//! The Interval class is a static class that holds helper functions for the Interval
|
|
7837
|
-
//! type.
|
|
7838
|
-
class Interval {
|
|
7839
|
-
public:
|
|
7840
|
-
static constexpr const int32_t MONTHS_PER_MILLENIUM = 12000;
|
|
7841
|
-
static constexpr const int32_t MONTHS_PER_CENTURY = 1200;
|
|
7842
|
-
static constexpr const int32_t MONTHS_PER_DECADE = 120;
|
|
7843
|
-
static constexpr const int32_t MONTHS_PER_YEAR = 12;
|
|
7844
|
-
static constexpr const int32_t MONTHS_PER_QUARTER = 3;
|
|
7845
|
-
static constexpr const int32_t DAYS_PER_WEEK = 7;
|
|
7846
|
-
//! only used for interval comparison/ordering purposes, in which case a month counts as 30 days
|
|
7847
|
-
static constexpr const int64_t DAYS_PER_MONTH = 30;
|
|
7848
|
-
static constexpr const int64_t DAYS_PER_YEAR = 365;
|
|
7849
|
-
static constexpr const int64_t MSECS_PER_SEC = 1000;
|
|
7850
|
-
static constexpr const int32_t SECS_PER_MINUTE = 60;
|
|
7851
|
-
static constexpr const int32_t MINS_PER_HOUR = 60;
|
|
7852
|
-
static constexpr const int32_t HOURS_PER_DAY = 24;
|
|
7853
|
-
static constexpr const int32_t SECS_PER_HOUR = SECS_PER_MINUTE * MINS_PER_HOUR;
|
|
7854
|
-
static constexpr const int32_t SECS_PER_DAY = SECS_PER_HOUR * HOURS_PER_DAY;
|
|
7855
|
-
static constexpr const int32_t SECS_PER_WEEK = SECS_PER_DAY * DAYS_PER_WEEK;
|
|
7856
|
-
|
|
7857
|
-
static constexpr const int64_t MICROS_PER_MSEC = 1000;
|
|
7858
|
-
static constexpr const int64_t MICROS_PER_SEC = MICROS_PER_MSEC * MSECS_PER_SEC;
|
|
7859
|
-
static constexpr const int64_t MICROS_PER_MINUTE = MICROS_PER_SEC * SECS_PER_MINUTE;
|
|
7860
|
-
static constexpr const int64_t MICROS_PER_HOUR = MICROS_PER_MINUTE * MINS_PER_HOUR;
|
|
7861
|
-
static constexpr const int64_t MICROS_PER_DAY = MICROS_PER_HOUR * HOURS_PER_DAY;
|
|
7862
|
-
static constexpr const int64_t MICROS_PER_WEEK = MICROS_PER_DAY * DAYS_PER_WEEK;
|
|
7863
|
-
static constexpr const int64_t MICROS_PER_MONTH = MICROS_PER_DAY * DAYS_PER_MONTH;
|
|
7864
|
-
|
|
7865
|
-
static constexpr const int64_t NANOS_PER_MICRO = 1000;
|
|
7866
|
-
static constexpr const int64_t NANOS_PER_MSEC = NANOS_PER_MICRO * MICROS_PER_MSEC;
|
|
7867
|
-
static constexpr const int64_t NANOS_PER_SEC = NANOS_PER_MSEC * MSECS_PER_SEC;
|
|
7868
|
-
static constexpr const int64_t NANOS_PER_MINUTE = NANOS_PER_SEC * SECS_PER_MINUTE;
|
|
7869
|
-
static constexpr const int64_t NANOS_PER_HOUR = NANOS_PER_MINUTE * MINS_PER_HOUR;
|
|
7870
|
-
static constexpr const int64_t NANOS_PER_DAY = NANOS_PER_HOUR * HOURS_PER_DAY;
|
|
7871
|
-
static constexpr const int64_t NANOS_PER_WEEK = NANOS_PER_DAY * DAYS_PER_WEEK;
|
|
7872
|
-
|
|
7873
|
-
public:
|
|
7874
|
-
//! Convert a string to an interval object
|
|
7875
|
-
static bool FromString(const string &str, interval_t &result);
|
|
7876
|
-
//! Convert a string to an interval object
|
|
7877
|
-
static bool FromCString(const char *str, idx_t len, interval_t &result, string *error_message, bool strict);
|
|
7878
|
-
//! Convert an interval object to a string
|
|
7879
|
-
static string ToString(const interval_t &val);
|
|
7880
|
-
|
|
7881
|
-
//! Convert milliseconds to a normalised interval
|
|
7882
|
-
DUCKDB_API static interval_t FromMicro(int64_t micros);
|
|
7883
|
-
|
|
7884
|
-
//! Get Interval in milliseconds
|
|
7885
|
-
static int64_t GetMilli(const interval_t &val);
|
|
7886
|
-
|
|
7887
|
-
//! Get Interval in microseconds
|
|
7888
|
-
static int64_t GetMicro(const interval_t &val);
|
|
7889
|
-
|
|
7890
|
-
//! Get Interval in Nanoseconds
|
|
7891
|
-
static int64_t GetNanoseconds(const interval_t &val);
|
|
7892
|
-
|
|
7893
|
-
//! Returns the age between two timestamps (including 30 day months)
|
|
7894
|
-
static interval_t GetAge(timestamp_t timestamp_1, timestamp_t timestamp_2);
|
|
7895
|
-
|
|
7896
|
-
//! Returns the exact difference between two timestamps (days and seconds)
|
|
7897
|
-
static interval_t GetDifference(timestamp_t timestamp_1, timestamp_t timestamp_2);
|
|
7898
|
-
|
|
7899
|
-
//! Returns the inverted interval
|
|
7900
|
-
static interval_t Invert(interval_t interval);
|
|
8248
|
+
DUCKDB_API bool Hugeint::TryCast(hugeint_t input, long double &result);
|
|
7901
8249
|
|
|
7902
|
-
|
|
7903
|
-
|
|
7904
|
-
|
|
7905
|
-
|
|
7906
|
-
|
|
7907
|
-
|
|
7908
|
-
|
|
8250
|
+
template <>
|
|
8251
|
+
bool Hugeint::TryConvert(int8_t value, hugeint_t &result);
|
|
8252
|
+
template <>
|
|
8253
|
+
bool Hugeint::TryConvert(int16_t value, hugeint_t &result);
|
|
8254
|
+
template <>
|
|
8255
|
+
bool Hugeint::TryConvert(int32_t value, hugeint_t &result);
|
|
8256
|
+
template <>
|
|
8257
|
+
bool Hugeint::TryConvert(int64_t value, hugeint_t &result);
|
|
8258
|
+
template <>
|
|
8259
|
+
bool Hugeint::TryConvert(uint8_t value, hugeint_t &result);
|
|
8260
|
+
template <>
|
|
8261
|
+
bool Hugeint::TryConvert(uint16_t value, hugeint_t &result);
|
|
8262
|
+
template <>
|
|
8263
|
+
bool Hugeint::TryConvert(uint32_t value, hugeint_t &result);
|
|
8264
|
+
template <>
|
|
8265
|
+
bool Hugeint::TryConvert(uint64_t value, hugeint_t &result);
|
|
8266
|
+
template <>
|
|
8267
|
+
bool Hugeint::TryConvert(float value, hugeint_t &result);
|
|
8268
|
+
template <>
|
|
8269
|
+
bool Hugeint::TryConvert(double value, hugeint_t &result);
|
|
8270
|
+
template <>
|
|
8271
|
+
bool Hugeint::TryConvert(long double value, hugeint_t &result);
|
|
7909
8272
|
|
|
7910
|
-
//! Comparison operators
|
|
7911
|
-
static bool Equals(interval_t left, interval_t right);
|
|
7912
|
-
static bool GreaterThan(interval_t left, interval_t right);
|
|
7913
|
-
static bool GreaterThanEquals(interval_t left, interval_t right);
|
|
7914
|
-
};
|
|
7915
8273
|
} // namespace duckdb
|
|
7916
8274
|
|
|
7917
8275
|
|
|
7918
8276
|
|
|
8277
|
+
|
|
7919
8278
|
#include <cstring>
|
|
7920
8279
|
|
|
7921
8280
|
namespace duckdb {
|
|
@@ -17399,6 +17758,7 @@ public:
|
|
|
17399
17758
|
namespace duckdb {
|
|
17400
17759
|
|
|
17401
17760
|
struct string_t;
|
|
17761
|
+
struct interval_t;
|
|
17402
17762
|
|
|
17403
17763
|
// efficient hash function that maximizes the avalanche effect and minimizes
|
|
17404
17764
|
// bias
|
|
@@ -21098,145 +21458,6 @@ DUCKDB_API void duckdb_destroy_task_state(duckdb_task_state state);
|
|
|
21098
21458
|
//===----------------------------------------------------------------------===//
|
|
21099
21459
|
// DuckDB
|
|
21100
21460
|
//
|
|
21101
|
-
// duckdb/common/types/date.hpp
|
|
21102
|
-
//
|
|
21103
|
-
//
|
|
21104
|
-
//===----------------------------------------------------------------------===//
|
|
21105
|
-
|
|
21106
|
-
|
|
21107
|
-
|
|
21108
|
-
|
|
21109
|
-
|
|
21110
|
-
|
|
21111
|
-
|
|
21112
|
-
|
|
21113
|
-
namespace duckdb {
|
|
21114
|
-
|
|
21115
|
-
//! The Date class is a static class that holds helper functions for the Date type.
|
|
21116
|
-
class Date {
|
|
21117
|
-
public:
|
|
21118
|
-
static const char *PINF; // NOLINT
|
|
21119
|
-
static const char *NINF; // NOLINT
|
|
21120
|
-
static const char *EPOCH; // NOLINT
|
|
21121
|
-
|
|
21122
|
-
static const string_t MONTH_NAMES[12];
|
|
21123
|
-
static const string_t MONTH_NAMES_ABBREVIATED[12];
|
|
21124
|
-
static const string_t DAY_NAMES[7];
|
|
21125
|
-
static const string_t DAY_NAMES_ABBREVIATED[7];
|
|
21126
|
-
static const int32_t NORMAL_DAYS[13];
|
|
21127
|
-
static const int32_t CUMULATIVE_DAYS[13];
|
|
21128
|
-
static const int32_t LEAP_DAYS[13];
|
|
21129
|
-
static const int32_t CUMULATIVE_LEAP_DAYS[13];
|
|
21130
|
-
static const int32_t CUMULATIVE_YEAR_DAYS[401];
|
|
21131
|
-
static const int8_t MONTH_PER_DAY_OF_YEAR[365];
|
|
21132
|
-
static const int8_t LEAP_MONTH_PER_DAY_OF_YEAR[366];
|
|
21133
|
-
|
|
21134
|
-
// min date is 5877642-06-25 (BC) (-2^31+2)
|
|
21135
|
-
constexpr static const int32_t DATE_MIN_YEAR = -5877641;
|
|
21136
|
-
constexpr static const int32_t DATE_MIN_MONTH = 6;
|
|
21137
|
-
constexpr static const int32_t DATE_MIN_DAY = 25;
|
|
21138
|
-
// max date is 5881580-07-10 (2^31-2)
|
|
21139
|
-
constexpr static const int32_t DATE_MAX_YEAR = 5881580;
|
|
21140
|
-
constexpr static const int32_t DATE_MAX_MONTH = 7;
|
|
21141
|
-
constexpr static const int32_t DATE_MAX_DAY = 10;
|
|
21142
|
-
constexpr static const int32_t EPOCH_YEAR = 1970;
|
|
21143
|
-
|
|
21144
|
-
constexpr static const int32_t YEAR_INTERVAL = 400;
|
|
21145
|
-
constexpr static const int32_t DAYS_PER_YEAR_INTERVAL = 146097;
|
|
21146
|
-
|
|
21147
|
-
public:
|
|
21148
|
-
//! Convert a string in the format "YYYY-MM-DD" to a date object
|
|
21149
|
-
DUCKDB_API static date_t FromString(const string &str, bool strict = false);
|
|
21150
|
-
//! Convert a string in the format "YYYY-MM-DD" to a date object
|
|
21151
|
-
DUCKDB_API static date_t FromCString(const char *str, idx_t len, bool strict = false);
|
|
21152
|
-
//! Convert a date object to a string in the format "YYYY-MM-DD"
|
|
21153
|
-
DUCKDB_API static string ToString(date_t date);
|
|
21154
|
-
//! Try to convert text in a buffer to a date; returns true if parsing was successful
|
|
21155
|
-
//! If the date was a "special" value, the special flag will be set.
|
|
21156
|
-
DUCKDB_API static bool TryConvertDate(const char *buf, idx_t len, idx_t &pos, date_t &result, bool &special,
|
|
21157
|
-
bool strict = false);
|
|
21158
|
-
|
|
21159
|
-
//! Create a string "YYYY-MM-DD" from a specified (year, month, day)
|
|
21160
|
-
//! combination
|
|
21161
|
-
DUCKDB_API static string Format(int32_t year, int32_t month, int32_t day);
|
|
21162
|
-
|
|
21163
|
-
//! Extract the year, month and day from a given date object
|
|
21164
|
-
DUCKDB_API static void Convert(date_t date, int32_t &out_year, int32_t &out_month, int32_t &out_day);
|
|
21165
|
-
//! Create a Date object from a specified (year, month, day) combination
|
|
21166
|
-
DUCKDB_API static date_t FromDate(int32_t year, int32_t month, int32_t day);
|
|
21167
|
-
DUCKDB_API static bool TryFromDate(int32_t year, int32_t month, int32_t day, date_t &result);
|
|
21168
|
-
|
|
21169
|
-
//! Returns true if (year) is a leap year, and false otherwise
|
|
21170
|
-
DUCKDB_API static bool IsLeapYear(int32_t year);
|
|
21171
|
-
|
|
21172
|
-
//! Returns true if the specified (year, month, day) combination is a valid
|
|
21173
|
-
//! date
|
|
21174
|
-
DUCKDB_API static bool IsValid(int32_t year, int32_t month, int32_t day);
|
|
21175
|
-
|
|
21176
|
-
//! Returns true if the specified date is finite
|
|
21177
|
-
static inline bool IsFinite(date_t date) {
|
|
21178
|
-
return date != date_t::infinity() && date != date_t::ninfinity();
|
|
21179
|
-
}
|
|
21180
|
-
|
|
21181
|
-
//! The max number of days in a month of a given year
|
|
21182
|
-
DUCKDB_API static int32_t MonthDays(int32_t year, int32_t month);
|
|
21183
|
-
|
|
21184
|
-
//! Extract the epoch from the date (seconds since 1970-01-01)
|
|
21185
|
-
DUCKDB_API static int64_t Epoch(date_t date);
|
|
21186
|
-
//! Extract the epoch from the date (nanoseconds since 1970-01-01)
|
|
21187
|
-
DUCKDB_API static int64_t EpochNanoseconds(date_t date);
|
|
21188
|
-
//! Extract the epoch from the date (microseconds since 1970-01-01)
|
|
21189
|
-
DUCKDB_API static int64_t EpochMicroseconds(date_t date);
|
|
21190
|
-
//! Convert the epoch (seconds since 1970-01-01) to a date_t
|
|
21191
|
-
DUCKDB_API static date_t EpochToDate(int64_t epoch);
|
|
21192
|
-
|
|
21193
|
-
//! Extract the number of days since epoch (days since 1970-01-01)
|
|
21194
|
-
DUCKDB_API static int32_t EpochDays(date_t date);
|
|
21195
|
-
//! Convert the epoch number of days to a date_t
|
|
21196
|
-
DUCKDB_API static date_t EpochDaysToDate(int32_t epoch);
|
|
21197
|
-
|
|
21198
|
-
//! Extract year of a date entry
|
|
21199
|
-
DUCKDB_API static int32_t ExtractYear(date_t date);
|
|
21200
|
-
//! Extract year of a date entry, but optimized to first try the last year found
|
|
21201
|
-
DUCKDB_API static int32_t ExtractYear(date_t date, int32_t *last_year);
|
|
21202
|
-
DUCKDB_API static int32_t ExtractYear(timestamp_t ts, int32_t *last_year);
|
|
21203
|
-
//! Extract month of a date entry
|
|
21204
|
-
DUCKDB_API static int32_t ExtractMonth(date_t date);
|
|
21205
|
-
//! Extract day of a date entry
|
|
21206
|
-
DUCKDB_API static int32_t ExtractDay(date_t date);
|
|
21207
|
-
//! Extract the day of the week (1-7)
|
|
21208
|
-
DUCKDB_API static int32_t ExtractISODayOfTheWeek(date_t date);
|
|
21209
|
-
//! Extract the day of the year
|
|
21210
|
-
DUCKDB_API static int32_t ExtractDayOfTheYear(date_t date);
|
|
21211
|
-
//! Extract the ISO week number
|
|
21212
|
-
//! ISO weeks start on Monday and the first week of a year
|
|
21213
|
-
//! contains January 4 of that year.
|
|
21214
|
-
//! In the ISO week-numbering system, it is possible for early-January dates
|
|
21215
|
-
//! to be part of the 52nd or 53rd week of the previous year.
|
|
21216
|
-
DUCKDB_API static void ExtractISOYearWeek(date_t date, int32_t &year, int32_t &week);
|
|
21217
|
-
DUCKDB_API static int32_t ExtractISOWeekNumber(date_t date);
|
|
21218
|
-
DUCKDB_API static int32_t ExtractISOYearNumber(date_t date);
|
|
21219
|
-
//! Extract the week number as Python handles it.
|
|
21220
|
-
//! Either Monday or Sunday is the first day of the week,
|
|
21221
|
-
//! and any date before the first Monday/Sunday returns week 0
|
|
21222
|
-
//! This is a bit more consistent because week numbers in a year are always incrementing
|
|
21223
|
-
DUCKDB_API static int32_t ExtractWeekNumberRegular(date_t date, bool monday_first = true);
|
|
21224
|
-
//! Returns the date of the monday of the current week.
|
|
21225
|
-
DUCKDB_API static date_t GetMondayOfCurrentWeek(date_t date);
|
|
21226
|
-
|
|
21227
|
-
//! Helper function to parse two digits from a string (e.g. "30" -> 30, "03" -> 3, "3" -> 3)
|
|
21228
|
-
DUCKDB_API static bool ParseDoubleDigit(const char *buf, idx_t len, idx_t &pos, int32_t &result);
|
|
21229
|
-
|
|
21230
|
-
DUCKDB_API static string ConversionError(const string &str);
|
|
21231
|
-
DUCKDB_API static string ConversionError(string_t str);
|
|
21232
|
-
|
|
21233
|
-
private:
|
|
21234
|
-
static void ExtractYearOffset(int32_t &n, int32_t &year, int32_t &year_offset);
|
|
21235
|
-
};
|
|
21236
|
-
} // namespace duckdb
|
|
21237
|
-
//===----------------------------------------------------------------------===//
|
|
21238
|
-
// DuckDB
|
|
21239
|
-
//
|
|
21240
21461
|
// duckdb/common/arrow/arrow_converter.hpp
|
|
21241
21462
|
//
|
|
21242
21463
|
//
|
|
@@ -21416,86 +21637,6 @@ public:
|
|
|
21416
21637
|
}
|
|
21417
21638
|
};
|
|
21418
21639
|
|
|
21419
|
-
} // namespace duckdb
|
|
21420
|
-
//===----------------------------------------------------------------------===//
|
|
21421
|
-
// DuckDB
|
|
21422
|
-
//
|
|
21423
|
-
// duckdb/common/types/timestamp.hpp
|
|
21424
|
-
//
|
|
21425
|
-
//
|
|
21426
|
-
//===----------------------------------------------------------------------===//
|
|
21427
|
-
|
|
21428
|
-
|
|
21429
|
-
|
|
21430
|
-
|
|
21431
|
-
|
|
21432
|
-
|
|
21433
|
-
|
|
21434
|
-
namespace duckdb {
|
|
21435
|
-
|
|
21436
|
-
//! The Timestamp class is a static class that holds helper functions for the Timestamp
|
|
21437
|
-
//! type.
|
|
21438
|
-
class Timestamp {
|
|
21439
|
-
public:
|
|
21440
|
-
// min timestamp is 290308-12-22 (BC)
|
|
21441
|
-
constexpr static const int32_t MIN_YEAR = -290308;
|
|
21442
|
-
constexpr static const int32_t MIN_MONTH = 12;
|
|
21443
|
-
constexpr static const int32_t MIN_DAY = 22;
|
|
21444
|
-
|
|
21445
|
-
public:
|
|
21446
|
-
//! Convert a string in the format "YYYY-MM-DD hh:mm:ss[.f][-+TH[:tm]]" to a timestamp object
|
|
21447
|
-
DUCKDB_API static timestamp_t FromString(const string &str);
|
|
21448
|
-
//! Convert a string where the offset can also be a time zone string: / [A_Za-z0-9/_]+/
|
|
21449
|
-
//! If has_offset is true, then the result is an instant that was offset from UTC
|
|
21450
|
-
//! If the tz is not empty, the result is still an instant, but the parts can be extracted and applied to the TZ
|
|
21451
|
-
DUCKDB_API static bool TryConvertTimestampTZ(const char *str, idx_t len, timestamp_t &result, bool &has_offset,
|
|
21452
|
-
string_t &tz);
|
|
21453
|
-
DUCKDB_API static bool TryConvertTimestamp(const char *str, idx_t len, timestamp_t &result);
|
|
21454
|
-
DUCKDB_API static timestamp_t FromCString(const char *str, idx_t len);
|
|
21455
|
-
//! Convert a date object to a string in the format "YYYY-MM-DD hh:mm:ss"
|
|
21456
|
-
DUCKDB_API static string ToString(timestamp_t timestamp);
|
|
21457
|
-
|
|
21458
|
-
DUCKDB_API static date_t GetDate(timestamp_t timestamp);
|
|
21459
|
-
|
|
21460
|
-
DUCKDB_API static dtime_t GetTime(timestamp_t timestamp);
|
|
21461
|
-
//! Create a Timestamp object from a specified (date, time) combination
|
|
21462
|
-
DUCKDB_API static timestamp_t FromDatetime(date_t date, dtime_t time);
|
|
21463
|
-
DUCKDB_API static bool TryFromDatetime(date_t date, dtime_t time, timestamp_t &result);
|
|
21464
|
-
|
|
21465
|
-
//! Is the timestamp finite or infinite?
|
|
21466
|
-
static inline bool IsFinite(timestamp_t timestamp) {
|
|
21467
|
-
return timestamp != timestamp_t::infinity() && timestamp != timestamp_t::ninfinity();
|
|
21468
|
-
}
|
|
21469
|
-
|
|
21470
|
-
//! Extract the date and time from a given timestamp object
|
|
21471
|
-
DUCKDB_API static void Convert(timestamp_t date, date_t &out_date, dtime_t &out_time);
|
|
21472
|
-
//! Returns current timestamp
|
|
21473
|
-
DUCKDB_API static timestamp_t GetCurrentTimestamp();
|
|
21474
|
-
|
|
21475
|
-
//! Convert the epoch (in sec) to a timestamp
|
|
21476
|
-
DUCKDB_API static timestamp_t FromEpochSeconds(int64_t ms);
|
|
21477
|
-
//! Convert the epoch (in ms) to a timestamp
|
|
21478
|
-
DUCKDB_API static timestamp_t FromEpochMs(int64_t ms);
|
|
21479
|
-
//! Convert the epoch (in microseconds) to a timestamp
|
|
21480
|
-
DUCKDB_API static timestamp_t FromEpochMicroSeconds(int64_t micros);
|
|
21481
|
-
//! Convert the epoch (in nanoseconds) to a timestamp
|
|
21482
|
-
DUCKDB_API static timestamp_t FromEpochNanoSeconds(int64_t micros);
|
|
21483
|
-
|
|
21484
|
-
//! Convert the epoch (in seconds) to a timestamp
|
|
21485
|
-
DUCKDB_API static int64_t GetEpochSeconds(timestamp_t timestamp);
|
|
21486
|
-
//! Convert the epoch (in ms) to a timestamp
|
|
21487
|
-
DUCKDB_API static int64_t GetEpochMs(timestamp_t timestamp);
|
|
21488
|
-
//! Convert a timestamp to epoch (in microseconds)
|
|
21489
|
-
DUCKDB_API static int64_t GetEpochMicroSeconds(timestamp_t timestamp);
|
|
21490
|
-
//! Convert a timestamp to epoch (in nanoseconds)
|
|
21491
|
-
DUCKDB_API static int64_t GetEpochNanoSeconds(timestamp_t timestamp);
|
|
21492
|
-
|
|
21493
|
-
DUCKDB_API static bool TryParseUTCOffset(const char *str, idx_t &pos, idx_t len, int &hour_offset,
|
|
21494
|
-
int &minute_offset);
|
|
21495
|
-
|
|
21496
|
-
DUCKDB_API static string ConversionError(const string &str);
|
|
21497
|
-
DUCKDB_API static string ConversionError(string_t str);
|
|
21498
|
-
};
|
|
21499
21640
|
} // namespace duckdb
|
|
21500
21641
|
//===----------------------------------------------------------------------===//
|
|
21501
21642
|
// DuckDB
|
|
@@ -21513,6 +21654,8 @@ public:
|
|
|
21513
21654
|
|
|
21514
21655
|
namespace duckdb {
|
|
21515
21656
|
|
|
21657
|
+
struct dtime_t;
|
|
21658
|
+
|
|
21516
21659
|
//! The Time class is a static class that holds helper functions for the Time
|
|
21517
21660
|
//! type.
|
|
21518
21661
|
class Time {
|