duckdb 0.6.1-dev12.0 → 0.6.1-dev131.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/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 "7fbaefc8a1"
15
- #define DUCKDB_VERSION "v0.6.1-dev12"
14
+ #define DUCKDB_SOURCE_ID "799db99fc3"
15
+ #define DUCKDB_VERSION "v0.6.1-dev131"
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 &micros) const {return dtime_t(this->micros + micros);};
734
- inline dtime_t operator+(const double &micros) const {return dtime_t(this->micros + int64_t(micros));};
735
- inline dtime_t operator-(const int64_t &micros) 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 &micros) {this->micros += micros; return *this;};
742
- inline dtime_t &operator-=(const int64_t &micros) {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
- public:
2969
- //! Create an empty NULL value of the specified type
2970
- DUCKDB_API explicit Value(LogicalType type = LogicalType::SQLNULL);
2971
- //! Create an INTEGER value
2972
- DUCKDB_API Value(int32_t val); // NOLINT: Allow implicit conversion from `int32_t`
2973
- //! Create a BIGINT value
2974
- DUCKDB_API Value(int64_t val); // NOLINT: Allow implicit conversion from `int64_t`
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
- inline LogicalType &type() {
3000
- return type_;
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
- inline const LogicalType &type() const {
3003
- return type_;
2735
+ DUCKDB_API static idx_t Digits() {
2736
+ return 3;
3004
2737
  }
3005
- inline bool IsNull() const {
3006
- return is_null;
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
- //! Create the lowest possible value of a given type (numeric only)
3010
- DUCKDB_API static Value MinimumValue(const LogicalType &type);
3011
- //! Create the highest possible value of a given type (numeric only)
3012
- DUCKDB_API static Value MaximumValue(const LogicalType &type);
3013
- //! Create a Numeric value of the specified type with the specified value
3014
- DUCKDB_API static Value Numeric(const LogicalType &type, int64_t value);
3015
- DUCKDB_API static Value Numeric(const LogicalType &type, hugeint_t value);
3016
-
3017
- //! Create a tinyint Value from a specified value
3018
- DUCKDB_API static Value BOOLEAN(int8_t value);
3019
- //! Create a tinyint Value from a specified value
3020
- DUCKDB_API static Value TINYINT(int8_t value);
3021
- //! Create a smallint Value from a specified value
3022
- DUCKDB_API static Value SMALLINT(int16_t value);
3023
- //! Create an integer Value from a specified value
3024
- DUCKDB_API static Value INTEGER(int32_t value);
3025
- //! Create a bigint Value from a specified value
3026
- DUCKDB_API static Value BIGINT(int64_t value);
3027
- //! Create an unsigned tinyint Value from a specified value
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 &micros) const {
3446
+ return dtime_t(this->micros + micros);
3447
+ };
3448
+ inline dtime_t operator+(const double &micros) const {
3449
+ return dtime_t(this->micros + int64_t(micros));
3450
+ };
3451
+ inline dtime_t operator-(const int64_t &micros) 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 &micros) {
3466
+ this->micros += micros;
3467
+ return *this;
3468
+ };
3469
+ inline dtime_t &operator-=(const int64_t &micros) {
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,
@@ -3722,183 +4389,48 @@ public:
3722
4389
 
3723
4390
  private:
3724
4391
  //! 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
- }
4392
+ Allocator &allocator;
4393
+ idx_t current_capacity;
4394
+ unique_ptr<ArenaChunk> head;
4395
+ ArenaChunk *tail;
4396
+ };
3847
4397
 
3848
- idx_t GetSize() const {
3849
- return value.inlined.length;
3850
- }
4398
+ } // namespace duckdb
3851
4399
 
3852
- string GetString() const {
3853
- return string(GetDataUnsafe(), GetSize());
3854
- }
3855
4400
 
