duckdb 0.6.1-dev5.0 → 0.6.1-dev71.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 +130 -35
- package/src/duckdb.hpp +1193 -1032
- package/src/parquet-amalgamation.cpp +37404 -37402
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 "e56ace47fe"
|
|
15
|
+
#define DUCKDB_VERSION "v0.6.1-dev71"
|
|
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);
|
|
@@ -3612,6 +4276,9 @@ private:
|
|
|
3612
4276
|
};
|
|
3613
4277
|
|
|
3614
4278
|
class Allocator {
|
|
4279
|
+
// 281TB ought to be enough for anybody
|
|
4280
|
+
static constexpr const idx_t MAXIMUM_ALLOC_SIZE = 281474976710656ULL;
|
|
4281
|
+
|
|
3615
4282
|
public:
|
|
3616
4283
|
DUCKDB_API Allocator();
|
|
3617
4284
|
DUCKDB_API Allocator(allocate_function_ptr_t allocate_function_p, free_function_ptr_t free_function_p,
|
|
@@ -3720,185 +4387,50 @@ public:
|
|
|
3720
4387
|
|
|
3721
4388
|
bool IsEmpty();
|
|
3722
4389
|
|
|
3723
|
-
private:
|
|
3724
|
-
//! Internal allocator that is used by the arena allocator
|
|
3725
|
-
Allocator &allocator;
|
|
3726
|
-
idx_t current_capacity;
|
|
3727
|
-
unique_ptr<ArenaChunk> head;
|
|
3728
|
-
ArenaChunk *tail;
|
|
3729
|
-
};
|
|
3730
|
-
|
|
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
|
-
}
|
|
4390
|
+
private:
|
|
4391
|
+
//! Internal allocator that is used by the arena allocator
|
|
4392
|
+
Allocator &allocator;
|
|
4393
|
+
idx_t current_capacity;
|
|
4394
|
+
unique_ptr<ArenaChunk> head;
|
|
4395
|
+
ArenaChunk *tail;
|
|
4396
|
+
};
|
|
3847
4397
|
|
|
3848
|
-
|
|
3849
|
-
return value.inlined.length;
|
|
3850
|
-
}
|
|
4398
|
+
} // namespace duckdb
|
|
3851
4399
|
|
|
3852
|
-
string GetString() const {
|
|
3853
|
-
return string(GetDataUnsafe(), GetSize());
|
|
3854
|
-
}
|
|
3855
4400
|
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
4401
|
+
namespace duckdb {
|
|
4402
|
+
//! A string heap is the owner of a set of strings, strings can be inserted into
|
|
4403
|
+
//! it On every insert, a pointer to the inserted string is returned The
|
|
4404
|
+
//! returned pointer will remain valid until the StringHeap is destroyed
|
|
4405
|
+
class StringHeap {
|
|
4406
|
+
public:
|
|
4407
|
+
StringHeap();
|
|
3859
4408
|
|
|
3860
|
-
void
|
|
3861
|
-
|
|
3862
|
-
if (GetSize() <= INLINE_LENGTH) {
|
|
3863
|
-
// fill prefix with zeros if the length is smaller than the prefix length
|
|
3864
|
-
for (idx_t i = GetSize(); i < INLINE_BYTES; i++) {
|
|
3865
|
-
value.inlined.inlined[i] = '\0';
|
|
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
|
-
}
|
|
4409
|
+
void Destroy();
|
|
4410
|
+
void Move(StringHeap &other);
|
|
3877
4411
|
|
|
3878
|
-
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
4412
|
+
//! Add a string to the string heap, returns a pointer to the string
|
|
4413
|
+
string_t AddString(const char *data, idx_t len);
|
|
4414
|
+
//! Add a string to the string heap, returns a pointer to the string
|
|
4415
|
+
string_t AddString(const char *data);
|
|
4416
|
+
//! Add a string to the string heap, returns a pointer to the string
|
|
4417
|
+
string_t AddString(const string &data);
|
|
4418
|
+
//! Add a string to the string heap, returns a pointer to the string
|
|
4419
|
+
string_t AddString(const string_t &data);
|
|
4420
|
+
//! Add a blob to the string heap; blobs can be non-valid UTF8
|
|
4421
|
+
string_t AddBlob(const string_t &data);
|
|
4422
|
+
//! Add a blob to the string heap; blobs can be non-valid UTF8
|
|
4423
|
+
string_t AddBlob(const char *data, idx_t len);
|
|
4424
|
+
//! Allocates space for an empty string of size "len" on the heap
|
|
4425
|
+
string_t EmptyString(idx_t len);
|
|
3885
4426
|
|
|
3886
4427
|
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;
|
|
4428
|
+
ArenaAllocator allocator;
|
|
3898
4429
|
};
|
|
3899
4430
|
|
|
3900
4431
|
} // namespace duckdb
|
|
3901
4432
|
|
|
4433
|
+
|
|
3902
4434
|
//===----------------------------------------------------------------------===//
|
|
3903
4435
|
// DuckDB
|
|
3904
4436
|
//
|
|
@@ -7463,214 +7995,138 @@ public:
|
|
|
7463
7995
|
};
|
|
7464
7996
|
|
|
7465
7997
|
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;
|
|
7998
|
+
ExecuteFunctionState(const Expression &expr, ExpressionExecutorState &root);
|
|
7999
|
+
~ExecuteFunctionState();
|
|
8000
|
+
|
|
8001
|
+
unique_ptr<FunctionLocalState> local_state;
|
|
8002
|
+
|
|
8003
|
+
public:
|
|
8004
|
+
static FunctionLocalState *GetFunctionState(ExpressionState &state) {
|
|
8005
|
+
return ((ExecuteFunctionState &)state).local_state.get();
|
|
7645
8006
|
}
|
|
7646
8007
|
};
|
|
7647
|
-
|
|
7648
|
-
struct
|
|
7649
|
-
|
|
7650
|
-
|
|
7651
|
-
|
|
7652
|
-
|
|
7653
|
-
|
|
7654
|
-
|
|
7655
|
-
|
|
7656
|
-
|
|
8008
|
+
|
|
8009
|
+
struct ExpressionExecutorState {
|
|
8010
|
+
explicit ExpressionExecutorState(const string &name);
|
|
8011
|
+
|
|
8012
|
+
unique_ptr<ExpressionState> root_state;
|
|
8013
|
+
ExpressionExecutor *executor = nullptr;
|
|
8014
|
+
CycleCounter profiler;
|
|
8015
|
+
string name;
|
|
8016
|
+
|
|
8017
|
+
void Verify();
|
|
7657
8018
|
};
|
|
7658
|
-
|
|
7659
|
-
|
|
7660
|
-
|
|
7661
|
-
|
|
7662
|
-
|
|
7663
|
-
|
|
7664
|
-
|
|
7665
|
-
|
|
7666
|
-
|
|
8019
|
+
|
|
8020
|
+
} // namespace duckdb
|
|
8021
|
+
|
|
8022
|
+
|
|
8023
|
+
//===----------------------------------------------------------------------===//
|
|
8024
|
+
// DuckDB
|
|
8025
|
+
//
|
|
8026
|
+
// duckdb/storage/statistics/base_statistics.hpp
|
|
8027
|
+
//
|
|
8028
|
+
//
|
|
8029
|
+
//===----------------------------------------------------------------------===//
|
|
8030
|
+
|
|
8031
|
+
|
|
8032
|
+
|
|
8033
|
+
|
|
8034
|
+
|
|
8035
|
+
//===----------------------------------------------------------------------===//
|
|
8036
|
+
// DuckDB
|
|
8037
|
+
//
|
|
8038
|
+
// duckdb/common/operator/comparison_operators.hpp
|
|
8039
|
+
//
|
|
8040
|
+
//
|
|
8041
|
+
//===----------------------------------------------------------------------===//
|
|
8042
|
+
|
|
8043
|
+
|
|
8044
|
+
|
|
8045
|
+
|
|
8046
|
+
|
|
8047
|
+
//===----------------------------------------------------------------------===//
|
|
8048
|
+
// DuckDB
|
|
8049
|
+
//
|
|
8050
|
+
// duckdb/common/types/hugeint.hpp
|
|
8051
|
+
//
|
|
8052
|
+
//
|
|
8053
|
+
//===----------------------------------------------------------------------===//
|
|
8054
|
+
|
|
8055
|
+
|
|
8056
|
+
|
|
8057
|
+
|
|
8058
|
+
|
|
8059
|
+
|
|
8060
|
+
|
|
8061
|
+
|
|
8062
|
+
|
|
8063
|
+
|
|
8064
|
+
|
|
8065
|
+
|
|
8066
|
+
namespace duckdb {
|
|
8067
|
+
|
|
8068
|
+
//! Returns the PhysicalType for the given type
|
|
8069
|
+
template <class T>
|
|
8070
|
+
PhysicalType GetTypeId() {
|
|
8071
|
+
if (std::is_same<T, bool>()) {
|
|
8072
|
+
return PhysicalType::BOOL;
|
|
8073
|
+
} else if (std::is_same<T, int8_t>()) {
|
|
8074
|
+
return PhysicalType::INT8;
|
|
8075
|
+
} else if (std::is_same<T, int16_t>()) {
|
|
8076
|
+
return PhysicalType::INT16;
|
|
8077
|
+
} else if (std::is_same<T, int32_t>()) {
|
|
8078
|
+
return PhysicalType::INT32;
|
|
8079
|
+
} else if (std::is_same<T, int64_t>()) {
|
|
8080
|
+
return PhysicalType::INT64;
|
|
8081
|
+
} else if (std::is_same<T, uint8_t>()) {
|
|
8082
|
+
return PhysicalType::UINT8;
|
|
8083
|
+
} else if (std::is_same<T, uint16_t>()) {
|
|
8084
|
+
return PhysicalType::UINT16;
|
|
8085
|
+
} else if (std::is_same<T, uint32_t>()) {
|
|
8086
|
+
return PhysicalType::UINT32;
|
|
8087
|
+
} else if (std::is_same<T, uint64_t>()) {
|
|
8088
|
+
return PhysicalType::UINT64;
|
|
8089
|
+
} else if (std::is_same<T, hugeint_t>()) {
|
|
8090
|
+
return PhysicalType::INT128;
|
|
8091
|
+
} else if (std::is_same<T, date_t>()) {
|
|
8092
|
+
return PhysicalType::INT32;
|
|
8093
|
+
} else if (std::is_same<T, dtime_t>()) {
|
|
8094
|
+
return PhysicalType::INT64;
|
|
8095
|
+
} else if (std::is_same<T, timestamp_t>()) {
|
|
8096
|
+
return PhysicalType::INT64;
|
|
8097
|
+
} else if (std::is_same<T, float>()) {
|
|
8098
|
+
return PhysicalType::FLOAT;
|
|
8099
|
+
} else if (std::is_same<T, double>()) {
|
|
8100
|
+
return PhysicalType::DOUBLE;
|
|
8101
|
+
} else if (std::is_same<T, const char *>() || std::is_same<T, char *>() || std::is_same<T, string_t>()) {
|
|
8102
|
+
return PhysicalType::VARCHAR;
|
|
8103
|
+
} else if (std::is_same<T, interval_t>()) {
|
|
8104
|
+
return PhysicalType::INTERVAL;
|
|
8105
|
+
} else {
|
|
8106
|
+
return PhysicalType::INVALID;
|
|
7667
8107
|
}
|
|
7668
|
-
}
|
|
8108
|
+
}
|
|
8109
|
+
|
|
8110
|
+
template <class T>
|
|
8111
|
+
bool TypeIsNumber() {
|
|
8112
|
+
return std::is_integral<T>() || std::is_floating_point<T>() || std::is_same<T, hugeint_t>();
|
|
8113
|
+
}
|
|
8114
|
+
|
|
8115
|
+
template <class T>
|
|
8116
|
+
bool IsValidType() {
|
|
8117
|
+
return GetTypeId<T>() != PhysicalType::INVALID;
|
|
8118
|
+
}
|
|
8119
|
+
|
|
8120
|
+
template <class T>
|
|
8121
|
+
bool IsIntegerType() {
|
|
8122
|
+
return TypeIsIntegral(GetTypeId<T>());
|
|
8123
|
+
}
|
|
7669
8124
|
|
|
7670
8125
|
} // namespace duckdb
|
|
7671
8126
|
|
|
7672
8127
|
|
|
7673
8128
|
|
|
8129
|
+
|
|
7674
8130
|
namespace duckdb {
|
|
7675
8131
|
|
|
7676
8132
|
//! The Hugeint class contains static operations for the INT128 type
|
|
@@ -7794,128 +8250,36 @@ DUCKDB_API bool Hugeint::TryCast(hugeint_t input, double &result);
|
|
|
7794
8250
|
template <>
|
|
7795
8251
|
DUCKDB_API bool Hugeint::TryCast(hugeint_t input, long double &result);
|
|
7796
8252
|
|
|
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
|
-
|
|
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);
|
|
7901
|
-
|
|
7902
|
-
//! Add an interval to a date
|
|
7903
|
-
static date_t Add(date_t left, interval_t right);
|
|
7904
|
-
//! Add an interval to a timestamp
|
|
7905
|
-
static timestamp_t Add(timestamp_t left, interval_t right);
|
|
7906
|
-
//! Add an interval to a time. In case the time overflows or underflows, modify the date by the overflow.
|
|
7907
|
-
//! For example if we go from 23:00 to 02:00, we add a day to the date
|
|
7908
|
-
static dtime_t Add(dtime_t left, interval_t right, date_t &date);
|
|
7909
|
-
|
|
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
|
-
};
|
|
8253
|
+
template <>
|
|
8254
|
+
bool Hugeint::TryConvert(int8_t value, hugeint_t &result);
|
|
8255
|
+
template <>
|
|
8256
|
+
bool Hugeint::TryConvert(int16_t value, hugeint_t &result);
|
|
8257
|
+
template <>
|
|
8258
|
+
bool Hugeint::TryConvert(int32_t value, hugeint_t &result);
|
|
8259
|
+
template <>
|
|
8260
|
+
bool Hugeint::TryConvert(int64_t value, hugeint_t &result);
|
|
8261
|
+
template <>
|
|
8262
|
+
bool Hugeint::TryConvert(uint8_t value, hugeint_t &result);
|
|
8263
|
+
template <>
|
|
8264
|
+
bool Hugeint::TryConvert(uint16_t value, hugeint_t &result);
|
|
8265
|
+
template <>
|
|
8266
|
+
bool Hugeint::TryConvert(uint32_t value, hugeint_t &result);
|
|
8267
|
+
template <>
|
|
8268
|
+
bool Hugeint::TryConvert(uint64_t value, hugeint_t &result);
|
|
8269
|
+
template <>
|
|
8270
|
+
bool Hugeint::TryConvert(float value, hugeint_t &result);
|
|
8271
|
+
template <>
|
|
8272
|
+
bool Hugeint::TryConvert(double value, hugeint_t &result);
|
|
8273
|
+
template <>
|
|
8274
|
+
bool Hugeint::TryConvert(long double value, hugeint_t &result);
|
|
8275
|
+
template <>
|
|
8276
|
+
bool Hugeint::TryConvert(const char *value, hugeint_t &result);
|
|
8277
|
+
|
|
7915
8278
|
} // namespace duckdb
|
|
7916
8279
|
|
|
7917
8280
|
|
|
7918
8281
|
|
|
8282
|
+
|
|
7919
8283
|
#include <cstring>
|
|
7920
8284
|
|
|
7921
8285
|
namespace duckdb {
|
|
@@ -17399,6 +17763,7 @@ public:
|
|
|
17399
17763
|
namespace duckdb {
|
|
17400
17764
|
|
|
17401
17765
|
struct string_t;
|
|
17766
|
+
struct interval_t;
|
|
17402
17767
|
|
|
17403
17768
|
// efficient hash function that maximizes the avalanche effect and minimizes
|
|
17404
17769
|
// bias
|
|
@@ -19440,6 +19805,8 @@ DUCKDB_API const char *duckdb_result_error(duckdb_result *result);
|
|
|
19440
19805
|
/*!
|
|
19441
19806
|
Fetches a data chunk from the duckdb_result. This function should be called repeatedly until the result is exhausted.
|
|
19442
19807
|
|
|
19808
|
+
The result must be destroyed with `duckdb_destroy_data_chunk`.
|
|
19809
|
+
|
|
19443
19810
|
This function supersedes all `duckdb_value` functions, as well as the `duckdb_column_data` and `duckdb_nullmask_data`
|
|
19444
19811
|
functions. It results in significantly better performance, and should be preferred in newer code-bases.
|
|
19445
19812
|
|
|
@@ -21096,145 +21463,6 @@ DUCKDB_API void duckdb_destroy_task_state(duckdb_task_state state);
|
|
|
21096
21463
|
//===----------------------------------------------------------------------===//
|
|
21097
21464
|
// DuckDB
|
|
21098
21465
|
//
|
|
21099
|
-
// duckdb/common/types/date.hpp
|
|
21100
|
-
//
|
|
21101
|
-
//
|
|
21102
|
-
//===----------------------------------------------------------------------===//
|
|
21103
|
-
|
|
21104
|
-
|
|
21105
|
-
|
|
21106
|
-
|
|
21107
|
-
|
|
21108
|
-
|
|
21109
|
-
|
|
21110
|
-
|
|
21111
|
-
namespace duckdb {
|
|
21112
|
-
|
|
21113
|
-
//! The Date class is a static class that holds helper functions for the Date type.
|
|
21114
|
-
class Date {
|
|
21115
|
-
public:
|
|
21116
|
-
static const char *PINF; // NOLINT
|
|
21117
|
-
static const char *NINF; // NOLINT
|
|
21118
|
-
static const char *EPOCH; // NOLINT
|
|
21119
|
-
|
|
21120
|
-
static const string_t MONTH_NAMES[12];
|
|
21121
|
-
static const string_t MONTH_NAMES_ABBREVIATED[12];
|
|
21122
|
-
static const string_t DAY_NAMES[7];
|
|
21123
|
-
static const string_t DAY_NAMES_ABBREVIATED[7];
|
|
21124
|
-
static const int32_t NORMAL_DAYS[13];
|
|
21125
|
-
static const int32_t CUMULATIVE_DAYS[13];
|
|
21126
|
-
static const int32_t LEAP_DAYS[13];
|
|
21127
|
-
static const int32_t CUMULATIVE_LEAP_DAYS[13];
|
|
21128
|
-
static const int32_t CUMULATIVE_YEAR_DAYS[401];
|
|
21129
|
-
static const int8_t MONTH_PER_DAY_OF_YEAR[365];
|
|
21130
|
-
static const int8_t LEAP_MONTH_PER_DAY_OF_YEAR[366];
|
|
21131
|
-
|
|
21132
|
-
// min date is 5877642-06-25 (BC) (-2^31+2)
|
|
21133
|
-
constexpr static const int32_t DATE_MIN_YEAR = -5877641;
|
|
21134
|
-
constexpr static const int32_t DATE_MIN_MONTH = 6;
|
|
21135
|
-
constexpr static const int32_t DATE_MIN_DAY = 25;
|
|
21136
|
-
// max date is 5881580-07-10 (2^31-2)
|
|
21137
|
-
constexpr static const int32_t DATE_MAX_YEAR = 5881580;
|
|
21138
|
-
constexpr static const int32_t DATE_MAX_MONTH = 7;
|
|
21139
|
-
constexpr static const int32_t DATE_MAX_DAY = 10;
|
|
21140
|
-
constexpr static const int32_t EPOCH_YEAR = 1970;
|
|
21141
|
-
|
|
21142
|
-
constexpr static const int32_t YEAR_INTERVAL = 400;
|
|
21143
|
-
constexpr static const int32_t DAYS_PER_YEAR_INTERVAL = 146097;
|
|
21144
|
-
|
|
21145
|
-
public:
|
|
21146
|
-
//! Convert a string in the format "YYYY-MM-DD" to a date object
|
|
21147
|
-
DUCKDB_API static date_t FromString(const string &str, bool strict = false);
|
|
21148
|
-
//! Convert a string in the format "YYYY-MM-DD" to a date object
|
|
21149
|
-
DUCKDB_API static date_t FromCString(const char *str, idx_t len, bool strict = false);
|
|
21150
|
-
//! Convert a date object to a string in the format "YYYY-MM-DD"
|
|
21151
|
-
DUCKDB_API static string ToString(date_t date);
|
|
21152
|
-
//! Try to convert text in a buffer to a date; returns true if parsing was successful
|
|
21153
|
-
//! If the date was a "special" value, the special flag will be set.
|
|
21154
|
-
DUCKDB_API static bool TryConvertDate(const char *buf, idx_t len, idx_t &pos, date_t &result, bool &special,
|
|
21155
|
-
bool strict = false);
|
|
21156
|
-
|
|
21157
|
-
//! Create a string "YYYY-MM-DD" from a specified (year, month, day)
|
|
21158
|
-
//! combination
|
|
21159
|
-
DUCKDB_API static string Format(int32_t year, int32_t month, int32_t day);
|
|
21160
|
-
|
|
21161
|
-
//! Extract the year, month and day from a given date object
|
|
21162
|
-
DUCKDB_API static void Convert(date_t date, int32_t &out_year, int32_t &out_month, int32_t &out_day);
|
|
21163
|
-
//! Create a Date object from a specified (year, month, day) combination
|
|
21164
|
-
DUCKDB_API static date_t FromDate(int32_t year, int32_t month, int32_t day);
|
|
21165
|
-
DUCKDB_API static bool TryFromDate(int32_t year, int32_t month, int32_t day, date_t &result);
|
|
21166
|
-
|
|
21167
|
-
//! Returns true if (year) is a leap year, and false otherwise
|
|
21168
|
-
DUCKDB_API static bool IsLeapYear(int32_t year);
|
|
21169
|
-
|
|
21170
|
-
//! Returns true if the specified (year, month, day) combination is a valid
|
|
21171
|
-
//! date
|
|
21172
|
-
DUCKDB_API static bool IsValid(int32_t year, int32_t month, int32_t day);
|
|
21173
|
-
|
|
21174
|
-
//! Returns true if the specified date is finite
|
|
21175
|
-
static inline bool IsFinite(date_t date) {
|
|
21176
|
-
return date != date_t::infinity() && date != date_t::ninfinity();
|
|
21177
|
-
}
|
|
21178
|
-
|
|
21179
|
-
//! The max number of days in a month of a given year
|
|
21180
|
-
DUCKDB_API static int32_t MonthDays(int32_t year, int32_t month);
|
|
21181
|
-
|
|
21182
|
-
//! Extract the epoch from the date (seconds since 1970-01-01)
|
|
21183
|
-
DUCKDB_API static int64_t Epoch(date_t date);
|
|
21184
|
-
//! Extract the epoch from the date (nanoseconds since 1970-01-01)
|
|
21185
|
-
DUCKDB_API static int64_t EpochNanoseconds(date_t date);
|
|
21186
|
-
//! Extract the epoch from the date (microseconds since 1970-01-01)
|
|
21187
|
-
DUCKDB_API static int64_t EpochMicroseconds(date_t date);
|
|
21188
|
-
//! Convert the epoch (seconds since 1970-01-01) to a date_t
|
|
21189
|
-
DUCKDB_API static date_t EpochToDate(int64_t epoch);
|
|
21190
|
-
|
|
21191
|
-
//! Extract the number of days since epoch (days since 1970-01-01)
|
|
21192
|
-
DUCKDB_API static int32_t EpochDays(date_t date);
|
|
21193
|
-
//! Convert the epoch number of days to a date_t
|
|
21194
|
-
DUCKDB_API static date_t EpochDaysToDate(int32_t epoch);
|
|
21195
|
-
|
|
21196
|
-
//! Extract year of a date entry
|
|
21197
|
-
DUCKDB_API static int32_t ExtractYear(date_t date);
|
|
21198
|
-
//! Extract year of a date entry, but optimized to first try the last year found
|
|
21199
|
-
DUCKDB_API static int32_t ExtractYear(date_t date, int32_t *last_year);
|
|
21200
|
-
DUCKDB_API static int32_t ExtractYear(timestamp_t ts, int32_t *last_year);
|
|
21201
|
-
//! Extract month of a date entry
|
|
21202
|
-
DUCKDB_API static int32_t ExtractMonth(date_t date);
|
|
21203
|
-
//! Extract day of a date entry
|
|
21204
|
-
DUCKDB_API static int32_t ExtractDay(date_t date);
|
|
21205
|
-
//! Extract the day of the week (1-7)
|
|
21206
|
-
DUCKDB_API static int32_t ExtractISODayOfTheWeek(date_t date);
|
|
21207
|
-
//! Extract the day of the year
|
|
21208
|
-
DUCKDB_API static int32_t ExtractDayOfTheYear(date_t date);
|
|
21209
|
-
//! Extract the ISO week number
|
|
21210
|
-
//! ISO weeks start on Monday and the first week of a year
|
|
21211
|
-
//! contains January 4 of that year.
|
|
21212
|
-
//! In the ISO week-numbering system, it is possible for early-January dates
|
|
21213
|
-
//! to be part of the 52nd or 53rd week of the previous year.
|
|
21214
|
-
DUCKDB_API static void ExtractISOYearWeek(date_t date, int32_t &year, int32_t &week);
|
|
21215
|
-
DUCKDB_API static int32_t ExtractISOWeekNumber(date_t date);
|
|
21216
|
-
DUCKDB_API static int32_t ExtractISOYearNumber(date_t date);
|
|
21217
|
-
//! Extract the week number as Python handles it.
|
|
21218
|
-
//! Either Monday or Sunday is the first day of the week,
|
|
21219
|
-
//! and any date before the first Monday/Sunday returns week 0
|
|
21220
|
-
//! This is a bit more consistent because week numbers in a year are always incrementing
|
|
21221
|
-
DUCKDB_API static int32_t ExtractWeekNumberRegular(date_t date, bool monday_first = true);
|
|
21222
|
-
//! Returns the date of the monday of the current week.
|
|
21223
|
-
DUCKDB_API static date_t GetMondayOfCurrentWeek(date_t date);
|
|
21224
|
-
|
|
21225
|
-
//! Helper function to parse two digits from a string (e.g. "30" -> 30, "03" -> 3, "3" -> 3)
|
|
21226
|
-
DUCKDB_API static bool ParseDoubleDigit(const char *buf, idx_t len, idx_t &pos, int32_t &result);
|
|
21227
|
-
|
|
21228
|
-
DUCKDB_API static string ConversionError(const string &str);
|
|
21229
|
-
DUCKDB_API static string ConversionError(string_t str);
|
|
21230
|
-
|
|
21231
|
-
private:
|
|
21232
|
-
static void ExtractYearOffset(int32_t &n, int32_t &year, int32_t &year_offset);
|
|
21233
|
-
};
|
|
21234
|
-
} // namespace duckdb
|
|
21235
|
-
//===----------------------------------------------------------------------===//
|
|
21236
|
-
// DuckDB
|
|
21237
|
-
//
|
|
21238
21466
|
// duckdb/common/arrow/arrow_converter.hpp
|
|
21239
21467
|
//
|
|
21240
21468
|
//
|
|
@@ -21414,86 +21642,6 @@ public:
|
|
|
21414
21642
|
}
|
|
21415
21643
|
};
|
|
21416
21644
|
|
|
21417
|
-
} // namespace duckdb
|
|
21418
|
-
//===----------------------------------------------------------------------===//
|
|
21419
|
-
// DuckDB
|
|
21420
|
-
//
|
|
21421
|
-
// duckdb/common/types/timestamp.hpp
|
|
21422
|
-
//
|
|
21423
|
-
//
|
|
21424
|
-
//===----------------------------------------------------------------------===//
|
|
21425
|
-
|
|
21426
|
-
|
|
21427
|
-
|
|
21428
|
-
|
|
21429
|
-
|
|
21430
|
-
|
|
21431
|
-
|
|
21432
|
-
namespace duckdb {
|
|
21433
|
-
|
|
21434
|
-
//! The Timestamp class is a static class that holds helper functions for the Timestamp
|
|
21435
|
-
//! type.
|
|
21436
|
-
class Timestamp {
|
|
21437
|
-
public:
|
|
21438
|
-
// min timestamp is 290308-12-22 (BC)
|
|
21439
|
-
constexpr static const int32_t MIN_YEAR = -290308;
|
|
21440
|
-
constexpr static const int32_t MIN_MONTH = 12;
|
|
21441
|
-
constexpr static const int32_t MIN_DAY = 22;
|
|
21442
|
-
|
|
21443
|
-
public:
|
|
21444
|
-
//! Convert a string in the format "YYYY-MM-DD hh:mm:ss[.f][-+TH[:tm]]" to a timestamp object
|
|
21445
|
-
DUCKDB_API static timestamp_t FromString(const string &str);
|
|
21446
|
-
//! Convert a string where the offset can also be a time zone string: / [A_Za-z0-9/_]+/
|
|
21447
|
-
//! If has_offset is true, then the result is an instant that was offset from UTC
|
|
21448
|
-
//! If the tz is not empty, the result is still an instant, but the parts can be extracted and applied to the TZ
|
|
21449
|
-
DUCKDB_API static bool TryConvertTimestampTZ(const char *str, idx_t len, timestamp_t &result, bool &has_offset,
|
|
21450
|
-
string_t &tz);
|
|
21451
|
-
DUCKDB_API static bool TryConvertTimestamp(const char *str, idx_t len, timestamp_t &result);
|
|
21452
|
-
DUCKDB_API static timestamp_t FromCString(const char *str, idx_t len);
|
|
21453
|
-
//! Convert a date object to a string in the format "YYYY-MM-DD hh:mm:ss"
|
|
21454
|
-
DUCKDB_API static string ToString(timestamp_t timestamp);
|
|
21455
|
-
|
|
21456
|
-
DUCKDB_API static date_t GetDate(timestamp_t timestamp);
|
|
21457
|
-
|
|
21458
|
-
DUCKDB_API static dtime_t GetTime(timestamp_t timestamp);
|
|
21459
|
-
//! Create a Timestamp object from a specified (date, time) combination
|
|
21460
|
-
DUCKDB_API static timestamp_t FromDatetime(date_t date, dtime_t time);
|
|
21461
|
-
DUCKDB_API static bool TryFromDatetime(date_t date, dtime_t time, timestamp_t &result);
|
|
21462
|
-
|
|
21463
|
-
//! Is the timestamp finite or infinite?
|
|
21464
|
-
static inline bool IsFinite(timestamp_t timestamp) {
|
|
21465
|
-
return timestamp != timestamp_t::infinity() && timestamp != timestamp_t::ninfinity();
|
|
21466
|
-
}
|
|
21467
|
-
|
|
21468
|
-
//! Extract the date and time from a given timestamp object
|
|
21469
|
-
DUCKDB_API static void Convert(timestamp_t date, date_t &out_date, dtime_t &out_time);
|
|
21470
|
-
//! Returns current timestamp
|
|
21471
|
-
DUCKDB_API static timestamp_t GetCurrentTimestamp();
|
|
21472
|
-
|
|
21473
|
-
//! Convert the epoch (in sec) to a timestamp
|
|
21474
|
-
DUCKDB_API static timestamp_t FromEpochSeconds(int64_t ms);
|
|
21475
|
-
//! Convert the epoch (in ms) to a timestamp
|
|
21476
|
-
DUCKDB_API static timestamp_t FromEpochMs(int64_t ms);
|
|
21477
|
-
//! Convert the epoch (in microseconds) to a timestamp
|
|
21478
|
-
DUCKDB_API static timestamp_t FromEpochMicroSeconds(int64_t micros);
|
|
21479
|
-
//! Convert the epoch (in nanoseconds) to a timestamp
|
|
21480
|
-
DUCKDB_API static timestamp_t FromEpochNanoSeconds(int64_t micros);
|
|
21481
|
-
|
|
21482
|
-
//! Convert the epoch (in seconds) to a timestamp
|
|
21483
|
-
DUCKDB_API static int64_t GetEpochSeconds(timestamp_t timestamp);
|
|
21484
|
-
//! Convert the epoch (in ms) to a timestamp
|
|
21485
|
-
DUCKDB_API static int64_t GetEpochMs(timestamp_t timestamp);
|
|
21486
|
-
//! Convert a timestamp to epoch (in microseconds)
|
|
21487
|
-
DUCKDB_API static int64_t GetEpochMicroSeconds(timestamp_t timestamp);
|
|
21488
|
-
//! Convert a timestamp to epoch (in nanoseconds)
|
|
21489
|
-
DUCKDB_API static int64_t GetEpochNanoSeconds(timestamp_t timestamp);
|
|
21490
|
-
|
|
21491
|
-
DUCKDB_API static bool TryParseUTCOffset(const char *str, idx_t &pos, idx_t len, int &hour_offset,
|
|
21492
|
-
int &minute_offset);
|
|
21493
|
-
|
|
21494
|
-
DUCKDB_API static string ConversionError(const string &str);
|
|
21495
|
-
DUCKDB_API static string ConversionError(string_t str);
|
|
21496
|
-
};
|
|
21497
21645
|
} // namespace duckdb
|
|
21498
21646
|
//===----------------------------------------------------------------------===//
|
|
21499
21647
|
// DuckDB
|
|
@@ -21511,6 +21659,8 @@ public:
|
|
|
21511
21659
|
|
|
21512
21660
|
namespace duckdb {
|
|
21513
21661
|
|
|
21662
|
+
struct dtime_t;
|
|
21663
|
+
|
|
21514
21664
|
//! The Time class is a static class that holds helper functions for the Time
|
|
21515
21665
|
//! type.
|
|
21516
21666
|
class Time {
|
|
@@ -21561,6 +21711,11 @@ class DuckDB;
|
|
|
21561
21711
|
class TableCatalogEntry;
|
|
21562
21712
|
class Connection;
|
|
21563
21713
|
|
|
21714
|
+
enum class AppenderType : uint8_t {
|
|
21715
|
+
LOGICAL, // Cast input -> LogicalType
|
|
21716
|
+
PHYSICAL // Cast input -> PhysicalType
|
|
21717
|
+
};
|
|
21718
|
+
|
|
21564
21719
|
//! The Appender class can be used to append elements to a table.
|
|
21565
21720
|
class BaseAppender {
|
|
21566
21721
|
protected:
|
|
@@ -21576,10 +21731,14 @@ protected:
|
|
|
21576
21731
|
DataChunk chunk;
|
|
21577
21732
|
//! The current column to append to
|
|
21578
21733
|
idx_t column = 0;
|
|
21734
|
+
//! The type of the appender
|
|
21735
|
+
AppenderType appender_type;
|
|
21736
|
+
|
|
21737
|
+
protected:
|
|
21738
|
+
DUCKDB_API BaseAppender(Allocator &allocator, AppenderType type);
|
|
21739
|
+
DUCKDB_API BaseAppender(Allocator &allocator, vector<LogicalType> types, AppenderType type);
|
|
21579
21740
|
|
|
21580
21741
|
public:
|
|
21581
|
-
DUCKDB_API BaseAppender(Allocator &allocator);
|
|
21582
|
-
DUCKDB_API BaseAppender(Allocator &allocator, vector<LogicalType> types);
|
|
21583
21742
|
DUCKDB_API virtual ~BaseAppender();
|
|
21584
21743
|
|
|
21585
21744
|
//! Begins a new row append, after calling this the other AppendX() functions
|
|
@@ -21627,6 +21786,8 @@ protected:
|
|
|
21627
21786
|
void AppendValueInternal(T value);
|
|
21628
21787
|
template <class SRC, class DST>
|
|
21629
21788
|
void AppendValueInternal(Vector &vector, SRC input);
|
|
21789
|
+
template <class SRC, class DST>
|
|
21790
|
+
void AppendDecimalValueInternal(Vector &vector, SRC input);
|
|
21630
21791
|
|
|
21631
21792
|
void AppendRowRecursive() {
|
|
21632
21793
|
EndRow();
|