duckdb 0.3.3-dev997.0 → 0.3.4-dev7.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.
Files changed (4) hide show
  1. package/package.json +1 -1
  2. package/src/duckdb.cpp +109199 -104548
  3. package/src/duckdb.hpp +1665 -785
  4. package/src/parquet-amalgamation.cpp +36651 -36670
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 "8b798681f"
15
- #define DUCKDB_VERSION "v0.3.3-dev997"
14
+ #define DUCKDB_SOURCE_ID "dd74d9dde"
15
+ #define DUCKDB_VERSION "v0.3.4-dev7"
16
16
  //===----------------------------------------------------------------------===//
17
17
  // DuckDB
18
18
  //
@@ -1242,9 +1242,10 @@ enum class ExceptionFormatValueType : uint8_t {
1242
1242
  };
1243
1243
 
1244
1244
  struct ExceptionFormatValue {
1245
- DUCKDB_API ExceptionFormatValue(double dbl_val); // NOLINT
1246
- DUCKDB_API ExceptionFormatValue(int64_t int_val); // NOLINT
1247
- DUCKDB_API ExceptionFormatValue(string str_val); // NOLINT
1245
+ DUCKDB_API ExceptionFormatValue(double dbl_val); // NOLINT
1246
+ DUCKDB_API ExceptionFormatValue(int64_t int_val); // NOLINT
1247
+ DUCKDB_API ExceptionFormatValue(string str_val); // NOLINT
1248
+ DUCKDB_API ExceptionFormatValue(hugeint_t hg_val); // NOLINT
1248
1249
 
1249
1250
  ExceptionFormatValueType type;
1250
1251
 
@@ -1274,6 +1275,8 @@ template <>
1274
1275
  DUCKDB_API ExceptionFormatValue ExceptionFormatValue::CreateFormatValue(const char *value);
1275
1276
  template <>
1276
1277
  DUCKDB_API ExceptionFormatValue ExceptionFormatValue::CreateFormatValue(char *value);
1278
+ template <>
1279
+ DUCKDB_API ExceptionFormatValue ExceptionFormatValue::CreateFormatValue(hugeint_t value);
1277
1280
 
1278
1281
  } // namespace duckdb
1279
1282
 
@@ -2841,17 +2844,20 @@ public:
2841
2844
  DUCKDB_API bool operator<=(const int64_t &rhs) const;
2842
2845
  DUCKDB_API bool operator>=(const int64_t &rhs) const;
2843
2846
 
2844
- DUCKDB_API static bool FloatIsValid(float value);
2845
- DUCKDB_API static bool DoubleIsValid(double value);
2846
- DUCKDB_API static bool StringIsValid(const char *str, idx_t length);
2847
- static bool StringIsValid(const string &str) {
2848
- return StringIsValid(str.c_str(), str.size());
2847
+ DUCKDB_API static bool FloatIsFinite(float value);
2848
+ DUCKDB_API static bool DoubleIsFinite(double value);
2849
+ template <class T>
2850
+ static bool IsNan(T value) {
2851
+ throw InternalException("Unimplemented template type for Value::IsNan");
2849
2852
  }
2850
-
2851
2853
  template <class T>
2852
- static bool IsValid(T value) {
2854
+ static bool IsFinite(T value) {
2853
2855
  return true;
2854
2856
  }
2857
+ DUCKDB_API static bool StringIsValid(const char *str, idx_t length);
2858
+ static bool StringIsValid(const string &str) {
2859
+ return StringIsValid(str.c_str(), str.size());
2860
+ }
2855
2861
 
2856
2862
  //! Returns true if the values are (approximately) equivalent. Note this is NOT the SQL equivalence. For this
2857
2863
  //! function, NULL values are equivalent and floating point values that are close are equivalent.
@@ -3138,9 +3144,14 @@ template <>
3138
3144
  DUCKDB_API interval_t &Value::GetReferenceUnsafe();
3139
3145
 
3140
3146
  template <>
3141
- DUCKDB_API bool Value::IsValid(float value);
3147
+ DUCKDB_API bool Value::IsNan(float input);
3148
+ template <>
3149
+ DUCKDB_API bool Value::IsNan(double input);
3150
+
3151
+ template <>
3152
+ DUCKDB_API bool Value::IsFinite(float input);
3142
3153
  template <>
3143
- DUCKDB_API bool Value::IsValid(double value);
3154
+ DUCKDB_API bool Value::IsFinite(double input);
3144
3155
 
3145
3156
  } // namespace duckdb
3146
3157
 
@@ -3412,7 +3423,7 @@ public:
3412
3423
  return aux_data.get();
3413
3424
  }
3414
3425
 
