duckdb 0.3.2-dev903.0 → 0.3.2-dev930.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 "de4145741"
15
- #define DUCKDB_VERSION "0.3.2-dev903"
14
+ #define DUCKDB_SOURCE_ID "7e441464b"
15
+ #define DUCKDB_VERSION "0.3.2-dev930"
16
16
  //===----------------------------------------------------------------------===//
17
17
  // DuckDB
18
18
  //
@@ -109,6 +109,25 @@ using std::string;
109
109
 
110
110
  namespace duckdb {
111
111
 
112
+ // API versions
113
+ // if no explicit API version is defined, the latest API version is used
114
+ // Note that using older API versions (i.e. not using DUCKDB_API_LATEST) is deprecated.
115
+ // These will not be supported long-term, and will be removed in future versions.
116
+
117
+ #ifndef DUCKDB_API_0_3_1
118
+ #define DUCKDB_API_0_3_1 1
119
+ #endif
120
+ #ifndef DUCKDB_API_0_3_2
121
+ #define DUCKDB_API_0_3_2 2
122
+ #endif
123
+ #ifndef DUCKDB_API_LATEST
124
+ #define DUCKDB_API_LATEST DUCKDB_API_0_3_2
125
+ #endif
126
+
127
+ #ifndef DUCKDB_API_VERSION
128
+ #define DUCKDB_API_VERSION DUCKDB_API_LATEST
129
+ #endif
130
+
112
131
  //! inline std directives that we use frequently
113
132
  using std::move;
114
133
  using std::shared_ptr;
@@ -972,7 +991,7 @@ struct LogicalType {
972
991
  return *this;
973
992
  }
974
993
  // move assignment
975
- inline LogicalType& operator=(LogicalType&& other) {
994
+ inline LogicalType& operator=(LogicalType&& other) noexcept {
976
995
  id_ = other.id_;
977
996
  physical_type_ = other.physical_type_;
978
997
  type_info_ = move(other.type_info_);
@@ -2549,7 +2568,9 @@ class Serializer;
2549
2568
  //! The Value object holds a single arbitrary value of any type that can be
2550
2569
  //! stored in the database.
2551
2570
  class Value {
2552
- friend class Vector;
2571
+ friend struct StringValue;
2572
+ friend struct StructValue;
2573
+ friend struct ListValue;
2553
2574
 
2554
2575
  public:
2555
2576
  //! Create an empty NULL value of the specified type
@@ -2570,10 +2591,24 @@ public:
2570
2591
  DUCKDB_API Value(string_t val); // NOLINT: Allow implicit conversion from `string_t`
2571
2592
  //! Create a VARCHAR value
2572
2593
  DUCKDB_API Value(string val); // NOLINT: Allow implicit conversion from `string`
2594
+ //! Copy constructor
2595
+ DUCKDB_API Value(const Value &other);
2596
+ //! Move constructor
2597
+ DUCKDB_API Value(Value &&other) noexcept;
2598
+ //! Destructor
2599
+ DUCKDB_API ~Value();
2600
+
2601
+ // copy assignment
2602
+ DUCKDB_API Value &operator=(const Value &other);
2603
+ // move assignment
2604
+ DUCKDB_API Value &operator=(Value &&other) noexcept;
2573
2605
 
2574
2606
  inline const LogicalType &type() const {
2575
2607
  return type_;
2576
2608
  }
2609
+ inline bool IsNull() const {
2610
+ return is_null;
2611
+ }
2577
2612
 
2578
2613
  //! Create the lowest possible value of a given type (numeric only)
2579
2614
  DUCKDB_API static Value MinimumValue(const LogicalType &type);
@@ -2653,7 +2688,7 @@ public:
2653
2688
  DUCKDB_API static Value LIST(vector<Value> values);
2654
2689
  //! Create a list value with the given entries
2655
2690
  DUCKDB_API static Value LIST(LogicalType child_type, vector<Value> values);
2656
- //! Create an empty list with the specified type
2691
+ //! Create an empty list with the specified child-type
2657
2692
  DUCKDB_API static Value EMPTYLIST(LogicalType child_type);
2658
2693
  //! Creat a map value from a (key, value) pair
2659
2694
  DUCKDB_API static Value MAP(Value key, Value value);
@@ -2668,17 +2703,22 @@ public:
2668
2703
 
2669
2704
  template <class T>
2670
2705
  T GetValue() const {
2671
- throw NotImplementedException("Unimplemented template type for Value::GetValue");
2706
+ throw InternalException("Unimplemented template type for Value::GetValue");
2672
2707
  }
2673
2708
  template <class T>
2674
2709
  static Value CreateValue(T value) {
2675
- throw NotImplementedException("Unimplemented template type for Value::CreateValue");
2710
+ throw InternalException("Unimplemented template type for Value::CreateValue");
2676
2711
  }
2677
2712
  // Returns the internal value. Unlike GetValue(), this method does not perform casting, and assumes T matches the
2678
2713
  // type of the value. Only use this if you know what you are doing.
2679
2714
  template <class T>
2680
- T &GetValueUnsafe() {
2681
- throw NotImplementedException("Unimplemented template type for Value::GetValueUnsafe");
2715
+ T GetValueUnsafe() const {
2716
+ throw InternalException("Unimplemented template type for Value::GetValueUnsafe");
2717
+ }
2718
+ //! Returns a reference to the internal value. This can only be used for primitive types.
2719
+ template <class T>
2720
+ T &GetReferenceUnsafe() {
2721
+ throw InternalException("Unimplemented template type for Value::GetReferenceUnsafe");
2682
2722
  }
2683
2723
 
2684
2724
  //! Return a copy of this value
@@ -2686,6 +2726,8 @@ public:
2686
2726
  return Value(*this);
2687
2727
  }
2688
2728
 
2729
+ //! Hashes the Value
2730
+ DUCKDB_API hash_t Hash() const;
2689
2731
  //! Convert this value to a string
2690
2732
  DUCKDB_API string ToString() const;
2691
2733
 
@@ -2704,15 +2746,6 @@ public:
2704
2746
  //! Deserializes a Value from a blob
2705
2747
  DUCKDB_API static Value Deserialize(Deserializer &source);
2706
2748
 
2707
- //===--------------------------------------------------------------------===//
2708
- // Numeric Operators
2709
- //===--------------------------------------------------------------------===//
2710
- DUCKDB_API Value operator+(const Value &rhs) const;
2711
- DUCKDB_API Value operator-(const Value &rhs) const;
2712
- DUCKDB_API Value operator*(const Value &rhs) const;
2713
- DUCKDB_API Value operator/(const Value &rhs) const;
2714
- DUCKDB_API Value operator%(const Value &rhs) const;
2715
-
2716
2749
  //===--------------------------------------------------------------------===//
2717
2750
  // Comparison Operators
2718
2751
  //===--------------------------------------------------------------------===//
@@ -2756,7 +2789,9 @@ private:
2756
2789
  //! The logical of the value
2757
2790
  LogicalType type_;
2758
2791
 
2792
+ #if DUCKDB_API_VERSION < DUCKDB_API_0_3_2
2759
2793
  public:
2794
+ #endif
2760
2795
  //! Whether or not the value is NULL
2761
2796
  bool is_null;
2762
2797
 
@@ -2791,17 +2826,93 @@ public:
2791
2826
  private:
2792
2827
  template <class T>
2793
2828
  T GetValueInternal() const;
2794
- //! Templated helper function for casting
2795
- template <class DST, class OP>
2796
- static DST _cast(const Value &v);
2829
+ };
2797
2830
 
2798
- //! Templated helper function for binary operations
2799
- template <class OP>
2800
- static void _templated_binary_operation(const Value &left, const Value &right, Value &result, bool ignore_null);
2831
+ //===--------------------------------------------------------------------===//
2832
+ // Type-specific getters
2833
+ //===--------------------------------------------------------------------===//
2834
+ // Note that these are equivalent to calling GetValueUnsafe<X>, meaning no cast will be performed
2835
+ // instead, an assertion will be triggered if the value is not of the correct type
2836
+ struct BooleanValue {
2837
+ DUCKDB_API static bool Get(const Value &value);
2838
+ };
2801
2839
 
2802
- //! Templated helper function for boolean operations
2803
- template <class OP>
2804
- static bool _templated_boolean_operation(const Value &left, const Value &right);
2840
+ struct TinyIntValue {
2841
+ DUCKDB_API static int8_t Get(const Value &value);
2842
+ };
2843
+
2844
+ struct SmallIntValue {
2845
+ DUCKDB_API static int16_t Get(const Value &value);
2846
+ };
2847
+
2848
+ struct IntegerValue {
2849
+ DUCKDB_API static int32_t Get(const Value &value);
2850
+ };
2851
+
2852
+ struct BigIntValue {
2853
+ DUCKDB_API static int64_t Get(const Value &value);
2854
+ };
2855
+
2856
+ struct HugeIntValue {
2857
+ DUCKDB_API static hugeint_t Get(const Value &value);
2858
+ };
2859
+
2860
+ struct UTinyIntValue {
2861
+ DUCKDB_API static uint8_t Get(const Value &value);
2862
+ };
2863
+
2864
+ struct USmallIntValue {
2865
+ DUCKDB_API static uint16_t Get(const Value &value);
2866
+ };
2867
+
2868
+ struct UIntegerValue {
2869
+ DUCKDB_API static uint32_t Get(const Value &value);
2870
+ };
2871
+
2872
+ struct UBigIntValue {
2873
+ DUCKDB_API static uint64_t Get(const Value &value);
2874
+ };
2875
+
2876
+ struct FloatValue {
2877
+ DUCKDB_API static float Get(const Value &value);
2878
+ };
2879
+
2880
+ struct DoubleValue {
2881
+ DUCKDB_API static double Get(const Value &value);
2882
+ };
2883
+
2884
+ struct StringValue {
2885
+ DUCKDB_API static const string &Get(const Value &value);
2886
+ };
2887
+
2888
+ struct DateValue {
2889
+ DUCKDB_API static date_t Get(const Value &value);
2890
+ };
2891
+
2892
+ struct TimeValue {
2893
+ DUCKDB_API static dtime_t Get(const Value &value);
2894
+ };
2895
+
2896
+ struct TimestampValue {
2897
+ DUCKDB_API static timestamp_t Get(const Value &value);
2898
+ };
2899
+
2900
+ struct IntervalValue {
2901
+ DUCKDB_API static interval_t Get(const Value &value);
2902
+ };
2903
+
2904
+ struct StructValue {
2905
+ DUCKDB_API static const vector<Value> &GetChildren(const Value &value);
2906
+ };
2907
+
2908
+ struct ListValue {
2909
+ DUCKDB_API static const vector<Value> &GetChildren(const Value &value);
2910
+ };
2911
+
2912
+ //! Return the internal integral value for any type that is stored as an integral value internally
2913
+ //! This can be used on values of type integer, uinteger, but also date, timestamp, decimal, etc
2914
+ struct IntegralValue {
2915
+ static hugeint_t Get(const Value &value);
2805
2916
  };
2806
2917
 
2807
2918
  template <>
@@ -2881,37 +2992,72 @@ template <>
2881
2992
  DUCKDB_API interval_t Value::GetValue() const;
2882
2993
 
2883
2994
  template <>
2884
- DUCKDB_API int8_t &Value::GetValueUnsafe();
2995
+ DUCKDB_API bool Value::GetValueUnsafe() const;
2885
2996
  template <>
2886
- DUCKDB_API int16_t &Value::GetValueUnsafe();
2997
+ DUCKDB_API int8_t Value::GetValueUnsafe() const;
2887
2998
  template <>
2888
- DUCKDB_API int32_t &Value::GetValueUnsafe();
2999
+ DUCKDB_API int16_t Value::GetValueUnsafe() const;
2889
3000
  template <>
2890
- DUCKDB_API int64_t &Value::GetValueUnsafe();
3001
+ DUCKDB_API int32_t Value::GetValueUnsafe() const;
2891
3002
  template <>
2892
- DUCKDB_API hugeint_t &Value::GetValueUnsafe();
3003
+ DUCKDB_API int64_t Value::GetValueUnsafe() const;
2893
3004
  template <>
2894
- DUCKDB_API uint8_t &Value::GetValueUnsafe();
3005
+ DUCKDB_API hugeint_t Value::GetValueUnsafe() const;
2895
3006
  template <>
2896
- DUCKDB_API uint16_t &Value::GetValueUnsafe();
3007
+ DUCKDB_API uint8_t Value::GetValueUnsafe() const;
2897
3008
  template <>
2898
- DUCKDB_API uint32_t &Value::GetValueUnsafe();
3009
+ DUCKDB_API uint16_t Value::GetValueUnsafe() const;
2899
3010
  template <>
2900
- DUCKDB_API uint64_t &Value::GetValueUnsafe();
3011
+ DUCKDB_API uint32_t Value::GetValueUnsafe() const;
2901
3012
  template <>
2902
- DUCKDB_API string &Value::GetValueUnsafe();
3013
+ DUCKDB_API uint64_t Value::GetValueUnsafe() const;
2903
3014
  template <>
2904
- DUCKDB_API float &Value::GetValueUnsafe();
3015
+ DUCKDB_API string Value::GetValueUnsafe() const;
2905
3016
  template <>
2906
- DUCKDB_API double &Value::GetValueUnsafe();
3017
+ DUCKDB_API string_t Value::GetValueUnsafe() const;
2907
3018
  template <>
2908
- DUCKDB_API date_t &Value::GetValueUnsafe();
3019
+ DUCKDB_API float Value::GetValueUnsafe() const;
2909
3020
  template <>
2910
- DUCKDB_API dtime_t &Value::GetValueUnsafe();
3021
+ DUCKDB_API double Value::GetValueUnsafe() const;
2911
3022
  template <>
2912
- DUCKDB_API timestamp_t &Value::GetValueUnsafe();
3023
+ DUCKDB_API date_t Value::GetValueUnsafe() const;
2913
3024
  template <>
2914
- DUCKDB_API interval_t &Value::GetValueUnsafe();
3025
+ DUCKDB_API dtime_t Value::GetValueUnsafe() const;
3026
+ template <>
3027
+ DUCKDB_API timestamp_t Value::GetValueUnsafe() const;
3028
+ template <>
3029
+ DUCKDB_API interval_t Value::GetValueUnsafe() const;
3030
+
3031
+ template <>
3032
+ DUCKDB_API int8_t &Value::GetReferenceUnsafe();
3033
+ template <>
3034
+ DUCKDB_API int16_t &Value::GetReferenceUnsafe();
3035
+ template <>
3036
+ DUCKDB_API int32_t &Value::GetReferenceUnsafe();
3037
+ template <>
3038
+ DUCKDB_API int64_t &Value::GetReferenceUnsafe();
3039
+ template <>
3040
+ DUCKDB_API hugeint_t &Value::GetReferenceUnsafe();
3041
+ template <>
3042
+ DUCKDB_API uint8_t &Value::GetReferenceUnsafe();
3043
+ template <>
3044
+ DUCKDB_API uint16_t &Value::GetReferenceUnsafe();
3045
+ template <>
3046
+ DUCKDB_API uint32_t &Value::GetReferenceUnsafe();
3047
+ template <>
3048
+ DUCKDB_API uint64_t &Value::GetReferenceUnsafe();
3049
+ template <>
3050
+ DUCKDB_API float &Value::GetReferenceUnsafe();
3051
+ template <>
3052
+ DUCKDB_API double &Value::GetReferenceUnsafe();
3053
+ template <>
3054
+ DUCKDB_API date_t &Value::GetReferenceUnsafe();
3055
+ template <>
3056
+ DUCKDB_API dtime_t &Value::GetReferenceUnsafe();
3057
+ template <>
3058
+ DUCKDB_API timestamp_t &Value::GetReferenceUnsafe();
3059
+ template <>
3060
+ DUCKDB_API interval_t &Value::GetReferenceUnsafe();
2915
3061
 
2916
3062
  template <>
2917
3063
  DUCKDB_API bool Value::IsValid(float value);
@@ -3274,7 +3420,7 @@ public:
3274
3420
  void Append(const Vector &to_append, idx_t to_append_size, idx_t source_offset = 0);
3275
3421
  void Append(const Vector &to_append, const SelectionVector &sel, idx_t to_append_size, idx_t source_offset = 0);
3276
3422
 
3277
- void PushBack(Value &insert);
3423
+ void PushBack(const Value &insert);
3278
3424
 
3279
3425
  idx_t capacity = 0;
3280
3426
  idx_t size = 0;
@@ -3592,8 +3738,8 @@ struct ListVector {
3592
3738
  DUCKDB_API static void Append(Vector &target, const Vector &source, idx_t source_size, idx_t source_offset = 0);
3593
3739
  DUCKDB_API static void Append(Vector &target, const Vector &source, const SelectionVector &sel, idx_t source_size,
3594
3740
  idx_t source_offset = 0);
3595
- DUCKDB_API static void PushBack(Vector &target, Value &insert);
3596
- DUCKDB_API static vector<idx_t> Search(Vector &list, Value &key, idx_t row);
3741
+ DUCKDB_API static void PushBack(Vector &target, const Value &insert);
3742
+ DUCKDB_API static vector<idx_t> Search(Vector &list, const Value &key, idx_t row);
3597
3743
  DUCKDB_API static Value GetValuesFromOffsets(Vector &list, vector<idx_t> &offsets);
3598
3744
  //! Share the entry of the other list vector
3599
3745
  DUCKDB_API static void ReferenceEntry(Vector &vector, Vector &other);
@@ -20098,31 +20244,12 @@ public:
20098
20244
  }
20099
20245
 
20100
20246
  template <class T>
20101
- static inline void Update(SegmentStatistics &stats, T new_value);
20247
+ static inline void Update(SegmentStatistics &stats, T new_value) {
20248
+ auto &nstats = (NumericStatistics &)*stats.statistics;
20249
+ UpdateValue<T>(new_value, nstats.min.GetReferenceUnsafe<T>(), nstats.max.GetReferenceUnsafe<T>());
20250
+ }
20102
20251
  };
20103
20252
 
20104
- template <>
20105
- void NumericStatistics::Update<int8_t>(SegmentStatistics &stats, int8_t new_value);
20106
- template <>
20107
- void NumericStatistics::Update<int16_t>(SegmentStatistics &stats, int16_t new_value);
20108
- template <>
20109
- void NumericStatistics::Update<int32_t>(SegmentStatistics &stats, int32_t new_value);
20110
- template <>
20111
- void NumericStatistics::Update<int64_t>(SegmentStatistics &stats, int64_t new_value);
20112
- template <>
20113
- void NumericStatistics::Update<uint8_t>(SegmentStatistics &stats, uint8_t new_value);
20114
- template <>
20115
- void NumericStatistics::Update<uint16_t>(SegmentStatistics &stats, uint16_t new_value);
20116
- template <>
20117
- void NumericStatistics::Update<uint32_t>(SegmentStatistics &stats, uint32_t new_value);
20118
- template <>
20119
- void NumericStatistics::Update<uint64_t>(SegmentStatistics &stats, uint64_t new_value);
20120
- template <>
20121
- void NumericStatistics::Update<hugeint_t>(SegmentStatistics &stats, hugeint_t new_value);
20122
- template <>
20123
- void NumericStatistics::Update<float>(SegmentStatistics &stats, float new_value);
20124
- template <>
20125
- void NumericStatistics::Update<double>(SegmentStatistics &stats, double new_value);
20126
20253
  template <>
20127
20254
  void NumericStatistics::Update<interval_t>(SegmentStatistics &stats, interval_t new_value);
20128
20255
  template <>