3856
- explicit operator string() const {
3857
- return GetString();
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 Finalize() {
3861
- // set trailing NULL byte
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
- void Verify() const;
3879
- void VerifyNull() const;
3880
- bool operator<(const string_t &r) const {
3881
- auto this_str = this->GetString();
3882
- auto r_str = r.GetString();
3883
- return this_str < r_str;
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
- union {
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
  //
@@ -7523,13 +8055,9 @@ struct ExpressionExecutorState {
7523
8055
 
7524
8056
 
7525
8057
 
7526
- //===----------------------------------------------------------------------===//
7527
- // DuckDB
7528
- //
7529
- // duckdb/common/limits.hpp
7530
- //
7531
- //
7532
- //===----------------------------------------------------------------------===//
8058
+
8059
+
8060
+
7533
8061
 
7534
8062
 
7535
8063
 
@@ -7537,140 +8065,68 @@ struct ExpressionExecutorState {
7537
8065
 
7538
8066
  namespace duckdb {
7539
8067
 
8068
+ //! Returns the PhysicalType for the given type
7540
8069
  template <class T>
7541
- struct NumericLimits {
7542
- DUCKDB_API static T Minimum();
7543
- DUCKDB_API static T Maximum();
7544
- DUCKDB_API static bool IsSigned();
7545
- DUCKDB_API static idx_t Digits();
7546
- };
7547
-
7548
- template <>
7549
- struct NumericLimits<int8_t> {
7550
- DUCKDB_API static int8_t Minimum();
7551
- DUCKDB_API static int8_t Maximum();
7552
- DUCKDB_API static bool IsSigned() {
7553
- return true;
7554
- }
7555
- DUCKDB_API static idx_t Digits() {
7556
- return 3;
7557
- }
7558
- };
7559
- template <>
7560
- struct NumericLimits<int16_t> {
7561
- DUCKDB_API static int16_t Minimum();
7562
- DUCKDB_API static int16_t Maximum();
7563
- DUCKDB_API static bool IsSigned() {
7564
- return true;
7565
- }
7566
- DUCKDB_API static idx_t Digits() {
7567
- return 5;
7568
- }
7569
- };
7570
- template <>
7571
- struct NumericLimits<int32_t> {
7572
- DUCKDB_API static int32_t Minimum();
7573
- DUCKDB_API static int32_t Maximum();
7574
- DUCKDB_API static bool IsSigned() {
7575
- return true;
7576
- }
7577
- DUCKDB_API static idx_t Digits() {
7578
- return 10;
7579
- }
7580
- };
7581
- template <>
7582
- struct NumericLimits<int64_t> {
7583
- DUCKDB_API static int64_t Minimum();
7584
- DUCKDB_API static int64_t Maximum();
7585
- DUCKDB_API static bool IsSigned() {
7586
- return true;
7587
- }
7588
- DUCKDB_API static idx_t Digits() {
7589
- return 19;
7590
- }
7591
- };
7592
- template <>
7593
- struct NumericLimits<hugeint_t> {
7594
- DUCKDB_API static hugeint_t Minimum();
7595
- DUCKDB_API static hugeint_t Maximum();
7596
- DUCKDB_API static bool IsSigned() {
7597
- return true;
7598
- }
7599
- DUCKDB_API static idx_t Digits() {
7600
- return 39;
7601
- }
7602
- };
7603
- template <>
7604
- struct NumericLimits<uint8_t> {
7605
- DUCKDB_API static uint8_t Minimum();
7606
- DUCKDB_API static uint8_t Maximum();
7607
- DUCKDB_API static bool IsSigned() {
7608
- return false;
7609
- }
7610
- DUCKDB_API static idx_t Digits() {
7611
- return 3;
7612
- }
7613
- };
7614
- template <>
7615
- struct NumericLimits<uint16_t> {
7616
- DUCKDB_API static uint16_t Minimum();
7617
- DUCKDB_API static uint16_t Maximum();
7618
- DUCKDB_API static bool IsSigned() {
7619
- return false;
7620
- }
7621
- DUCKDB_API static idx_t Digits() {
7622
- return 5;
7623
- }
7624
- };
7625
- template <>
7626
- struct NumericLimits<uint32_t> {
7627
- DUCKDB_API static uint32_t Minimum();
7628
- DUCKDB_API static uint32_t Maximum();
7629
- DUCKDB_API static bool IsSigned() {
7630
- return false;
7631
- }
7632
- DUCKDB_API static idx_t Digits() {
7633
- return 10;
7634
- }
7635
- };
7636
- template <>
7637
- struct NumericLimits<uint64_t> {
7638
- DUCKDB_API static uint64_t Minimum();
7639
- DUCKDB_API static uint64_t Maximum();
7640
- DUCKDB_API static bool IsSigned() {
7641
- return false;
7642
- }
7643
- DUCKDB_API static idx_t Digits() {
7644
- return 20;
7645
- }
7646
- };
7647
- template <>
7648
- struct NumericLimits<float> {
7649
- DUCKDB_API static float Minimum();
7650
- DUCKDB_API static float Maximum();
7651
- DUCKDB_API static bool IsSigned() {
7652
- return true;
7653
- }
7654
- DUCKDB_API static idx_t Digits() {
7655
- return 127;
7656
- }
7657
- };
7658
- template <>
7659
- struct NumericLimits<double> {
7660
- DUCKDB_API static double Minimum();
7661
- DUCKDB_API static double Maximum();
7662
- DUCKDB_API static bool IsSigned() {
7663
- return true;
7664
- }
7665
- DUCKDB_API static idx_t Digits() {
7666
- return 250;
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
@@ -7816,103 +8272,11 @@ template <>
7816
8272
  bool Hugeint::TryConvert(double value, hugeint_t &result);
7817
8273
  template <>
7818
8274
  bool Hugeint::TryConvert(long double value, hugeint_t &result);
8275
+ template <>
8276
+ bool Hugeint::TryConvert(const char *value, hugeint_t &result);
7819
8277
 
7820
8278
  } // namespace duckdb
7821
8279
 
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
- };
7915
- } // namespace duckdb
7916
8280
 
7917
8281
 
7918
8282
 
@@ -8807,6 +9171,7 @@ public:
8807
9171
 
8808
9172
  public:
8809
9173
  virtual unique_ptr<CatalogEntry> AlterEntry(ClientContext &context, AlterInfo *info);
9174
+ virtual void UndoAlter(ClientContext &context, AlterInfo *info);
8810
9175
 
8811
9176
  virtual unique_ptr<CatalogEntry> Copy(ClientContext &context);
8812
9177
 
@@ -10798,6 +11163,8 @@ public:
10798
11163
  public:
10799
11164
  bool HasGeneratedColumns() const;
10800
11165
  unique_ptr<CatalogEntry> AlterEntry(ClientContext &context, AlterInfo *info) override;
11166
+ void UndoAlter(ClientContext &context, AlterInfo *info) override;
11167
+
10801
11168
  //! Returns whether or not a column with the given name exists
10802
11169
  DUCKDB_API bool ColumnExists(const string &name);
10803
11170
  //! Returns a reference to the column of the specified name. Throws an
@@ -10976,6 +11343,9 @@ public:
10976
11343
  return true;
10977
11344
  }
10978
11345
 
11346
+ //! Returns the set of table indexes of this operator
11347
+ virtual vector<idx_t> GetTableIndex() const;
11348
+
10979
11349
  protected:
10980
11350
  //! Resolve types for this specific operator
10981
11351
  virtual void ResolveTypes() = 0;
@@ -13826,6 +14196,9 @@ public:
13826
14196
  void Reset();
13827
14197
  void ResetSink();
13828
14198
  void ResetSource(bool force);
14199
+ void ClearSource() {
14200
+ source_state.reset();
14201
+ }
13829
14202
  void Schedule(shared_ptr<Event> &event);
13830
14203
 
13831
14204
  //! Finalize this pipeline
@@ -17399,6 +17772,7 @@ public:
17399
17772
  namespace duckdb {
17400
17773
 
17401
17774
  struct string_t;
17775
+ struct interval_t;
17402
17776
 
17403
17777
  // efficient hash function that maximizes the avalanche effect and minimizes
17404
17778
  // bias
@@ -21077,163 +21451,24 @@ DUCKDB_API void duckdb_finish_execution(duckdb_task_state state);
21077
21451
  /*!
21078
21452
  Check if the provided duckdb_task_state has finished execution
21079
21453
 
21080
- * state: The task state to inspect
21081
- * returns: Whether or not duckdb_finish_execution has been called on the task state
21082
- */
21083
- DUCKDB_API bool duckdb_task_state_is_finished(duckdb_task_state state);
21084
-
21085
- /*!
21086
- Destroys the task state returned from duckdb_create_task_state.
21087
-
21088
- Note that this should not be called while there is an active duckdb_execute_tasks_state running
21089
- on the task state.
21090
-
21091
- * state: The task state to clean up
21092
- */
21093
- DUCKDB_API void duckdb_destroy_task_state(duckdb_task_state state);
21094
-
21095
- #ifdef __cplusplus
21096
- }
21097
- #endif
21098
- //===----------------------------------------------------------------------===//
21099
- // DuckDB
21100
- //
21101
- // duckdb/common/types/date.hpp
21102
- //
21103
- //
21104
- //===----------------------------------------------------------------------===//
21105
-
21106
-
21107
-
21108
-
21109
-
21110
-
21111
-
21112
-
21113
- namespace duckdb {
21114
-
21115
- //! The Date class is a static class that holds helper functions for the Date type.
21116
- class Date {
21117
- public:
21118
- static const char *PINF; // NOLINT
21119
- static const char *NINF; // NOLINT
21120
- static const char *EPOCH; // NOLINT
21121
-
21122
- static const string_t MONTH_NAMES[12];
21123
- static const string_t MONTH_NAMES_ABBREVIATED[12];
21124
- static const string_t DAY_NAMES[7];
21125
- static const string_t DAY_NAMES_ABBREVIATED[7];
21126
- static const int32_t NORMAL_DAYS[13];
21127
- static const int32_t CUMULATIVE_DAYS[13];
21128
- static const int32_t LEAP_DAYS[13];
21129
- static const int32_t CUMULATIVE_LEAP_DAYS[13];
21130
- static const int32_t CUMULATIVE_YEAR_DAYS[401];
21131
- static const int8_t MONTH_PER_DAY_OF_YEAR[365];
21132
- static const int8_t LEAP_MONTH_PER_DAY_OF_YEAR[366];
21133
-
21134
- // min date is 5877642-06-25 (BC) (-2^31+2)
21135
- constexpr static const int32_t DATE_MIN_YEAR = -5877641;
21136
- constexpr static const int32_t DATE_MIN_MONTH = 6;
21137
- constexpr static const int32_t DATE_MIN_DAY = 25;
21138
- // max date is 5881580-07-10 (2^31-2)
21139
- constexpr static const int32_t DATE_MAX_YEAR = 5881580;
21140
- constexpr static const int32_t DATE_MAX_MONTH = 7;
21141
- constexpr static const int32_t DATE_MAX_DAY = 10;
21142
- constexpr static const int32_t EPOCH_YEAR = 1970;
21143
-
21144
- constexpr static const int32_t YEAR_INTERVAL = 400;
21145
- constexpr static const int32_t DAYS_PER_YEAR_INTERVAL = 146097;
21146
-
21147
- public:
21148
- //! Convert a string in the format "YYYY-MM-DD" to a date object
21149
- DUCKDB_API static date_t FromString(const string &str, bool strict = false);
21150
- //! Convert a string in the format "YYYY-MM-DD" to a date object
21151
- DUCKDB_API static date_t FromCString(const char *str, idx_t len, bool strict = false);
21152
- //! Convert a date object to a string in the format "YYYY-MM-DD"
21153
- DUCKDB_API static string ToString(date_t date);
21154
- //! Try to convert text in a buffer to a date; returns true if parsing was successful
21155
- //! If the date was a "special" value, the special flag will be set.
21156
- DUCKDB_API static bool TryConvertDate(const char *buf, idx_t len, idx_t &pos, date_t &result, bool &special,
21157
- bool strict = false);
21158
-
21159
- //! Create a string "YYYY-MM-DD" from a specified (year, month, day)
21160
- //! combination
21161
- DUCKDB_API static string Format(int32_t year, int32_t month, int32_t day);
21162
-
21163
- //! Extract the year, month and day from a given date object
21164
- DUCKDB_API static void Convert(date_t date, int32_t &out_year, int32_t &out_month, int32_t &out_day);
21165
- //! Create a Date object from a specified (year, month, day) combination
21166
- DUCKDB_API static date_t FromDate(int32_t year, int32_t month, int32_t day);
21167
- DUCKDB_API static bool TryFromDate(int32_t year, int32_t month, int32_t day, date_t &result);
21168
-
21169
- //! Returns true if (year) is a leap year, and false otherwise
21170
- DUCKDB_API static bool IsLeapYear(int32_t year);
21171
-
21172
- //! Returns true if the specified (year, month, day) combination is a valid
21173
- //! date
21174
- DUCKDB_API static bool IsValid(int32_t year, int32_t month, int32_t day);
21175
-
21176
- //! Returns true if the specified date is finite
21177
- static inline bool IsFinite(date_t date) {
21178
- return date != date_t::infinity() && date != date_t::ninfinity();
21179
- }
21180
-
21181
- //! The max number of days in a month of a given year
21182
- DUCKDB_API static int32_t MonthDays(int32_t year, int32_t month);
21183
-
21184
- //! Extract the epoch from the date (seconds since 1970-01-01)
21185
- DUCKDB_API static int64_t Epoch(date_t date);
21186
- //! Extract the epoch from the date (nanoseconds since 1970-01-01)
21187
- DUCKDB_API static int64_t EpochNanoseconds(date_t date);
21188
- //! Extract the epoch from the date (microseconds since 1970-01-01)
21189
- DUCKDB_API static int64_t EpochMicroseconds(date_t date);
21190
- //! Convert the epoch (seconds since 1970-01-01) to a date_t
21191
- DUCKDB_API static date_t EpochToDate(int64_t epoch);
21192
-
21193
- //! Extract the number of days since epoch (days since 1970-01-01)
21194
- DUCKDB_API static int32_t EpochDays(date_t date);
21195
- //! Convert the epoch number of days to a date_t
21196
- DUCKDB_API static date_t EpochDaysToDate(int32_t epoch);
21197
-
21198
- //! Extract year of a date entry
21199
- DUCKDB_API static int32_t ExtractYear(date_t date);
21200
- //! Extract year of a date entry, but optimized to first try the last year found
21201
- DUCKDB_API static int32_t ExtractYear(date_t date, int32_t *last_year);
21202
- DUCKDB_API static int32_t ExtractYear(timestamp_t ts, int32_t *last_year);
21203
- //! Extract month of a date entry
21204
- DUCKDB_API static int32_t ExtractMonth(date_t date);
21205
- //! Extract day of a date entry
21206
- DUCKDB_API static int32_t ExtractDay(date_t date);
21207
- //! Extract the day of the week (1-7)
21208
- DUCKDB_API static int32_t ExtractISODayOfTheWeek(date_t date);
21209
- //! Extract the day of the year
21210
- DUCKDB_API static int32_t ExtractDayOfTheYear(date_t date);
21211
- //! Extract the ISO week number
21212
- //! ISO weeks start on Monday and the first week of a year
21213
- //! contains January 4 of that year.
21214
- //! In the ISO week-numbering system, it is possible for early-January dates
21215
- //! to be part of the 52nd or 53rd week of the previous year.
21216
- DUCKDB_API static void ExtractISOYearWeek(date_t date, int32_t &year, int32_t &week);
21217
- DUCKDB_API static int32_t ExtractISOWeekNumber(date_t date);
21218
- DUCKDB_API static int32_t ExtractISOYearNumber(date_t date);
21219
- //! Extract the week number as Python handles it.
21220
- //! Either Monday or Sunday is the first day of the week,
21221
- //! and any date before the first Monday/Sunday returns week 0
21222
- //! This is a bit more consistent because week numbers in a year are always incrementing
21223
- DUCKDB_API static int32_t ExtractWeekNumberRegular(date_t date, bool monday_first = true);
21224
- //! Returns the date of the monday of the current week.
21225
- DUCKDB_API static date_t GetMondayOfCurrentWeek(date_t date);
21226
-
21227
- //! Helper function to parse two digits from a string (e.g. "30" -> 30, "03" -> 3, "3" -> 3)
21228
- DUCKDB_API static bool ParseDoubleDigit(const char *buf, idx_t len, idx_t &pos, int32_t &result);
21454
+ * state: The task state to inspect
21455
+ * returns: Whether or not duckdb_finish_execution has been called on the task state
21456
+ */
21457
+ DUCKDB_API bool duckdb_task_state_is_finished(duckdb_task_state state);
21229
21458
 
21230
- DUCKDB_API static string ConversionError(const string &str);
21231
- DUCKDB_API static string ConversionError(string_t str);
21459
+ /*!
21460
+ Destroys the task state returned from duckdb_create_task_state.
21232
21461
 
21233
- private:
21234
- static void ExtractYearOffset(int32_t &n, int32_t &year, int32_t &year_offset);
21235
- };
21236
- } // namespace duckdb
21462
+ Note that this should not be called while there is an active duckdb_execute_tasks_state running
21463
+ on the task state.
21464
+
21465
+ * state: The task state to clean up
21466
+ */
21467
+ DUCKDB_API void duckdb_destroy_task_state(duckdb_task_state state);
21468
+
21469
+ #ifdef __cplusplus
21470
+ }
21471
+ #endif
21237
21472
  //===----------------------------------------------------------------------===//
21238
21473
  // DuckDB
21239
21474
  //
@@ -21416,86 +21651,6 @@ public:
21416
21651
  }
21417
21652
  };
21418
21653
 
21419
- } // namespace duckdb
21420
- //===----------------------------------------------------------------------===//
21421
- // DuckDB
21422
- //
21423
- // duckdb/common/types/timestamp.hpp
21424
- //
21425
- //
21426
- //===----------------------------------------------------------------------===//
21427
-
21428
-
21429
-
21430
-
21431
-
21432
-
21433
-
21434
- namespace duckdb {
21435
-
21436
- //! The Timestamp class is a static class that holds helper functions for the Timestamp
21437
- //! type.
21438
- class Timestamp {
21439
- public:
21440
- // min timestamp is 290308-12-22 (BC)
21441
- constexpr static const int32_t MIN_YEAR = -290308;
21442
- constexpr static const int32_t MIN_MONTH = 12;
21443
- constexpr static const int32_t MIN_DAY = 22;
21444
-
21445
- public:
21446
- //! Convert a string in the format "YYYY-MM-DD hh:mm:ss[.f][-+TH[:tm]]" to a timestamp object
21447
- DUCKDB_API static timestamp_t FromString(const string &str);
21448
- //! Convert a string where the offset can also be a time zone string: / [A_Za-z0-9/_]+/
21449
- //! If has_offset is true, then the result is an instant that was offset from UTC
21450
- //! If the tz is not empty, the result is still an instant, but the parts can be extracted and applied to the TZ
21451
- DUCKDB_API static bool TryConvertTimestampTZ(const char *str, idx_t len, timestamp_t &result, bool &has_offset,
21452
- string_t &tz);
21453
- DUCKDB_API static bool TryConvertTimestamp(const char *str, idx_t len, timestamp_t &result);
21454
- DUCKDB_API static timestamp_t FromCString(const char *str, idx_t len);
21455
- //! Convert a date object to a string in the format "YYYY-MM-DD hh:mm:ss"
21456
- DUCKDB_API static string ToString(timestamp_t timestamp);
21457
-
21458
- DUCKDB_API static date_t GetDate(timestamp_t timestamp);
21459
-
21460
- DUCKDB_API static dtime_t GetTime(timestamp_t timestamp);
21461
- //! Create a Timestamp object from a specified (date, time) combination
21462
- DUCKDB_API static timestamp_t FromDatetime(date_t date, dtime_t time);
21463
- DUCKDB_API static bool TryFromDatetime(date_t date, dtime_t time, timestamp_t &result);
21464
-
21465
- //! Is the timestamp finite or infinite?
21466
- static inline bool IsFinite(timestamp_t timestamp) {
21467
- return timestamp != timestamp_t::infinity() && timestamp != timestamp_t::ninfinity();
21468
- }
21469
-
21470
- //! Extract the date and time from a given timestamp object
21471
- DUCKDB_API static void Convert(timestamp_t date, date_t &out_date, dtime_t &out_time);
21472
- //! Returns current timestamp
21473
- DUCKDB_API static timestamp_t GetCurrentTimestamp();
21474
-
21475
- //! Convert the epoch (in sec) to a timestamp
21476
- DUCKDB_API static timestamp_t FromEpochSeconds(int64_t ms);
21477
- //! Convert the epoch (in ms) to a timestamp
21478
- DUCKDB_API static timestamp_t FromEpochMs(int64_t ms);
21479
- //! Convert the epoch (in microseconds) to a timestamp
21480
- DUCKDB_API static timestamp_t FromEpochMicroSeconds(int64_t micros);
21481
- //! Convert the epoch (in nanoseconds) to a timestamp
21482
- DUCKDB_API static timestamp_t FromEpochNanoSeconds(int64_t micros);
21483
-
21484
- //! Convert the epoch (in seconds) to a timestamp
21485
- DUCKDB_API static int64_t GetEpochSeconds(timestamp_t timestamp);
21486
- //! Convert the epoch (in ms) to a timestamp
21487
- DUCKDB_API static int64_t GetEpochMs(timestamp_t timestamp);
21488
- //! Convert a timestamp to epoch (in microseconds)
21489
- DUCKDB_API static int64_t GetEpochMicroSeconds(timestamp_t timestamp);
21490
- //! Convert a timestamp to epoch (in nanoseconds)
21491
- DUCKDB_API static int64_t GetEpochNanoSeconds(timestamp_t timestamp);
21492
-
21493
- DUCKDB_API static bool TryParseUTCOffset(const char *str, idx_t &pos, idx_t len, int &hour_offset,
21494
- int &minute_offset);
21495
-
21496
- DUCKDB_API static string ConversionError(const string &str);
21497
- DUCKDB_API static string ConversionError(string_t str);
21498
- };
21499
21654
  } // namespace duckdb
21500
21655
  //===----------------------------------------------------------------------===//
21501
21656
  // DuckDB
@@ -21513,6 +21668,8 @@ public:
21513
21668
 
21514
21669
  namespace duckdb {
21515
21670
 
21671
+ struct dtime_t;
21672
+
21516
21673
  //! The Time class is a static class that holds helper functions for the Time
21517
21674
  //! type.
21518
21675
  class Time {
@@ -21563,6 +21720,11 @@ class DuckDB;
21563
21720
  class TableCatalogEntry;
21564
21721
  class Connection;
21565
21722
 
21723
+ enum class AppenderType : uint8_t {
21724
+ LOGICAL, // Cast input -> LogicalType
21725
+ PHYSICAL // Cast input -> PhysicalType
21726
+ };
21727
+
21566
21728
  //! The Appender class can be used to append elements to a table.
21567
21729
  class BaseAppender {
21568
21730
  protected:
@@ -21578,10 +21740,14 @@ protected:
21578
21740
  DataChunk chunk;
21579
21741
  //! The current column to append to
21580
21742
  idx_t column = 0;
21743
+ //! The type of the appender
21744
+ AppenderType appender_type;
21745
+
21746
+ protected:
21747
+ DUCKDB_API BaseAppender(Allocator &allocator, AppenderType type);
21748
+ DUCKDB_API BaseAppender(Allocator &allocator, vector<LogicalType> types, AppenderType type);
21581
21749
 
21582
21750
  public:
21583
- DUCKDB_API BaseAppender(Allocator &allocator);
21584
- DUCKDB_API BaseAppender(Allocator &allocator, vector<LogicalType> types);
21585
21751
  DUCKDB_API virtual ~BaseAppender();
21586
21752
 
21587
21753
  //! Begins a new row append, after calling this the other AppendX() functions
@@ -21629,6 +21795,8 @@ protected:
21629
21795
  void AppendValueInternal(T value);
21630
21796
  template <class SRC, class DST>
21631
21797
  void AppendValueInternal(Vector &vector, SRC input);
21798
+ template <class SRC, class DST>
21799
+ void AppendDecimalValueInternal(Vector &vector, SRC input);
21632
21800
 
21633
21801
  void AppendRowRecursive() {
21634
21802
  EndRow();
@@ -30618,6 +30786,7 @@ public:
30618
30786
 
30619
30787
  void Serialize(FieldWriter &writer) const override;
30620
30788
  static unique_ptr<LogicalOperator> Deserialize(LogicalDeserializationState &state, FieldReader &reader);
30789
+ vector<idx_t> GetTableIndex() const override;
30621
30790
 
30622
30791
  protected:
30623
30792
  void ResolveTypes() override;
@@ -30743,10 +30912,12 @@ public:
30743
30912
  }
30744
30913
  };
30745
30914
  } // namespace duckdb
30915
+
30916
+
30746
30917
  //===----------------------------------------------------------------------===//
30747
30918
  // DuckDB
30748
30919
  //
30749
- // duckdb/parser/expression/positional_reference_expression.hpp
30920
+ // duckdb/parser/expression/case_expression.hpp
30750
30921
  //
30751
30922
  //
30752
30923
  //===----------------------------------------------------------------------===//
@@ -30755,32 +30926,97 @@ public:
30755
30926
 
30756
30927
 
30757
30928
 
30929
+
30758
30930
  namespace duckdb {
30759
- class PositionalReferenceExpression : public ParsedExpression {
30931
+
30932
+ struct CaseCheck {
30933
+ unique_ptr<ParsedExpression> when_expr;
30934
+ unique_ptr<ParsedExpression> then_expr;
30935
+ };
30936
+
30937
+ //! The CaseExpression represents a CASE expression in the query
30938
+ class CaseExpression : public ParsedExpression {
30760
30939
  public:
30761
- DUCKDB_API PositionalReferenceExpression(idx_t index);
30940
+ DUCKDB_API CaseExpression();
30762
30941
 
30763
- idx_t index;
30942
+ vector<CaseCheck> case_checks;
30943
+ unique_ptr<ParsedExpression> else_expr;
30764
30944
 
30765
30945
  public:
30766
- bool IsScalar() const override {
30767
- return false;
30946
+ string ToString() const override;
30947
+
30948
+ static bool Equals(const CaseExpression *a, const CaseExpression *b);
30949
+
30950
+ unique_ptr<ParsedExpression> Copy() const override;
30951
+
30952
+ void Serialize(FieldWriter &writer) const override;
30953
+ static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
30954
+
30955
+ public:
30956
+ template <class T, class BASE>
30957
+ static string ToString(const T &entry) {
30958
+ string case_str = "CASE ";
30959
+ for (auto &check : entry.case_checks) {
30960
+ case_str += " WHEN (" + check.when_expr->ToString() + ")";
30961
+ case_str += " THEN (" + check.then_expr->ToString() + ")";
30962
+ }
30963
+ case_str += " ELSE " + entry.else_expr->ToString();
30964
+ case_str += " END";
30965
+ return case_str;
30768
30966
  }
30967
+ };
30968
+ } // namespace duckdb
30969
+
30970
+ //===----------------------------------------------------------------------===//
30971
+ // DuckDB
30972
+ //
30973
+ // duckdb/parser/expression/cast_expression.hpp
30974
+ //
30975
+ //
30976
+ //===----------------------------------------------------------------------===//
30977
+
30978
+
30979
+
30980
+
30981
+
30982
+
30983
+ namespace duckdb {
30984
+
30985
+ //! CastExpression represents a type cast from one SQL type to another SQL type
30986
+ class CastExpression : public ParsedExpression {
30987
+ public:
30988
+ DUCKDB_API CastExpression(LogicalType target, unique_ptr<ParsedExpression> child, bool try_cast = false);
30989
+
30990
+ //! The child of the cast expression
30991
+ unique_ptr<ParsedExpression> child;
30992
+ //! The type to cast to
30993
+ LogicalType cast_type;
30994
+ //! Whether or not this is a try_cast expression
30995
+ bool try_cast;
30769
30996
 
30997
+ public:
30770
30998
  string ToString() const override;
30771
30999
 
30772
- static bool Equals(const PositionalReferenceExpression *a, const PositionalReferenceExpression *b);
31000
+ static bool Equals(const CastExpression *a, const CastExpression *b);
31001
+
30773
31002
  unique_ptr<ParsedExpression> Copy() const override;
30774
- hash_t Hash() const override;
30775
31003
 
30776
31004
  void Serialize(FieldWriter &writer) const override;
30777
31005
  static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
31006
+
31007
+ public:
31008
+ template <class T, class BASE>
31009
+ static string ToString(const T &entry) {
31010
+ return (entry.try_cast ? "TRY_CAST(" : "CAST(") + entry.child->ToString() + " AS " +
31011
+ entry.cast_type.ToString() + ")";
31012
+ }
30778
31013
  };
30779
31014
  } // namespace duckdb
31015
+
30780
31016
  //===----------------------------------------------------------------------===//
30781
31017
  // DuckDB
30782
31018
  //
30783
- // duckdb/parser/expression/case_expression.hpp
31019
+ // duckdb/parser/expression/collate_expression.hpp
30784
31020
  //
30785
31021
  //
30786
31022
  //===----------------------------------------------------------------------===//
@@ -30789,26 +31025,58 @@ public:
30789
31025
 
30790
31026
 
30791
31027
 
30792
-
30793
31028
  namespace duckdb {
30794
31029
 
30795
- struct CaseCheck {
30796
- unique_ptr<ParsedExpression> when_expr;
30797
- unique_ptr<ParsedExpression> then_expr;
31030
+ //! CollateExpression represents a COLLATE statement
31031
+ class CollateExpression : public ParsedExpression {
31032
+ public:
31033
+ CollateExpression(string collation, unique_ptr<ParsedExpression> child);
31034
+
31035
+ //! The child of the cast expression
31036
+ unique_ptr<ParsedExpression> child;
31037
+ //! The collation clause
31038
+ string collation;
31039
+
31040
+ public:
31041
+ string ToString() const override;
31042
+
31043
+ static bool Equals(const CollateExpression *a, const CollateExpression *b);
31044
+
31045
+ unique_ptr<ParsedExpression> Copy() const override;
31046
+
31047
+ void Serialize(FieldWriter &writer) const override;
31048
+ static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
30798
31049
  };
31050
+ } // namespace duckdb
30799
31051
 
30800
- //! The CaseExpression represents a CASE expression in the query
30801
- class CaseExpression : public ParsedExpression {
31052
+
31053
+ //===----------------------------------------------------------------------===//
31054
+ // DuckDB
31055
+ //
31056
+ // duckdb/parser/expression/comparison_expression.hpp
31057
+ //
31058
+ //
31059
+ //===----------------------------------------------------------------------===//
31060
+
31061
+
31062
+
31063
+
31064
+
31065
+ namespace duckdb {
31066
+ //! ComparisonExpression represents a boolean comparison (e.g. =, >=, <>). Always returns a boolean
31067
+ //! and has two children.
31068
+ class ComparisonExpression : public ParsedExpression {
30802
31069
  public:
30803
- DUCKDB_API CaseExpression();
31070
+ DUCKDB_API ComparisonExpression(ExpressionType type, unique_ptr<ParsedExpression> left,
31071
+ unique_ptr<ParsedExpression> right);
30804
31072
 
30805
- vector<CaseCheck> case_checks;
30806
- unique_ptr<ParsedExpression> else_expr;
31073
+ unique_ptr<ParsedExpression> left;
31074
+ unique_ptr<ParsedExpression> right;
30807
31075
 
30808
31076
  public:
30809
31077
  string ToString() const override;
30810
31078
 
30811
- static bool Equals(const CaseExpression *a, const CaseExpression *b);
31079
+ static bool Equals(const ComparisonExpression *a, const ComparisonExpression *b);
30812
31080
 
30813
31081
  unique_ptr<ParsedExpression> Copy() const override;
30814
31082
 
@@ -30817,22 +31085,17 @@ public:
30817
31085
 
30818
31086
  public:
30819
31087
  template <class T, class BASE>
30820
- static string ToString(const T &entry) {
30821
- string case_str = "CASE ";
30822
- for (auto &check : entry.case_checks) {
30823
- case_str += " WHEN (" + check.when_expr->ToString() + ")";
30824
- case_str += " THEN (" + check.then_expr->ToString() + ")";
30825
- }
30826
- case_str += " ELSE " + entry.else_expr->ToString();
30827
- case_str += " END";
30828
- return case_str;
31088
+ static string ToString(const T &entry) {
31089
+ return StringUtil::Format("(%s %s %s)", entry.left->ToString(), ExpressionTypeToOperator(entry.type),
31090
+ entry.right->ToString());
30829
31091
  }
30830
31092
  };
30831
31093
  } // namespace duckdb
31094
+
30832
31095
  //===----------------------------------------------------------------------===//
30833
31096
  // DuckDB
30834
31097
  //
30835
- // duckdb/parser/expression/comparison_expression.hpp
31098
+ // duckdb/parser/expression/conjunction_expression.hpp
30836
31099
  //
30837
31100
  //
30838
31101
  //===----------------------------------------------------------------------===//
@@ -30841,21 +31104,25 @@ public:
30841
31104
 
30842
31105
 
30843
31106
 
31107
+
30844
31108
  namespace duckdb {
30845
- //! ComparisonExpression represents a boolean comparison (e.g. =, >=, <>). Always returns a boolean
30846
- //! and has two children.
30847
- class ComparisonExpression : public ParsedExpression {
31109
+
31110
+ //! Represents a conjunction (AND/OR)
31111
+ class ConjunctionExpression : public ParsedExpression {
30848
31112
  public:
30849
- DUCKDB_API ComparisonExpression(ExpressionType type, unique_ptr<ParsedExpression> left,
30850
- unique_ptr<ParsedExpression> right);
31113
+ DUCKDB_API explicit ConjunctionExpression(ExpressionType type);
31114
+ DUCKDB_API ConjunctionExpression(ExpressionType type, vector<unique_ptr<ParsedExpression>> children);
31115
+ DUCKDB_API ConjunctionExpression(ExpressionType type, unique_ptr<ParsedExpression> left,
31116
+ unique_ptr<ParsedExpression> right);
30851
31117
 
30852
- unique_ptr<ParsedExpression> left;
30853
- unique_ptr<ParsedExpression> right;
31118
+ vector<unique_ptr<ParsedExpression>> children;
30854
31119
 
30855
31120
  public:
31121
+ void AddExpression(unique_ptr<ParsedExpression> expr);
31122
+
30856
31123
  string ToString() const override;
30857
31124
 
30858
- static bool Equals(const ComparisonExpression *a, const ComparisonExpression *b);
31125
+ static bool Equals(const ConjunctionExpression *a, const ConjunctionExpression *b);
30859
31126
 
30860
31127
  unique_ptr<ParsedExpression> Copy() const override;
30861
31128
 
@@ -30865,11 +31132,15 @@ public:
30865
31132
  public:
30866
31133
  template <class T, class BASE>
30867
31134
  static string ToString(const T &entry) {
30868
- return StringUtil::Format("(%s %s %s)", entry.left->ToString(), ExpressionTypeToOperator(entry.type),
30869
- entry.right->ToString());
31135
+ string result = "(" + entry.children[0]->ToString();
31136
+ for (idx_t i = 1; i < entry.children.size(); i++) {
31137
+ result += " " + ExpressionTypeToOperator(entry.type) + " " + entry.children[i]->ToString();
31138
+ }
31139
+ return result + ")";
30870
31140
  }
30871
31141
  };
30872
31142
  } // namespace duckdb
31143
+
30873
31144
  //===----------------------------------------------------------------------===//
30874
31145
  // DuckDB
30875
31146
  //
@@ -30906,10 +31177,11 @@ public:
30906
31177
  };
30907
31178
 
30908
31179
  } // namespace duckdb
31180
+
30909
31181
  //===----------------------------------------------------------------------===//
30910
31182
  // DuckDB
30911
31183
  //
30912
- // duckdb/parser/expression/star_expression.hpp
31184
+ // duckdb/parser/expression/default_expression.hpp
30913
31185
  //
30914
31186
  //
30915
31187
  //===----------------------------------------------------------------------===//
@@ -30918,29 +31190,18 @@ public:
30918
31190
 
30919
31191
 
30920
31192
 
30921
-
30922
31193
  namespace duckdb {
30923
-
30924
- //! Represents a * expression in the SELECT clause
30925
- class StarExpression : public ParsedExpression {
31194
+ //! Represents the default value of a column
31195
+ class DefaultExpression : public ParsedExpression {
30926
31196
  public:
30927
- StarExpression(string relation_name = string());
30928
-
30929
- //! The relation name in case of tbl.*, or empty if this is a normal *
30930
- string relation_name;
30931
- //! List of columns to exclude from the STAR expression
30932
- case_insensitive_set_t exclude_list;
30933
- //! List of columns to replace with another expression
30934
- case_insensitive_map_t<unique_ptr<ParsedExpression>> replace_list;
30935
- //! Regular expression to select columns (if any)
30936
- string regex;
30937
- //! Whether or not this is a COLUMNS expression
30938
- bool columns = false;
31197
+ DefaultExpression();
30939
31198
 
30940
31199
  public:
30941
- string ToString() const override;
31200
+ bool IsScalar() const override {
31201
+ return false;
31202
+ }
30942
31203
 
30943
- static bool Equals(const StarExpression *a, const StarExpression *b);
31204
+ string ToString() const override;
30944
31205
 
30945
31206
  unique_ptr<ParsedExpression> Copy() const override;
30946
31207
 
@@ -30948,10 +31209,11 @@ public:
30948
31209
  static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
30949
31210
  };
30950
31211
  } // namespace duckdb
31212
+
30951
31213
  //===----------------------------------------------------------------------===//
30952
31214
  // DuckDB
30953
31215
  //
30954
- // duckdb/parser/expression/default_expression.hpp
31216
+ // duckdb/parser/expression/function_expression.hpp
30955
31217
  //
30956
31218
  //
30957
31219
  //===----------------------------------------------------------------------===//
@@ -30960,25 +31222,113 @@ public:
30960
31222
 
30961
31223
 
30962
31224
 
31225
+
31226
+
30963
31227
  namespace duckdb {
30964
- //! Represents the default value of a column
30965
- class DefaultExpression : public ParsedExpression {
31228
+ //! Represents a function call
31229
+ class FunctionExpression : public ParsedExpression {
30966
31230
  public:
30967
- DefaultExpression();
31231
+ DUCKDB_API FunctionExpression(string schema_name, const string &function_name,
31232
+ vector<unique_ptr<ParsedExpression>> children,
31233
+ unique_ptr<ParsedExpression> filter = nullptr,
31234
+ unique_ptr<OrderModifier> order_bys = nullptr, bool distinct = false,
31235
+ bool is_operator = false, bool export_state = false);
31236
+ DUCKDB_API FunctionExpression(const string &function_name, vector<unique_ptr<ParsedExpression>> children,
31237
+ unique_ptr<ParsedExpression> filter = nullptr,
31238
+ unique_ptr<OrderModifier> order_bys = nullptr, bool distinct = false,
31239
+ bool is_operator = false, bool export_state = false);
30968
31240
 
30969
- public:
30970
- bool IsScalar() const override {
30971
- return false;
30972
- }
31241
+ //! Schema of the function
31242
+ string schema;
31243
+ //! Function name
31244
+ string function_name;
31245
+ //! Whether or not the function is an operator, only used for rendering
31246
+ bool is_operator;
31247
+ //! List of arguments to the function
31248
+ vector<unique_ptr<ParsedExpression>> children;
31249
+ //! Whether or not the aggregate function is distinct, only used for aggregates
31250
+ bool distinct;
31251
+ //! Expression representing a filter, only used for aggregates
31252
+ unique_ptr<ParsedExpression> filter;
31253
+ //! Modifier representing an ORDER BY, only used for aggregates
31254
+ unique_ptr<OrderModifier> order_bys;
31255
+ //! whether this function should export its state or not
31256
+ bool export_state;
30973
31257
 
31258
+ public:
30974
31259
  string ToString() const override;
30975
31260
 
30976
31261
  unique_ptr<ParsedExpression> Copy() const override;
30977
31262
 
31263
+ static bool Equals(const FunctionExpression *a, const FunctionExpression *b);
31264
+ hash_t Hash() const override;
31265
+
30978
31266
  void Serialize(FieldWriter &writer) const override;
30979
31267
  static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
31268
+
31269
+ void Verify() const override;
31270
+
31271
+ public:
31272
+ template <class T, class BASE>
31273
+ static string ToString(const T &entry, const string &schema, const string &function_name, bool is_operator = false,
31274
+ bool distinct = false, BASE *filter = nullptr, OrderModifier *order_bys = nullptr,
31275
+ bool export_state = false, bool add_alias = false) {
31276
+ if (is_operator) {
31277
+ // built-in operator
31278
+ D_ASSERT(!distinct);
31279
+ if (entry.children.size() == 1) {
31280
+ if (StringUtil::Contains(function_name, "__postfix")) {
31281
+ return "(" + entry.children[0]->ToString() + ")" +
31282
+ StringUtil::Replace(function_name, "__postfix", "");
31283
+ } else {
31284
+ return function_name + "(" + entry.children[0]->ToString() + ")";
31285
+ }
31286
+ } else if (entry.children.size() == 2) {
31287
+ return StringUtil::Format("(%s %s %s)", entry.children[0]->ToString(), function_name,
31288
+ entry.children[1]->ToString());
31289
+ }
31290
+ }
31291
+ // standard function call
31292
+ string result = schema.empty() ? function_name : schema + "." + function_name;
31293
+ result += "(";
31294
+ if (distinct) {
31295
+ result += "DISTINCT ";
31296
+ }
31297
+ result += StringUtil::Join(entry.children, entry.children.size(), ", ", [&](const unique_ptr<BASE> &child) {
31298
+ return child->alias.empty() || !add_alias
31299
+ ? child->ToString()
31300
+ : KeywordHelper::WriteOptionallyQuoted(child->alias) + " := " + child->ToString();
31301
+ });
31302
+ // ordered aggregate
31303
+ if (order_bys && !order_bys->orders.empty()) {
31304
+ if (entry.children.empty()) {
31305
+ result += ") WITHIN GROUP (";
31306
+ }
31307
+ result += " ORDER BY ";
31308
+ for (idx_t i = 0; i < order_bys->orders.size(); i++) {
31309
+ if (i > 0) {
31310
+ result += ", ";
31311
+ }
31312
+ result += order_bys->orders[i].ToString();
31313
+ }
31314
+ }
31315
+ result += ")";
31316
+
31317
+ // filtered aggregate
31318
+ if (filter) {
31319
+ result += " FILTER (WHERE " + filter->ToString() + ")";
31320
+ }
31321
+
31322
+ if (export_state) {
31323
+ result += " EXPORT_STATE";
31324
+ }
31325
+
31326
+ return result;
31327
+ }
30980
31328
  };
30981
31329
  } // namespace duckdb
31330
+
31331
+
30982
31332
  //===----------------------------------------------------------------------===//
30983
31333
  // DuckDB
30984
31334
  //
@@ -31082,104 +31432,18 @@ public:
31082
31432
  result += "])";
31083
31433
  return result;
31084
31434
  }
31085
- default:
31086
- throw InternalException("Unrecognized operator type");
31087
- }
31088
- }
31089
- };
31090
-
31091
- } // namespace duckdb
31092
-
31093
-
31094
-
31095
- //===----------------------------------------------------------------------===//
31096
- // DuckDB
31097
- //
31098
- // duckdb/parser/expression/cast_expression.hpp
31099
- //
31100
- //
31101
- //===----------------------------------------------------------------------===//
31102
-
31103
-
31104
-
31105
-
31106
-
31107
-
31108
- namespace duckdb {
31109
-
31110
- //! CastExpression represents a type cast from one SQL type to another SQL type
31111
- class CastExpression : public ParsedExpression {
31112
- public:
31113
- DUCKDB_API CastExpression(LogicalType target, unique_ptr<ParsedExpression> child, bool try_cast = false);
31114
-
31115
- //! The child of the cast expression
31116
- unique_ptr<ParsedExpression> child;
31117
- //! The type to cast to
31118
- LogicalType cast_type;
31119
- //! Whether or not this is a try_cast expression
31120
- bool try_cast;
31121
-
31122
- public:
31123
- string ToString() const override;
31124
-
31125
- static bool Equals(const CastExpression *a, const CastExpression *b);
31126
-
31127
- unique_ptr<ParsedExpression> Copy() const override;
31128
-
31129
- void Serialize(FieldWriter &writer) const override;
31130
- static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
31131
-
31132
- public:
31133
- template <class T, class BASE>
31134
- static string ToString(const T &entry) {
31135
- return (entry.try_cast ? "TRY_CAST(" : "CAST(") + entry.child->ToString() + " AS " +
31136
- entry.cast_type.ToString() + ")";
31137
- }
31138
- };
31139
- } // namespace duckdb
31140
-
31141
- //===----------------------------------------------------------------------===//
31142
- // DuckDB
31143
- //
31144
- // duckdb/parser/expression/collate_expression.hpp
31145
- //
31146
- //
31147
- //===----------------------------------------------------------------------===//
31148
-
31149
-
31150
-
31151
-
31152
-
31153
- namespace duckdb {
31154
-
31155
- //! CollateExpression represents a COLLATE statement
31156
- class CollateExpression : public ParsedExpression {
31157
- public:
31158
- CollateExpression(string collation, unique_ptr<ParsedExpression> child);
31159
-
31160
- //! The child of the cast expression
31161
- unique_ptr<ParsedExpression> child;
31162
- //! The collation clause
31163
- string collation;
31164
-
31165
- public:
31166
- string ToString() const override;
31167
-
31168
- static bool Equals(const CollateExpression *a, const CollateExpression *b);
31169
-
31170
- unique_ptr<ParsedExpression> Copy() const override;
31171
-
31172
- void Serialize(FieldWriter &writer) const override;
31173
- static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
31435
+ default:
31436
+ throw InternalException("Unrecognized operator type");
31437
+ }
31438
+ }
31174
31439
  };
31175
- } // namespace duckdb
31176
-
31177
31440
 
31441
+ } // namespace duckdb
31178
31442
 
31179
31443
  //===----------------------------------------------------------------------===//
31180
31444
  // DuckDB
31181
31445
  //
31182
- // duckdb/parser/expression/conjunction_expression.hpp
31446
+ // duckdb/parser/expression/parameter_expression.hpp
31183
31447
  //
31184
31448
  //
31185
31449
  //===----------------------------------------------------------------------===//
@@ -31188,49 +31452,37 @@ public:
31188
31452
 
31189
31453
 
31190
31454
 
31191
-
31192
31455
  namespace duckdb {
31193
-
31194
- //! Represents a conjunction (AND/OR)
31195
- class ConjunctionExpression : public ParsedExpression {
31456
+ class ParameterExpression : public ParsedExpression {
31196
31457
  public:
31197
- DUCKDB_API explicit ConjunctionExpression(ExpressionType type);
31198
- DUCKDB_API ConjunctionExpression(ExpressionType type, vector<unique_ptr<ParsedExpression>> children);
31199
- DUCKDB_API ConjunctionExpression(ExpressionType type, unique_ptr<ParsedExpression> left,
31200
- unique_ptr<ParsedExpression> right);
31458
+ ParameterExpression();
31201
31459
 
31202
- vector<unique_ptr<ParsedExpression>> children;
31460
+ idx_t parameter_nr;
31203
31461
 
31204
31462
  public:
31205
- void AddExpression(unique_ptr<ParsedExpression> expr);
31463
+ bool IsScalar() const override {
31464
+ return true;
31465
+ }
31466
+ bool HasParameter() const override {
31467
+ return true;
31468
+ }
31206
31469
 
31207
31470
  string ToString() const override;
31208
31471
 
31209
- static bool Equals(const ConjunctionExpression *a, const ConjunctionExpression *b);
31472
+ static bool Equals(const ParameterExpression *a, const ParameterExpression *b);
31210
31473
 
31211
31474
  unique_ptr<ParsedExpression> Copy() const override;
31475
+ hash_t Hash() const override;
31212
31476
 
31213
31477
  void Serialize(FieldWriter &writer) const override;
31214
31478
  static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
31215
-
31216
- public:
31217
- template <class T, class BASE>
31218
- static string ToString(const T &entry) {
31219
- string result = "(" + entry.children[0]->ToString();
31220
- for (idx_t i = 1; i < entry.children.size(); i++) {
31221
- result += " " + ExpressionTypeToOperator(entry.type) + " " + entry.children[i]->ToString();
31222
- }
31223
- return result + ")";
31224
- }
31225
31479
  };
31226
31480
  } // namespace duckdb
31227
31481
 
31228
-
31229
-
31230
31482
  //===----------------------------------------------------------------------===//
31231
31483
  // DuckDB
31232
31484
  //
31233
- // duckdb/parser/expression/function_expression.hpp
31485
+ // duckdb/parser/expression/positional_reference_expression.hpp
31234
31486
  //
31235
31487
  //
31236
31488
  //===----------------------------------------------------------------------===//
@@ -31239,118 +31491,33 @@ public:
31239
31491
 
31240
31492
 
31241
31493
 
31242
-
31243
-
31244
31494
  namespace duckdb {
31245
- //! Represents a function call
31246
- class FunctionExpression : public ParsedExpression {
31495
+ class PositionalReferenceExpression : public ParsedExpression {
31247
31496
  public:
31248
- DUCKDB_API FunctionExpression(string schema_name, const string &function_name,
31249
- vector<unique_ptr<ParsedExpression>> children,
31250
- unique_ptr<ParsedExpression> filter = nullptr,
31251
- unique_ptr<OrderModifier> order_bys = nullptr, bool distinct = false,
31252
- bool is_operator = false, bool export_state = false);
31253
- DUCKDB_API FunctionExpression(const string &function_name, vector<unique_ptr<ParsedExpression>> children,
31254
- unique_ptr<ParsedExpression> filter = nullptr,
31255
- unique_ptr<OrderModifier> order_bys = nullptr, bool distinct = false,
31256
- bool is_operator = false, bool export_state = false);
31497
+ DUCKDB_API PositionalReferenceExpression(idx_t index);
31257
31498
 
31258
- //! Schema of the function
31259
- string schema;
31260
- //! Function name
31261
- string function_name;
31262
- //! Whether or not the function is an operator, only used for rendering
31263
- bool is_operator;
31264
- //! List of arguments to the function
31265
- vector<unique_ptr<ParsedExpression>> children;
31266
- //! Whether or not the aggregate function is distinct, only used for aggregates
31267
- bool distinct;
31268
- //! Expression representing a filter, only used for aggregates
31269
- unique_ptr<ParsedExpression> filter;
31270
- //! Modifier representing an ORDER BY, only used for aggregates
31271
- unique_ptr<OrderModifier> order_bys;
31272
- //! whether this function should export its state or not
31273
- bool export_state;
31499
+ idx_t index;
31274
31500
 
31275
31501
  public:
31502
+ bool IsScalar() const override {
31503
+ return false;
31504
+ }
31505
+
31276
31506
  string ToString() const override;
31277
31507
 
31508
+ static bool Equals(const PositionalReferenceExpression *a, const PositionalReferenceExpression *b);
31278
31509
  unique_ptr<ParsedExpression> Copy() const override;
31279
-
31280
- static bool Equals(const FunctionExpression *a, const FunctionExpression *b);
31281
31510
  hash_t Hash() const override;
31282
31511
 
31283
31512
  void Serialize(FieldWriter &writer) const override;
31284
31513
  static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
31285
-
31286
- void Verify() const override;
31287
-
31288
- public:
31289
- template <class T, class BASE>
31290
- static string ToString(const T &entry, const string &schema, const string &function_name, bool is_operator = false,
31291
- bool distinct = false, BASE *filter = nullptr, OrderModifier *order_bys = nullptr,
31292
- bool export_state = false, bool add_alias = false) {
31293
- if (is_operator) {
31294
- // built-in operator
31295
- D_ASSERT(!distinct);
31296
- if (entry.children.size() == 1) {
31297
- if (StringUtil::Contains(function_name, "__postfix")) {
31298
- return "(" + entry.children[0]->ToString() + ")" +
31299
- StringUtil::Replace(function_name, "__postfix", "");
31300
- } else {
31301
- return function_name + "(" + entry.children[0]->ToString() + ")";
31302
- }
31303
- } else if (entry.children.size() == 2) {
31304
- return StringUtil::Format("(%s %s %s)", entry.children[0]->ToString(), function_name,
31305
- entry.children[1]->ToString());
31306
- }
31307
- }
31308
- // standard function call
31309
- string result = schema.empty() ? function_name : schema + "." + function_name;
31310
- result += "(";
31311
- if (distinct) {
31312
- result += "DISTINCT ";
31313
- }
31314
- result += StringUtil::Join(entry.children, entry.children.size(), ", ", [&](const unique_ptr<BASE> &child) {
31315
- return child->alias.empty() || !add_alias
31316
- ? child->ToString()
31317
- : KeywordHelper::WriteOptionallyQuoted(child->alias) + " := " + child->ToString();
31318
- });
31319
- // ordered aggregate
31320
- if (order_bys && !order_bys->orders.empty()) {
31321
- if (entry.children.empty()) {
31322
- result += ") WITHIN GROUP (";
31323
- }
31324
- result += " ORDER BY ";
31325
- for (idx_t i = 0; i < order_bys->orders.size(); i++) {
31326
- if (i > 0) {
31327
- result += ", ";
31328
- }
31329
- result += order_bys->orders[i].ToString();
31330
- }
31331
- }
31332
- result += ")";
31333
-
31334
- // filtered aggregate
31335
- if (filter) {
31336
- result += " FILTER (WHERE " + filter->ToString() + ")";
31337
- }
31338
-
31339
- if (export_state) {
31340
- result += " EXPORT_STATE";
31341
- }
31342
-
31343
- return result;
31344
- }
31345
31514
  };
31346
31515
  } // namespace duckdb
31347
31516
 
31348
-
31349
-
31350
31517
  //===----------------------------------------------------------------------===//
31351
31518
  // DuckDB
31352
31519
  //
31353
- // duckdb/parser/expression/parameter_expression.hpp
31520
+ // duckdb/parser/expression/star_expression.hpp
31354
31521
  //
31355
31522
  //
31356
31523
  //===----------------------------------------------------------------------===//
@@ -31359,35 +31526,37 @@ public:
31359
31526
 
31360
31527
 
31361
31528
 
31529
+
31362
31530
  namespace duckdb {
31363
- class ParameterExpression : public ParsedExpression {
31531
+
31532
+ //! Represents a * expression in the SELECT clause
31533
+ class StarExpression : public ParsedExpression {
31364
31534
  public:
31365
- ParameterExpression();
31535
+ StarExpression(string relation_name = string());
31366
31536
 
31367
- idx_t parameter_nr;
31537
+ //! The relation name in case of tbl.*, or empty if this is a normal *
31538
+ string relation_name;
31539
+ //! List of columns to exclude from the STAR expression
31540
+ case_insensitive_set_t exclude_list;
31541
+ //! List of columns to replace with another expression
31542
+ case_insensitive_map_t<unique_ptr<ParsedExpression>> replace_list;
31543
+ //! Regular expression to select columns (if any)
31544
+ string regex;
31545
+ //! Whether or not this is a COLUMNS expression
31546
+ bool columns = false;
31368
31547
 
31369
31548
  public:
31370
- bool IsScalar() const override {
31371
- return true;
31372
- }
31373
- bool HasParameter() const override {
31374
- return true;
31375
- }
31376
-
31377
31549
  string ToString() const override;
31378
31550
 
31379
- static bool Equals(const ParameterExpression *a, const ParameterExpression *b);
31551
+ static bool Equals(const StarExpression *a, const StarExpression *b);
31380
31552
 
31381
31553
  unique_ptr<ParsedExpression> Copy() const override;
31382
- hash_t Hash() const override;
31383
31554
 
31384
31555
  void Serialize(FieldWriter &writer) const override;
31385
31556
  static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
31386
31557
  };
31387
31558
  } // namespace duckdb
31388
31559
 
31389
-
31390
-
31391
31560
  //===----------------------------------------------------------------------===//
31392
31561
  // DuckDB
31393
31562
  //
@@ -31442,7 +31611,7 @@ public:
31442
31611
  //===----------------------------------------------------------------------===//
31443
31612
  // DuckDB
31444
31613
  //
31445
- // duckdb/parser/parsed_data/create_type_info.hpp
31614
+ // duckdb/parser/parsed_data/create_view_info.hpp
31446
31615
  //
31447
31616
  //
31448
31617
  //===----------------------------------------------------------------------===//
@@ -31452,40 +31621,104 @@ public:
31452
31621
 
31453
31622
 
31454
31623
 
31624
+ namespace duckdb {
31455
31625
 
31626
+ struct CreateViewInfo : public CreateInfo {
31627
+ CreateViewInfo() : CreateInfo(CatalogType::VIEW_ENTRY, INVALID_SCHEMA) {
31628
+ }
31629
+ CreateViewInfo(string schema, string view_name)
31630
+ : CreateInfo(CatalogType::VIEW_ENTRY, schema), view_name(view_name) {
31631
+ }
31456
31632
 
31457
- namespace duckdb {
31633
+ //! Table name to insert to
31634
+ string view_name;
31635
+ //! Aliases of the view
31636
+ vector<string> aliases;
31637
+ //! Return types
31638
+ vector<LogicalType> types;
31639
+ //! The SelectStatement of the view
31640
+ unique_ptr<SelectStatement> query;
31458
31641
 
31459
- struct CreateTypeInfo : public CreateInfo {
31460
- CreateTypeInfo() : CreateInfo(CatalogType::TYPE_ENTRY) {
31642
+ public:
31643
+ unique_ptr<CreateInfo> Copy() const override {
31644
+ auto result = make_unique<CreateViewInfo>(schema, view_name);
31645
+ CopyProperties(*result);
31646
+ result->aliases = aliases;
31647
+ result->types = types;
31648
+ result->query = unique_ptr_cast<SQLStatement, SelectStatement>(query->Copy());
31649
+ return move(result);
31461
31650
  }
31462
- CreateTypeInfo(string name_p, LogicalType type_p)
31463
- : CreateInfo(CatalogType::TYPE_ENTRY), name(move(name_p)), type(move(type_p)) {
31651
+
31652
+ static unique_ptr<CreateViewInfo> Deserialize(Deserializer &deserializer) {
31653
+ auto result = make_unique<CreateViewInfo>();
31654
+ result->DeserializeBase(deserializer);
31655
+
31656
+ FieldReader reader(deserializer);
31657
+ result->view_name = reader.ReadRequired<string>();
31658
+ result->aliases = reader.ReadRequiredList<string>();
31659
+ result->types = reader.ReadRequiredSerializableList<LogicalType, LogicalType>();
31660
+ result->query = reader.ReadOptional<SelectStatement>(nullptr);
31661
+ reader.Finalize();
31662
+
31663
+ return result;
31664
+ }
31665
+
31666
+ protected:
31667
+ void SerializeInternal(Serializer &serializer) const override {
31668
+ FieldWriter writer(serializer);
31669
+ writer.WriteString(view_name);
31670
+ writer.WriteList<string>(aliases);
31671
+ writer.WriteRegularSerializableList(types);
31672
+ writer.WriteOptional(query);
31673
+ writer.Finalize();
31464
31674
  }
31675
+ };
31676
+
31677
+ } // namespace duckdb
31678
+ //===----------------------------------------------------------------------===//
31679
+ // DuckDB
31680
+ //
31681
+ // duckdb/parser/parsed_data/alter_function_info.hpp
31682
+ //
31683
+ //
31684
+ //===----------------------------------------------------------------------===//
31685
+
31686
+
31687
+
31688
+
31689
+
31690
+
31691
+
31692
+ namespace duckdb {
31693
+
31694
+ //===--------------------------------------------------------------------===//
31695
+ // Alter Table
31696
+ //===--------------------------------------------------------------------===//
31697
+ enum class AlterFunctionType : uint8_t { INVALID = 0, ADD_FUNCTION_OVERLOADS = 1 };
31698
+
31699
+ struct AlterFunctionInfo : public AlterInfo {
31700
+ AlterFunctionInfo(AlterFunctionType type, string schema, string name, bool if_exists);
31701
+ virtual ~AlterFunctionInfo() override;
31465
31702
 
31466
- //! Name of the Type
31467
- string name;
31468
- //! Logical Type
31469
- LogicalType type;
31470
- //! Used by create enum from query
31471
- unique_ptr<SQLStatement> query;
31703
+ AlterFunctionType alter_function_type;
31472
31704
 
31473
31705
  public:
31474
- unique_ptr<CreateInfo> Copy() const override {
31475
- auto result = make_unique<CreateTypeInfo>();
31476
- CopyProperties(*result);
31477
- result->name = name;
31478
- result->type = type;
31479
- if (query) {
31480
- result->query = query->Copy();
31481
- }
31482
- return move(result);
31483
- }
31706
+ CatalogType GetCatalogType() const override;
31707
+ void Serialize(FieldWriter &writer) const override;
31708
+ static unique_ptr<AlterInfo> Deserialize(FieldReader &reader);
31709
+ };
31484
31710
 
31485
- protected:
31486
- void SerializeInternal(Serializer &) const override {
31487
- throw NotImplementedException("Cannot serialize '%s'", CatalogTypeToString(CreateInfo::type));
31488
- }
31711
+ //===--------------------------------------------------------------------===//
31712
+ // AddFunctionOverloadInfo
31713
+ //===--------------------------------------------------------------------===//
31714
+ struct AddFunctionOverloadInfo : public AlterFunctionInfo {
31715
+ AddFunctionOverloadInfo(string schema, string name, bool if_exists, ScalarFunctionSet new_overloads);
31716
+ ~AddFunctionOverloadInfo() override;
31717
+
31718
+ ScalarFunctionSet new_overloads;
31719
+
31720
+ public:
31721
+ unique_ptr<AlterInfo> Copy() const override;
31489
31722
  };
31490
31723
 
31491
31724
  } // namespace duckdb
@@ -31539,7 +31772,7 @@ public:
31539
31772
  //===----------------------------------------------------------------------===//
31540
31773
  // DuckDB
31541
31774
  //
31542
- // duckdb/parser/parsed_data/create_aggregate_function_info.hpp
31775
+ // duckdb/parser/parsed_data/show_select_info.hpp
31543
31776
  //
31544
31777
  //
31545
31778
  //===----------------------------------------------------------------------===//
@@ -31551,28 +31784,23 @@ public:
31551
31784
 
31552
31785
  namespace duckdb {
31553
31786
 
31554
- struct CreateAggregateFunctionInfo : public CreateFunctionInfo {
31555
- explicit CreateAggregateFunctionInfo(AggregateFunction function)
31556
- : CreateFunctionInfo(CatalogType::AGGREGATE_FUNCTION_ENTRY), functions(function.name) {
31557
- name = function.name;
31558
- functions.AddFunction(move(function));
31559
- }
31560
-
31561
- explicit CreateAggregateFunctionInfo(AggregateFunctionSet set)
31562
- : CreateFunctionInfo(CatalogType::AGGREGATE_FUNCTION_ENTRY), functions(move(set)) {
31563
- name = functions.name;
31564
- for (auto &func : functions.functions) {
31565
- func.name = functions.name;
31566
- }
31567
- }
31568
-
31569
- AggregateFunctionSet functions;
31787
+ struct ShowSelectInfo : public ParseInfo {
31788
+ //! Types of projected columns
31789
+ vector<LogicalType> types;
31790
+ //! The QueryNode of select query
31791
+ unique_ptr<QueryNode> query;
31792
+ //! Aliases of projected columns
31793
+ vector<string> aliases;
31794
+ //! Whether or not we are requesting a summary or a describe
31795
+ bool is_summary;
31570
31796
 
31571
- public:
31572
- unique_ptr<CreateInfo> Copy() const override {
31573
- auto result = make_unique<CreateAggregateFunctionInfo>(functions);
31574
- CopyProperties(*result);
31575
- return move(result);
31797
+ unique_ptr<ShowSelectInfo> Copy() {
31798
+ auto result = make_unique<ShowSelectInfo>();
31799
+ result->types = types;
31800
+ result->query = query->Copy();
31801
+ result->aliases = aliases;
31802
+ result->is_summary = is_summary;
31803
+ return result;
31576
31804
  }
31577
31805
  };
31578
31806
 
@@ -31580,7 +31808,7 @@ public:
31580
31808
  //===----------------------------------------------------------------------===//
31581
31809
  // DuckDB
31582
31810
  //
31583
- // duckdb/parser/parsed_data/vacuum_info.hpp
31811
+ // duckdb/parser/parsed_data/create_index_info.hpp
31584
31812
  //
31585
31813
  //
31586
31814
  //===----------------------------------------------------------------------===//
@@ -31589,20 +31817,11 @@ public:
31589
31817
 
31590
31818
 
31591
31819
 
31592
- //===----------------------------------------------------------------------===//
31593
- // DuckDB
31594
- //
31595
- // duckdb/planner/tableref/bound_basetableref.hpp
31596
- //
31597
- //
31598
- //===----------------------------------------------------------------------===//
31599
-
31600
-
31601
31820
 
31602
31821
  //===----------------------------------------------------------------------===//
31603
31822
  // DuckDB
31604
31823
  //
31605
- // duckdb/planner/bound_tableref.hpp
31824
+ // duckdb/parser/tableref/basetableref.hpp
31606
31825
  //
31607
31826
  //
31608
31827
  //===----------------------------------------------------------------------===//
@@ -31612,163 +31831,78 @@ public:
31612
31831
 
31613
31832
 
31614
31833
 
31615
-
31616
- namespace duckdb {
31617
-
31618
- class BoundTableRef {
31619
- public:
31620
- explicit BoundTableRef(TableReferenceType type) : type(type) {
31621
- }
31622
- virtual ~BoundTableRef() {
31623
- }
31624
-
31625
- //! The type of table reference
31626
- TableReferenceType type;
31627
- //! The sample options (if any)
31628
- unique_ptr<SampleOptions> sample;
31629
- };
31630
- } // namespace duckdb
31631
-
31632
-
31633
-
31634
31834
  namespace duckdb {
31635
- class TableCatalogEntry;
31636
-
31637
31835
  //! Represents a TableReference to a base table in the schema
31638
- class BoundBaseTableRef : public BoundTableRef {
31836
+ class BaseTableRef : public TableRef {
31639
31837
  public:
31640
- BoundBaseTableRef(TableCatalogEntry *table, unique_ptr<LogicalOperator> get)
31641
- : BoundTableRef(TableReferenceType::BASE_TABLE), table(table), get(move(get)) {
31838
+ BaseTableRef() : TableRef(TableReferenceType::BASE_TABLE), schema_name(INVALID_SCHEMA) {
31642
31839
  }
31643
31840
 
31644
- TableCatalogEntry *table;
31645
- unique_ptr<LogicalOperator> get;
31646
- };
31647
- } // namespace duckdb
31648
-
31649
-
31650
-
31651
- namespace duckdb {
31652
-
31653
- struct VacuumOptions {
31654
- bool vacuum;
31655
- bool analyze;
31656
- };
31841
+ //! Schema name
31842
+ string schema_name;
31843
+ //! Table name
31844
+ string table_name;
31845
+ //! Aliases for the column names
31846
+ vector<string> column_name_alias;
31657
31847
 
31658
- struct VacuumInfo : public ParseInfo {
31659
31848
  public:
31660
- explicit VacuumInfo(VacuumOptions options) : options(options), has_table(false), table(nullptr) {};
31661
-
31662
- unique_ptr<VacuumInfo> Copy() {
31663
- auto result = make_unique<VacuumInfo>(options);
31664
- result->has_table = has_table;
31665
- if (has_table) {
31666
- result->ref = ref->Copy();
31667
- }
31668
- return result;
31669
- }
31849
+ string ToString() const override;
31850
+ bool Equals(const TableRef *other_p) const override;
31670
31851
 
31671
- const VacuumOptions options;
31852
+ unique_ptr<TableRef> Copy() override;
31672
31853
 
31673
- public:
31674
- bool has_table;
31675
- unique_ptr<TableRef> ref;
31676
- TableCatalogEntry *table;
31677
- unordered_map<idx_t, idx_t> column_id_map;
31678
- vector<string> columns;
31854
+ //! Serializes a blob into a BaseTableRef
31855
+ void Serialize(FieldWriter &serializer) const override;
31856
+ //! Deserializes a blob back into a BaseTableRef
31857
+ static unique_ptr<TableRef> Deserialize(FieldReader &source);
31679
31858
  };
31680
-
31681
31859
  } // namespace duckdb
31682
- //===----------------------------------------------------------------------===//
31683
- // DuckDB
31684
- //
31685
- // duckdb/parser/parsed_data/drop_info.hpp
31686
- //
31687
- //
31688
- //===----------------------------------------------------------------------===//
31689
-
31690
-
31691
31860
 
31692
31861
 
31693
31862
 
31694
31863
 
31695
31864
  namespace duckdb {
31696
31865
 
31697
- struct DropInfo : public ParseInfo {
31698
- DropInfo() : schema(INVALID_SCHEMA), if_exists(false), cascade(false) {
31699
- }
31700
-
31701
- //! The catalog type to drop
31702
- CatalogType type;
31703
- //! Schema name to drop from, if any
31704
- string schema;
31705
- //! Element name to drop
31706
- string name;
31707
- //! Ignore if the entry does not exist instead of failing
31708
- bool if_exists = false;
31709
- //! Cascade drop (drop all dependents instead of throwing an error if there
31710
- //! are any)
31711
- bool cascade = false;
31712
-
31713
- public:
31714
- unique_ptr<DropInfo> Copy() const {
31715
- auto result = make_unique<DropInfo>();
31716
- result->type = type;
31717
- result->schema = schema;
31718
- result->name = name;
31719
- result->if_exists = if_exists;
31720
- result->cascade = cascade;
31721
- return result;
31866
+ struct CreateIndexInfo : public CreateInfo {
31867
+ CreateIndexInfo() : CreateInfo(CatalogType::INDEX_ENTRY) {
31722
31868
  }
31723
- };
31724
-
31725
- } // namespace duckdb
31726
- //===----------------------------------------------------------------------===//
31727
- // DuckDB
31728
- //
31729
- // duckdb/parser/parsed_data/export_table_data.hpp
31730
- //
31731
- //
31732
- //===----------------------------------------------------------------------===//
31733
-
31734
31869
 
31870
+ //! Index Type (e.g., B+-tree, Skip-List, ...)
31871
+ IndexType index_type;
31872
+ //! Name of the Index
31873
+ string index_name;
31874
+ //! Index Constraint Type
31875
+ IndexConstraintType constraint_type;
31876
+ //! The table to create the index on
31877
+ unique_ptr<BaseTableRef> table;
31878
+ //! Set of expressions to index by
31879
+ vector<unique_ptr<ParsedExpression>> expressions;
31880
+ vector<unique_ptr<ParsedExpression>> parsed_expressions;
31735
31881
 
31882
+ //! Types used for the CREATE INDEX scan
31883
+ vector<LogicalType> scan_types;
31884
+ //! The names of the columns, used for the CREATE INDEX scan
31885
+ vector<string> names;
31886
+ //! Column IDs needed for index creation
31887
+ vector<column_t> column_ids;
31736
31888
 
31889
+ protected:
31890
+ void SerializeInternal(Serializer &serializer) const override;
31737
31891
 
31892
+ public:
31893
+ unique_ptr<CreateInfo> Copy() const override;
31738
31894
 
31739
- namespace duckdb {
31740
- class TableCatalogEntry;
31741
-
31742
- struct ExportedTableData {
31743
- //! Name of the exported table
31744
- string table_name;
31745
-
31746
- //! Name of the schema
31747
- string schema_name;
31748
-
31749
- //! Path to be exported
31750
- string file_path;
31751
- };
31752
-
31753
- struct ExportedTableInfo {
31754
- TableCatalogEntry *entry;
31755
- ExportedTableData table_data;
31756
- };
31757
-
31758
- struct BoundExportData : public ParseInfo {
31759
- std::vector<ExportedTableInfo> data;
31895
+ static unique_ptr<CreateIndexInfo> Deserialize(Deserializer &deserializer);
31760
31896
  };
31761
31897
 
31762
31898
  } // namespace duckdb
31763
31899
  //===----------------------------------------------------------------------===//
31764
31900
  // DuckDB
31765
31901
  //
31766
- // duckdb/parser/parsed_data/alter_function_info.hpp
31902
+ // duckdb/parser/parsed_data/transaction_info.hpp
31767
31903
  //
31768
31904
  //
31769
- //===----------------------------------------------------------------------===//
31770
-
31771
-
31905
+ //===----------------------------------------------------------------------===//
31772
31906
 
31773
31907
 
31774
31908
 
@@ -31776,34 +31910,14 @@ struct BoundExportData : public ParseInfo {
31776
31910
 
31777
31911
  namespace duckdb {
31778
31912
 
31779
- //===--------------------------------------------------------------------===//
31780
- // Alter Table
31781
- //===--------------------------------------------------------------------===//
31782
- enum class AlterFunctionType : uint8_t { INVALID = 0, ADD_FUNCTION_OVERLOADS = 1 };
31783
-
31784
- struct AlterFunctionInfo : public AlterInfo {
31785
- AlterFunctionInfo(AlterFunctionType type, string schema, string name, bool if_exists);
31786
- virtual ~AlterFunctionInfo() override;
31787
-
31788
- AlterFunctionType alter_function_type;
31789
-
31790
- public:
31791
- CatalogType GetCatalogType() const override;
31792
- void Serialize(FieldWriter &writer) const override;
31793
- static unique_ptr<AlterInfo> Deserialize(FieldReader &reader);
31794
- };
31795
-
31796
- //===--------------------------------------------------------------------===//
31797
- // AddFunctionOverloadInfo
31798
- //===--------------------------------------------------------------------===//
31799
- struct AddFunctionOverloadInfo : public AlterFunctionInfo {
31800
- AddFunctionOverloadInfo(string schema, string name, bool if_exists, ScalarFunctionSet new_overloads);
31801
- ~AddFunctionOverloadInfo() override;
31913
+ enum class TransactionType : uint8_t { INVALID, BEGIN_TRANSACTION, COMMIT, ROLLBACK };
31802
31914
 
31803
- ScalarFunctionSet new_overloads;
31915
+ struct TransactionInfo : public ParseInfo {
31916
+ explicit TransactionInfo(TransactionType type) : type(type) {
31917
+ }
31804
31918
 
31805
- public:
31806
- unique_ptr<AlterInfo> Copy() const override;
31919
+ //! The type of transaction statement
31920
+ TransactionType type;
31807
31921
  };
31808
31922
 
31809
31923
  } // namespace duckdb
@@ -31840,7 +31954,7 @@ public:
31840
31954
  //===----------------------------------------------------------------------===//
31841
31955
  // DuckDB
31842
31956
  //
31843
- // duckdb/parser/parsed_data/create_view_info.hpp
31957
+ // duckdb/parser/parsed_data/export_table_data.hpp
31844
31958
  //
31845
31959
  //
31846
31960
  //===----------------------------------------------------------------------===//
@@ -31851,63 +31965,33 @@ public:
31851
31965
 
31852
31966
 
31853
31967
  namespace duckdb {
31968
+ class TableCatalogEntry;
31854
31969
 
31855
- struct CreateViewInfo : public CreateInfo {
31856
- CreateViewInfo() : CreateInfo(CatalogType::VIEW_ENTRY, INVALID_SCHEMA) {
31857
- }
31858
- CreateViewInfo(string schema, string view_name)
31859
- : CreateInfo(CatalogType::VIEW_ENTRY, schema), view_name(view_name) {
31860
- }
31861
-
31862
- //! Table name to insert to
31863
- string view_name;
31864
- //! Aliases of the view
31865
- vector<string> aliases;
31866
- //! Return types
31867
- vector<LogicalType> types;
31868
- //! The SelectStatement of the view
31869
- unique_ptr<SelectStatement> query;
31870
-
31871
- public:
31872
- unique_ptr<CreateInfo> Copy() const override {
31873
- auto result = make_unique<CreateViewInfo>(schema, view_name);
31874
- CopyProperties(*result);
31875
- result->aliases = aliases;
31876
- result->types = types;
31877
- result->query = unique_ptr_cast<SQLStatement, SelectStatement>(query->Copy());
31878
- return move(result);
31879
- }
31970
+ struct ExportedTableData {
31971
+ //! Name of the exported table
31972
+ string table_name;
31880
31973
 
31881
- static unique_ptr<CreateViewInfo> Deserialize(Deserializer &deserializer) {
31882
- auto result = make_unique<CreateViewInfo>();
31883
- result->DeserializeBase(deserializer);
31974
+ //! Name of the schema
31975
+ string schema_name;
31884
31976
 
31885
- FieldReader reader(deserializer);
31886
- result->view_name = reader.ReadRequired<string>();
31887
- result->aliases = reader.ReadRequiredList<string>();
31888
- result->types = reader.ReadRequiredSerializableList<LogicalType, LogicalType>();
31889
- result->query = reader.ReadOptional<SelectStatement>(nullptr);
31890
- reader.Finalize();
31977
+ //! Path to be exported
31978
+ string file_path;
31979
+ };
31891
31980
 
31892
- return result;
31893
- }
31981
+ struct ExportedTableInfo {
31982
+ TableCatalogEntry *entry;
31983
+ ExportedTableData table_data;
31984
+ };
31894
31985
 
31895
- protected:
31896
- void SerializeInternal(Serializer &serializer) const override {
31897
- FieldWriter writer(serializer);
31898
- writer.WriteString(view_name);
31899
- writer.WriteList<string>(aliases);
31900
- writer.WriteRegularSerializableList(types);
31901
- writer.WriteOptional(query);
31902
- writer.Finalize();
31903
- }
31986
+ struct BoundExportData : public ParseInfo {
31987
+ std::vector<ExportedTableInfo> data;
31904
31988
  };
31905
31989
 
31906
31990
  } // namespace duckdb
31907
31991
  //===----------------------------------------------------------------------===//
31908
31992
  // DuckDB
31909
31993
  //
31910
- // duckdb/parser/parsed_data/create_schema_info.hpp
31994
+ // duckdb/parser/parsed_data/create_aggregate_function_info.hpp
31911
31995
  //
31912
31996
  //
31913
31997
  //===----------------------------------------------------------------------===//
@@ -31916,28 +32000,32 @@ protected:
31916
32000
 
31917
32001
 
31918
32002
 
32003
+
31919
32004
  namespace duckdb {
31920
32005
 
31921
- struct CreateSchemaInfo : public CreateInfo {
31922
- CreateSchemaInfo() : CreateInfo(CatalogType::SCHEMA_ENTRY) {
32006
+ struct CreateAggregateFunctionInfo : public CreateFunctionInfo {
32007
+ explicit CreateAggregateFunctionInfo(AggregateFunction function)
32008
+ : CreateFunctionInfo(CatalogType::AGGREGATE_FUNCTION_ENTRY), functions(function.name) {
32009
+ name = function.name;
32010
+ functions.AddFunction(move(function));
32011
+ }
32012
+
32013
+ explicit CreateAggregateFunctionInfo(AggregateFunctionSet set)
32014
+ : CreateFunctionInfo(CatalogType::AGGREGATE_FUNCTION_ENTRY), functions(move(set)) {
32015
+ name = functions.name;
32016
+ for (auto &func : functions.functions) {
32017
+ func.name = functions.name;
32018
+ }
31923
32019
  }
31924
32020
 
32021
+ AggregateFunctionSet functions;
32022
+
31925
32023
  public:
31926
32024
  unique_ptr<CreateInfo> Copy() const override {
31927
- auto result = make_unique<CreateSchemaInfo>();
32025
+ auto result = make_unique<CreateAggregateFunctionInfo>(functions);
31928
32026
  CopyProperties(*result);
31929
32027
  return move(result);
31930
32028
  }
31931
-
31932
- static unique_ptr<CreateSchemaInfo> Deserialize(Deserializer &deserializer) {
31933
- auto result = make_unique<CreateSchemaInfo>();
31934
- result->DeserializeBase(deserializer);
31935
- return result;
31936
- }
31937
-
31938
- protected:
31939
- void SerializeInternal(Serializer &) const override {
31940
- }
31941
32029
  };
31942
32030
 
31943
32031
  } // namespace duckdb
@@ -32024,6 +32112,43 @@ public:
32024
32112
  }
32025
32113
  };
32026
32114
 
32115
+ } // namespace duckdb
32116
+ //===----------------------------------------------------------------------===//
32117
+ // DuckDB
32118
+ //
32119
+ // duckdb/parser/parsed_data/create_schema_info.hpp
32120
+ //
32121
+ //
32122
+ //===----------------------------------------------------------------------===//
32123
+
32124
+
32125
+
32126
+
32127
+
32128
+ namespace duckdb {
32129
+
32130
+ struct CreateSchemaInfo : public CreateInfo {
32131
+ CreateSchemaInfo() : CreateInfo(CatalogType::SCHEMA_ENTRY) {
32132
+ }
32133
+
32134
+ public:
32135
+ unique_ptr<CreateInfo> Copy() const override {
32136
+ auto result = make_unique<CreateSchemaInfo>();
32137
+ CopyProperties(*result);
32138
+ return move(result);
32139
+ }
32140
+
32141
+ static unique_ptr<CreateSchemaInfo> Deserialize(Deserializer &deserializer) {
32142
+ auto result = make_unique<CreateSchemaInfo>();
32143
+ result->DeserializeBase(deserializer);
32144
+ return result;
32145
+ }
32146
+
32147
+ protected:
32148
+ void SerializeInternal(Serializer &) const override {
32149
+ }
32150
+ };
32151
+
32027
32152
  } // namespace duckdb
32028
32153
  //===----------------------------------------------------------------------===//
32029
32154
  // DuckDB
@@ -32066,7 +32191,7 @@ public:
32066
32191
  //===----------------------------------------------------------------------===//
32067
32192
  // DuckDB
32068
32193
  //
32069
- // duckdb/parser/parsed_data/transaction_info.hpp
32194
+ // duckdb/parser/parsed_data/vacuum_info.hpp
32070
32195
  //
32071
32196
  //
32072
32197
  //===----------------------------------------------------------------------===//
@@ -32075,36 +32200,20 @@ public:
32075
32200
 
32076
32201
 
32077
32202
 
32078
- namespace duckdb {
32079
-
32080
- enum class TransactionType : uint8_t { INVALID, BEGIN_TRANSACTION, COMMIT, ROLLBACK };
32081
-
32082
- struct TransactionInfo : public ParseInfo {
32083
- explicit TransactionInfo(TransactionType type) : type(type) {
32084
- }
32085
-
32086
- //! The type of transaction statement
32087
- TransactionType type;
32088
- };
32089
-
32090
- } // namespace duckdb
32091
32203
  //===----------------------------------------------------------------------===//
32092
32204
  // DuckDB
32093
32205
  //
32094
- // duckdb/parser/parsed_data/create_index_info.hpp
32206
+ // duckdb/planner/tableref/bound_basetableref.hpp
32095
32207
  //
32096
32208
  //
32097
32209
  //===----------------------------------------------------------------------===//
32098
32210
 
32099
32211
 
32100
32212
 
32101
-
32102
-
32103
-
32104
32213
  //===----------------------------------------------------------------------===//
32105
32214
  // DuckDB
32106
32215
  //
32107
- // duckdb/parser/tableref/basetableref.hpp
32216
+ // duckdb/planner/bound_tableref.hpp
32108
32217
  //
32109
32218
  //
32110
32219
  //===----------------------------------------------------------------------===//
@@ -32114,75 +32223,77 @@ struct TransactionInfo : public ParseInfo {
32114
32223
 
32115
32224
 
32116
32225
 
32226
+
32117
32227
  namespace duckdb {
32118
- //! Represents a TableReference to a base table in the schema
32119
- class BaseTableRef : public TableRef {
32228
+
32229
+ class BoundTableRef {
32120
32230
  public:
32121
- BaseTableRef() : TableRef(TableReferenceType::BASE_TABLE), schema_name(INVALID_SCHEMA) {
32231
+ explicit BoundTableRef(TableReferenceType type) : type(type) {
32232
+ }
32233
+ virtual ~BoundTableRef() {
32122
32234
  }
32123
32235
 
32124
- //! Schema name
32125
- string schema_name;
32126
- //! Table name
32127
- string table_name;
32128
- //! Aliases for the column names
32129
- vector<string> column_name_alias;
32236
+ //! The type of table reference
32237
+ TableReferenceType type;
32238
+ //! The sample options (if any)
32239
+ unique_ptr<SampleOptions> sample;
32240
+ };
32241
+ } // namespace duckdb
32130
32242
 
32131
- public:
32132
- string ToString() const override;
32133
- bool Equals(const TableRef *other_p) const override;
32134
32243
 
32135
- unique_ptr<TableRef> Copy() override;
32136
32244
 
32137
- //! Serializes a blob into a BaseTableRef
32138
- void Serialize(FieldWriter &serializer) const override;
32139
- //! Deserializes a blob back into a BaseTableRef
32140
- static unique_ptr<TableRef> Deserialize(FieldReader &source);
32245
+ namespace duckdb {
32246
+ class TableCatalogEntry;
32247
+
32248
+ //! Represents a TableReference to a base table in the schema
32249
+ class BoundBaseTableRef : public BoundTableRef {
32250
+ public:
32251
+ BoundBaseTableRef(TableCatalogEntry *table, unique_ptr<LogicalOperator> get)
32252
+ : BoundTableRef(TableReferenceType::BASE_TABLE), table(table), get(move(get)) {
32253
+ }
32254
+
32255
+ TableCatalogEntry *table;
32256
+ unique_ptr<LogicalOperator> get;
32141
32257
  };
32142
32258
  } // namespace duckdb
32143
32259
 
32144
32260
 
32145
32261
 
32146
-
32147
32262
  namespace duckdb {
32148
32263
 
32149
- struct CreateIndexInfo : public CreateInfo {
32150
- CreateIndexInfo() : CreateInfo(CatalogType::INDEX_ENTRY) {
32151
- }
32264
+ struct VacuumOptions {
32265
+ bool vacuum;
32266
+ bool analyze;
32267
+ };
32152
32268
 
32153
- //! Index Type (e.g., B+-tree, Skip-List, ...)
32154
- IndexType index_type;
32155
- //! Name of the Index
32156
- string index_name;
32157
- //! Index Constraint Type
32158
- IndexConstraintType constraint_type;
32159
- //! The table to create the index on
32160
- unique_ptr<BaseTableRef> table;
32161
- //! Set of expressions to index by
32162
- vector<unique_ptr<ParsedExpression>> expressions;
32163
- vector<unique_ptr<ParsedExpression>> parsed_expressions;
32269
+ struct VacuumInfo : public ParseInfo {
32270
+ public:
32271
+ explicit VacuumInfo(VacuumOptions options) : options(options), has_table(false), table(nullptr) {};
32164
32272
 
32165
- //! Types used for the CREATE INDEX scan
32166
- vector<LogicalType> scan_types;
32167
- //! The names of the columns, used for the CREATE INDEX scan
32168
- vector<string> names;
32169
- //! Column IDs needed for index creation
32170
- vector<column_t> column_ids;
32273
+ unique_ptr<VacuumInfo> Copy() {
32274
+ auto result = make_unique<VacuumInfo>(options);
32275
+ result->has_table = has_table;
32276
+ if (has_table) {
32277
+ result->ref = ref->Copy();
32278
+ }
32279
+ return result;
32280
+ }
32171
32281
 
32172
- protected:
32173
- void SerializeInternal(Serializer &serializer) const override;
32282
+ const VacuumOptions options;
32174
32283
 
32175
32284
  public:
32176
- unique_ptr<CreateInfo> Copy() const override;
32177
-
32178
- static unique_ptr<CreateIndexInfo> Deserialize(Deserializer &deserializer);
32285
+ bool has_table;
32286
+ unique_ptr<TableRef> ref;
32287
+ TableCatalogEntry *table;
32288
+ unordered_map<idx_t, idx_t> column_id_map;
32289
+ vector<string> columns;
32179
32290
  };
32180
32291
 
32181
32292
  } // namespace duckdb
32182
32293
  //===----------------------------------------------------------------------===//
32183
32294
  // DuckDB
32184
32295
  //
32185
- // duckdb/parser/parsed_data/show_select_info.hpp
32296
+ // duckdb/parser/parsed_data/drop_info.hpp
32186
32297
  //
32187
32298
  //
32188
32299
  //===----------------------------------------------------------------------===//
@@ -32194,22 +32305,30 @@ public:
32194
32305
 
32195
32306
  namespace duckdb {
32196
32307
 
32197
- struct ShowSelectInfo : public ParseInfo {
32198
- //! Types of projected columns
32199
- vector<LogicalType> types;
32200
- //! The QueryNode of select query
32201
- unique_ptr<QueryNode> query;
32202
- //! Aliases of projected columns
32203
- vector<string> aliases;
32204
- //! Whether or not we are requesting a summary or a describe
32205
- bool is_summary;
32308
+ struct DropInfo : public ParseInfo {
32309
+ DropInfo() : schema(INVALID_SCHEMA), if_exists(false), cascade(false) {
32310
+ }
32206
32311
 
32207
- unique_ptr<ShowSelectInfo> Copy() {
32208
- auto result = make_unique<ShowSelectInfo>();
32209
- result->types = types;
32210
- result->query = query->Copy();
32211
- result->aliases = aliases;
32212
- result->is_summary = is_summary;
32312
+ //! The catalog type to drop
32313
+ CatalogType type;
32314
+ //! Schema name to drop from, if any
32315
+ string schema;
32316
+ //! Element name to drop
32317
+ string name;
32318
+ //! Ignore if the entry does not exist instead of failing
32319
+ bool if_exists = false;
32320
+ //! Cascade drop (drop all dependents instead of throwing an error if there
32321
+ //! are any)
32322
+ bool cascade = false;
32323
+
32324
+ public:
32325
+ unique_ptr<DropInfo> Copy() const {
32326
+ auto result = make_unique<DropInfo>();
32327
+ result->type = type;
32328
+ result->schema = schema;
32329
+ result->name = name;
32330
+ result->if_exists = if_exists;
32331
+ result->cascade = cascade;
32213
32332
  return result;
32214
32333
  }
32215
32334
  };
@@ -32218,7 +32337,7 @@ struct ShowSelectInfo : public ParseInfo {
32218
32337
  //===----------------------------------------------------------------------===//
32219
32338
  // DuckDB
32220
32339
  //
32221
- // duckdb/parser/tableref/expressionlistref.hpp
32340
+ // duckdb/parser/parsed_data/create_type_info.hpp
32222
32341
  //
32223
32342
  //
32224
32343
  //===----------------------------------------------------------------------===//
@@ -32231,35 +32350,44 @@ struct ShowSelectInfo : public ParseInfo {
32231
32350
 
32232
32351
 
32233
32352
  namespace duckdb {
32234
- //! Represents an expression list as generated by a VALUES statement
32235
- class ExpressionListRef : public TableRef {
32236
- public:
32237
- ExpressionListRef() : TableRef(TableReferenceType::EXPRESSION_LIST) {
32353
+
32354
+ struct CreateTypeInfo : public CreateInfo {
32355
+ CreateTypeInfo() : CreateInfo(CatalogType::TYPE_ENTRY) {
32356
+ }
32357
+ CreateTypeInfo(string name_p, LogicalType type_p)
32358
+ : CreateInfo(CatalogType::TYPE_ENTRY), name(move(name_p)), type(move(type_p)) {
32238
32359
  }
32239
32360
 
32240
- //! Value list, only used for VALUES statement
32241
- vector<vector<unique_ptr<ParsedExpression>>> values;
32242
- //! Expected SQL types
32243
- vector<LogicalType> expected_types;
32244
- //! The set of expected names
32245
- vector<string> expected_names;
32361
+ //! Name of the Type
32362
+ string name;
32363
+ //! Logical Type
32364
+ LogicalType type;
32365
+ //! Used by create enum from query
32366
+ unique_ptr<SQLStatement> query;
32246
32367
 
32247
32368
  public:
32248
- string ToString() const override;
32249
- bool Equals(const TableRef *other_p) const override;
32250
-
32251
- unique_ptr<TableRef> Copy() override;
32369
+ unique_ptr<CreateInfo> Copy() const override {
32370
+ auto result = make_unique<CreateTypeInfo>();
32371
+ CopyProperties(*result);
32372
+ result->name = name;
32373
+ result->type = type;
32374
+ if (query) {
32375
+ result->query = query->Copy();
32376
+ }
32377
+ return move(result);
32378
+ }
32252
32379
 
32253
- //! Serializes a blob into a ExpressionListRef
32254
- void Serialize(FieldWriter &serializer) const override;
32255
- //! Deserializes a blob back into a ExpressionListRef
32256
- static unique_ptr<TableRef> Deserialize(FieldReader &source);
32380
+ protected:
32381
+ void SerializeInternal(Serializer &) const override {
32382
+ throw NotImplementedException("Cannot serialize '%s'", CatalogTypeToString(CreateInfo::type));
32383
+ }
32257
32384
  };
32385
+
32258
32386
  } // namespace duckdb
32259
32387
  //===----------------------------------------------------------------------===//
32260
32388
  // DuckDB
32261
32389
  //
32262
- // duckdb/parser/tableref/joinref.hpp
32390
+ // duckdb/parser/tableref/table_function_ref.hpp
32263
32391
  //
32264
32392
  //
32265
32393
  //===----------------------------------------------------------------------===//
@@ -32273,41 +32401,38 @@ public:
32273
32401
 
32274
32402
 
32275
32403
  namespace duckdb {
32276
- //! Represents a JOIN between two expressions
32277
- class JoinRef : public TableRef {
32404
+ //! Represents a Table producing function
32405
+ class TableFunctionRef : public TableRef {
32278
32406
  public:
32279
- JoinRef() : TableRef(TableReferenceType::JOIN), is_natural(false) {
32280
- }
32407
+ DUCKDB_API TableFunctionRef();
32281
32408
 
32282
- //! The left hand side of the join
32283
- unique_ptr<TableRef> left;
32284
- //! The right hand side of the join
32285
- unique_ptr<TableRef> right;
32286
- //! The join condition
32287
- unique_ptr<ParsedExpression> condition;
32288
- //! The join type
32289
- JoinType type;
32290
- //! Natural join
32291
- bool is_natural;
32292
- //! The set of USING columns (if any)
32293
- vector<string> using_columns;
32409
+ unique_ptr<ParsedExpression> function;
32410
+ vector<string> column_name_alias;
32411
+
32412
+ // if the function takes a subquery as argument its in here
32413
+ unique_ptr<SelectStatement> subquery;
32414
+
32415
+ // External dependencies of this table funcion
32416
+ unique_ptr<ExternalDependency> external_dependency;
32294
32417
 
32295
32418
  public:
32296
32419
  string ToString() const override;
32420
+
32297
32421
  bool Equals(const TableRef *other_p) const override;
32298
32422
 
32299
32423
  unique_ptr<TableRef> Copy() override;
32300
32424
 
32301
- //! Serializes a blob into a JoinRef
32425
+ //! Serializes a blob into a BaseTableRef
32302
32426
  void Serialize(FieldWriter &serializer) const override;
32303
- //! Deserializes a blob back into a JoinRef
32427
+ //! Deserializes a blob back into a BaseTableRef
32304
32428
  static unique_ptr<TableRef> Deserialize(FieldReader &source);
32305
32429
  };
32306
32430
  } // namespace duckdb
32431
+
32307
32432
  //===----------------------------------------------------------------------===//
32308
32433
  // DuckDB
32309
32434
  //
32310
- // duckdb/parser/tableref/subqueryref.hpp
32435
+ // duckdb/parser/tableref/crossproductref.hpp
32311
32436
  //
32312
32437
  //
32313
32438
  //===----------------------------------------------------------------------===//
@@ -32316,17 +32441,17 @@ public:
32316
32441
 
32317
32442
 
32318
32443
 
32319
-
32320
32444
  namespace duckdb {
32321
- //! Represents a subquery
32322
- class SubqueryRef : public TableRef {
32445
+ //! Represents a cross product
32446
+ class CrossProductRef : public TableRef {
32323
32447
  public:
32324
- explicit SubqueryRef(unique_ptr<SelectStatement> subquery, string alias = string());
32448
+ CrossProductRef() : TableRef(TableReferenceType::CROSS_PRODUCT) {
32449
+ }
32325
32450
 
32326
- //! The subquery
32327
- unique_ptr<SelectStatement> subquery;
32328
- //! Aliases for the column names
32329
- vector<string> column_name_alias;
32451
+ //! The left hand side of the cross product
32452
+ unique_ptr<TableRef> left;
32453
+ //! The right hand side of the cross product
32454
+ unique_ptr<TableRef> right;
32330
32455
 
32331
32456
  public:
32332
32457
  string ToString() const override;
@@ -32334,12 +32459,13 @@ public:
32334
32459
 
32335
32460
  unique_ptr<TableRef> Copy() override;
32336
32461
 
32337
- //! Serializes a blob into a SubqueryRef
32462
+ //! Serializes a blob into a CrossProductRef
32338
32463
  void Serialize(FieldWriter &serializer) const override;
32339
- //! Deserializes a blob back into a SubqueryRef
32464
+ //! Deserializes a blob back into a CrossProductRef
32340
32465
  static unique_ptr<TableRef> Deserialize(FieldReader &source);
32341
32466
  };
32342
32467
  } // namespace duckdb
32468
+
32343
32469
  //===----------------------------------------------------------------------===//
32344
32470
  // DuckDB
32345
32471
  //
@@ -32371,10 +32497,11 @@ public:
32371
32497
  static unique_ptr<TableRef> Deserialize(FieldReader &source);
32372
32498
  };
32373
32499
  } // namespace duckdb
32500
+
32374
32501
  //===----------------------------------------------------------------------===//
32375
32502
  // DuckDB
32376
32503
  //
32377
- // duckdb/parser/tableref/crossproductref.hpp
32504
+ // duckdb/parser/tableref/expressionlistref.hpp
32378
32505
  //
32379
32506
  //
32380
32507
  //===----------------------------------------------------------------------===//
@@ -32383,17 +32510,22 @@ public:
32383
32510
 
32384
32511
 
32385
32512
 
32513
+
32514
+
32515
+
32386
32516
  namespace duckdb {
32387
- //! Represents a cross product
32388
- class CrossProductRef : public TableRef {
32517
+ //! Represents an expression list as generated by a VALUES statement
32518
+ class ExpressionListRef : public TableRef {
32389
32519
  public:
32390
- CrossProductRef() : TableRef(TableReferenceType::CROSS_PRODUCT) {
32520
+ ExpressionListRef() : TableRef(TableReferenceType::EXPRESSION_LIST) {
32391
32521
  }
32392
32522
 
32393
- //! The left hand side of the cross product
32394
- unique_ptr<TableRef> left;
32395
- //! The right hand side of the cross product
32396
- unique_ptr<TableRef> right;
32523
+ //! Value list, only used for VALUES statement
32524
+ vector<vector<unique_ptr<ParsedExpression>>> values;
32525
+ //! Expected SQL types
32526
+ vector<LogicalType> expected_types;
32527
+ //! The set of expected names
32528
+ vector<string> expected_names;
32397
32529
 
32398
32530
  public:
32399
32531
  string ToString() const override;
@@ -32401,16 +32533,17 @@ public:
32401
32533
 
32402
32534
  unique_ptr<TableRef> Copy() override;
32403
32535
 
32404
- //! Serializes a blob into a CrossProductRef
32536
+ //! Serializes a blob into a ExpressionListRef
32405
32537
  void Serialize(FieldWriter &serializer) const override;
32406
- //! Deserializes a blob back into a CrossProductRef
32538
+ //! Deserializes a blob back into a ExpressionListRef
32407
32539
  static unique_ptr<TableRef> Deserialize(FieldReader &source);
32408
32540
  };
32409
32541
  } // namespace duckdb
32542
+
32410
32543
  //===----------------------------------------------------------------------===//
32411
32544
  // DuckDB
32412
32545
  //
32413
- // duckdb/parser/tableref/table_function_ref.hpp
32546
+ // duckdb/parser/tableref/joinref.hpp
32414
32547
  //
32415
32548
  //
32416
32549
  //===----------------------------------------------------------------------===//
@@ -32424,37 +32557,73 @@ public:
32424
32557
 
32425
32558
 
32426
32559
  namespace duckdb {
32427
- //! Represents a Table producing function
32428
- class TableFunctionRef : public TableRef {
32560
+ //! Represents a JOIN between two expressions
32561
+ class JoinRef : public TableRef {
32429
32562
  public:
32430
- DUCKDB_API TableFunctionRef();
32431
-
32432
- unique_ptr<ParsedExpression> function;
32433
- vector<string> column_name_alias;
32434
-
32435
- // if the function takes a subquery as argument its in here
32436
- unique_ptr<SelectStatement> subquery;
32563
+ JoinRef() : TableRef(TableReferenceType::JOIN), is_natural(false) {
32564
+ }
32437
32565
 
32438
- // External dependencies of this table funcion
32439
- unique_ptr<ExternalDependency> external_dependency;
32566
+ //! The left hand side of the join
32567
+ unique_ptr<TableRef> left;
32568
+ //! The right hand side of the join
32569
+ unique_ptr<TableRef> right;
32570
+ //! The join condition
32571
+ unique_ptr<ParsedExpression> condition;
32572
+ //! The join type
32573
+ JoinType type;
32574
+ //! Natural join
32575
+ bool is_natural;
32576
+ //! The set of USING columns (if any)
32577
+ vector<string> using_columns;
32440
32578
 
32441
32579
  public:
32442
32580
  string ToString() const override;
32443
-
32444
32581
  bool Equals(const TableRef *other_p) const override;
32445
32582
 
32446
32583
  unique_ptr<TableRef> Copy() override;
32447
32584
 
32448
- //! Serializes a blob into a BaseTableRef
32585
+ //! Serializes a blob into a JoinRef
32449
32586
  void Serialize(FieldWriter &serializer) const override;
32450
- //! Deserializes a blob back into a BaseTableRef
32587
+ //! Deserializes a blob back into a JoinRef
32451
32588
  static unique_ptr<TableRef> Deserialize(FieldReader &source);
32452
32589
  };
32453
32590
  } // namespace duckdb
32454
32591
 
32592
+ //===----------------------------------------------------------------------===//
32593
+ // DuckDB
32594
+ //
32595
+ // duckdb/parser/tableref/subqueryref.hpp
32596
+ //
32597
+ //
32598
+ //===----------------------------------------------------------------------===//
32599
+
32600
+
32601
+
32602
+
32603
+
32604
+
32605
+ namespace duckdb {
32606
+ //! Represents a subquery
32607
+ class SubqueryRef : public TableRef {
32608
+ public:
32609
+ explicit SubqueryRef(unique_ptr<SelectStatement> subquery, string alias = string());
32455
32610
 
32611
+ //! The subquery
32612
+ unique_ptr<SelectStatement> subquery;
32613
+ //! Aliases for the column names
32614
+ vector<string> column_name_alias;
32456
32615
 
32616
+ public:
32617
+ string ToString() const override;
32618
+ bool Equals(const TableRef *other_p) const override;
32457
32619
 
32620
+ unique_ptr<TableRef> Copy() override;
32458
32621
 
32622
+ //! Serializes a blob into a SubqueryRef
32623
+ void Serialize(FieldWriter &serializer) const override;
32624
+ //! Deserializes a blob back into a SubqueryRef
32625
+ static unique_ptr<TableRef> Deserialize(FieldReader &source);
32626
+ };
32627
+ } // namespace duckdb
32459
32628
 
32460
32629