3415
- void SetAuxiliaryData(unique_ptr<VectorAuxiliaryData> aux_data_p, VectorAuxiliaryDataType aux_type_p) {
3426
+ void SetAuxiliaryData(unique_ptr<VectorAuxiliaryData> aux_data_p) {
3416
3427
  aux_data = move(aux_data_p);
3417
3428
  }
3418
3429
 
@@ -4213,45 +4224,47 @@ struct VectorOperations {
4213
4224
  //===--------------------------------------------------------------------===//
4214
4225
  // In-Place Operators
4215
4226
  //===--------------------------------------------------------------------===//
4216
- //! A += B
4217
- static void AddInPlace(Vector &A, int64_t B, idx_t count);
4227
+ //! left += delta
4228
+ static void AddInPlace(Vector &left, int64_t delta, idx_t count);
4218
4229
 
4219
4230
  //===--------------------------------------------------------------------===//
4220
4231
  // NULL Operators
4221
4232
  //===--------------------------------------------------------------------===//
4222
- //! result = IS NOT NULL(A)
4223
- static void IsNotNull(Vector &A, Vector &result, idx_t count);
4224
- //! result = IS NULL (A)
4225
- static void IsNull(Vector &A, Vector &result, idx_t count);
4226
- // Returns whether or not a vector has a NULL value
4227
- static bool HasNull(Vector &A, idx_t count);
4228
- static bool HasNotNull(Vector &A, idx_t count);
4233
+ //! result = IS NOT NULL(input)
4234
+ static void IsNotNull(Vector &arg, Vector &result, idx_t count);
4235
+ //! result = IS NULL (input)
4236
+ static void IsNull(Vector &input, Vector &result, idx_t count);
4237
+ // Returns whether or not arg vector has a NULL value
4238
+ static bool HasNull(Vector &input, idx_t count);
4239
+ static bool HasNotNull(Vector &input, idx_t count);
4240
+ //! Count the number of not-NULL values.
4241
+ static idx_t CountNotNull(Vector &input, const idx_t count);
4229
4242
 
4230
4243
  //===--------------------------------------------------------------------===//
4231
4244
  // Boolean Operations
4232
4245
  //===--------------------------------------------------------------------===//
4233
- // result = A && B
4234
- static void And(Vector &A, Vector &B, Vector &result, idx_t count);
4235
- // result = A || B
4236
- static void Or(Vector &A, Vector &B, Vector &result, idx_t count);
4237
- // result = NOT(A)
4238
- static void Not(Vector &A, Vector &result, idx_t count);
4246
+ // result = left && right
4247
+ static void And(Vector &left, Vector &right, Vector &result, idx_t count);
4248
+ // result = left || right
4249
+ static void Or(Vector &left, Vector &right, Vector &result, idx_t count);
4250
+ // result = NOT(left)
4251
+ static void Not(Vector &left, Vector &result, idx_t count);
4239
4252
 
4240
4253
  //===--------------------------------------------------------------------===//
4241
4254
  // Comparison Operations
4242
4255
  //===--------------------------------------------------------------------===//
4243
- // result = A == B
4244
- static void Equals(Vector &A, Vector &B, Vector &result, idx_t count);
4245
- // result = A != B
4246
- static void NotEquals(Vector &A, Vector &B, Vector &result, idx_t count);
4247
- // result = A > B
4248
- static void GreaterThan(Vector &A, Vector &B, Vector &result, idx_t count);
4249
- // result = A >= B
4250
- static void GreaterThanEquals(Vector &A, Vector &B, Vector &result, idx_t count);
4251
- // result = A < B
4252
- static void LessThan(Vector &A, Vector &B, Vector &result, idx_t count);
4253
- // result = A <= B
4254
- static void LessThanEquals(Vector &A, Vector &B, Vector &result, idx_t count);
4256
+ // result = left == right
4257
+ static void Equals(Vector &left, Vector &right, Vector &result, idx_t count);
4258
+ // result = left != right
4259
+ static void NotEquals(Vector &left, Vector &right, Vector &result, idx_t count);
4260
+ // result = left > right
4261
+ static void GreaterThan(Vector &left, Vector &right, Vector &result, idx_t count);
4262
+ // result = left >= right
4263
+ static void GreaterThanEquals(Vector &left, Vector &right, Vector &result, idx_t count);
4264
+ // result = left < right
4265
+ static void LessThan(Vector &left, Vector &right, Vector &result, idx_t count);
4266
+ // result = left <= right
4267
+ static void LessThanEquals(Vector &left, Vector &right, Vector &result, idx_t count);
4255
4268
 
4256
4269
  // result = A != B with nulls being equal
4257
4270
  static void DistinctFrom(Vector &left, Vector &right, Vector &result, idx_t count);
@@ -4311,35 +4324,22 @@ struct VectorOperations {
4311
4324
  //===--------------------------------------------------------------------===//
4312
4325
  // Nested Comparisons
4313
4326
  //===--------------------------------------------------------------------===//
4314
- // true := A != B with nulls being equal, inputs selected
4315
- static idx_t NestedNotEquals(Vector &left, Vector &right, idx_t vcount, const SelectionVector &sel, idx_t count,
4327
+ // true := A != B with nulls being equal
4328
+ static idx_t NestedNotEquals(Vector &left, Vector &right, const SelectionVector &sel, idx_t count,
4316
4329
  SelectionVector *true_sel, SelectionVector *false_sel);
4317
- // true := A == B with nulls being equal, inputs selected
4318
- static idx_t NestedEquals(Vector &left, Vector &right, idx_t vcount, const SelectionVector &sel, idx_t count,
4330
+ // true := A == B with nulls being equal
4331
+ static idx_t NestedEquals(Vector &left, Vector &right, const SelectionVector &sel, idx_t count,
4319
4332
  SelectionVector *true_sel, SelectionVector *false_sel);
4320
4333
 
4321
- // true := A > B with nulls being maximal, inputs selected
4322
- static idx_t NestedGreaterThan(Vector &left, Vector &right, idx_t vcount, const SelectionVector &sel, idx_t count,
4323
- SelectionVector *true_sel, SelectionVector *false_sel);
4324
- // true := A >= B with nulls being maximal, inputs selected
4325
- static idx_t NestedGreaterThanEquals(Vector &left, Vector &right, idx_t vcount, const SelectionVector &sel,
4326
- idx_t count, SelectionVector *true_sel, SelectionVector *false_sel);
4327
- // true := A < B with nulls being maximal, inputs selected
4328
- static idx_t NestedLessThan(Vector &left, Vector &right, idx_t vcount, const SelectionVector &sel, idx_t count,
4329
- SelectionVector *true_sel, SelectionVector *false_sel);
4330
- // true := A <= B with nulls being maximal, inputs selected
4331
- static idx_t NestedLessThanEquals(Vector &left, Vector &right, idx_t vcount, const SelectionVector &sel,
4332
- idx_t count, SelectionVector *true_sel, SelectionVector *false_sel);
4333
-
4334
4334
  //===--------------------------------------------------------------------===//
4335
4335
  // Hash functions
4336
4336
  //===--------------------------------------------------------------------===//
4337
- // result = HASH(A)
4337
+ // hashes = HASH(input)
4338
4338
  static void Hash(Vector &input, Vector &hashes, idx_t count);
4339
4339
  static void Hash(Vector &input, Vector &hashes, const SelectionVector &rsel, idx_t count);
4340
- // A ^= HASH(B)
4341
- static void CombineHash(Vector &hashes, Vector &B, idx_t count);
4342
- static void CombineHash(Vector &hashes, Vector &B, const SelectionVector &rsel, idx_t count);
4340
+ // hashes ^= HASH(input)
4341
+ static void CombineHash(Vector &hashes, Vector &input, idx_t count);
4342
+ static void CombineHash(Vector &hashes, Vector &input, const SelectionVector &rsel, idx_t count);
4343
4343
 
4344
4344
  //===--------------------------------------------------------------------===//
4345
4345
  // Generate functions
@@ -5494,10 +5494,9 @@ class CycleCounter {
5494
5494
  friend struct ExpressionInfo;
5495
5495
  friend struct ExpressionRootInfo;
5496
5496
  static constexpr int SAMPLING_RATE = 50;
5497
- static constexpr int SAMPLING_VARIANCE = 100;
5498
5497
 
5499
5498
  public:
5500
- CycleCounter() : random(-1) {
5499
+ CycleCounter() {
5501
5500
  }
5502
5501
  // Next_sample determines if a sample needs to be taken, if so start the profiler
5503
5502
  void BeginSample() {
@@ -5512,7 +5511,7 @@ public:
5512
5511
  time += Tick() - tmp;
5513
5512
  }
5514
5513
  if (current_count >= next_sample) {
5515
- next_sample = SAMPLING_RATE + random.NextRandomInteger() % SAMPLING_VARIANCE;
5514
+ next_sample = SAMPLING_RATE;
5516
5515
  ++sample_count;
5517
5516
  sample_tuples_count += chunk_size;
5518
5517
  current_count = 0;
@@ -5538,8 +5537,6 @@ private:
5538
5537
  uint64_t sample_tuples_count = 0;
5539
5538
  //! Count the number of ALL tuples
5540
5539
  uint64_t tuples_count = 0;
5541
- //! the random number generator used for sampling
5542
- RandomEngine random;
5543
5540
  };
5544
5541
 
5545
5542
  } // namespace duckdb
@@ -6469,7 +6466,8 @@ public:
6469
6466
  class BaseScalarFunction : public SimpleFunction {
6470
6467
  public:
6471
6468
  DUCKDB_API BaseScalarFunction(string name, vector<LogicalType> arguments, LogicalType return_type,
6472
- bool has_side_effects, LogicalType varargs = LogicalType(LogicalTypeId::INVALID));
6469
+ bool has_side_effects, LogicalType varargs = LogicalType(LogicalTypeId::INVALID),
6470
+ bool propagates_null_values = false);
6473
6471
  DUCKDB_API ~BaseScalarFunction() override;
6474
6472
 
6475
6473
  //! Return type of the function
@@ -6477,6 +6475,8 @@ public:
6477
6475
  //! Whether or not the function has side effects (e.g. sequence increments, random() functions, NOW()). Functions
6478
6476
  //! with side-effects cannot be constant-folded.
6479
6477
  bool has_side_effects;
6478
+ //! Whether or not the function propagates null values
6479
+ bool propagates_null_values;
6480
6480
 
6481
6481
  public:
6482
6482
  DUCKDB_API hash_t Hash() const;
@@ -6899,15 +6899,17 @@ struct Equals {
6899
6899
  struct NotEquals {
6900
6900
  template <class T>
6901
6901
  static inline bool Operation(T left, T right) {
6902
- return left != right;
6902
+ return !Equals::Operation(left, right);
6903
6903
  }
6904
6904
  };
6905
+
6905
6906
  struct GreaterThan {
6906
6907
  template <class T>
6907
6908
  static inline bool Operation(T left, T right) {
6908
6909
  return left > right;
6909
6910
  }
6910
6911
  };
6912
+
6911
6913
  struct GreaterThanEquals {
6912
6914
  template <class T>
6913
6915
  static inline bool Operation(T left, T right) {
@@ -6918,30 +6920,46 @@ struct GreaterThanEquals {
6918
6920
  struct LessThan {
6919
6921
  template <class T>
6920
6922
  static inline bool Operation(T left, T right) {
6921
- return left < right;
6923
+ return GreaterThan::Operation(right, left);
6922
6924
  }
6923
6925
  };
6926
+
6924
6927
  struct LessThanEquals {
6925
6928
  template <class T>
6926
6929
  static inline bool Operation(T left, T right) {
6927
- return left <= right;
6930
+ return GreaterThanEquals::Operation(right, left);
6928
6931
  }
6929
6932
  };
6930
6933
 
6934
+ template <>
6935
+ bool Equals::Operation(float left, float right);
6936
+ template <>
6937
+ bool Equals::Operation(double left, double right);
6938
+
6939
+ template <>
6940
+ bool GreaterThan::Operation(float left, float right);
6941
+ template <>
6942
+ bool GreaterThan::Operation(double left, double right);
6943
+
6944
+ template <>
6945
+ bool GreaterThanEquals::Operation(float left, float right);
6946
+ template <>
6947
+ bool GreaterThanEquals::Operation(double left, double right);
6948
+
6931
6949
  // Distinct semantics are from Postgres record sorting. NULL = NULL and not-NULL < NULL
6932
6950
  // Deferring to the non-distinct operations removes the need for further specialisation.
6933
6951
  // TODO: To reverse the semantics, swap left_null and right_null for comparisons
6934
6952
  struct DistinctFrom {
6935
6953
  template <class T>
6936
6954
  static inline bool Operation(T left, T right, bool left_null, bool right_null) {
6937
- return (left_null != right_null) || (!left_null && !right_null && (left != right));
6955
+ return (left_null != right_null) || (!left_null && !right_null && NotEquals::Operation(left, right));
6938
6956
  }
6939
6957
  };
6940
6958
 
6941
6959
  struct NotDistinctFrom {
6942
6960
  template <class T>
6943
6961
  static inline bool Operation(T left, T right, bool left_null, bool right_null) {
6944
- return (left_null && right_null) || (!left_null && !right_null && (left == right));
6962
+ return (left_null && right_null) || (!left_null && !right_null && Equals::Operation(left, right));
6945
6963
  }
6946
6964
  };
6947
6965
 
@@ -7218,12 +7236,13 @@ public:
7218
7236
  scalar_function_t function, bool has_side_effects = false,
7219
7237
  bind_scalar_function_t bind = nullptr, dependency_function_t dependency = nullptr,
7220
7238
  function_statistics_t statistics = nullptr, init_local_state_t init_local_state = nullptr,
7221
- LogicalType varargs = LogicalType(LogicalTypeId::INVALID));
7239
+ LogicalType varargs = LogicalType(LogicalTypeId::INVALID),
7240
+ bool propagate_null_values = false);
7222
7241
 
7223
7242
  DUCKDB_API ScalarFunction(vector<LogicalType> arguments, LogicalType return_type, scalar_function_t function,
7224
- bool has_side_effects = false, bind_scalar_function_t bind = nullptr,
7225
- dependency_function_t dependency = nullptr, function_statistics_t statistics = nullptr,
7226
- init_local_state_t init_local_state = nullptr,
7243
+ bool propagate_null_values = false, bool has_side_effects = false,
7244
+ bind_scalar_function_t bind = nullptr, dependency_function_t dependency = nullptr,
7245
+ function_statistics_t statistics = nullptr, init_local_state_t init_local_state = nullptr,
7227
7246
  LogicalType varargs = LogicalType(LogicalTypeId::INVALID));
7228
7247
 
7229
7248
  //! The main scalar function to execute
@@ -8010,6 +8029,7 @@ enum class CatalogType : uint8_t {
8010
8029
  PRAGMA_FUNCTION_ENTRY = 28,
8011
8030
  COPY_FUNCTION_ENTRY = 29,
8012
8031
  MACRO_ENTRY = 30,
8032
+ TABLE_MACRO_ENTRY = 31,
8013
8033
 
8014
8034
  // version info
8015
8035
  UPDATED_ENTRY = 50,
@@ -8512,6 +8532,7 @@ public:
8512
8532
  bool IsScalar() const override;
8513
8533
  bool HasParameter() const override;
8514
8534
  virtual bool HasSideEffects() const;
8535
+ virtual bool PropagatesNullValues() const;
8515
8536
  virtual bool IsFoldable() const;
8516
8537
 
8517
8538
  hash_t Hash() const override;
@@ -8939,6 +8960,19 @@ typedef void (*aggregate_window_t)(Vector inputs[], FunctionData *bind_data, idx
8939
8960
 
8940
8961
  class AggregateFunction : public BaseScalarFunction {
8941
8962
  public:
8963
+ DUCKDB_API AggregateFunction(const string &name, const vector<LogicalType> &arguments,
8964
+ const LogicalType &return_type, aggregate_size_t state_size,
8965
+ aggregate_initialize_t initialize, aggregate_update_t update,
8966
+ aggregate_combine_t combine, aggregate_finalize_t finalize,
8967
+ bool propagates_null_values = false, aggregate_simple_update_t simple_update = nullptr,
8968
+ bind_aggregate_function_t bind = nullptr, aggregate_destructor_t destructor = nullptr,
8969
+ aggregate_statistics_t statistics = nullptr, aggregate_window_t window = nullptr)
8970
+ : BaseScalarFunction(name, arguments, return_type, false, LogicalType(LogicalTypeId::INVALID),
8971
+ propagates_null_values),
8972
+ state_size(state_size), initialize(initialize), update(update), combine(combine), finalize(finalize),
8973
+ simple_update(simple_update), window(window), bind(bind), destructor(destructor), statistics(statistics) {
8974
+ }
8975
+
8942
8976
  DUCKDB_API AggregateFunction(const string &name, const vector<LogicalType> &arguments,
8943
8977
  const LogicalType &return_type, aggregate_size_t state_size,
8944
8978
  aggregate_initialize_t initialize, aggregate_update_t update,
@@ -8946,21 +8980,30 @@ public:
8946
8980
  aggregate_simple_update_t simple_update = nullptr,
8947
8981
  bind_aggregate_function_t bind = nullptr, aggregate_destructor_t destructor = nullptr,
8948
8982
  aggregate_statistics_t statistics = nullptr, aggregate_window_t window = nullptr)
8949
- : BaseScalarFunction(name, arguments, return_type, false), state_size(state_size), initialize(initialize),
8950
- update(update), combine(combine), finalize(finalize), simple_update(simple_update), window(window),
8951
- bind(bind), destructor(destructor), statistics(statistics) {
8983
+ : BaseScalarFunction(name, arguments, return_type, false, LogicalType(LogicalTypeId::INVALID), false),
8984
+ state_size(state_size), initialize(initialize), update(update), combine(combine), finalize(finalize),
8985
+ simple_update(simple_update), window(window), bind(bind), destructor(destructor), statistics(statistics) {
8952
8986
  }
8953
8987
 
8954
8988
  DUCKDB_API AggregateFunction(const vector<LogicalType> &arguments, const LogicalType &return_type,
8955
8989
  aggregate_size_t state_size, aggregate_initialize_t initialize,
8956
8990
  aggregate_update_t update, aggregate_combine_t combine, aggregate_finalize_t finalize,
8957
- aggregate_simple_update_t simple_update = nullptr,
8991
+ bool propagates_null_values = false, aggregate_simple_update_t simple_update = nullptr,
8958
8992
  bind_aggregate_function_t bind = nullptr, aggregate_destructor_t destructor = nullptr,
8959
8993
  aggregate_statistics_t statistics = nullptr, aggregate_window_t window = nullptr)
8960
8994
  : AggregateFunction(string(), arguments, return_type, state_size, initialize, update, combine, finalize,
8961
- simple_update, bind, destructor, statistics, window) {
8995
+ propagates_null_values, simple_update, bind, destructor, statistics, window) {
8962
8996
  }
8963
8997
 
8998
+ DUCKDB_API AggregateFunction(const vector<LogicalType> &arguments, const LogicalType &return_type,
8999
+ aggregate_size_t state_size, aggregate_initialize_t initialize,
9000
+ aggregate_update_t update, aggregate_combine_t combine, aggregate_finalize_t finalize,
9001
+ aggregate_simple_update_t simple_update = nullptr,
9002
+ bind_aggregate_function_t bind = nullptr, aggregate_destructor_t destructor = nullptr,
9003
+ aggregate_statistics_t statistics = nullptr, aggregate_window_t window = nullptr)
9004
+ : AggregateFunction(string(), arguments, return_type, state_size, initialize, update, combine, finalize, false,
9005
+ simple_update, bind, destructor, statistics, window) {
9006
+ }
8964
9007
  //! The hashed aggregate state sizing function
8965
9008
  aggregate_size_t state_size;
8966
9009
  //! The hashed aggregate state initialization function
@@ -9012,12 +9055,13 @@ public:
9012
9055
  }
9013
9056
 
9014
9057
  template <class STATE, class INPUT_TYPE, class RESULT_TYPE, class OP>
9015
- static AggregateFunction UnaryAggregate(const LogicalType &input_type, LogicalType return_type) {
9058
+ static AggregateFunction UnaryAggregate(const LogicalType &input_type, LogicalType return_type,
9059
+ bool propagates_null_values = false) {
9016
9060
  return AggregateFunction(
9017
9061
  {input_type}, return_type, AggregateFunction::StateSize<STATE>,
9018
9062
  AggregateFunction::StateInitialize<STATE, OP>, AggregateFunction::UnaryScatterUpdate<STATE, INPUT_TYPE, OP>,
9019
9063
  AggregateFunction::StateCombine<STATE, OP>, AggregateFunction::StateFinalize<STATE, RESULT_TYPE, OP>,
9020
- AggregateFunction::UnaryUpdate<STATE, INPUT_TYPE, OP>);
9064
+ propagates_null_values, AggregateFunction::UnaryUpdate<STATE, INPUT_TYPE, OP>);
9021
9065
  }
9022
9066
 
9023
9067
  template <class STATE, class INPUT_TYPE, class RESULT_TYPE, class OP>
@@ -9995,6 +10039,7 @@ enum class PhysicalOperatorType : uint8_t {
9995
10039
  HASH_JOIN,
9996
10040
  CROSS_PRODUCT,
9997
10041
  PIECEWISE_MERGE_JOIN,
10042
+ IE_JOIN,
9998
10043
  DELIM_JOIN,
9999
10044
  INDEX_JOIN,
10000
10045
  // -----------------------------
@@ -10130,6 +10175,12 @@ public:
10130
10175
  }
10131
10176
  };
10132
10177
 
10178
+ class GlobalOperatorState {
10179
+ public:
10180
+ virtual ~GlobalOperatorState() {
10181
+ }
10182
+ };
10183
+
10133
10184
  class GlobalSinkState {
10134
10185
  public:
10135
10186
  GlobalSinkState() : state(SinkFinalizeType::READY) {
@@ -10183,6 +10234,8 @@ public:
10183
10234
  idx_t estimated_cardinality;
10184
10235
  //! The global sink state of this operator
10185
10236
  unique_ptr<GlobalSinkState> sink_state;
10237
+ //! The global state of this operator
10238
+ unique_ptr<GlobalOperatorState> op_state;
10186
10239
 
10187
10240
  public:
10188
10241
  virtual string GetName() const;
@@ -10204,8 +10257,9 @@ public:
10204
10257
  public:
10205
10258
  // Operator interface
10206
10259
  virtual unique_ptr<OperatorState> GetOperatorState(ClientContext &context) const;
10260
+ virtual unique_ptr<GlobalOperatorState> GetGlobalOperatorState(ClientContext &context) const;
10207
10261
  virtual OperatorResultType Execute(ExecutionContext &context, DataChunk &input, DataChunk &chunk,
10208
- OperatorState &state) const;
10262
+ GlobalOperatorState &gstate, OperatorState &state) const;
10209
10263
 
10210
10264
  virtual bool ParallelOperator() const {
10211
10265
  return false;
@@ -10290,16 +10344,32 @@ struct FunctionOperatorData {
10290
10344
  DUCKDB_API virtual ~FunctionOperatorData();
10291
10345
  };
10292
10346
 
10347
+ struct TableFunctionInfo {
10348
+ DUCKDB_API virtual ~TableFunctionInfo();
10349
+ };
10350
+
10293
10351
  struct TableFilterCollection {
10294
10352
  DUCKDB_API explicit TableFilterCollection(TableFilterSet *table_filters);
10295
10353
 
10296
10354
  TableFilterSet *table_filters;
10297
10355
  };
10298
10356
 
10299
- typedef unique_ptr<FunctionData> (*table_function_bind_t)(ClientContext &context, vector<Value> &inputs,
10300
- named_parameter_map_t &named_parameters,
10301
- vector<LogicalType> &input_table_types,
10302
- vector<string> &input_table_names,
10357
+ struct TableFunctionBindInput {
10358
+ TableFunctionBindInput(vector<Value> &inputs, named_parameter_map_t &named_parameters,
10359
+ vector<LogicalType> &input_table_types, vector<string> &input_table_names,
10360
+ TableFunctionInfo *info)
10361
+ : inputs(inputs), named_parameters(named_parameters), input_table_types(input_table_types),
10362
+ input_table_names(input_table_names), info(info) {
10363
+ }
10364
+
10365
+ vector<Value> &inputs;
10366
+ named_parameter_map_t &named_parameters;
10367
+ vector<LogicalType> &input_table_types;
10368
+ vector<string> &input_table_names;
10369
+ TableFunctionInfo *info;
10370
+ };
10371
+
10372
+ typedef unique_ptr<FunctionData> (*table_function_bind_t)(ClientContext &context, TableFunctionBindInput &input,
10303
10373
  vector<LogicalType> &return_types, vector<string> &names);
10304
10374
  typedef unique_ptr<FunctionOperatorData> (*table_function_init_t)(ClientContext &context, const FunctionData *bind_data,
10305
10375
  const vector<column_t> &column_ids,
@@ -10410,6 +10480,8 @@ public:
10410
10480
  //! Whether or not the table function supports filter pushdown. If not supported a filter will be added
10411
10481
  //! that applies the table filter directly.
10412
10482
  bool filter_pushdown;
10483
+ //! Additional function info, passed to the bind
10484
+ shared_ptr<TableFunctionInfo> function_info;
10413
10485
  };
10414
10486
 
10415
10487
  } // namespace duckdb
@@ -10570,7 +10642,7 @@ class Pipeline : public std::enable_shared_from_this<Pipeline> {
10570
10642
  friend class PipelineFinishEvent;
10571
10643
 
10572
10644
  public:
10573
- Pipeline(Executor &execution_context);
10645
+ explicit Pipeline(Executor &execution_context);
10574
10646
 
10575
10647
  Executor &executor;
10576
10648
 
@@ -12101,6 +12173,7 @@ public:
12101
12173
  bool IsFoldable() const override {
12102
12174
  return false;
12103
12175
  }
12176
+ bool PropagatesNullValues() const override;
12104
12177
 
12105
12178
  string ToString() const override;
12106
12179
 
@@ -12336,6 +12409,8 @@ public:
12336
12409
 
12337
12410
  bool Equals(const BaseExpression *other) const override;
12338
12411
 
12412
+ bool PropagatesNullValues() const override;
12413
+
12339
12414
  unique_ptr<Expression> Copy() override;
12340
12415
  };
12341
12416
  } // namespace duckdb
@@ -12445,7 +12520,7 @@ public:
12445
12520
  bool HasSideEffects() const override;
12446
12521
  bool IsFoldable() const override;
12447
12522
  string ToString() const override;
12448
-
12523
+ bool PropagatesNullValues() const override;
12449
12524
  hash_t Hash() const override;
12450
12525
  bool Equals(const BaseExpression *other) const override;
12451
12526
 
@@ -12976,7 +13051,7 @@ class QueryNode;
12976
13051
 
12977
13052
  class ScalarFunctionCatalogEntry;
12978
13053
  class AggregateFunctionCatalogEntry;
12979
- class MacroCatalogEntry;
13054
+ class ScalarMacroCatalogEntry;
12980
13055
  class CatalogEntry;
12981
13056
  class SimpleFunction;
12982
13057
 
@@ -13012,6 +13087,8 @@ public:
13012
13087
  //! be added. Defaults to INVALID.
13013
13088
  LogicalType target_type;
13014
13089
 
13090
+ MacroBinding *macro_binding;
13091
+
13015
13092
  public:
13016
13093
  unique_ptr<Expression> Bind(unique_ptr<ParsedExpression> &expr, LogicalType *result_type = nullptr,
13017
13094
  bool root_expression = true);
@@ -13058,6 +13135,8 @@ public:
13058
13135
  virtual BindResult BindExpression(unique_ptr<ParsedExpression> *expr_ptr, idx_t depth,
13059
13136
  bool root_expression = false);
13060
13137
 
13138
+ void ReplaceMacroParametersRecursive(unique_ptr<ParsedExpression> &expr);
13139
+
13061
13140
  protected:
13062
13141
  BindResult BindExpression(BetweenExpression &expr, idx_t depth);
13063
13142
  BindResult BindExpression(CaseExpression &expr, idx_t depth);
@@ -13080,18 +13159,15 @@ protected:
13080
13159
  virtual BindResult BindFunction(FunctionExpression &expr, ScalarFunctionCatalogEntry *function, idx_t depth);
13081
13160
  virtual BindResult BindAggregate(FunctionExpression &expr, AggregateFunctionCatalogEntry *function, idx_t depth);
13082
13161
  virtual BindResult BindUnnest(FunctionExpression &expr, idx_t depth);
13083
- virtual BindResult BindMacro(FunctionExpression &expr, MacroCatalogEntry *macro, idx_t depth,
13162
+ virtual BindResult BindMacro(FunctionExpression &expr, ScalarMacroCatalogEntry *macro, idx_t depth,
13084
13163
  unique_ptr<ParsedExpression> *expr_ptr);
13085
13164
 
13086
- void ReplaceMacroParametersRecursive(unique_ptr<ParsedExpression> &expr);
13087
-
13088
13165
  virtual string UnsupportedAggregateMessage();
13089
13166
  virtual string UnsupportedUnnestMessage();
13090
13167
 
13091
13168
  Binder &binder;
13092
13169
  ClientContext &context;
13093
13170
  ExpressionBinder *stored_binder;
13094
- MacroBinding *macro_binding;
13095
13171
  vector<BoundColumnReferenceInfo> bound_columns;
13096
13172
  };
13097
13173
 
@@ -13248,6 +13324,8 @@ public:
13248
13324
  const vector<LogicalType> &types, LogicalGet &get);
13249
13325
  //! Adds a subquery with a given alias to the BindContext.
13250
13326
  void AddSubquery(idx_t index, const string &alias, SubqueryRef &ref, BoundQueryNode &subquery);
13327
+ //! Adds a subquery with a given alias to the BindContext.
13328
+ void AddSubquery(idx_t index, const string &alias, TableFunctionRef &ref, BoundQueryNode &subquery);
13251
13329
  //! Adds a base table with the given alias to the BindContext.
13252
13330
  void AddGenericBinding(idx_t index, const string &alias, const vector<string> &names,
13253
13331
  const vector<LogicalType> &types);
@@ -13323,6 +13401,8 @@ private:
13323
13401
 
13324
13402
 
13325
13403
 
13404
+ //#include "duckdb/catalog/catalog_entry/table_macro_catalog_entry.hpp"
13405
+
13326
13406
  namespace duckdb {
13327
13407
  class BoundResultModifier;
13328
13408
  class BoundSelectNode;
@@ -13332,6 +13412,7 @@ class LimitModifier;
13332
13412
  class OrderBinder;
13333
13413
  class TableCatalogEntry;
13334
13414
  class ViewCatalogEntry;
13415
+ class TableMacroCatalogEntry;
13335
13416
 
13336
13417
  struct CreateInfo;
13337
13418
  struct BoundCreateTableInfo;
@@ -13489,9 +13570,10 @@ private:
13489
13570
  private:
13490
13571
  //! Bind the default values of the columns of a table
13491
13572
  void BindDefaultValues(vector<ColumnDefinition> &columns, vector<unique_ptr<Expression>> &bound_defaults);
13492
- //! Bind a delimiter value (LIMIT or OFFSET)
13493
- unique_ptr<Expression> BindDelimiter(ClientContext &context, unique_ptr<ParsedExpression> delimiter,
13494
- const LogicalType &type, Value &delimiter_value);
13573
+ //! Bind a limit value (LIMIT or OFFSET)
13574
+ unique_ptr<Expression> BindDelimiter(ClientContext &context, OrderBinder &order_binder,
13575
+ unique_ptr<ParsedExpression> delimiter, const LogicalType &type,
13576
+ Value &delimiter_value);
13495
13577
 
13496
13578
  //! Move correlated expressions from the child binder to this binder
13497
13579
  void MoveCorrelatedExpressions(Binder &other);
@@ -13514,6 +13596,11 @@ private:
13514
13596
  BoundStatement Bind(ExportStatement &stmt);
13515
13597
  BoundStatement Bind(SetStatement &stmt);
13516
13598
  BoundStatement Bind(LoadStatement &stmt);
13599
+ BoundStatement BindReturning(vector<unique_ptr<ParsedExpression>> returning_list, TableCatalogEntry *table,
13600
+ idx_t update_table_index, unique_ptr<LogicalOperator> child_operator,
13601
+ BoundStatement result);
13602
+
13603
+ unique_ptr<QueryNode> BindTableMacro(FunctionExpression &function, TableMacroCatalogEntry *macro_func, idx_t depth);
13517
13604
 
13518
13605
  unique_ptr<BoundQueryNode> BindNode(SelectNode &node);
13519
13606
  unique_ptr<BoundQueryNode> BindNode(SetOperationNode &node);
@@ -13547,10 +13634,6 @@ private:
13547
13634
  unique_ptr<LogicalOperator> CreatePlan(BoundExpressionListRef &ref);
13548
13635
  unique_ptr<LogicalOperator> CreatePlan(BoundCTERef &ref);
13549
13636
 
13550
- unique_ptr<LogicalOperator> BindTable(TableCatalogEntry &table, BaseTableRef &ref);
13551
- unique_ptr<LogicalOperator> BindView(ViewCatalogEntry &view, BaseTableRef &ref);
13552
- unique_ptr<LogicalOperator> BindTableOrView(BaseTableRef &ref);
13553
-
13554
13637
  BoundStatement BindCopyTo(CopyStatement &stmt);
13555
13638
  BoundStatement BindCopyFrom(CopyStatement &stmt);
13556
13639
 
@@ -13558,8 +13641,8 @@ private:
13558
13641
  void BindModifierTypes(BoundQueryNode &result, const vector<LogicalType> &sql_types, idx_t projection_index);
13559
13642
 
13560
13643
  BoundStatement BindSummarize(ShowStatement &stmt);
13561
- unique_ptr<BoundResultModifier> BindLimit(LimitModifier &limit_mod);
13562
- unique_ptr<BoundResultModifier> BindLimitPercent(LimitPercentModifier &limit_mod);
13644
+ unique_ptr<BoundResultModifier> BindLimit(OrderBinder &order_binder, LimitModifier &limit_mod);
13645
+ unique_ptr<BoundResultModifier> BindLimitPercent(OrderBinder &order_binder, LimitPercentModifier &limit_mod);
13563
13646
  unique_ptr<Expression> BindOrderExpression(OrderBinder &order_binder, unique_ptr<ParsedExpression> expr);
13564
13647
 
13565
13648
  unique_ptr<LogicalOperator> PlanFilter(unique_ptr<Expression> condition, unique_ptr<LogicalOperator> root);
@@ -13982,6 +14065,8 @@ public:
13982
14065
  bool Equals(const BaseExpression *other) const override;
13983
14066
 
13984
14067
  unique_ptr<Expression> Copy() override;
14068
+
14069
+ bool PropagatesNullValues() const override;
13985
14070
  };
13986
14071
  } // namespace duckdb
13987
14072
 
@@ -14362,9 +14447,9 @@ struct ColumnFetchState {
14362
14447
  struct LocalScanState {
14363
14448
  ~LocalScanState();
14364
14449
 
14365
- void SetStorage(LocalTableStorage *storage);
14450
+ void SetStorage(shared_ptr<LocalTableStorage> storage);
14366
14451
  LocalTableStorage *GetStorage() {
14367
- return storage;
14452
+ return storage.get();
14368
14453
  }
14369
14454
 
14370
14455
  idx_t chunk_index;
@@ -14373,7 +14458,7 @@ struct LocalScanState {
14373
14458
  TableFilterSet *table_filters;
14374
14459
 
14375
14460
  private:
14376
- LocalTableStorage *storage = nullptr;
14461
+ shared_ptr<LocalTableStorage> storage;
14377
14462
  };
14378
14463
 
14379
14464
  class RowGroupScanState {
@@ -14434,7 +14519,7 @@ class DataTable;
14434
14519
  class WriteAheadLog;
14435
14520
  struct TableAppendState;
14436
14521
 
14437
- class LocalTableStorage {
14522
+ class LocalTableStorage : public std::enable_shared_from_this<LocalTableStorage> {
14438
14523
  public:
14439
14524
  explicit LocalTableStorage(DataTable &table);
14440
14525
  ~LocalTableStorage();
@@ -14517,7 +14602,7 @@ private:
14517
14602
 
14518
14603
  private:
14519
14604
  Transaction &transaction;
14520
- unordered_map<DataTable *, unique_ptr<LocalTableStorage>> table_storage;
14605
+ unordered_map<DataTable *, shared_ptr<LocalTableStorage>> table_storage;
14521
14606
 
14522
14607
  void Flush(DataTable &table, LocalTableStorage &storage);
14523
14608
  };
@@ -14944,7 +15029,7 @@ typedef enum DUCKDB_TYPE {
14944
15029
  DUCKDB_TYPE_FLOAT,
14945
15030
  // double
14946
15031
  DUCKDB_TYPE_DOUBLE,
14947
- // duckdb_timestamp
15032
+ // duckdb_timestamp, in microseconds
14948
15033
  DUCKDB_TYPE_TIMESTAMP,
14949
15034
  // duckdb_date
14950
15035
  DUCKDB_TYPE_DATE,
@@ -14959,7 +15044,25 @@ typedef enum DUCKDB_TYPE {
14959
15044
  // duckdb_blob
14960
15045
  DUCKDB_TYPE_BLOB,
14961
15046
  // decimal
14962
- DUCKDB_TYPE_DECIMAL
15047
+ DUCKDB_TYPE_DECIMAL,
15048
+ // duckdb_timestamp, in seconds
15049
+ DUCKDB_TYPE_TIMESTAMP_S,
15050
+ // duckdb_timestamp, in milliseconds
15051
+ DUCKDB_TYPE_TIMESTAMP_MS,
15052
+ // duckdb_timestamp, in nanoseconds
15053
+ DUCKDB_TYPE_TIMESTAMP_NS,
15054
+ // enum type, only useful as logical type
15055
+ DUCKDB_TYPE_ENUM,
15056
+ // list type, only useful as logical type
15057
+ DUCKDB_TYPE_LIST,
15058
+ // struct type, only useful as logical type
15059
+ DUCKDB_TYPE_STRUCT,
15060
+ // map type, only useful as logical type
15061
+ DUCKDB_TYPE_MAP,
15062
+ // duckdb_hugeint
15063
+ DUCKDB_TYPE_UUID,
15064
+ // const char*
15065
+ DUCKDB_TYPE_JSON,
14963
15066
  } duckdb_type;
14964
15067
 
14965
15068
  //! Days are stored as days since 1970-01-01
@@ -15073,6 +15176,10 @@ typedef void *duckdb_arrow;
15073
15176
  typedef void *duckdb_config;
15074
15177
  typedef void *duckdb_arrow_schema;
15075
15178
  typedef void *duckdb_arrow_array;
15179
+ typedef void *duckdb_logical_type;
15180
+ typedef void *duckdb_data_chunk;
15181
+ typedef void *duckdb_vector;
15182
+ typedef void *duckdb_value;
15076
15183
 
15077
15184
  typedef enum { DuckDBSuccess = 0, DuckDBError = 1 } duckdb_state;
15078
15185
 
@@ -15236,6 +15343,19 @@ Returns `DUCKDB_TYPE_INVALID` if the column is out of range.
15236
15343
  */
15237
15344
  DUCKDB_API duckdb_type duckdb_column_type(duckdb_result *result, idx_t col);
15238
15345
 
15346
+ /*!
15347
+ Returns the logical column type of the specified column.
15348
+
15349
+ The return type of this call should be destroyed with `duckdb_destroy_logical_type`.
15350
+
15351
+ Returns `NULL` if the column is out of range.
15352
+
15353
+ * result: The result object to fetch the column type from.
15354
+ * col: The column index.
15355
+ * returns: The logical column type of the specified column.
15356
+ */
15357
+ DUCKDB_API duckdb_logical_type duckdb_column_logical_type(duckdb_result *result, idx_t col);
15358
+
15239
15359
  /*!
15240
15360
  Returns the number of columns present in a the result object.
15241
15361
 
@@ -15262,9 +15382,9 @@ queries. For other queries the rows_changed will be 0.
15262
15382
  DUCKDB_API idx_t duckdb_rows_changed(duckdb_result *result);
15263
15383
 
15264
15384
  /*!
15265
- Returns the data of a specific column of a result in columnar format. This is the fastest way of accessing data in a
15266
- query result, as no conversion or type checking must be performed (outside of the original switch). If performance
15267
- is a concern, it is recommended to use this API over the `duckdb_value` functions.
15385
+ **DEPRECATED**: Prefer using `duckdb_result_get_chunk` instead.
15386
+
15387
+ Returns the data of a specific column of a result in columnar format.
15268
15388
 
15269
15389
  The function returns a dense array which contains the result data. The exact type stored in the array depends on the
15270
15390
  corresponding duckdb_type (as provided by `duckdb_column_type`). For the exact type by which the data should be
@@ -15283,6 +15403,8 @@ printf("Data for row %d: %d\n", row, data[row]);
15283
15403
  DUCKDB_API void *duckdb_column_data(duckdb_result *result, idx_t col);
15284
15404
 
15285
15405
  /*!
15406
+ **DEPRECATED**: Prefer using `duckdb_result_get_chunk` instead.
15407
+
15286
15408
  Returns the nullmask of a specific column of a result in columnar format. The nullmask indicates for every row
15287
15409
  whether or not the corresponding row is `NULL`. If a row is `NULL`, the values present in the array provided
15288
15410
  by `duckdb_column_data` are undefined.
@@ -15311,17 +15433,42 @@ The result of this function must not be freed. It will be cleaned up when `duckd
15311
15433
  * result: The result object to fetch the nullmask from.
15312
15434
  * returns: The error of the result.
15313
15435
  */
15314
- DUCKDB_API char *duckdb_result_error(duckdb_result *result);
15436
+ DUCKDB_API const char *duckdb_result_error(duckdb_result *result);
15315
15437
 
15316
15438
  //===--------------------------------------------------------------------===//
15317
15439
  // Result Functions
15318
15440
  //===--------------------------------------------------------------------===//
15319
15441
 
15442
+ /*!
15443
+ Fetches a data chunk from the duckdb_result. This function should be called repeatedly until the result is exhausted.
15444
+
15445
+ This function supersedes all `duckdb_value` functions, as well as the `duckdb_column_data` and `duckdb_nullmask_data`
15446
+ functions. It results in significantly better performance, and should be preferred in newer code-bases.
15447
+
15448
+ If this function is used, none of the other result functions can be used and vice versa (i.e. this function cannot be
15449
+ mixed with the legacy result functions).
15450
+
15451
+ Use `duckdb_result_chunk_count` to figure out how many chunks there are in the result.
15452
+
15453
+ * result: The result object to fetch the data chunk from.
15454
+ * chunk_index: The chunk index to fetch from.
15455
+ * returns: The resulting data chunk. Returns `NULL` if the chunk index is out of bounds.
15456
+ */
15457
+ DUCKDB_API duckdb_data_chunk duckdb_result_get_chunk(duckdb_result result, idx_t chunk_index);
15458
+
15459
+ /*!
15460
+ Returns the number of data chunks present in the result.
15461
+
15462
+ * result: The result object
15463
+ * returns: The resulting data chunk. Returns `NULL` if the chunk index is out of bounds.
15464
+ */
15465
+ DUCKDB_API idx_t duckdb_result_chunk_count(duckdb_result result);
15466
+
15320
15467
  // Safe fetch functions
15321
15468
  // These functions will perform conversions if necessary.
15322
15469
  // On failure (e.g. if conversion cannot be performed or if the value is NULL) a default value is returned.
15323
15470
  // Note that these functions are slow since they perform bounds checking and conversion
15324
- // For fast access of values prefer using duckdb_column_data and duckdb_nullmask_data
15471
+ // For fast access of values prefer using `duckdb_result_get_chunk`
15325
15472
 
15326
15473
  /*!
15327
15474
  * returns: The boolean value at the specified location, or false if the value cannot be converted.
@@ -15452,6 +15599,14 @@ Free a value returned from `duckdb_malloc`, `duckdb_value_varchar` or `duckdb_va
15452
15599
  */
15453
15600
  DUCKDB_API void duckdb_free(void *ptr);
15454
15601
 
15602
+ /*!
15603
+ The internal vector size used by DuckDB.
15604
+ This is the amount of tuples that will fit into a data chunk created by `duckdb_create_data_chunk`.
15605
+
15606
+ * returns: The vector size.
15607
+ */
15608
+ DUCKDB_API idx_t duckdb_vector_size();
15609
+
15455
15610
  //===--------------------------------------------------------------------===//
15456
15611
  // Date/Time/Timestamp Helpers
15457
15612
  //===--------------------------------------------------------------------===//
@@ -15565,7 +15720,7 @@ DUCKDB_API duckdb_state duckdb_prepare(duckdb_connection connection, const char
15565
15720
  duckdb_prepared_statement *out_prepared_statement);
15566
15721
 
15567
15722
  /*!
15568
- Closes the prepared statement and de-allocates all memory allocated for that connection.
15723
+ Closes the prepared statement and de-allocates all memory allocated for the statement.
15569
15724
 
15570
15725
  * prepared_statement: The prepared statement to destroy.
15571
15726
  */
@@ -15734,196 +15889,897 @@ DUCKDB_API duckdb_state duckdb_execute_prepared_arrow(duckdb_prepared_statement
15734
15889
  duckdb_arrow *out_result);
15735
15890
 
15736
15891
  //===--------------------------------------------------------------------===//
15737
- // Appender
15892
+ // Value Interface
15738
15893
  //===--------------------------------------------------------------------===//
15739
-
15740
- // Appenders are the most efficient way of loading data into DuckDB from within the C interface, and are recommended for
15741
- // fast data loading. The appender is much faster than using prepared statements or individual `INSERT INTO` statements.
15742
-
15743
- // Appends are made in row-wise format. For every column, a `duckdb_append_[type]` call should be made, after which
15744
- // the row should be finished by calling `duckdb_appender_end_row`. After all rows have been appended,
15745
- // `duckdb_appender_destroy` should be used to finalize the appender and clean up the resulting memory.
15746
-
15747
- // Note that `duckdb_appender_destroy` should always be called on the resulting appender, even if the function returns
15748
- // `DuckDBError`.
15749
-
15750
15894
  /*!
15751
- Creates an appender object.
15895
+ Destroys the value and de-allocates all memory allocated for that type.
15752
15896
 
15753
- * connection: The connection context to create the appender in.
15754
- * schema: The schema of the table to append to, or `nullptr` for the default schema.
15755
- * table: The table name to append to.
15756
- * out_appender: The resulting appender object.
15757
- * returns: `DuckDBSuccess` on success or `DuckDBError` on failure.
15897
+ * value: The value to destroy.
15758
15898
  */
15759
- DUCKDB_API duckdb_state duckdb_appender_create(duckdb_connection connection, const char *schema, const char *table,
15760
- duckdb_appender *out_appender);
15899
+ DUCKDB_API void duckdb_destroy_value(duckdb_value *value);
15761
15900
 
15762
15901
  /*!
15763
- Returns the error message associated with the given appender.
15764
- If the appender has no error message, this returns `nullptr` instead.
15765
-
15766
- The error message should not be freed. It will be de-allocated when `duckdb_appender_destroy` is called.
15902
+ Creates a value from a null-terminated string
15767
15903
 
15768
- * appender: The appender to get the error from.
15769
- * returns: The error message, or `nullptr` if there is none.
15904
+ * value: The null-terminated string
15905
+ * returns: The value. This must be destroyed with `duckdb_destroy_value`.
15770
15906
  */
15771
- DUCKDB_API const char *duckdb_appender_error(duckdb_appender appender);
15907
+ DUCKDB_API duckdb_value duckdb_create_varchar(const char *text);
15772
15908
 
15773
15909
  /*!
15774
- Flush the appender to the table, forcing the cache of the appender to be cleared and the data to be appended to the
15775
- base table.
15910
+ Creates a value from a string
15776
15911
 
15777
- This should generally not be used unless you know what you are doing. Instead, call `duckdb_appender_destroy` when you
15778
- are done with the appender.
15779
-
15780
- * appender: The appender to flush.
15781
- * returns: `DuckDBSuccess` on success or `DuckDBError` on failure.
15912
+ * value: The text
15913
+ * length: The length of the text
15914
+ * returns: The value. This must be destroyed with `duckdb_destroy_value`.
15782
15915
  */
15783
- DUCKDB_API duckdb_state duckdb_appender_flush(duckdb_appender appender);
15916
+ DUCKDB_API duckdb_value duckdb_create_varchar_length(const char *text, idx_t length);
15784
15917
 
15785
15918
  /*!
15786
- Close the appender, flushing all intermediate state in the appender to the table and closing it for further appends.
15787
-
15788
- This is generally not necessary. Call `duckdb_appender_destroy` instead.
15919
+ Creates a value from an int64
15789
15920
 
15790
- * appender: The appender to flush and close.
15791
- * returns: `DuckDBSuccess` on success or `DuckDBError` on failure.
15921
+ * value: The bigint value
15922
+ * returns: The value. This must be destroyed with `duckdb_destroy_value`.
15792
15923
  */
15793
- DUCKDB_API duckdb_state duckdb_appender_close(duckdb_appender appender);
15924
+ DUCKDB_API duckdb_value duckdb_create_int64(int64_t val);
15794
15925
 
15795
15926
  /*!
15796
- Close the appender and destroy it. Flushing all intermediate state in the appender to the table, and de-allocating
15797
- all memory associated with the appender.
15927
+ Obtains a string representation of the given value.
15928
+ The result must be destroyed with `duckdb_free`.
15798
15929
 
15799
- * appender: The appender to flush, close and destroy.
15800
- * returns: `DuckDBSuccess` on success or `DuckDBError` on failure.
15930
+ * value: The value
15931
+ * returns: The string value. This must be destroyed with `duckdb_free`.
15801
15932
  */
15802
- DUCKDB_API duckdb_state duckdb_appender_destroy(duckdb_appender *appender);
15933
+ DUCKDB_API char *duckdb_get_varchar(duckdb_value value);
15803
15934
 
15804
15935
  /*!
15805
- A nop function, provided for backwards compatibility reasons. Does nothing. Only `duckdb_appender_end_row` is required.
15936
+ Obtains an int64 of the given value.
15937
+
15938
+ * value: The value
15939
+ * returns: The int64 value, or 0 if no conversion is possible
15806
15940
  */
15807
- DUCKDB_API duckdb_state duckdb_appender_begin_row(duckdb_appender appender);
15941
+ DUCKDB_API int64_t duckdb_get_int64(duckdb_value value);
15942
+
15943
+ //===--------------------------------------------------------------------===//
15944
+ // Logical Type Interface
15945
+ //===--------------------------------------------------------------------===//
15808
15946
 
15809
15947
  /*!
15810
- Finish the current row of appends. After end_row is called, the next row can be appended.
15948
+ Creates a `duckdb_logical_type` from a standard primitive type.
15949
+ The resulting type should be destroyed with `duckdb_destroy_logical_type`.
15811
15950
 
15812
- * appender: The appender.
15813
- * returns: `DuckDBSuccess` on success or `DuckDBError` on failure.
15951
+ This should not be used with `DUCKDB_TYPE_DECIMAL`.
15952
+
15953
+ * type: The primitive type to create.
15954
+ * returns: The logical type.
15814
15955
  */
15815
- DUCKDB_API duckdb_state duckdb_appender_end_row(duckdb_appender appender);
15956
+ DUCKDB_API duckdb_logical_type duckdb_create_logical_type(duckdb_type type);
15816
15957
 
15817
15958
  /*!
15818
- Append a bool value to the appender.
15959
+ Creates a `duckdb_logical_type` of type decimal with the specified width and scale
15960
+ The resulting type should be destroyed with `duckdb_destroy_logical_type`.
15961
+
15962
+ * width: The width of the decimal type
15963
+ * scale: The scale of the decimal type
15964
+ * returns: The logical type.
15819
15965
  */
15820
- DUCKDB_API duckdb_state duckdb_append_bool(duckdb_appender appender, bool value);
15966
+ DUCKDB_API duckdb_logical_type duckdb_create_decimal_type(uint8_t width, uint8_t scale);
15821
15967
 
15822
15968
  /*!
15823
- Append an int8_t value to the appender.
15969
+ Retrieves the type class of a `duckdb_logical_type`.
15970
+
15971
+ * type: The logical type object
15972
+ * returns: The type id
15824
15973
  */
15825
- DUCKDB_API duckdb_state duckdb_append_int8(duckdb_appender appender, int8_t value);
15974
+ DUCKDB_API duckdb_type duckdb_get_type_id(duckdb_logical_type type);
15975
+
15826
15976
  /*!
15827
- Append an int16_t value to the appender.
15977
+ Retrieves the width of a decimal type.
15978
+
15979
+ * type: The logical type object
15980
+ * returns: The width of the decimal type
15828
15981
  */
15829
- DUCKDB_API duckdb_state duckdb_append_int16(duckdb_appender appender, int16_t value);
15982
+ DUCKDB_API uint8_t duckdb_decimal_width(duckdb_logical_type type);
15983
+
15830
15984
  /*!
15831
- Append an int32_t value to the appender.
15985
+ Retrieves the scale of a decimal type.
15986
+
15987
+ * type: The logical type object
15988
+ * returns: The scale of the decimal type
15832
15989
  */
15833
- DUCKDB_API duckdb_state duckdb_append_int32(duckdb_appender appender, int32_t value);
15990
+ DUCKDB_API uint8_t duckdb_decimal_scale(duckdb_logical_type type);
15991
+
15834
15992
  /*!
15835
- Append an int64_t value to the appender.
15993
+ Retrieves the internal storage type of a decimal type.
15994
+
15995
+ * type: The logical type object
15996
+ * returns: The internal type of the decimal type
15836
15997
  */
15837
- DUCKDB_API duckdb_state duckdb_append_int64(duckdb_appender appender, int64_t value);
15998
+ DUCKDB_API duckdb_type duckdb_decimal_internal_type(duckdb_logical_type type);
15999
+
15838
16000
  /*!
15839
- Append a duckdb_hugeint value to the appender.
16001
+ Retrieves the internal storage type of an enum type.
16002
+
16003
+ * type: The logical type object
16004
+ * returns: The internal type of the enum type
15840
16005
  */
15841
- DUCKDB_API duckdb_state duckdb_append_hugeint(duckdb_appender appender, duckdb_hugeint value);
16006
+ DUCKDB_API duckdb_type duckdb_enum_internal_type(duckdb_logical_type type);
15842
16007
 
15843
16008
  /*!
15844
- Append a uint8_t value to the appender.
16009
+ Retrieves the dictionary size of the enum type
16010
+
16011
+ * type: The logical type object
16012
+ * returns: The dictionary size of the enum type
15845
16013
  */
15846
- DUCKDB_API duckdb_state duckdb_append_uint8(duckdb_appender appender, uint8_t value);
16014
+ DUCKDB_API uint32_t duckdb_enum_dictionary_size(duckdb_logical_type type);
16015
+
15847
16016
  /*!
15848
- Append a uint16_t value to the appender.
16017
+ Retrieves the dictionary value at the specified position from the enum.
16018
+
16019
+ The result must be freed with `duckdb_free`
16020
+
16021
+ * type: The logical type object
16022
+ * index: The index in the dictionary
16023
+ * returns: The string value of the enum type. Must be freed with `duckdb_free`.
15849
16024
  */
15850
- DUCKDB_API duckdb_state duckdb_append_uint16(duckdb_appender appender, uint16_t value);
16025
+ DUCKDB_API char *duckdb_enum_dictionary_value(duckdb_logical_type type, idx_t index);
16026
+
15851
16027
  /*!
15852
- Append a uint32_t value to the appender.
16028
+ Retrieves the child type of the given list type.
16029
+
16030
+ The result must be freed with `duckdb_destroy_logical_type`
16031
+
16032
+ * type: The logical type object
16033
+ * returns: The child type of the list type. Must be destroyed with `duckdb_destroy_logical_type`.
15853
16034
  */
15854
- DUCKDB_API duckdb_state duckdb_append_uint32(duckdb_appender appender, uint32_t value);
16035
+ DUCKDB_API duckdb_logical_type duckdb_list_type_child_type(duckdb_logical_type type);
16036
+
15855
16037
  /*!
15856
- Append a uint64_t value to the appender.
16038
+ Returns the number of children of a struct type.
16039
+
16040
+ * type: The logical type object
16041
+ * returns: The number of children of a struct type.
15857
16042
  */
15858
- DUCKDB_API duckdb_state duckdb_append_uint64(duckdb_appender appender, uint64_t value);
16043
+ DUCKDB_API idx_t duckdb_struct_type_child_count(duckdb_logical_type type);
15859
16044
 
15860
16045
  /*!
15861
- Append a float value to the appender.
16046
+ Retrieves the name of the struct child.
16047
+
16048
+ The result must be freed with `duckdb_free`
16049
+
16050
+ * type: The logical type object
16051
+ * index: The child index
16052
+ * returns: The name of the struct type. Must be freed with `duckdb_free`.
15862
16053
  */
15863
- DUCKDB_API duckdb_state duckdb_append_float(duckdb_appender appender, float value);
16054
+ DUCKDB_API char *duckdb_struct_type_child_name(duckdb_logical_type type, idx_t index);
16055
+
15864
16056
  /*!
15865
- Append a double value to the appender.
16057
+ Retrieves the child type of the given struct type at the specified index.
16058
+
16059
+ The result must be freed with `duckdb_destroy_logical_type`
16060
+
16061
+ * type: The logical type object
16062
+ * index: The child index
16063
+ * returns: The child type of the struct type. Must be destroyed with `duckdb_destroy_logical_type`.
15866
16064
  */
15867
- DUCKDB_API duckdb_state duckdb_append_double(duckdb_appender appender, double value);
16065
+ DUCKDB_API duckdb_logical_type duckdb_struct_type_child_type(duckdb_logical_type type, idx_t index);
15868
16066
 
15869
16067
  /*!
15870
- Append a duckdb_date value to the appender.
16068
+ Destroys the logical type and de-allocates all memory allocated for that type.
16069
+
16070
+ * type: The logical type to destroy.
15871
16071
  */
15872
- DUCKDB_API duckdb_state duckdb_append_date(duckdb_appender appender, duckdb_date value);
16072
+ DUCKDB_API void duckdb_destroy_logical_type(duckdb_logical_type *type);
16073
+
16074
+ //===--------------------------------------------------------------------===//
16075
+ // Data Chunk Interface
16076
+ //===--------------------------------------------------------------------===//
15873
16077
  /*!
15874
- Append a duckdb_time value to the appender.
16078
+ Creates an empty DataChunk with the specified set of types.
16079
+
16080
+ * types: An array of types of the data chunk.
16081
+ * column_count: The number of columns.
16082
+ * returns: The data chunk.
15875
16083
  */
15876
- DUCKDB_API duckdb_state duckdb_append_time(duckdb_appender appender, duckdb_time value);
16084
+ DUCKDB_API duckdb_data_chunk duckdb_create_data_chunk(duckdb_logical_type *types, idx_t column_count);
16085
+
15877
16086
  /*!
15878
- Append a duckdb_timestamp value to the appender.
16087
+ Destroys the data chunk and de-allocates all memory allocated for that chunk.
16088
+
16089
+ * chunk: The data chunk to destroy.
15879
16090
  */
15880
- DUCKDB_API duckdb_state duckdb_append_timestamp(duckdb_appender appender, duckdb_timestamp value);
16091
+ DUCKDB_API void duckdb_destroy_data_chunk(duckdb_data_chunk *chunk);
16092
+
15881
16093
  /*!
15882
- Append a duckdb_interval value to the appender.
16094
+ Resets a data chunk, clearing the validity masks and setting the cardinality of the data chunk to 0.
16095
+
16096
+ * chunk: The data chunk to reset.
15883
16097
  */
15884
- DUCKDB_API duckdb_state duckdb_append_interval(duckdb_appender appender, duckdb_interval value);
16098
+ DUCKDB_API void duckdb_data_chunk_reset(duckdb_data_chunk chunk);
15885
16099
 
15886
16100
  /*!
15887
- Append a varchar value to the appender.
16101
+ Retrieves the number of columns in a data chunk.
16102
+
16103
+ * chunk: The data chunk to get the data from
16104
+ * returns: The number of columns in the data chunk
15888
16105
  */
15889
- DUCKDB_API duckdb_state duckdb_append_varchar(duckdb_appender appender, const char *val);
16106
+ DUCKDB_API idx_t duckdb_data_chunk_get_column_count(duckdb_data_chunk chunk);
16107
+
15890
16108
  /*!
15891
- Append a varchar value to the appender.
16109
+ Retrieves the vector at the specified column index in the data chunk.
16110
+
16111
+ The pointer to the vector is valid for as long as the chunk is alive.
16112
+ It does NOT need to be destroyed.
16113
+
16114
+ * chunk: The data chunk to get the data from
16115
+ * returns: The vector
15892
16116
  */
15893
- DUCKDB_API duckdb_state duckdb_append_varchar_length(duckdb_appender appender, const char *val, idx_t length);
16117
+ DUCKDB_API duckdb_vector duckdb_data_chunk_get_vector(duckdb_data_chunk chunk, idx_t col_idx);
16118
+
15894
16119
  /*!
15895
- Append a blob value to the appender.
16120
+ Retrieves the current number of tuples in a data chunk.
16121
+
16122
+ * chunk: The data chunk to get the data from
16123
+ * returns: The number of tuples in the data chunk
15896
16124
  */
15897
- DUCKDB_API duckdb_state duckdb_append_blob(duckdb_appender appender, const void *data, idx_t length);
16125
+ DUCKDB_API idx_t duckdb_data_chunk_get_size(duckdb_data_chunk chunk);
16126
+
15898
16127
  /*!
15899
- Append a NULL value to the appender (of any type).
16128
+ Sets the current number of tuples in a data chunk.
16129
+
16130
+ * chunk: The data chunk to set the size in
16131
+ * size: The number of tuples in the data chunk
15900
16132
  */
15901
- DUCKDB_API duckdb_state duckdb_append_null(duckdb_appender appender);
16133
+ DUCKDB_API void duckdb_data_chunk_set_size(duckdb_data_chunk chunk, idx_t size);
15902
16134
 
15903
16135
  //===--------------------------------------------------------------------===//
15904
- // Arrow Interface
16136
+ // Vector Interface
15905
16137
  //===--------------------------------------------------------------------===//
15906
16138
  /*!
15907
- Executes a SQL query within a connection and stores the full (materialized) result in an arrow structure.
15908
- If the query fails to execute, DuckDBError is returned and the error message can be retrieved by calling
15909
- `duckdb_query_arrow_error`.
16139
+ Retrieves the column type of the specified vector.
15910
16140
 
15911
- Note that after running `duckdb_query_arrow`, `duckdb_destroy_arrow` must be called on the result object even if the
15912
- query fails, otherwise the error stored within the result will not be freed correctly.
16141
+ The result must be destroyed with `duckdb_destroy_logical_type`.
15913
16142
 
15914
- * connection: The connection to perform the query in.
15915
- * query: The SQL query to run.
15916
- * out_result: The query result.
15917
- * returns: `DuckDBSuccess` on success or `DuckDBError` on failure.
16143
+ * vector: The vector get the data from
16144
+ * returns: The type of the vector
15918
16145
  */
15919
- DUCKDB_API duckdb_state duckdb_query_arrow(duckdb_connection connection, const char *query, duckdb_arrow *out_result);
16146
+ DUCKDB_API duckdb_logical_type duckdb_vector_get_column_type(duckdb_vector vector);
15920
16147
 
15921
16148
  /*!
15922
- Fetch the internal arrow schema from the arrow result.
16149
+ Retrieves the data pointer of the vector.
15923
16150
 
15924
- * result: The result to fetch the schema from.
15925
- * out_schema: The output schema.
15926
- * returns: `DuckDBSuccess` on success or `DuckDBError` on failure.
16151
+ The data pointer can be used to read or write values from the vector.
16152
+ How to read or write values depends on the type of the vector.
16153
+
16154
+ * vector: The vector to get the data from
16155
+ * returns: The data pointer
16156
+ */
16157
+ DUCKDB_API void *duckdb_vector_get_data(duckdb_vector vector);
16158
+
16159
+ /*!
16160
+ Retrieves the validity mask pointer of the specified vector.
16161
+
16162
+ If all values are valid, this function MIGHT return NULL!
16163
+
16164
+ The validity mask is a bitset that signifies null-ness within the data chunk.
16165
+ It is a series of uint64_t values, where each uint64_t value contains validity for 64 tuples.
16166
+ The bit is set to 1 if the value is valid (i.e. not NULL) or 0 if the value is invalid (i.e. NULL).
16167
+
16168
+ Validity of a specific value can be obtained like this:
16169
+
16170
+ idx_t entry_idx = row_idx / 64;
16171
+ idx_t idx_in_entry = row_idx % 64;
16172
+ bool is_valid = validity_mask[entry_idx] & (1 << idx_in_entry);
16173
+
16174
+ Alternatively, the (slower) duckdb_validity_row_is_valid function can be used.
16175
+
16176
+ * vector: The vector to get the data from
16177
+ * returns: The pointer to the validity mask, or NULL if no validity mask is present
16178
+ */
16179
+ DUCKDB_API uint64_t *duckdb_vector_get_validity(duckdb_vector vector);
16180
+
16181
+ /*!
16182
+ Ensures the validity mask is writable by allocating it.
16183
+
16184
+ After this function is called, `duckdb_vector_get_validity` will ALWAYS return non-NULL.
16185
+ This allows null values to be written to the vector, regardless of whether a validity mask was present before.
16186
+
16187
+ * vector: The vector to alter
16188
+ */
16189
+ DUCKDB_API void duckdb_vector_ensure_validity_writable(duckdb_vector vector);
16190
+
16191
+ /*!
16192
+ Assigns a string element in the vector at the specified location.
16193
+
16194
+ * vector: The vector to alter
16195
+ * index: The row position in the vector to assign the string to
16196
+ * str: The null-terminated string
16197
+ */
16198
+ DUCKDB_API void duckdb_vector_assign_string_element(duckdb_vector vector, idx_t index, const char *str);
16199
+
16200
+ /*!
16201
+ Assigns a string element in the vector at the specified location.
16202
+
16203
+ * vector: The vector to alter
16204
+ * index: The row position in the vector to assign the string to
16205
+ * str: The string
16206
+ * str_len: The length of the string (in bytes)
16207
+ */
16208
+ DUCKDB_API void duckdb_vector_assign_string_element_len(duckdb_vector vector, idx_t index, const char *str,
16209
+ idx_t str_len);
16210
+
16211
+ /*!
16212
+ Retrieves the child vector of a list vector.
16213
+
16214
+ The resulting vector is valid as long as the parent vector is valid.
16215
+
16216
+ * vector: The vector
16217
+ * returns: The child vector
16218
+ */
16219
+ DUCKDB_API duckdb_vector duckdb_list_vector_get_child(duckdb_vector vector);
16220
+
16221
+ /*!
16222
+ Returns the size of the child vector of the list
16223
+
16224
+ * vector: The vector
16225
+ * returns: The size of the child list
16226
+ */
16227
+ DUCKDB_API idx_t duckdb_list_vector_get_size(duckdb_vector vector);
16228
+
16229
+ /*!
16230
+ Retrieves the child vector of a struct vector.
16231
+
16232
+ The resulting vector is valid as long as the parent vector is valid.
16233
+
16234
+ * vector: The vector
16235
+ * index: The child index
16236
+ * returns: The child vector
16237
+ */
16238
+ DUCKDB_API duckdb_vector duckdb_struct_vector_get_child(duckdb_vector vector, idx_t index);
16239
+
16240
+ //===--------------------------------------------------------------------===//
16241
+ // Validity Mask Functions
16242
+ //===--------------------------------------------------------------------===//
16243
+ /*!
16244
+ Returns whether or not a row is valid (i.e. not NULL) in the given validity mask.
16245
+
16246
+ * validity: The validity mask, as obtained through `duckdb_data_chunk_get_validity`
16247
+ * row: The row index
16248
+ * returns: true if the row is valid, false otherwise
16249
+ */
16250
+ DUCKDB_API bool duckdb_validity_row_is_valid(uint64_t *validity, idx_t row);
16251
+
16252
+ /*!
16253
+ In a validity mask, sets a specific row to either valid or invalid.
16254
+
16255
+ Note that `duckdb_data_chunk_ensure_validity_writable` should be called before calling `duckdb_data_chunk_get_validity`,
16256
+ to ensure that there is a validity mask to write to.
16257
+
16258
+ * validity: The validity mask, as obtained through `duckdb_data_chunk_get_validity`.
16259
+ * row: The row index
16260
+ * valid: Whether or not to set the row to valid, or invalid
16261
+ */
16262
+ DUCKDB_API void duckdb_validity_set_row_validity(uint64_t *validity, idx_t row, bool valid);
16263
+
16264
+ /*!
16265
+ In a validity mask, sets a specific row to invalid.
16266
+
16267
+ Equivalent to `duckdb_validity_set_row_validity` with valid set to false.
16268
+
16269
+ * validity: The validity mask
16270
+ * row: The row index
16271
+ */
16272
+ DUCKDB_API void duckdb_validity_set_row_invalid(uint64_t *validity, idx_t row);
16273
+
16274
+ /*!
16275
+ In a validity mask, sets a specific row to valid.
16276
+
16277
+ Equivalent to `duckdb_validity_set_row_validity` with valid set to true.
16278
+
16279
+ * validity: The validity mask
16280
+ * row: The row index
16281
+ */
16282
+ DUCKDB_API void duckdb_validity_set_row_valid(uint64_t *validity, idx_t row);
16283
+
16284
+ //===--------------------------------------------------------------------===//
16285
+ // Table Functions
16286
+ //===--------------------------------------------------------------------===//
16287
+ typedef void *duckdb_table_function;
16288
+ typedef void *duckdb_bind_info;
16289
+ typedef void *duckdb_init_info;
16290
+ typedef void *duckdb_function_info;
16291
+
16292
+ typedef void (*duckdb_table_function_bind_t)(duckdb_bind_info info);
16293
+ typedef void (*duckdb_table_function_init_t)(duckdb_init_info info);
16294
+ typedef void (*duckdb_table_function_t)(duckdb_function_info info, duckdb_data_chunk output);
16295
+ typedef void (*duckdb_delete_callback_t)(void *data);
16296
+
16297
+ /*!
16298
+ Creates a new empty table function.
16299
+
16300
+ The return value should be destroyed with `duckdb_destroy_table_function`.
16301
+
16302
+ * returns: The table function object.
16303
+ */
16304
+ DUCKDB_API duckdb_table_function duckdb_create_table_function();
16305
+
16306
+ /*!
16307
+ Destroys the given table function object.
16308
+
16309
+ * table_function: The table function to destroy
16310
+ */
16311
+ DUCKDB_API void duckdb_destroy_table_function(duckdb_table_function *table_function);
16312
+
16313
+ /*!
16314
+ Sets the name of the given table function.
16315
+
16316
+ * table_function: The table function
16317
+ * name: The name of the table function
16318
+ */
16319
+ DUCKDB_API void duckdb_table_function_set_name(duckdb_table_function table_function, const char *name);
16320
+
16321
+ /*!
16322
+ Adds a parameter to the table function.
16323
+
16324
+ * table_function: The table function
16325
+ * type: The type of the parameter to add.
16326
+ */
16327
+ DUCKDB_API void duckdb_table_function_add_parameter(duckdb_table_function table_function, duckdb_logical_type type);
16328
+
16329
+ /*!
16330
+ Assigns extra information to the table function that can be fetched during binding, etc.
16331
+
16332
+ * table_function: The table function
16333
+ * extra_info: The extra information
16334
+ * destroy: The callback that will be called to destroy the bind data (if any)
16335
+ */
16336
+ DUCKDB_API void duckdb_table_function_set_extra_info(duckdb_table_function table_function, void *extra_info,
16337
+ duckdb_delete_callback_t destroy);
16338
+
16339
+ /*!
16340
+ Sets the bind function of the table function
16341
+
16342
+ * table_function: The table function
16343
+ * bind: The bind function
16344
+ */
16345
+ DUCKDB_API void duckdb_table_function_set_bind(duckdb_table_function table_function, duckdb_table_function_bind_t bind);
16346
+
16347
+ /*!
16348
+ Sets the init function of the table function
16349
+
16350
+ * table_function: The table function
16351
+ * init: The init function
16352
+ */
16353
+ DUCKDB_API void duckdb_table_function_set_init(duckdb_table_function table_function, duckdb_table_function_init_t init);
16354
+
16355
+ /*!
16356
+ Sets the main function of the table function
16357
+
16358
+ * table_function: The table function
16359
+ * function: The function
16360
+ */
16361
+ DUCKDB_API void duckdb_table_function_set_function(duckdb_table_function table_function,
16362
+ duckdb_table_function_t function);
16363
+
16364
+ /*!
16365
+ Sets whether or not the given table function supports projection pushdown.
16366
+
16367
+ If this is set to true, the system will provide a list of all required columns in the `init` stage through
16368
+ the `duckdb_init_get_column_count` and `duckdb_init_get_column_index` functions.
16369
+ If this is set to false (the default), the system will expect all columns to be projected.
16370
+
16371
+ * table_function: The table function
16372
+ * pushdown: True if the table function supports projection pushdown, false otherwise.
16373
+ */
16374
+ DUCKDB_API void duckdb_table_function_supports_projection_pushdown(duckdb_table_function table_function, bool pushdown);
16375
+
16376
+ /*!
16377
+ Register the table function object within the given connection.
16378
+
16379
+ The function requires at least a name, a bind function, an init function and a main function.
16380
+
16381
+ If the function is incomplete or a function with this name already exists DuckDBError is returned.
16382
+
16383
+ * con: The connection to register it in.
16384
+ * function: The function pointer
16385
+ * returns: Whether or not the registration was successful.
16386
+ */
16387
+ DUCKDB_API duckdb_state duckdb_register_table_function(duckdb_connection con, duckdb_table_function function);
16388
+
16389
+ //===--------------------------------------------------------------------===//
16390
+ // Table Function Bind
16391
+ //===--------------------------------------------------------------------===//
16392
+ /*!
16393
+ Retrieves the extra info of the function as set in `duckdb_table_function_set_extra_info`
16394
+
16395
+ * info: The info object
16396
+ * returns: The extra info
16397
+ */
16398
+ DUCKDB_API void *duckdb_bind_get_extra_info(duckdb_bind_info info);
16399
+
16400
+ /*!
16401
+ Adds a result column to the output of the table function.
16402
+
16403
+ * info: The info object
16404
+ * name: The name of the column
16405
+ * type: The logical type of the column
16406
+ */
16407
+ DUCKDB_API void duckdb_bind_add_result_column(duckdb_bind_info info, const char *name, duckdb_logical_type type);
16408
+
16409
+ /*!
16410
+ Retrieves the number of regular (non-named) parameters to the function.
16411
+
16412
+ * info: The info object
16413
+ * returns: The number of parameters
16414
+ */
16415
+ DUCKDB_API idx_t duckdb_bind_get_parameter_count(duckdb_bind_info info);
16416
+
16417
+ /*!
16418
+ Retrieves the parameter at the given index.
16419
+
16420
+ The result must be destroyed with `duckdb_destroy_value`.
16421
+
16422
+ * info: The info object
16423
+ * index: The index of the parameter to get
16424
+ * returns: The value of the parameter. Must be destroyed with `duckdb_destroy_value`.
16425
+ */
16426
+ DUCKDB_API duckdb_value duckdb_bind_get_parameter(duckdb_bind_info info, idx_t index);
16427
+
16428
+ /*!
16429
+ Sets the user-provided bind data in the bind object. This object can be retrieved again during execution.
16430
+
16431
+ * info: The info object
16432
+ * extra_data: The bind data object.
16433
+ * destroy: The callback that will be called to destroy the bind data (if any)
16434
+ */
16435
+ DUCKDB_API void duckdb_bind_set_bind_data(duckdb_bind_info info, void *bind_data, duckdb_delete_callback_t destroy);
16436
+
16437
+ /*!
16438
+ Report that an error has occurred while calling bind.
16439
+
16440
+ * info: The info object
16441
+ * error: The error message
16442
+ */
16443
+ DUCKDB_API void duckdb_bind_set_error(duckdb_bind_info info, const char *error);
16444
+
16445
+ //===--------------------------------------------------------------------===//
16446
+ // Table Function Init
16447
+ //===--------------------------------------------------------------------===//
16448
+
16449
+ /*!
16450
+ Retrieves the extra info of the function as set in `duckdb_table_function_set_extra_info`
16451
+
16452
+ * info: The info object
16453
+ * returns: The extra info
16454
+ */
16455
+ DUCKDB_API void *duckdb_init_get_extra_info(duckdb_init_info info);
16456
+
16457
+ /*!
16458
+ Gets the bind data set by `duckdb_bind_set_bind_data` during the bind.
16459
+
16460
+ Note that the bind data should be considered as read-only.
16461
+ For tracking state, use the init data instead.
16462
+
16463
+ * info: The info object
16464
+ * returns: The bind data object
16465
+ */
16466
+ DUCKDB_API void *duckdb_init_get_bind_data(duckdb_init_info info);
16467
+
16468
+ /*!
16469
+ Sets the user-provided init data in the init object. This object can be retrieved again during execution.
16470
+
16471
+ * info: The info object
16472
+ * extra_data: The init data object.
16473
+ * destroy: The callback that will be called to destroy the init data (if any)
16474
+ */
16475
+ DUCKDB_API void duckdb_init_set_init_data(duckdb_init_info info, void *init_data, duckdb_delete_callback_t destroy);
16476
+
16477
+ /*!
16478
+ Returns the number of projected columns.
16479
+
16480
+ This function must be used if projection pushdown is enabled to figure out which columns to emit.
16481
+
16482
+ * info: The info object
16483
+ * returns: The number of projected columns.
16484
+ */
16485
+ DUCKDB_API idx_t duckdb_init_get_column_count(duckdb_init_info info);
16486
+
16487
+ /*!
16488
+ Returns the column index of the projected column at the specified position.
16489
+
16490
+ This function must be used if projection pushdown is enabled to figure out which columns to emit.
16491
+
16492
+ * info: The info object
16493
+ * column_index: The index at which to get the projected column index, from 0..duckdb_init_get_column_count(info)
16494
+ * returns: The column index of the projected column.
16495
+ */
16496
+ DUCKDB_API idx_t duckdb_init_get_column_index(duckdb_init_info info, idx_t column_index);
16497
+
16498
+ /*!
16499
+ Report that an error has occurred while calling init.
16500
+
16501
+ * info: The info object
16502
+ * error: The error message
16503
+ */
16504
+ DUCKDB_API void duckdb_init_set_error(duckdb_init_info info, const char *error);
16505
+
16506
+ //===--------------------------------------------------------------------===//
16507
+ // Table Function
16508
+ //===--------------------------------------------------------------------===//
16509
+
16510
+ /*!
16511
+ Retrieves the extra info of the function as set in `duckdb_table_function_set_extra_info`
16512
+
16513
+ * info: The info object
16514
+ * returns: The extra info
16515
+ */
16516
+ DUCKDB_API void *duckdb_function_get_extra_info(duckdb_function_info info);
16517
+ /*!
16518
+ Gets the bind data set by `duckdb_bind_set_bind_data` during the bind.
16519
+
16520
+ Note that the bind data should be considered as read-only.
16521
+ For tracking state, use the init data instead.
16522
+
16523
+ * info: The info object
16524
+ * returns: The bind data object
16525
+ */
16526
+ DUCKDB_API void *duckdb_function_get_bind_data(duckdb_function_info info);
16527
+
16528
+ /*!
16529
+ Gets the init data set by `duckdb_bind_set_init_data` during the bind.
16530
+
16531
+ * info: The info object
16532
+ * returns: The init data object
16533
+ */
16534
+ DUCKDB_API void *duckdb_function_get_init_data(duckdb_function_info info);
16535
+
16536
+ /*!
16537
+ Report that an error has occurred while executing the function.
16538
+
16539
+ * info: The info object
16540
+ * error: The error message
16541
+ */
16542
+ DUCKDB_API void duckdb_function_set_error(duckdb_function_info info, const char *error);
16543
+
16544
+ //===--------------------------------------------------------------------===//
16545
+ // Replacement Scans
16546
+ //===--------------------------------------------------------------------===//
16547
+ typedef void *duckdb_replacement_scan_info;
16548
+
16549
+ typedef void (*duckdb_replacement_callback_t)(duckdb_replacement_scan_info info, const char *table_name, void *data);
16550
+
16551
+ /*!
16552
+ Add a replacement scan definition to the specified database
16553
+
16554
+ * db: The database object to add the replacement scan to
16555
+ * replacement: The replacement scan callback
16556
+ * extra_data: Extra data that is passed back into the specified callback
16557
+ * delete_callback: The delete callback to call on the extra data, if any
16558
+ */
16559
+ DUCKDB_API void duckdb_add_replacement_scan(duckdb_database db, duckdb_replacement_callback_t replacement,
16560
+ void *extra_data, duckdb_delete_callback_t delete_callback);
16561
+
16562
+ /*!
16563
+ Sets the replacement function name to use. If this function is called in the replacement callback,
16564
+ the replacement scan is performed. If it is not called, the replacement callback is not performed.
16565
+
16566
+ * info: The info object
16567
+ * function_name: The function name to substitute.
16568
+ */
16569
+ DUCKDB_API void duckdb_replacement_scan_set_function_name(duckdb_replacement_scan_info info, const char *function_name);
16570
+
16571
+ /*!
16572
+ Adds a parameter to the replacement scan function.
16573
+
16574
+ * info: The info object
16575
+ * parameter: The parameter to add.
16576
+ */
16577
+ DUCKDB_API void duckdb_replacement_scan_add_parameter(duckdb_replacement_scan_info info, duckdb_value parameter);
16578
+
16579
+ //===--------------------------------------------------------------------===//
16580
+ // Appender
16581
+ //===--------------------------------------------------------------------===//
16582
+
16583
+ // Appenders are the most efficient way of loading data into DuckDB from within the C interface, and are recommended for
16584
+ // fast data loading. The appender is much faster than using prepared statements or individual `INSERT INTO` statements.
16585
+
16586
+ // Appends are made in row-wise format. For every column, a `duckdb_append_[type]` call should be made, after which
16587
+ // the row should be finished by calling `duckdb_appender_end_row`. After all rows have been appended,
16588
+ // `duckdb_appender_destroy` should be used to finalize the appender and clean up the resulting memory.
16589
+
16590
+ // Note that `duckdb_appender_destroy` should always be called on the resulting appender, even if the function returns
16591
+ // `DuckDBError`.
16592
+
16593
+ /*!
16594
+ Creates an appender object.
16595
+
16596
+ * connection: The connection context to create the appender in.
16597
+ * schema: The schema of the table to append to, or `nullptr` for the default schema.
16598
+ * table: The table name to append to.
16599
+ * out_appender: The resulting appender object.
16600
+ * returns: `DuckDBSuccess` on success or `DuckDBError` on failure.
16601
+ */
16602
+ DUCKDB_API duckdb_state duckdb_appender_create(duckdb_connection connection, const char *schema, const char *table,
16603
+ duckdb_appender *out_appender);
16604
+
16605
+ /*!
16606
+ Returns the error message associated with the given appender.
16607
+ If the appender has no error message, this returns `nullptr` instead.
16608
+
16609
+ The error message should not be freed. It will be de-allocated when `duckdb_appender_destroy` is called.
16610
+
16611
+ * appender: The appender to get the error from.
16612
+ * returns: The error message, or `nullptr` if there is none.
16613
+ */
16614
+ DUCKDB_API const char *duckdb_appender_error(duckdb_appender appender);
16615
+
16616
+ /*!
16617
+ Flush the appender to the table, forcing the cache of the appender to be cleared and the data to be appended to the
16618
+ base table.
16619
+
16620
+ This should generally not be used unless you know what you are doing. Instead, call `duckdb_appender_destroy` when you
16621
+ are done with the appender.
16622
+
16623
+ * appender: The appender to flush.
16624
+ * returns: `DuckDBSuccess` on success or `DuckDBError` on failure.
16625
+ */
16626
+ DUCKDB_API duckdb_state duckdb_appender_flush(duckdb_appender appender);
16627
+
16628
+ /*!
16629
+ Close the appender, flushing all intermediate state in the appender to the table and closing it for further appends.
16630
+
16631
+ This is generally not necessary. Call `duckdb_appender_destroy` instead.
16632
+
16633
+ * appender: The appender to flush and close.
16634
+ * returns: `DuckDBSuccess` on success or `DuckDBError` on failure.
16635
+ */
16636
+ DUCKDB_API duckdb_state duckdb_appender_close(duckdb_appender appender);
16637
+
16638
+ /*!
16639
+ Close the appender and destroy it. Flushing all intermediate state in the appender to the table, and de-allocating
16640
+ all memory associated with the appender.
16641
+
16642
+ * appender: The appender to flush, close and destroy.
16643
+ * returns: `DuckDBSuccess` on success or `DuckDBError` on failure.
16644
+ */
16645
+ DUCKDB_API duckdb_state duckdb_appender_destroy(duckdb_appender *appender);
16646
+
16647
+ /*!
16648
+ A nop function, provided for backwards compatibility reasons. Does nothing. Only `duckdb_appender_end_row` is required.
16649
+ */
16650
+ DUCKDB_API duckdb_state duckdb_appender_begin_row(duckdb_appender appender);
16651
+
16652
+ /*!
16653
+ Finish the current row of appends. After end_row is called, the next row can be appended.
16654
+
16655
+ * appender: The appender.
16656
+ * returns: `DuckDBSuccess` on success or `DuckDBError` on failure.
16657
+ */
16658
+ DUCKDB_API duckdb_state duckdb_appender_end_row(duckdb_appender appender);
16659
+
16660
+ /*!
16661
+ Append a bool value to the appender.
16662
+ */
16663
+ DUCKDB_API duckdb_state duckdb_append_bool(duckdb_appender appender, bool value);
16664
+
16665
+ /*!
16666
+ Append an int8_t value to the appender.
16667
+ */
16668
+ DUCKDB_API duckdb_state duckdb_append_int8(duckdb_appender appender, int8_t value);
16669
+ /*!
16670
+ Append an int16_t value to the appender.
16671
+ */
16672
+ DUCKDB_API duckdb_state duckdb_append_int16(duckdb_appender appender, int16_t value);
16673
+ /*!
16674
+ Append an int32_t value to the appender.
16675
+ */
16676
+ DUCKDB_API duckdb_state duckdb_append_int32(duckdb_appender appender, int32_t value);
16677
+ /*!
16678
+ Append an int64_t value to the appender.
16679
+ */
16680
+ DUCKDB_API duckdb_state duckdb_append_int64(duckdb_appender appender, int64_t value);
16681
+ /*!
16682
+ Append a duckdb_hugeint value to the appender.
16683
+ */
16684
+ DUCKDB_API duckdb_state duckdb_append_hugeint(duckdb_appender appender, duckdb_hugeint value);
16685
+
16686
+ /*!
16687
+ Append a uint8_t value to the appender.
16688
+ */
16689
+ DUCKDB_API duckdb_state duckdb_append_uint8(duckdb_appender appender, uint8_t value);
16690
+ /*!
16691
+ Append a uint16_t value to the appender.
16692
+ */
16693
+ DUCKDB_API duckdb_state duckdb_append_uint16(duckdb_appender appender, uint16_t value);
16694
+ /*!
16695
+ Append a uint32_t value to the appender.
16696
+ */
16697
+ DUCKDB_API duckdb_state duckdb_append_uint32(duckdb_appender appender, uint32_t value);
16698
+ /*!
16699
+ Append a uint64_t value to the appender.
16700
+ */
16701
+ DUCKDB_API duckdb_state duckdb_append_uint64(duckdb_appender appender, uint64_t value);
16702
+
16703
+ /*!
16704
+ Append a float value to the appender.
16705
+ */
16706
+ DUCKDB_API duckdb_state duckdb_append_float(duckdb_appender appender, float value);
16707
+ /*!
16708
+ Append a double value to the appender.
16709
+ */
16710
+ DUCKDB_API duckdb_state duckdb_append_double(duckdb_appender appender, double value);
16711
+
16712
+ /*!
16713
+ Append a duckdb_date value to the appender.
16714
+ */
16715
+ DUCKDB_API duckdb_state duckdb_append_date(duckdb_appender appender, duckdb_date value);
16716
+ /*!
16717
+ Append a duckdb_time value to the appender.
16718
+ */
16719
+ DUCKDB_API duckdb_state duckdb_append_time(duckdb_appender appender, duckdb_time value);
16720
+ /*!
16721
+ Append a duckdb_timestamp value to the appender.
16722
+ */
16723
+ DUCKDB_API duckdb_state duckdb_append_timestamp(duckdb_appender appender, duckdb_timestamp value);
16724
+ /*!
16725
+ Append a duckdb_interval value to the appender.
16726
+ */
16727
+ DUCKDB_API duckdb_state duckdb_append_interval(duckdb_appender appender, duckdb_interval value);
16728
+
16729
+ /*!
16730
+ Append a varchar value to the appender.
16731
+ */
16732
+ DUCKDB_API duckdb_state duckdb_append_varchar(duckdb_appender appender, const char *val);
16733
+ /*!
16734
+ Append a varchar value to the appender.
16735
+ */
16736
+ DUCKDB_API duckdb_state duckdb_append_varchar_length(duckdb_appender appender, const char *val, idx_t length);
16737
+ /*!
16738
+ Append a blob value to the appender.
16739
+ */
16740
+ DUCKDB_API duckdb_state duckdb_append_blob(duckdb_appender appender, const void *data, idx_t length);
16741
+ /*!
16742
+ Append a NULL value to the appender (of any type).
16743
+ */
16744
+ DUCKDB_API duckdb_state duckdb_append_null(duckdb_appender appender);
16745
+
16746
+ /*!
16747
+ Appends a pre-filled data chunk to the specified appender.
16748
+
16749
+ The types of the data chunk must exactly match the types of the table, no casting is performed.
16750
+ If the types do not match or the appender is in an invalid state, DuckDBError is returned.
16751
+ If the append is successful, DuckDBSuccess is returned.
16752
+
16753
+ * appender: The appender to append to.
16754
+ * chunk: The data chunk to append.
16755
+ * returns: The return state.
16756
+ */
16757
+ DUCKDB_API duckdb_state duckdb_append_data_chunk(duckdb_appender appender, duckdb_data_chunk chunk);
16758
+
16759
+ //===--------------------------------------------------------------------===//
16760
+ // Arrow Interface
16761
+ //===--------------------------------------------------------------------===//
16762
+ /*!
16763
+ Executes a SQL query within a connection and stores the full (materialized) result in an arrow structure.
16764
+ If the query fails to execute, DuckDBError is returned and the error message can be retrieved by calling
16765
+ `duckdb_query_arrow_error`.
16766
+
16767
+ Note that after running `duckdb_query_arrow`, `duckdb_destroy_arrow` must be called on the result object even if the
16768
+ query fails, otherwise the error stored within the result will not be freed correctly.
16769
+
16770
+ * connection: The connection to perform the query in.
16771
+ * query: The SQL query to run.
16772
+ * out_result: The query result.
16773
+ * returns: `DuckDBSuccess` on success or `DuckDBError` on failure.
16774
+ */
16775
+ DUCKDB_API duckdb_state duckdb_query_arrow(duckdb_connection connection, const char *query, duckdb_arrow *out_result);
16776
+
16777
+ /*!
16778
+ Fetch the internal arrow schema from the arrow result.
16779
+
16780
+ * result: The result to fetch the schema from.
16781
+ * out_schema: The output schema.
16782
+ * returns: `DuckDBSuccess` on success or `DuckDBError` on failure.
15927
16783
  */
15928
16784
  DUCKDB_API duckdb_state duckdb_query_arrow_schema(duckdb_arrow result, duckdb_arrow_schema *out_schema);
15929
16785
 
@@ -17027,18 +17883,26 @@ private:
17027
17883
 
17028
17884
  namespace duckdb {
17029
17885
 
17886
+ class ClientContext;
17030
17887
  class TableFunctionRef;
17031
17888
 
17032
- typedef unique_ptr<TableFunctionRef> (*replacement_scan_t)(const string &table_name, void *data);
17889
+ struct ReplacementScanData {
17890
+ virtual ~ReplacementScanData() {
17891
+ }
17892
+ };
17893
+
17894
+ typedef unique_ptr<TableFunctionRef> (*replacement_scan_t)(ClientContext &context, const string &table_name,
17895
+ ReplacementScanData *data);
17033
17896
 
17034
17897
  //! Replacement table scans are automatically attempted when a table name cannot be found in the schema
17035
17898
  //! This allows you to do e.g. SELECT * FROM 'filename.csv', and automatically convert this into a CSV scan
17036
17899
  struct ReplacementScan {
17037
- explicit ReplacementScan(replacement_scan_t function, void *data = nullptr) : function(function), data(data) {
17900
+ explicit ReplacementScan(replacement_scan_t function, unique_ptr<ReplacementScanData> data_p = nullptr)
17901
+ : function(function), data(move(data_p)) {
17038
17902
  }
17039
17903
 
17040
17904
  replacement_scan_t function;
17041
- void *data;
17905
+ unique_ptr<ReplacementScanData> data;
17042
17906
  };
17043
17907
 
17044
17908
  } // namespace duckdb
@@ -17953,6 +18817,7 @@ public:
17953
18817
  DUCKDB_API idx_t CurrentColumn() {
17954
18818
  return column;
17955
18819
  }
18820
+ DUCKDB_API void AppendDataChunk(DataChunk &value);
17956
18821
 
17957
18822
  protected:
17958
18823
  void Destructor();
@@ -18078,7 +18943,7 @@ struct CreateFunctionInfo : public CreateInfo {
18078
18943
  explicit CreateFunctionInfo(CatalogType type, string schema = DEFAULT_SCHEMA) : CreateInfo(type, schema) {
18079
18944
  D_ASSERT(type == CatalogType::SCALAR_FUNCTION_ENTRY || type == CatalogType::AGGREGATE_FUNCTION_ENTRY ||
18080
18945
  type == CatalogType::TABLE_FUNCTION_ENTRY || type == CatalogType::PRAGMA_FUNCTION_ENTRY ||
18081
- type == CatalogType::MACRO_ENTRY);
18946
+ type == CatalogType::MACRO_ENTRY || type == CatalogType::TABLE_MACRO_ENTRY);
18082
18947
  }
18083
18948
 
18084
18949
  //! Function name
@@ -20085,6 +20950,8 @@ public:
20085
20950
  return indexes.size();
20086
20951
  }
20087
20952
 
20953
+ Index *FindForeignKeyIndex(const vector<idx_t> &fk_keys, ForeignKeyType fk_type);
20954
+
20088
20955
  private:
20089
20956
  //! Indexes associated with the current table
20090
20957
  mutex indexes_lock;
@@ -21043,9 +21910,9 @@ protected:
21043
21910
  static idx_t GetSpecifierLength(StrTimeSpecifier specifier, date_t date, dtime_t time);
21044
21911
  char *WriteString(char *target, const string_t &str);
21045
21912
  char *Write2(char *target, uint8_t value);
21046
- char *WritePadded2(char *target, int32_t value);
21913
+ char *WritePadded2(char *target, uint32_t value);
21047
21914
  char *WritePadded3(char *target, uint32_t value);
21048
- char *WritePadded(char *target, int32_t value, int32_t padding);
21915
+ char *WritePadded(char *target, uint32_t value, size_t padding);
21049
21916
  bool IsDateSpecifier(StrTimeSpecifier specifier);
21050
21917
  char *WriteDateSpecifier(StrTimeSpecifier specifier, date_t date, char *target);
21051
21918
  char *WriteStandardSpecifier(StrTimeSpecifier specifier, int32_t data[], char *target);
@@ -21491,8 +22358,85 @@ public:
21491
22358
  void Serialize(FieldWriter &writer) const override;
21492
22359
  static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
21493
22360
  };
21494
-
22361
+
22362
+ } // namespace duckdb
22363
+ //===----------------------------------------------------------------------===//
22364
+ // DuckDB
22365
+ //
22366
+ // duckdb/parser/expression/collate_expression.hpp
22367
+ //
22368
+ //
22369
+ //===----------------------------------------------------------------------===//
22370
+
22371
+
22372
+
22373
+
22374
+
22375
+ namespace duckdb {
22376
+
22377
+ //! CollateExpression represents a COLLATE statement
22378
+ class CollateExpression : public ParsedExpression {
22379
+ public:
22380
+ CollateExpression(string collation, unique_ptr<ParsedExpression> child);
22381
+
22382
+ //! The child of the cast expression
22383
+ unique_ptr<ParsedExpression> child;
22384
+ //! The collation clause
22385
+ string collation;
22386
+
22387
+ public:
22388
+ string ToString() const override;
22389
+
22390
+ static bool Equals(const CollateExpression *a, const CollateExpression *b);
22391
+
22392
+ unique_ptr<ParsedExpression> Copy() const override;
22393
+
22394
+ void Serialize(FieldWriter &writer) const override;
22395
+ static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
22396
+ };
22397
+ } // namespace duckdb
22398
+ //===----------------------------------------------------------------------===//
22399
+ // DuckDB
22400
+ //
22401
+ // duckdb/parser/expression/between_expression.hpp
22402
+ //
22403
+ //
22404
+ //===----------------------------------------------------------------------===//
22405
+
22406
+
22407
+
22408
+
22409
+
22410
+ namespace duckdb {
22411
+
22412
+ class BetweenExpression : public ParsedExpression {
22413
+ public:
22414
+ BetweenExpression(unique_ptr<ParsedExpression> input, unique_ptr<ParsedExpression> lower,
22415
+ unique_ptr<ParsedExpression> upper);
22416
+
22417
+ unique_ptr<ParsedExpression> input;
22418
+ unique_ptr<ParsedExpression> lower;
22419
+ unique_ptr<ParsedExpression> upper;
22420
+
22421
+ public:
22422
+ string ToString() const override;
22423
+
22424
+ static bool Equals(const BetweenExpression *a, const BetweenExpression *b);
22425
+
22426
+ unique_ptr<ParsedExpression> Copy() const override;
22427
+
22428
+ void Serialize(FieldWriter &writer) const override;
22429
+ static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
22430
+
22431
+ public:
22432
+ template <class T, class BASE>
22433
+ static string ToString(const T &entry) {
22434
+ return entry.input->ToString() + " BETWEEN " + entry.lower->ToString() + " AND " + entry.upper->ToString();
22435
+ }
22436
+ };
21495
22437
  } // namespace duckdb
22438
+
22439
+
21496
22440
  //===----------------------------------------------------------------------===//
21497
22441
  // DuckDB
21498
22442
  //
@@ -21545,10 +22489,11 @@ public:
21545
22489
  }
21546
22490
  };
21547
22491
  } // namespace duckdb
22492
+
21548
22493
  //===----------------------------------------------------------------------===//
21549
22494
  // DuckDB
21550
22495
  //
21551
- // duckdb/parser/expression/conjunction_expression.hpp
22496
+ // duckdb/parser/expression/cast_expression.hpp
21552
22497
  //
21553
22498
  //
21554
22499
  //===----------------------------------------------------------------------===//
@@ -21560,22 +22505,22 @@ public:
21560
22505
 
21561
22506
  namespace duckdb {
21562
22507
 
21563
- //! Represents a conjunction (AND/OR)
21564
- class ConjunctionExpression : public ParsedExpression {
22508
+ //! CastExpression represents a type cast from one SQL type to another SQL type
22509
+ class CastExpression : public ParsedExpression {
21565
22510
  public:
21566
- DUCKDB_API explicit ConjunctionExpression(ExpressionType type);
21567
- DUCKDB_API ConjunctionExpression(ExpressionType type, vector<unique_ptr<ParsedExpression>> children);
21568
- DUCKDB_API ConjunctionExpression(ExpressionType type, unique_ptr<ParsedExpression> left,
21569
- unique_ptr<ParsedExpression> right);
22511
+ DUCKDB_API CastExpression(LogicalType target, unique_ptr<ParsedExpression> child, bool try_cast = false);
21570
22512
 
21571
- vector<unique_ptr<ParsedExpression>> children;
22513
+ //! The child of the cast expression
22514
+ unique_ptr<ParsedExpression> child;
22515
+ //! The type to cast to
22516
+ LogicalType cast_type;
22517
+ //! Whether or not this is a try_cast expression
22518
+ bool try_cast;
21572
22519
 
21573
22520
  public:
21574
- void AddExpression(unique_ptr<ParsedExpression> expr);
21575
-
21576
22521
  string ToString() const override;
21577
22522
 
21578
- static bool Equals(const ConjunctionExpression *a, const ConjunctionExpression *b);
22523
+ static bool Equals(const CastExpression *a, const CastExpression *b);
21579
22524
 
21580
22525
  unique_ptr<ParsedExpression> Copy() const override;
21581
22526
 
@@ -21585,18 +22530,18 @@ public:
21585
22530
  public:
21586
22531
  template <class T, class BASE>
21587
22532
  static string ToString(const T &entry) {
21588
- string result = entry.children[0]->ToString();
21589
- for (idx_t i = 1; i < entry.children.size(); i++) {
21590
- result += " " + ExpressionTypeToOperator(entry.type) + " " + entry.children[i]->ToString();
21591
- }
21592
- return result;
22533
+ return (entry.try_cast ? "TRY_CAST(" : "CAST(") + entry.child->ToString() + " AS " +
22534
+ entry.cast_type.ToString() + ")";
21593
22535
  }
21594
22536
  };
21595
22537
  } // namespace duckdb
22538
+
22539
+
22540
+
21596
22541
  //===----------------------------------------------------------------------===//
21597
22542
  // DuckDB
21598
22543
  //
21599
- // duckdb/parser/expression/function_expression.hpp
22544
+ // duckdb/parser/expression/comparison_expression.hpp
21600
22545
  //
21601
22546
  //
21602
22547
  //===----------------------------------------------------------------------===//
@@ -21605,112 +22550,39 @@ public:
21605
22550
 
21606
22551
 
21607
22552
 
21608
-
21609
-
21610
22553
  namespace duckdb {
21611
- //! Represents a function call
21612
- class FunctionExpression : public ParsedExpression {
22554
+ //! ComparisonExpression represents a boolean comparison (e.g. =, >=, <>). Always returns a boolean
22555
+ //! and has two children.
22556
+ class ComparisonExpression : public ParsedExpression {
21613
22557
  public:
21614
- DUCKDB_API FunctionExpression(string schema_name, const string &function_name,
21615
- vector<unique_ptr<ParsedExpression>> children,
21616
- unique_ptr<ParsedExpression> filter = nullptr,
21617
- unique_ptr<OrderModifier> order_bys = nullptr, bool distinct = false,
21618
- bool is_operator = false, bool export_state = false);
21619
- DUCKDB_API FunctionExpression(const string &function_name, vector<unique_ptr<ParsedExpression>> children,
21620
- unique_ptr<ParsedExpression> filter = nullptr,
21621
- unique_ptr<OrderModifier> order_bys = nullptr, bool distinct = false,
21622
- bool is_operator = false, bool export_state = false);
22558
+ DUCKDB_API ComparisonExpression(ExpressionType type, unique_ptr<ParsedExpression> left,
22559
+ unique_ptr<ParsedExpression> right);
21623
22560
 
21624
- //! Schema of the function
21625
- string schema;
21626
- //! Function name
21627
- string function_name;
21628
- //! Whether or not the function is an operator, only used for rendering
21629
- bool is_operator;
21630
- //! List of arguments to the function
21631
- vector<unique_ptr<ParsedExpression>> children;
21632
- //! Whether or not the aggregate function is distinct, only used for aggregates
21633
- bool distinct;
21634
- //! Expression representing a filter, only used for aggregates
21635
- unique_ptr<ParsedExpression> filter;
21636
- //! Modifier representing an ORDER BY, only used for aggregates
21637
- unique_ptr<OrderModifier> order_bys;
21638
- //! whether this function should export its state or not
21639
- bool export_state;
22561
+ unique_ptr<ParsedExpression> left;
22562
+ unique_ptr<ParsedExpression> right;
21640
22563
 
21641
22564
  public:
21642
22565
  string ToString() const override;
21643
22566
 
21644
- unique_ptr<ParsedExpression> Copy() const override;
22567
+ static bool Equals(const ComparisonExpression *a, const ComparisonExpression *b);
21645
22568
 
21646
- static bool Equals(const FunctionExpression *a, const FunctionExpression *b);
21647
- hash_t Hash() const override;
22569
+ unique_ptr<ParsedExpression> Copy() const override;
21648
22570
 
21649
22571
  void Serialize(FieldWriter &writer) const override;
21650
22572
  static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
21651
22573
 
21652
- void Verify() const override;
21653
-
21654
22574
  public:
21655
22575
  template <class T, class BASE>
21656
- static string ToString(const T &entry, const string &schema, const string &function_name, bool is_operator = false,
21657
- bool distinct = false, BASE *filter = nullptr, OrderModifier *order_bys = nullptr,
21658
- bool export_state = false) {
21659
- if (is_operator) {
21660
- // built-in operator
21661
- D_ASSERT(!distinct);
21662
- if (entry.children.size() == 1) {
21663
- if (StringUtil::Contains(function_name, "__postfix")) {
21664
- return "(" + entry.children[0]->ToString() + ")" +
21665
- StringUtil::Replace(function_name, "__postfix", "");
21666
- } else {
21667
- return function_name + "(" + entry.children[0]->ToString() + ")";
21668
- }
21669
- } else if (entry.children.size() == 2) {
21670
- return "(" + entry.children[0]->ToString() + " " + function_name + " " + entry.children[1]->ToString() +
21671
- ")";
21672
- }
21673
- }
21674
- // standard function call
21675
- string result = schema.empty() ? function_name : schema + "." + function_name;
21676
- result += "(";
21677
- if (distinct) {
21678
- result += "DISTINCT ";
21679
- }
21680
- result += StringUtil::Join(entry.children, entry.children.size(), ", ",
21681
- [](const unique_ptr<BASE> &child) { return child->ToString(); });
21682
- // ordered aggregate
21683
- if (order_bys && !order_bys->orders.empty()) {
21684
- if (entry.children.empty()) {
21685
- result += ") WITHIN GROUP (";
21686
- }
21687
- result += " ORDER BY ";
21688
- for (idx_t i = 0; i < order_bys->orders.size(); i++) {
21689
- if (i > 0) {
21690
- result += ", ";
21691
- }
21692
- result += order_bys->orders[i].ToString();
21693
- }
21694
- }
21695
- result += ")";
21696
-
21697
- // filtered aggregate
21698
- if (filter) {
21699
- result += " FILTER (WHERE " + filter->ToString() + ")";
21700
- }
21701
-
21702
- if (export_state) {
21703
- result += " EXPORT_STATE";
21704
- }
21705
-
21706
- return result;
22576
+ static string ToString(const T &entry) {
22577
+ return entry.left->ToString() + " " + ExpressionTypeToOperator(entry.type) + " " + entry.right->ToString();
21707
22578
  }
21708
22579
  };
21709
22580
  } // namespace duckdb
22581
+
21710
22582
  //===----------------------------------------------------------------------===//
21711
22583
  // DuckDB
21712
22584
  //
21713
- // duckdb/parser/expression/default_expression.hpp
22585
+ // duckdb/parser/expression/conjunction_expression.hpp
21714
22586
  //
21715
22587
  //
21716
22588
  //===----------------------------------------------------------------------===//
@@ -21719,29 +22591,47 @@ public:
21719
22591
 
21720
22592
 
21721
22593
 
22594
+
21722
22595
  namespace duckdb {
21723
- //! Represents the default value of a column
21724
- class DefaultExpression : public ParsedExpression {
22596
+
22597
+ //! Represents a conjunction (AND/OR)
22598
+ class ConjunctionExpression : public ParsedExpression {
21725
22599
  public:
21726
- DefaultExpression();
22600
+ DUCKDB_API explicit ConjunctionExpression(ExpressionType type);
22601
+ DUCKDB_API ConjunctionExpression(ExpressionType type, vector<unique_ptr<ParsedExpression>> children);
22602
+ DUCKDB_API ConjunctionExpression(ExpressionType type, unique_ptr<ParsedExpression> left,
22603
+ unique_ptr<ParsedExpression> right);
22604
+
22605
+ vector<unique_ptr<ParsedExpression>> children;
21727
22606
 
21728
22607
  public:
21729
- bool IsScalar() const override {
21730
- return false;
21731
- }
22608
+ void AddExpression(unique_ptr<ParsedExpression> expr);
21732
22609
 
21733
22610
  string ToString() const override;
21734
22611
 
22612
+ static bool Equals(const ConjunctionExpression *a, const ConjunctionExpression *b);
22613
+
21735
22614
  unique_ptr<ParsedExpression> Copy() const override;
21736
22615
 
21737
22616
  void Serialize(FieldWriter &writer) const override;
21738
22617
  static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
22618
+
22619
+ public:
22620
+ template <class T, class BASE>
22621
+ static string ToString(const T &entry) {
22622
+ string result = entry.children[0]->ToString();
22623
+ for (idx_t i = 1; i < entry.children.size(); i++) {
22624
+ result += " " + ExpressionTypeToOperator(entry.type) + " " + entry.children[i]->ToString();
22625
+ }
22626
+ return result;
22627
+ }
21739
22628
  };
21740
22629
  } // namespace duckdb
22630
+
21741
22631
  //===----------------------------------------------------------------------===//
21742
22632
  // DuckDB
21743
22633
  //
21744
- // duckdb/parser/expression/comparison_expression.hpp
22634
+ // duckdb/parser/expression/constant_expression.hpp
21745
22635
  //
21746
22636
  //
21747
22637
  //===----------------------------------------------------------------------===//
@@ -21750,38 +22640,67 @@ public:
21750
22640
 
21751
22641
 
21752
22642
 
22643
+
21753
22644
  namespace duckdb {
21754
- //! ComparisonExpression represents a boolean comparison (e.g. =, >=, <>). Always returns a boolean
21755
- //! and has two children.
21756
- class ComparisonExpression : public ParsedExpression {
22645
+
22646
+ //! ConstantExpression represents a constant value in the query
22647
+ class ConstantExpression : public ParsedExpression {
21757
22648
  public:
21758
- DUCKDB_API ComparisonExpression(ExpressionType type, unique_ptr<ParsedExpression> left,
21759
- unique_ptr<ParsedExpression> right);
22649
+ DUCKDB_API explicit ConstantExpression(Value val);
21760
22650
 
21761
- unique_ptr<ParsedExpression> left;
21762
- unique_ptr<ParsedExpression> right;
22651
+ //! The constant value referenced
22652
+ Value value;
21763
22653
 
21764
22654
  public:
21765
22655
  string ToString() const override;
21766
22656
 
21767
- static bool Equals(const ComparisonExpression *a, const ComparisonExpression *b);
22657
+ static bool Equals(const ConstantExpression *a, const ConstantExpression *b);
22658
+ hash_t Hash() const override;
21768
22659
 
21769
22660
  unique_ptr<ParsedExpression> Copy() const override;
21770
22661
 
21771
22662
  void Serialize(FieldWriter &writer) const override;
21772
22663
  static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
22664
+ };
22665
+
22666
+ } // namespace duckdb
22667
+
22668
+ //===----------------------------------------------------------------------===//
22669
+ // DuckDB
22670
+ //
22671
+ // duckdb/parser/expression/default_expression.hpp
22672
+ //
22673
+ //
22674
+ //===----------------------------------------------------------------------===//
22675
+
22676
+
22677
+
21773
22678
 
22679
+
22680
+ namespace duckdb {
22681
+ //! Represents the default value of a column
22682
+ class DefaultExpression : public ParsedExpression {
21774
22683
  public:
21775
- template <class T, class BASE>
21776
- static string ToString(const T &entry) {
21777
- return entry.left->ToString() + " " + ExpressionTypeToOperator(entry.type) + " " + entry.right->ToString();
22684
+ DefaultExpression();
22685
+
22686
+ public:
22687
+ bool IsScalar() const override {
22688
+ return false;
21778
22689
  }
22690
+
22691
+ string ToString() const override;
22692
+
22693
+ unique_ptr<ParsedExpression> Copy() const override;
22694
+
22695
+ void Serialize(FieldWriter &writer) const override;
22696
+ static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
21779
22697
  };
21780
22698
  } // namespace duckdb
22699
+
21781
22700
  //===----------------------------------------------------------------------===//
21782
22701
  // DuckDB
21783
22702
  //
21784
- // duckdb/parser/expression/constant_expression.hpp
22703
+ // duckdb/parser/expression/function_expression.hpp
21785
22704
  //
21786
22705
  //
21787
22706
  //===----------------------------------------------------------------------===//
@@ -21791,29 +22710,109 @@ public:
21791
22710
 
21792
22711
 
21793
22712
 
21794
- namespace duckdb {
21795
22713
 
21796
- //! ConstantExpression represents a constant value in the query
21797
- class ConstantExpression : public ParsedExpression {
22714
+ namespace duckdb {
22715
+ //! Represents a function call
22716
+ class FunctionExpression : public ParsedExpression {
21798
22717
  public:
21799
- DUCKDB_API explicit ConstantExpression(Value val);
22718
+ DUCKDB_API FunctionExpression(string schema_name, const string &function_name,
22719
+ vector<unique_ptr<ParsedExpression>> children,
22720
+ unique_ptr<ParsedExpression> filter = nullptr,
22721
+ unique_ptr<OrderModifier> order_bys = nullptr, bool distinct = false,
22722
+ bool is_operator = false, bool export_state = false);
22723
+ DUCKDB_API FunctionExpression(const string &function_name, vector<unique_ptr<ParsedExpression>> children,
22724
+ unique_ptr<ParsedExpression> filter = nullptr,
22725
+ unique_ptr<OrderModifier> order_bys = nullptr, bool distinct = false,
22726
+ bool is_operator = false, bool export_state = false);
21800
22727
 
21801
- //! The constant value referenced
21802
- Value value;
22728
+ //! Schema of the function
22729
+ string schema;
22730
+ //! Function name
22731
+ string function_name;
22732
+ //! Whether or not the function is an operator, only used for rendering
22733
+ bool is_operator;
22734
+ //! List of arguments to the function
22735
+ vector<unique_ptr<ParsedExpression>> children;
22736
+ //! Whether or not the aggregate function is distinct, only used for aggregates
22737
+ bool distinct;
22738
+ //! Expression representing a filter, only used for aggregates
22739
+ unique_ptr<ParsedExpression> filter;
22740
+ //! Modifier representing an ORDER BY, only used for aggregates
22741
+ unique_ptr<OrderModifier> order_bys;
22742
+ //! whether this function should export its state or not
22743
+ bool export_state;
21803
22744
 
21804
22745
  public:
21805
22746
  string ToString() const override;
21806
22747
 
21807
- static bool Equals(const ConstantExpression *a, const ConstantExpression *b);
21808
- hash_t Hash() const override;
21809
-
21810
22748
  unique_ptr<ParsedExpression> Copy() const override;
21811
22749
 
22750
+ static bool Equals(const FunctionExpression *a, const FunctionExpression *b);
22751
+ hash_t Hash() const override;
22752
+
21812
22753
  void Serialize(FieldWriter &writer) const override;
21813
22754
  static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
21814
- };
21815
22755
 
22756
+ void Verify() const override;
22757
+
22758
+ public:
22759
+ template <class T, class BASE>
22760
+ static string ToString(const T &entry, const string &schema, const string &function_name, bool is_operator = false,
22761
+ bool distinct = false, BASE *filter = nullptr, OrderModifier *order_bys = nullptr,
22762
+ bool export_state = false) {
22763
+ if (is_operator) {
22764
+ // built-in operator
22765
+ D_ASSERT(!distinct);
22766
+ if (entry.children.size() == 1) {
22767
+ if (StringUtil::Contains(function_name, "__postfix")) {
22768
+ return "(" + entry.children[0]->ToString() + ")" +
22769
+ StringUtil::Replace(function_name, "__postfix", "");
22770
+ } else {
22771
+ return function_name + "(" + entry.children[0]->ToString() + ")";
22772
+ }
22773
+ } else if (entry.children.size() == 2) {
22774
+ return "(" + entry.children[0]->ToString() + " " + function_name + " " + entry.children[1]->ToString() +
22775
+ ")";
22776
+ }
22777
+ }
22778
+ // standard function call
22779
+ string result = schema.empty() ? function_name : schema + "." + function_name;
22780
+ result += "(";
22781
+ if (distinct) {
22782
+ result += "DISTINCT ";
22783
+ }
22784
+ result += StringUtil::Join(entry.children, entry.children.size(), ", ",
22785
+ [](const unique_ptr<BASE> &child) { return child->ToString(); });
22786
+ // ordered aggregate
22787
+ if (order_bys && !order_bys->orders.empty()) {
22788
+ if (entry.children.empty()) {
22789
+ result += ") WITHIN GROUP (";
22790
+ }
22791
+ result += " ORDER BY ";
22792
+ for (idx_t i = 0; i < order_bys->orders.size(); i++) {
22793
+ if (i > 0) {
22794
+ result += ", ";
22795
+ }
22796
+ result += order_bys->orders[i].ToString();
22797
+ }
22798
+ }
22799
+ result += ")";
22800
+
22801
+ // filtered aggregate
22802
+ if (filter) {
22803
+ result += " FILTER (WHERE " + filter->ToString() + ")";
22804
+ }
22805
+
22806
+ if (export_state) {
22807
+ result += " EXPORT_STATE";
22808
+ }
22809
+
22810
+ return result;
22811
+ }
22812
+ };
21816
22813
  } // namespace duckdb
22814
+
22815
+
21817
22816
  //===----------------------------------------------------------------------===//
21818
22817
  // DuckDB
21819
22818
  //
@@ -21914,50 +22913,11 @@ public:
21914
22913
  };
21915
22914
 
21916
22915
  } // namespace duckdb
21917
- //===----------------------------------------------------------------------===//
21918
- // DuckDB
21919
- //
21920
- // duckdb/parser/expression/between_expression.hpp
21921
- //
21922
- //
21923
- //===----------------------------------------------------------------------===//
21924
-
21925
-
21926
-
21927
-
21928
-
21929
- namespace duckdb {
21930
-
21931
- class BetweenExpression : public ParsedExpression {
21932
- public:
21933
- BetweenExpression(unique_ptr<ParsedExpression> input, unique_ptr<ParsedExpression> lower,
21934
- unique_ptr<ParsedExpression> upper);
21935
-
21936
- unique_ptr<ParsedExpression> input;
21937
- unique_ptr<ParsedExpression> lower;
21938
- unique_ptr<ParsedExpression> upper;
21939
-
21940
- public:
21941
- string ToString() const override;
21942
-
21943
- static bool Equals(const BetweenExpression *a, const BetweenExpression *b);
21944
-
21945
- unique_ptr<ParsedExpression> Copy() const override;
21946
-
21947
- void Serialize(FieldWriter &writer) const override;
21948
- static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
21949
22916
 
21950
- public:
21951
- template <class T, class BASE>
21952
- static string ToString(const T &entry) {
21953
- return entry.input->ToString() + " BETWEEN " + entry.lower->ToString() + " AND " + entry.upper->ToString();
21954
- }
21955
- };
21956
- } // namespace duckdb
21957
22917
  //===----------------------------------------------------------------------===//
21958
22918
  // DuckDB
21959
22919
  //
21960
- // duckdb/parser/expression/positional_reference_expression.hpp
22920
+ // duckdb/parser/expression/parameter_expression.hpp
21961
22921
  //
21962
22922
  //
21963
22923
  //===----------------------------------------------------------------------===//
@@ -21967,124 +22927,34 @@ public:
21967
22927
 
21968
22928
 
21969
22929
  namespace duckdb {
21970
- class PositionalReferenceExpression : public ParsedExpression {
22930
+ class ParameterExpression : public ParsedExpression {
21971
22931
  public:
21972
- DUCKDB_API PositionalReferenceExpression(idx_t index);
22932
+ ParameterExpression();
21973
22933
 
21974
- idx_t index;
22934
+ idx_t parameter_nr;
21975
22935
 
21976
22936
  public:
21977
22937
  bool IsScalar() const override {
21978
- return false;
22938
+ return true;
21979
22939
  }
21980
-
21981
- string ToString() const override;
21982
-
21983
- static bool Equals(const PositionalReferenceExpression *a, const PositionalReferenceExpression *b);
21984
- unique_ptr<ParsedExpression> Copy() const override;
21985
- hash_t Hash() const override;
21986
-
21987
- void Serialize(FieldWriter &writer) const override;
21988
- static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
21989
- };
21990
- } // namespace duckdb
21991
-
21992
-
21993
-
21994
- //===----------------------------------------------------------------------===//
21995
- // DuckDB
21996
- //
21997
- // duckdb/parser/expression/cast_expression.hpp
21998
- //
21999
- //
22000
- //===----------------------------------------------------------------------===//
22001
-
22002
-
22003
-
22004
-
22005
-
22006
-
22007
- namespace duckdb {
22008
-
22009
- //! CastExpression represents a type cast from one SQL type to another SQL type
22010
- class CastExpression : public ParsedExpression {
22011
- public:
22012
- DUCKDB_API CastExpression(LogicalType target, unique_ptr<ParsedExpression> child, bool try_cast = false);
22013
-
22014
- //! The child of the cast expression
22015
- unique_ptr<ParsedExpression> child;
22016
- //! The type to cast to
22017
- LogicalType cast_type;
22018
- //! Whether or not this is a try_cast expression
22019
- bool try_cast;
22020
-
22021
- public:
22022
- string ToString() const override;
22023
-
22024
- static bool Equals(const CastExpression *a, const CastExpression *b);
22025
-
22026
- unique_ptr<ParsedExpression> Copy() const override;
22027
-
22028
- void Serialize(FieldWriter &writer) const override;
22029
- static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
22030
-
22031
- public:
22032
- template <class T, class BASE>
22033
- static string ToString(const T &entry) {
22034
- return (entry.try_cast ? "TRY_CAST(" : "CAST(") + entry.child->ToString() + " AS " +
22035
- entry.cast_type.ToString() + ")";
22940
+ bool HasParameter() const override {
22941
+ return true;
22036
22942
  }
22037
- };
22038
- } // namespace duckdb
22039
-
22040
- //===----------------------------------------------------------------------===//
22041
- // DuckDB
22042
- //
22043
- // duckdb/parser/expression/collate_expression.hpp
22044
- //
22045
- //
22046
- //===----------------------------------------------------------------------===//
22047
-
22048
-
22049
-
22050
-
22051
-
22052
- namespace duckdb {
22053
-
22054
- //! CollateExpression represents a COLLATE statement
22055
- class CollateExpression : public ParsedExpression {
22056
- public:
22057
- CollateExpression(string collation, unique_ptr<ParsedExpression> child);
22058
-
22059
- //! The child of the cast expression
22060
- unique_ptr<ParsedExpression> child;
22061
- //! The collation clause
22062
- string collation;
22063
22943
 
22064
- public:
22065
22944
  string ToString() const override;
22066
22945
 
22067
- static bool Equals(const CollateExpression *a, const CollateExpression *b);
22068
-
22069
22946
  unique_ptr<ParsedExpression> Copy() const override;
22947
+ hash_t Hash() const override;
22070
22948
 
22071
22949
  void Serialize(FieldWriter &writer) const override;
22072
22950
  static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
22073
22951
  };
22074
22952
  } // namespace duckdb
22075
22953
 
22076
-
22077
-
22078
-
22079
-
22080
-
22081
-
22082
-
22083
-
22084
22954
  //===----------------------------------------------------------------------===//
22085
22955
  // DuckDB
22086
22956
  //
22087
- // duckdb/parser/expression/parameter_expression.hpp
22957
+ // duckdb/parser/expression/positional_reference_expression.hpp
22088
22958
  //
22089
22959
  //
22090
22960
  //===----------------------------------------------------------------------===//
@@ -22094,22 +22964,20 @@ public:
22094
22964
 
22095
22965
 
22096
22966
  namespace duckdb {
22097
- class ParameterExpression : public ParsedExpression {
22967
+ class PositionalReferenceExpression : public ParsedExpression {
22098
22968
  public:
22099
- ParameterExpression();
22969
+ DUCKDB_API PositionalReferenceExpression(idx_t index);
22100
22970
 
22101
- idx_t parameter_nr;
22971
+ idx_t index;
22102
22972
 
22103
22973
  public:
22104
22974
  bool IsScalar() const override {
22105
- return true;
22106
- }
22107
- bool HasParameter() const override {
22108
- return true;
22975
+ return false;
22109
22976
  }
22110
22977
 
22111
22978
  string ToString() const override;
22112
22979
 
22980
+ static bool Equals(const PositionalReferenceExpression *a, const PositionalReferenceExpression *b);
22113
22981
  unique_ptr<ParsedExpression> Copy() const override;
22114
22982
  hash_t Hash() const override;
22115
22983
 
@@ -22118,7 +22986,6 @@ public:
22118
22986
  };
22119
22987
  } // namespace duckdb
22120
22988
 
22121
-
22122
22989
  //===----------------------------------------------------------------------===//
22123
22990
  // DuckDB
22124
22991
  //
@@ -22254,7 +23121,7 @@ public:
22254
23121
  //===----------------------------------------------------------------------===//
22255
23122
  // DuckDB
22256
23123
  //
22257
- // duckdb/parser/parsed_data/vacuum_info.hpp
23124
+ // duckdb/parser/parsed_data/create_schema_info.hpp
22258
23125
  //
22259
23126
  //
22260
23127
  //===----------------------------------------------------------------------===//
@@ -22265,18 +23132,15 @@ public:
22265
23132
 
22266
23133
  namespace duckdb {
22267
23134
 
22268
- enum class LoadType { LOAD, INSTALL, FORCE_INSTALL };
22269
-
22270
- struct LoadInfo : public ParseInfo {
22271
- std::string filename;
22272
- LoadType load_type;
23135
+ struct CreateSchemaInfo : public CreateInfo {
23136
+ CreateSchemaInfo() : CreateInfo(CatalogType::SCHEMA_ENTRY) {
23137
+ }
22273
23138
 
22274
23139
  public:
22275
- unique_ptr<LoadInfo> Copy() const {
22276
- auto result = make_unique<LoadInfo>();
22277
- result->filename = filename;
22278
- result->load_type = load_type;
22279
- return result;
23140
+ unique_ptr<CreateInfo> Copy() const override {
23141
+ auto result = make_unique<CreateSchemaInfo>();
23142
+ CopyProperties(*result);
23143
+ return move(result);
22280
23144
  }
22281
23145
  };
22282
23146
 
@@ -22320,7 +23184,26 @@ struct ShowSelectInfo : public ParseInfo {
22320
23184
  //===----------------------------------------------------------------------===//
22321
23185
  // DuckDB
22322
23186
  //
22323
- // duckdb/parser/parsed_data/create_aggregate_function_info.hpp
23187
+ // duckdb/parser/parsed_data/vacuum_info.hpp
23188
+ //
23189
+ //
23190
+ //===----------------------------------------------------------------------===//
23191
+
23192
+
23193
+
23194
+
23195
+
23196
+ namespace duckdb {
23197
+
23198
+ struct VacuumInfo : public ParseInfo {
23199
+ // nothing for now
23200
+ };
23201
+
23202
+ } // namespace duckdb
23203
+ //===----------------------------------------------------------------------===//
23204
+ // DuckDB
23205
+ //
23206
+ // duckdb/parser/parsed_data/create_index_info.hpp
22324
23207
  //
22325
23208
  //
22326
23209
  //===----------------------------------------------------------------------===//
@@ -22330,38 +23213,10 @@ struct ShowSelectInfo : public ParseInfo {
22330
23213
 
22331
23214
 
22332
23215
 
22333
- namespace duckdb {
22334
-
22335
- struct CreateAggregateFunctionInfo : public CreateFunctionInfo {
22336
- explicit CreateAggregateFunctionInfo(AggregateFunction function)
22337
- : CreateFunctionInfo(CatalogType::AGGREGATE_FUNCTION_ENTRY), functions(function.name) {
22338
- this->name = function.name;
22339
- functions.AddFunction(move(function));
22340
- }
22341
-
22342
- explicit CreateAggregateFunctionInfo(AggregateFunctionSet set)
22343
- : CreateFunctionInfo(CatalogType::AGGREGATE_FUNCTION_ENTRY), functions(move(set)) {
22344
- this->name = functions.name;
22345
- for (auto &func : functions.functions) {
22346
- func.name = functions.name;
22347
- }
22348
- }
22349
-
22350
- AggregateFunctionSet functions;
22351
-
22352
- public:
22353
- unique_ptr<CreateInfo> Copy() const override {
22354
- auto result = make_unique<CreateAggregateFunctionInfo>(functions);
22355
- CopyProperties(*result);
22356
- return move(result);
22357
- }
22358
- };
22359
-
22360
- } // namespace duckdb
22361
23216
  //===----------------------------------------------------------------------===//
22362
23217
  // DuckDB
22363
23218
  //
22364
- // duckdb/parser/parsed_data/create_type_info.hpp
23219
+ // duckdb/parser/tableref/basetableref.hpp
22365
23220
  //
22366
23221
  //
22367
23222
  //===----------------------------------------------------------------------===//
@@ -22371,26 +23226,63 @@ public:
22371
23226
 
22372
23227
 
22373
23228
 
23229
+ namespace duckdb {
23230
+ //! Represents a TableReference to a base table in the schema
23231
+ class BaseTableRef : public TableRef {
23232
+ public:
23233
+ BaseTableRef() : TableRef(TableReferenceType::BASE_TABLE), schema_name(INVALID_SCHEMA) {
23234
+ }
22374
23235
 
23236
+ //! Schema name
23237
+ string schema_name;
23238
+ //! Table name
23239
+ string table_name;
23240
+ //! Aliases for the column names
23241
+ vector<string> column_name_alias;
22375
23242
 
22376
- namespace duckdb {
23243
+ public:
23244
+ string ToString() const override;
23245
+ bool Equals(const TableRef *other_p) const override;
22377
23246
 
22378
- struct CreateTypeInfo : public CreateInfo {
23247
+ unique_ptr<TableRef> Copy() override;
22379
23248
 
22380
- CreateTypeInfo() : CreateInfo(CatalogType::TYPE_ENTRY) {
23249
+ //! Serializes a blob into a BaseTableRef
23250
+ void Serialize(FieldWriter &serializer) const override;
23251
+ //! Deserializes a blob back into a BaseTableRef
23252
+ static unique_ptr<TableRef> Deserialize(FieldReader &source);
23253
+ };
23254
+ } // namespace duckdb
23255
+
23256
+
23257
+
23258
+ namespace duckdb {
23259
+
23260
+ struct CreateIndexInfo : public CreateInfo {
23261
+ CreateIndexInfo() : CreateInfo(CatalogType::INDEX_ENTRY) {
22381
23262
  }
22382
23263
 
22383
- //! Name of the Type
22384
- string name;
22385
- //! Logical Type
22386
- LogicalType type;
23264
+ //! Index Type (e.g., B+-tree, Skip-List, ...)
23265
+ IndexType index_type;
23266
+ //! Name of the Index
23267
+ string index_name;
23268
+ //! If it is an unique index
23269
+ bool unique = false;
23270
+ //! The table to create the index on
23271
+ unique_ptr<BaseTableRef> table;
23272
+ //! Set of expressions to index by
23273
+ vector<unique_ptr<ParsedExpression>> expressions;
22387
23274
 
22388
23275
  public:
22389
23276
  unique_ptr<CreateInfo> Copy() const override {
22390
- auto result = make_unique<CreateTypeInfo>();
23277
+ auto result = make_unique<CreateIndexInfo>();
22391
23278
  CopyProperties(*result);
22392
- result->name = name;
22393
- result->type = type;
23279
+ result->index_type = index_type;
23280
+ result->index_name = index_name;
23281
+ result->unique = unique;
23282
+ result->table = unique_ptr_cast<TableRef, BaseTableRef>(table->Copy());
23283
+ for (auto &expr : expressions) {
23284
+ result->expressions.push_back(expr->Copy());
23285
+ }
22394
23286
  return move(result);
22395
23287
  }
22396
23288
  };
@@ -22399,7 +23291,7 @@ public:
22399
23291
  //===----------------------------------------------------------------------===//
22400
23292
  // DuckDB
22401
23293
  //
22402
- // duckdb/parser/parsed_data/vacuum_info.hpp
23294
+ // duckdb/parser/parsed_data/transaction_info.hpp
22403
23295
  //
22404
23296
  //
22405
23297
  //===----------------------------------------------------------------------===//
@@ -22410,15 +23302,21 @@ public:
22410
23302
 
22411
23303
  namespace duckdb {
22412
23304
 
22413
- struct VacuumInfo : public ParseInfo {
22414
- // nothing for now
23305
+ enum class TransactionType : uint8_t { INVALID, BEGIN_TRANSACTION, COMMIT, ROLLBACK };
23306
+
23307
+ struct TransactionInfo : public ParseInfo {
23308
+ explicit TransactionInfo(TransactionType type) : type(type) {
23309
+ }
23310
+
23311
+ //! The type of transaction statement
23312
+ TransactionType type;
22415
23313
  };
22416
23314
 
22417
23315
  } // namespace duckdb
22418
23316
  //===----------------------------------------------------------------------===//
22419
23317
  // DuckDB
22420
23318
  //
22421
- // duckdb/parser/parsed_data/drop_info.hpp
23319
+ // duckdb/parser/parsed_data/create_type_info.hpp
22422
23320
  //
22423
23321
  //
22424
23322
  //===----------------------------------------------------------------------===//
@@ -22428,33 +23326,27 @@ struct VacuumInfo : public ParseInfo {
22428
23326
 
22429
23327
 
22430
23328
 
23329
+
23330
+
22431
23331
  namespace duckdb {
22432
23332
 
22433
- struct DropInfo : public ParseInfo {
22434
- DropInfo() : schema(INVALID_SCHEMA), if_exists(false), cascade(false) {
23333
+ struct CreateTypeInfo : public CreateInfo {
23334
+
23335
+ CreateTypeInfo() : CreateInfo(CatalogType::TYPE_ENTRY) {
22435
23336
  }
22436
23337
 
22437
- //! The catalog type to drop
22438
- CatalogType type;
22439
- //! Schema name to drop from, if any
22440
- string schema;
22441
- //! Element name to drop
23338
+ //! Name of the Type
22442
23339
  string name;
22443
- //! Ignore if the entry does not exist instead of failing
22444
- bool if_exists = false;
22445
- //! Cascade drop (drop all dependents instead of throwing an error if there
22446
- //! are any)
22447
- bool cascade = false;
23340
+ //! Logical Type
23341
+ LogicalType type;
22448
23342
 
22449
23343
  public:
22450
- unique_ptr<DropInfo> Copy() const {
22451
- auto result = make_unique<DropInfo>();
22452
- result->type = type;
22453
- result->schema = schema;
23344
+ unique_ptr<CreateInfo> Copy() const override {
23345
+ auto result = make_unique<CreateTypeInfo>();
23346
+ CopyProperties(*result);
22454
23347
  result->name = name;
22455
- result->if_exists = if_exists;
22456
- result->cascade = cascade;
22457
- return result;
23348
+ result->type = type;
23349
+ return move(result);
22458
23350
  }
22459
23351
  };
22460
23352
 
@@ -22462,7 +23354,7 @@ public:
22462
23354
  //===----------------------------------------------------------------------===//
22463
23355
  // DuckDB
22464
23356
  //
22465
- // duckdb/parser/parsed_data/transaction_info.hpp
23357
+ // duckdb/parser/parsed_data/create_view_info.hpp
22466
23358
  //
22467
23359
  //
22468
23360
  //===----------------------------------------------------------------------===//
@@ -22471,16 +23363,34 @@ public:
22471
23363
 
22472
23364
 
22473
23365
 
22474
- namespace duckdb {
22475
23366
 
22476
- enum class TransactionType : uint8_t { INVALID, BEGIN_TRANSACTION, COMMIT, ROLLBACK };
23367
+ namespace duckdb {
22477
23368
 
22478
- struct TransactionInfo : public ParseInfo {
22479
- explicit TransactionInfo(TransactionType type) : type(type) {
23369
+ struct CreateViewInfo : public CreateInfo {
23370
+ CreateViewInfo() : CreateInfo(CatalogType::VIEW_ENTRY, INVALID_SCHEMA) {
23371
+ }
23372
+ CreateViewInfo(string schema, string view_name)
23373
+ : CreateInfo(CatalogType::VIEW_ENTRY, schema), view_name(view_name) {
22480
23374
  }
22481
23375
 
22482
- //! The type of transaction statement
22483
- TransactionType type;
23376
+ //! Table name to insert to
23377
+ string view_name;
23378
+ //! Aliases of the view
23379
+ vector<string> aliases;
23380
+ //! Return types
23381
+ vector<LogicalType> types;
23382
+ //! The SelectStatement of the view
23383
+ unique_ptr<SelectStatement> query;
23384
+
23385
+ public:
23386
+ unique_ptr<CreateInfo> Copy() const override {
23387
+ auto result = make_unique<CreateViewInfo>(schema, view_name);
23388
+ CopyProperties(*result);
23389
+ result->aliases = aliases;
23390
+ result->types = types;
23391
+ result->query = unique_ptr_cast<SQLStatement, SelectStatement>(query->Copy());
23392
+ return move(result);
23393
+ }
22484
23394
  };
22485
23395
 
22486
23396
  } // namespace duckdb
@@ -22504,6 +23414,8 @@ struct TransactionInfo : public ParseInfo {
22504
23414
  //===----------------------------------------------------------------------===//
22505
23415
 
22506
23416
 
23417
+ //! The SelectStatement of the view
23418
+
22507
23419
 
22508
23420
 
22509
23421
 
@@ -22512,25 +23424,33 @@ struct TransactionInfo : public ParseInfo {
22512
23424
 
22513
23425
  namespace duckdb {
22514
23426
 
22515
- class MacroCatalogEntry;
23427
+ enum class MacroType : uint8_t { VOID_MACRO = 0, TABLE_MACRO = 1, SCALAR_MACRO = 2 };
22516
23428
 
22517
23429
  class MacroFunction {
22518
23430
  public:
22519
- explicit MacroFunction(unique_ptr<ParsedExpression> expression);
23431
+ // explicit MacroFunction(unique_ptr<ParsedExpression> expression);
23432
+ MacroFunction(MacroType type);
22520
23433
 
22521
- //! Check whether the supplied arguments are valid
22522
- static string ValidateArguments(MacroCatalogEntry &macro_func, FunctionExpression &function_expr,
22523
- vector<unique_ptr<ParsedExpression>> &positionals,
22524
- unordered_map<string, unique_ptr<ParsedExpression>> &defaults);
22525
- //! The macro expression
22526
- unique_ptr<ParsedExpression> expression;
23434
+ // MacroFunction(void);
23435
+ // The type
23436
+ MacroType type;
22527
23437
  //! The positional parameters
22528
23438
  vector<unique_ptr<ParsedExpression>> parameters;
22529
23439
  //! The default parameters and their associated values
22530
23440
  unordered_map<string, unique_ptr<ParsedExpression>> default_parameters;
22531
23441
 
22532
23442
  public:
22533
- unique_ptr<MacroFunction> Copy();
23443
+ virtual ~MacroFunction() {
23444
+ }
23445
+
23446
+ void CopyProperties(MacroFunction &other);
23447
+
23448
+ virtual unique_ptr<MacroFunction> Copy() = 0;
23449
+
23450
+ static string ValidateArguments(MacroFunction &macro_function, const string &name,
23451
+ FunctionExpression &function_expr,
23452
+ vector<unique_ptr<ParsedExpression>> &positionals,
23453
+ unordered_map<string, unique_ptr<ParsedExpression>> &defaults);
22534
23454
  };
22535
23455
 
22536
23456
  } // namespace duckdb
@@ -22542,6 +23462,9 @@ struct CreateMacroInfo : public CreateFunctionInfo {
22542
23462
  CreateMacroInfo() : CreateFunctionInfo(CatalogType::MACRO_ENTRY, INVALID_SCHEMA) {
22543
23463
  }
22544
23464
 
23465
+ CreateMacroInfo(CatalogType type) : CreateFunctionInfo(type, INVALID_SCHEMA) {
23466
+ }
23467
+
22545
23468
  unique_ptr<MacroFunction> function;
22546
23469
 
22547
23470
  public:
@@ -22558,47 +23481,7 @@ public:
22558
23481
  //===----------------------------------------------------------------------===//
22559
23482
  // DuckDB
22560
23483
  //
22561
- // duckdb/parser/parsed_data/create_schema_info.hpp
22562
- //
22563
- //
22564
- //===----------------------------------------------------------------------===//
22565
-
22566
-
22567
-
22568
-
22569
-
22570
- namespace duckdb {
22571
-
22572
- struct CreateSchemaInfo : public CreateInfo {
22573
- CreateSchemaInfo() : CreateInfo(CatalogType::SCHEMA_ENTRY) {
22574
- }
22575
-
22576
- public:
22577
- unique_ptr<CreateInfo> Copy() const override {
22578
- auto result = make_unique<CreateSchemaInfo>();
22579
- CopyProperties(*result);
22580
- return move(result);
22581
- }
22582
- };
22583
-
22584
- } // namespace duckdb
22585
- //===----------------------------------------------------------------------===//
22586
- // DuckDB
22587
- //
22588
- // duckdb/parser/parsed_data/create_index_info.hpp
22589
- //
22590
- //
22591
- //===----------------------------------------------------------------------===//
22592
-
22593
-
22594
-
22595
-
22596
-
22597
-
22598
- //===----------------------------------------------------------------------===//
22599
- // DuckDB
22600
- //
22601
- // duckdb/parser/tableref/basetableref.hpp
23484
+ // duckdb/parser/parsed_data/export_table_data.hpp
22602
23485
  //
22603
23486
  //
22604
23487
  //===----------------------------------------------------------------------===//
@@ -22609,63 +23492,54 @@ public:
22609
23492
 
22610
23493
 
22611
23494
  namespace duckdb {
22612
- //! Represents a TableReference to a base table in the schema
22613
- class BaseTableRef : public TableRef {
22614
- public:
22615
- BaseTableRef() : TableRef(TableReferenceType::BASE_TABLE), schema_name(INVALID_SCHEMA) {
22616
- }
22617
23495
 
22618
- //! Schema name
22619
- string schema_name;
22620
- //! Table name
23496
+ struct ExportedTableData {
23497
+ //! Name of the exported table
22621
23498
  string table_name;
22622
- //! Aliases for the column names
22623
- vector<string> column_name_alias;
22624
23499
 
22625
- public:
22626
- string ToString() const override;
22627
- bool Equals(const TableRef *other_p) const override;
23500
+ //! Name of the schema
23501
+ string schema_name;
22628
23502
 
22629
- unique_ptr<TableRef> Copy() override;
23503
+ //! Path to be exported
23504
+ string file_path;
23505
+ };
22630
23506
 
22631
- //! Serializes a blob into a BaseTableRef
22632
- void Serialize(FieldWriter &serializer) const override;
22633
- //! Deserializes a blob back into a BaseTableRef
22634
- static unique_ptr<TableRef> Deserialize(FieldReader &source);
23507
+ struct ExportedTableInfo {
23508
+ TableCatalogEntry *entry;
23509
+ ExportedTableData table_data;
23510
+ };
23511
+
23512
+ struct BoundExportData : public ParseInfo {
23513
+ std::vector<ExportedTableInfo> data;
22635
23514
  };
23515
+
22636
23516
  } // namespace duckdb
23517
+ //===----------------------------------------------------------------------===//
23518
+ // DuckDB
23519
+ //
23520
+ // duckdb/parser/parsed_data/vacuum_info.hpp
23521
+ //
23522
+ //
23523
+ //===----------------------------------------------------------------------===//
23524
+
23525
+
22637
23526
 
22638
23527
 
22639
23528
 
22640
23529
  namespace duckdb {
22641
23530
 
22642
- struct CreateIndexInfo : public CreateInfo {
22643
- CreateIndexInfo() : CreateInfo(CatalogType::INDEX_ENTRY) {
22644
- }
23531
+ enum class LoadType { LOAD, INSTALL, FORCE_INSTALL };
22645
23532
 
22646
- //! Index Type (e.g., B+-tree, Skip-List, ...)
22647
- IndexType index_type;
22648
- //! Name of the Index
22649
- string index_name;
22650
- //! If it is an unique index
22651
- bool unique = false;
22652
- //! The table to create the index on
22653
- unique_ptr<BaseTableRef> table;
22654
- //! Set of expressions to index by
22655
- vector<unique_ptr<ParsedExpression>> expressions;
23533
+ struct LoadInfo : public ParseInfo {
23534
+ std::string filename;
23535
+ LoadType load_type;
22656
23536
 
22657
23537
  public:
22658
- unique_ptr<CreateInfo> Copy() const override {
22659
- auto result = make_unique<CreateIndexInfo>();
22660
- CopyProperties(*result);
22661
- result->index_type = index_type;
22662
- result->index_name = index_name;
22663
- result->unique = unique;
22664
- result->table = unique_ptr_cast<TableRef, BaseTableRef>(table->Copy());
22665
- for (auto &expr : expressions) {
22666
- result->expressions.push_back(expr->Copy());
22667
- }
22668
- return move(result);
23538
+ unique_ptr<LoadInfo> Copy() const {
23539
+ auto result = make_unique<LoadInfo>();
23540
+ result->filename = filename;
23541
+ result->load_type = load_type;
23542
+ return result;
22669
23543
  }
22670
23544
  };
22671
23545
 
@@ -22673,7 +23547,7 @@ public:
22673
23547
  //===----------------------------------------------------------------------===//
22674
23548
  // DuckDB
22675
23549
  //
22676
- // duckdb/parser/parsed_data/create_pragma_function_info.hpp
23550
+ // duckdb/parser/parsed_data/create_aggregate_function_info.hpp
22677
23551
  //
22678
23552
  //
22679
23553
  //===----------------------------------------------------------------------===//
@@ -22685,25 +23559,26 @@ public:
22685
23559
 
22686
23560
  namespace duckdb {
22687
23561
 
22688
- struct CreatePragmaFunctionInfo : public CreateFunctionInfo {
22689
- explicit CreatePragmaFunctionInfo(PragmaFunction function)
22690
- : CreateFunctionInfo(CatalogType::PRAGMA_FUNCTION_ENTRY) {
22691
- functions.push_back(move(function));
23562
+ struct CreateAggregateFunctionInfo : public CreateFunctionInfo {
23563
+ explicit CreateAggregateFunctionInfo(AggregateFunction function)
23564
+ : CreateFunctionInfo(CatalogType::AGGREGATE_FUNCTION_ENTRY), functions(function.name) {
22692
23565
  this->name = function.name;
23566
+ functions.AddFunction(move(function));
22693
23567
  }
22694
- CreatePragmaFunctionInfo(string name, vector<PragmaFunction> functions_)
22695
- : CreateFunctionInfo(CatalogType::PRAGMA_FUNCTION_ENTRY), functions(move(functions_)) {
22696
- this->name = name;
22697
- for (auto &function : functions) {
22698
- function.name = name;
23568
+
23569
+ explicit CreateAggregateFunctionInfo(AggregateFunctionSet set)
23570
+ : CreateFunctionInfo(CatalogType::AGGREGATE_FUNCTION_ENTRY), functions(move(set)) {
23571
+ this->name = functions.name;
23572
+ for (auto &func : functions.functions) {
23573
+ func.name = functions.name;
22699
23574
  }
22700
23575
  }
22701
23576
 
22702
- vector<PragmaFunction> functions;
23577
+ AggregateFunctionSet functions;
22703
23578
 
22704
23579
  public:
22705
23580
  unique_ptr<CreateInfo> Copy() const override {
22706
- auto result = make_unique<CreatePragmaFunctionInfo>(functions[0].name, functions);
23581
+ auto result = make_unique<CreateAggregateFunctionInfo>(functions);
22707
23582
  CopyProperties(*result);
22708
23583
  return move(result);
22709
23584
  }
@@ -22713,7 +23588,7 @@ public:
22713
23588
  //===----------------------------------------------------------------------===//
22714
23589
  // DuckDB
22715
23590
  //
22716
- // duckdb/parser/parsed_data/export_table_data.hpp
23591
+ // duckdb/parser/parsed_data/drop_info.hpp
22717
23592
  //
22718
23593
  //
22719
23594
  //===----------------------------------------------------------------------===//
@@ -22725,31 +23600,39 @@ public:
22725
23600
 
22726
23601
  namespace duckdb {
22727
23602
 
22728
- struct ExportedTableData {
22729
- //! Name of the exported table
22730
- string table_name;
22731
-
22732
- //! Name of the schema
22733
- string schema_name;
22734
-
22735
- //! Path to be exported
22736
- string file_path;
22737
- };
23603
+ struct DropInfo : public ParseInfo {
23604
+ DropInfo() : schema(INVALID_SCHEMA), if_exists(false), cascade(false) {
23605
+ }
22738
23606
 
22739
- struct ExportedTableInfo {
22740
- TableCatalogEntry *entry;
22741
- ExportedTableData table_data;
22742
- };
23607
+ //! The catalog type to drop
23608
+ CatalogType type;
23609
+ //! Schema name to drop from, if any
23610
+ string schema;
23611
+ //! Element name to drop
23612
+ string name;
23613
+ //! Ignore if the entry does not exist instead of failing
23614
+ bool if_exists = false;
23615
+ //! Cascade drop (drop all dependents instead of throwing an error if there
23616
+ //! are any)
23617
+ bool cascade = false;
22743
23618
 
22744
- struct BoundExportData : public ParseInfo {
22745
- std::vector<ExportedTableInfo> data;
23619
+ public:
23620
+ unique_ptr<DropInfo> Copy() const {
23621
+ auto result = make_unique<DropInfo>();
23622
+ result->type = type;
23623
+ result->schema = schema;
23624
+ result->name = name;
23625
+ result->if_exists = if_exists;
23626
+ result->cascade = cascade;
23627
+ return result;
23628
+ }
22746
23629
  };
22747
23630
 
22748
23631
  } // namespace duckdb
22749
23632
  //===----------------------------------------------------------------------===//
22750
23633
  // DuckDB
22751
23634
  //
22752
- // duckdb/parser/parsed_data/create_view_info.hpp
23635
+ // duckdb/parser/parsed_data/create_pragma_function_info.hpp
22753
23636
  //
22754
23637
  //
22755
23638
  //===----------------------------------------------------------------------===//
@@ -22761,29 +23644,26 @@ struct BoundExportData : public ParseInfo {
22761
23644
 
22762
23645
  namespace duckdb {
22763
23646
 
22764
- struct CreateViewInfo : public CreateInfo {
22765
- CreateViewInfo() : CreateInfo(CatalogType::VIEW_ENTRY, INVALID_SCHEMA) {
23647
+ struct CreatePragmaFunctionInfo : public CreateFunctionInfo {
23648
+ explicit CreatePragmaFunctionInfo(PragmaFunction function)
23649
+ : CreateFunctionInfo(CatalogType::PRAGMA_FUNCTION_ENTRY) {
23650
+ functions.push_back(move(function));
23651
+ this->name = function.name;
22766
23652
  }
22767
- CreateViewInfo(string schema, string view_name)
22768
- : CreateInfo(CatalogType::VIEW_ENTRY, schema), view_name(view_name) {
23653
+ CreatePragmaFunctionInfo(string name, vector<PragmaFunction> functions_)
23654
+ : CreateFunctionInfo(CatalogType::PRAGMA_FUNCTION_ENTRY), functions(move(functions_)) {
23655
+ this->name = name;
23656
+ for (auto &function : functions) {
23657
+ function.name = name;
23658
+ }
22769
23659
  }
22770
23660
 
22771
- //! Table name to insert to
22772
- string view_name;
22773
- //! Aliases of the view
22774
- vector<string> aliases;
22775
- //! Return types
22776
- vector<LogicalType> types;
22777
- //! The SelectStatement of the view
22778
- unique_ptr<SelectStatement> query;
23661
+ vector<PragmaFunction> functions;
22779
23662
 
22780
23663
  public:
22781
23664
  unique_ptr<CreateInfo> Copy() const override {
22782
- auto result = make_unique<CreateViewInfo>(schema, view_name);
23665
+ auto result = make_unique<CreatePragmaFunctionInfo>(functions[0].name, functions);
22783
23666
  CopyProperties(*result);
22784
- result->aliases = aliases;
22785
- result->types = types;
22786
- result->query = unique_ptr_cast<SQLStatement, SelectStatement>(query->Copy());
22787
23667
  return move(result);
22788
23668
  }
22789
23669
  };
@@ -22792,7 +23672,7 @@ public:
22792
23672
  //===----------------------------------------------------------------------===//
22793
23673
  // DuckDB
22794
23674
  //
22795
- // duckdb/parser/tableref/table_function_ref.hpp
23675
+ // duckdb/parser/tableref/expressionlistref.hpp
22796
23676
  //
22797
23677
  //
22798
23678
  //===----------------------------------------------------------------------===//
@@ -22805,31 +23685,31 @@ public:
22805
23685
 
22806
23686
 
22807
23687
  namespace duckdb {
22808
- //! Represents a Table producing function
22809
- class TableFunctionRef : public TableRef {
23688
+ //! Represents an expression list as generated by a VALUES statement
23689
+ class ExpressionListRef : public TableRef {
22810
23690
  public:
22811
- TableFunctionRef() : TableRef(TableReferenceType::TABLE_FUNCTION) {
23691
+ ExpressionListRef() : TableRef(TableReferenceType::EXPRESSION_LIST) {
22812
23692
  }
22813
23693
 
22814
- unique_ptr<ParsedExpression> function;
22815
- vector<string> column_name_alias;
22816
-
22817
- // if the function takes a subquery as argument its in here
22818
- unique_ptr<SelectStatement> subquery;
23694
+ //! Value list, only used for VALUES statement
23695
+ vector<vector<unique_ptr<ParsedExpression>>> values;
23696
+ //! Expected SQL types
23697
+ vector<LogicalType> expected_types;
23698
+ //! The set of expected names
23699
+ vector<string> expected_names;
22819
23700
 
22820
23701
  public:
22821
- string ToString() const override;
22822
-
22823
23702
  bool Equals(const TableRef *other_p) const override;
22824
23703
 
22825
23704
  unique_ptr<TableRef> Copy() override;
22826
23705
 
22827
- //! Serializes a blob into a BaseTableRef
23706
+ //! Serializes a blob into a ExpressionListRef
22828
23707
  void Serialize(FieldWriter &serializer) const override;
22829
- //! Deserializes a blob back into a BaseTableRef
23708
+ //! Deserializes a blob back into a ExpressionListRef
22830
23709
  static unique_ptr<TableRef> Deserialize(FieldReader &source);
22831
23710
  };
22832
23711
  } // namespace duckdb
23712
+
22833
23713
  //===----------------------------------------------------------------------===//
22834
23714
  // DuckDB
22835
23715
  //
@@ -22865,6 +23745,7 @@ public:
22865
23745
  static unique_ptr<TableRef> Deserialize(FieldReader &source);
22866
23746
  };
22867
23747
  } // namespace duckdb
23748
+
22868
23749
  //===----------------------------------------------------------------------===//
22869
23750
  // DuckDB
22870
23751
  //
@@ -22897,48 +23778,6 @@ public:
22897
23778
  } // namespace duckdb
22898
23779
 
22899
23780
 
22900
-
22901
- //===----------------------------------------------------------------------===//
22902
- // DuckDB
22903
- //
22904
- // duckdb/parser/tableref/expressionlistref.hpp
22905
- //
22906
- //
22907
- //===----------------------------------------------------------------------===//
22908
-
22909
-
22910
-
22911
-
22912
-
22913
-
22914
-
22915
-
22916
- namespace duckdb {
22917
- //! Represents an expression list as generated by a VALUES statement
22918
- class ExpressionListRef : public TableRef {
22919
- public:
22920
- ExpressionListRef() : TableRef(TableReferenceType::EXPRESSION_LIST) {
22921
- }
22922
-
22923
- //! Value list, only used for VALUES statement
22924
- vector<vector<unique_ptr<ParsedExpression>>> values;
22925
- //! Expected SQL types
22926
- vector<LogicalType> expected_types;
22927
- //! The set of expected names
22928
- vector<string> expected_names;
22929
-
22930
- public:
22931
- bool Equals(const TableRef *other_p) const override;
22932
-
22933
- unique_ptr<TableRef> Copy() override;
22934
-
22935
- //! Serializes a blob into a ExpressionListRef
22936
- void Serialize(FieldWriter &serializer) const override;
22937
- //! Deserializes a blob back into a ExpressionListRef
22938
- static unique_ptr<TableRef> Deserialize(FieldReader &source);
22939
- };
22940
- } // namespace duckdb
22941
-
22942
23781
  //===----------------------------------------------------------------------===//
22943
23782
  // DuckDB
22944
23783
  //
@@ -23023,4 +23862,45 @@ public:
23023
23862
  };
23024
23863
  } // namespace duckdb
23025
23864
 
23865
+ //===----------------------------------------------------------------------===//
23866
+ // DuckDB
23867
+ //
23868
+ // duckdb/parser/tableref/table_function_ref.hpp
23869
+ //
23870
+ //
23871
+ //===----------------------------------------------------------------------===//
23872
+
23873
+
23874
+
23875
+
23876
+
23877
+
23878
+
23879
+
23880
+ namespace duckdb {
23881
+ //! Represents a Table producing function
23882
+ class TableFunctionRef : public TableRef {
23883
+ public:
23884
+ TableFunctionRef() : TableRef(TableReferenceType::TABLE_FUNCTION) {
23885
+ }
23886
+
23887
+ unique_ptr<ParsedExpression> function;
23888
+ vector<string> column_name_alias;
23889
+
23890
+ // if the function takes a subquery as argument its in here
23891
+ unique_ptr<SelectStatement> subquery;
23892
+
23893
+ public:
23894
+ string ToString() const override;
23895
+
23896
+ bool Equals(const TableRef *other_p) const override;
23897
+
23898
+ unique_ptr<TableRef> Copy() override;
23899
+
23900
+ //! Serializes a blob into a BaseTableRef
23901
+ void Serialize(FieldWriter &serializer) const override;
23902
+ //! Deserializes a blob back into a BaseTableRef
23903
+ static unique_ptr<TableRef> Deserialize(FieldReader &source);
23904
+ };
23905
+ } // namespace duckdb
23026
23906