duckdb 0.3.5-dev46.0 → 0.3.5-dev464.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/duckdb.hpp CHANGED
@@ -11,8 +11,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
11
11
  #pragma once
12
12
  #define DUCKDB_AMALGAMATION 1
13
13
  #define DUCKDB_AMALGAMATION_EXTENDED 1
14
- #define DUCKDB_SOURCE_ID "0b96d12d4"
15
- #define DUCKDB_VERSION "v0.3.5-dev46"
14
+ #define DUCKDB_SOURCE_ID "e0f76077b"
15
+ #define DUCKDB_VERSION "v0.3.5-dev464"
16
16
  //===----------------------------------------------------------------------===//
17
17
  // DuckDB
18
18
  //
@@ -2789,7 +2789,7 @@ public:
2789
2789
  DUCKDB_API static Value LIST(LogicalType child_type, vector<Value> values);
2790
2790
  //! Create an empty list with the specified child-type
2791
2791
  DUCKDB_API static Value EMPTYLIST(LogicalType child_type);
2792
- //! Creat a map value from a (key, value) pair
2792
+ //! Create a map value from a (key, value) pair
2793
2793
  DUCKDB_API static Value MAP(Value key, Value value);
2794
2794
 
2795
2795
  //! Create a blob Value from a data pointer and a length: no bytes are interpreted
@@ -2882,6 +2882,8 @@ public:
2882
2882
  //! Returns true if the values are (approximately) equivalent. Note this is NOT the SQL equivalence. For this
2883
2883
  //! function, NULL values are equivalent and floating point values that are close are equivalent.
2884
2884
  DUCKDB_API static bool ValuesAreEqual(const Value &result_value, const Value &value);
2885
+ //! Returns true if the values are not distinct from each other, following SQL semantics for NOT DISTINCT FROM.
2886
+ DUCKDB_API static bool NotDistinctFrom(const Value &lvalue, const Value &rvalue);
2885
2887
 
2886
2888
  friend std::ostream &operator<<(std::ostream &out, const Value &val) {
2887
2889
  out << val.ToString();
@@ -3094,6 +3096,8 @@ template <>
3094
3096
  DUCKDB_API timestamp_t Value::GetValue() const;
3095
3097
  template <>
3096
3098
  DUCKDB_API interval_t Value::GetValue() const;
3099
+ template <>
3100
+ DUCKDB_API Value Value::GetValue() const;
3097
3101
 
3098
3102
  template <>
3099
3103
  DUCKDB_API bool Value::GetValueUnsafe() const;
@@ -3974,6 +3978,9 @@ struct SequenceVector {
3974
3978
  extern "C" {
3975
3979
  #endif
3976
3980
 
3981
+ #ifndef ARROW_C_DATA_INTERFACE
3982
+ #define ARROW_C_DATA_INTERFACE
3983
+
3977
3984
  #define ARROW_FLAG_DICTIONARY_ORDERED 1
3978
3985
  #define ARROW_FLAG_NULLABLE 2
3979
3986
  #define ARROW_FLAG_MAP_KEYS_SORTED 4
@@ -4010,7 +4017,10 @@ struct ArrowArray {
4010
4017
  // Opaque producer-specific data
4011
4018
  void *private_data;
4012
4019
  };
4020
+ #endif
4013
4021
 
4022
+ #ifndef ARROW_C_STREAM_INTERFACE
4023
+ #define ARROW_C_STREAM_INTERFACE
4014
4024
  // EXPERIMENTAL
4015
4025
  struct ArrowArrayStream {
4016
4026
  // Callback to get the stream type
@@ -4035,6 +4045,7 @@ struct ArrowArrayStream {
4035
4045
  // Opaque producer-specific data
4036
4046
  void *private_data;
4037
4047
  };
4048
+ #endif
4038
4049
 
4039
4050
  #ifdef __cplusplus
4040
4051
  }
@@ -5315,195 +5326,6 @@ using std::chrono::system_clock;
5315
5326
  using std::chrono::time_point;
5316
5327
  } // namespace duckdb
5317
5328
 
5318
- //===----------------------------------------------------------------------===//
5319
- // DuckDB
5320
- //
5321
- // duckdb/common/random_engine.hpp
5322
- //
5323
- //
5324
- //===----------------------------------------------------------------------===//
5325
-
5326
-
5327
-
5328
-
5329
- //===----------------------------------------------------------------------===//
5330
- // DuckDB
5331
- //
5332
- // duckdb/common/limits.hpp
5333
- //
5334
- //
5335
- //===----------------------------------------------------------------------===//
5336
-
5337
-
5338
-
5339
-
5340
-
5341
- namespace duckdb {
5342
-
5343
- template <class T>
5344
- struct NumericLimits {
5345
- static T Minimum();
5346
- static T Maximum();
5347
- static bool IsSigned();
5348
- static idx_t Digits();
5349
- };
5350
-
5351
- template <>
5352
- struct NumericLimits<int8_t> {
5353
- static int8_t Minimum();
5354
- static int8_t Maximum();
5355
- static bool IsSigned() {
5356
- return true;
5357
- }
5358
- static idx_t Digits() {
5359
- return 3;
5360
- }
5361
- };
5362
- template <>
5363
- struct NumericLimits<int16_t> {
5364
- static int16_t Minimum();
5365
- static int16_t Maximum();
5366
- static bool IsSigned() {
5367
- return true;
5368
- }
5369
- static idx_t Digits() {
5370
- return 5;
5371
- }
5372
- };
5373
- template <>
5374
- struct NumericLimits<int32_t> {
5375
- static int32_t Minimum();
5376
- static int32_t Maximum();
5377
- static bool IsSigned() {
5378
- return true;
5379
- }
5380
- static idx_t Digits() {
5381
- return 10;
5382
- }
5383
- };
5384
- template <>
5385
- struct NumericLimits<int64_t> {
5386
- static int64_t Minimum();
5387
- static int64_t Maximum();
5388
- static bool IsSigned() {
5389
- return true;
5390
- }
5391
- static idx_t Digits() {
5392
- return 19;
5393
- }
5394
- };
5395
- template <>
5396
- struct NumericLimits<hugeint_t> {
5397
- static hugeint_t Minimum();
5398
- static hugeint_t Maximum();
5399
- static bool IsSigned() {
5400
- return true;
5401
- }
5402
- static idx_t Digits() {
5403
- return 39;
5404
- }
5405
- };
5406
- template <>
5407
- struct NumericLimits<uint8_t> {
5408
- static uint8_t Minimum();
5409
- static uint8_t Maximum();
5410
- static bool IsSigned() {
5411
- return false;
5412
- }
5413
- static idx_t Digits() {
5414
- return 3;
5415
- }
5416
- };
5417
- template <>
5418
- struct NumericLimits<uint16_t> {
5419
- static uint16_t Minimum();
5420
- static uint16_t Maximum();
5421
- static bool IsSigned() {
5422
- return false;
5423
- }
5424
- static idx_t Digits() {
5425
- return 5;
5426
- }
5427
- };
5428
- template <>
5429
- struct NumericLimits<uint32_t> {
5430
- static uint32_t Minimum();
5431
- static uint32_t Maximum();
5432
- static bool IsSigned() {
5433
- return false;
5434
- }
5435
- static idx_t Digits() {
5436
- return 10;
5437
- }
5438
- };
5439
- template <>
5440
- struct NumericLimits<uint64_t> {
5441
- static uint64_t Minimum();
5442
- static uint64_t Maximum();
5443
- static bool IsSigned() {
5444
- return false;
5445
- }
5446
- static idx_t Digits() {
5447
- return 20;
5448
- }
5449
- };
5450
- template <>
5451
- struct NumericLimits<float> {
5452
- static float Minimum();
5453
- static float Maximum();
5454
- static bool IsSigned() {
5455
- return true;
5456
- }
5457
- static idx_t Digits() {
5458
- return 127;
5459
- }
5460
- };
5461
- template <>
5462
- struct NumericLimits<double> {
5463
- static double Minimum();
5464
- static double Maximum();
5465
- static bool IsSigned() {
5466
- return true;
5467
- }
5468
- static idx_t Digits() {
5469
- return 250;
5470
- }
5471
- };
5472
-
5473
- } // namespace duckdb
5474
-
5475
- #include <random>
5476
-
5477
- namespace duckdb {
5478
-
5479
- struct RandomEngine {
5480
- std::mt19937 random_engine;
5481
- RandomEngine(int64_t seed = -1) {
5482
- if (seed < 0) {
5483
- std::random_device rd;
5484
- random_engine.seed(rd());
5485
- } else {
5486
- random_engine.seed(seed);
5487
- }
5488
- }
5489
-
5490
- //! Generate a random number between min and max
5491
- double NextRandom(double min, double max) {
5492
- std::uniform_real_distribution<double> dist(min, max);
5493
- return dist(random_engine);
5494
- }
5495
- //! Generate a random number between 0 and 1
5496
- double NextRandom() {
5497
- return NextRandom(0, 1);
5498
- }
5499
- uint32_t NextRandomInteger() {
5500
- std::uniform_int_distribution<uint32_t> dist(0, NumericLimits<uint32_t>::Maximum());
5501
- return dist(random_engine);
5502
- }
5503
- };
5504
-
5505
- } // namespace duckdb
5506
-
5507
5329
 
5508
5330
  namespace duckdb {
5509
5331
 
@@ -5561,7 +5383,6 @@ private:
5561
5383
 
5562
5384
  } // namespace duckdb
5563
5385
 
5564
-
5565
5386
  //===----------------------------------------------------------------------===//
5566
5387
  // DuckDB
5567
5388
  //
@@ -6074,7 +5895,7 @@ public:
6074
5895
  //! Convert the Expression to a String
6075
5896
  virtual string ToString() const = 0;
6076
5897
  //! Print the expression to stdout
6077
- void Print();
5898
+ void Print() const;
6078
5899
 
6079
5900
  //! Creates a hash value of this expression. It is important that if two expressions are identical (i.e.
6080
5901
  //! Expression::Equals() returns true), that their hash value is identical as well.
@@ -6137,7 +5958,7 @@ public:
6137
5958
  static bool RequiresQuotes(const string &text);
6138
5959
 
6139
5960
  //! Writes a string that is optionally quoted + escaped so it can be used as an identifier
6140
- static string WriteOptionallyQuoted(const string &text);
5961
+ static string WriteOptionallyQuoted(const string &text, char quote = '"');
6141
5962
  };
6142
5963
 
6143
5964
  } // namespace duckdb
@@ -6390,14 +6211,19 @@ struct PragmaInfo;
6390
6211
  struct FunctionData {
6391
6212
  DUCKDB_API virtual ~FunctionData();
6392
6213
 
6393
- DUCKDB_API virtual unique_ptr<FunctionData> Copy();
6394
- DUCKDB_API virtual bool Equals(FunctionData &other);
6395
- DUCKDB_API static bool Equals(FunctionData *left, FunctionData *right);
6214
+ DUCKDB_API virtual unique_ptr<FunctionData> Copy() const = 0;
6215
+ DUCKDB_API virtual bool Equals(const FunctionData &other) const = 0;
6216
+ DUCKDB_API static bool Equals(const FunctionData *left, const FunctionData *right);
6396
6217
  };
6397
6218
 
6398
6219
  struct TableFunctionData : public FunctionData {
6399
6220
  // used to pass on projections to table functions that support them. NB, can contain COLUMN_IDENTIFIER_ROW_ID
6400
6221
  vector<idx_t> column_ids;
6222
+
6223
+ DUCKDB_API virtual ~TableFunctionData();
6224
+
6225
+ DUCKDB_API unique_ptr<FunctionData> Copy() const override;
6226
+ DUCKDB_API bool Equals(const FunctionData &other) const override;
6401
6227
  };
6402
6228
 
6403
6229
  struct FunctionParameters {
@@ -6427,11 +6253,14 @@ public:
6427
6253
  //! Bind a scalar function from the set of functions and input arguments. Returns the index of the chosen function,
6428
6254
  //! returns DConstants::INVALID_INDEX and sets error if none could be found
6429
6255
  DUCKDB_API static idx_t BindFunction(const string &name, vector<ScalarFunction> &functions,
6430
- vector<LogicalType> &arguments, string &error);
6256
+ vector<LogicalType> &arguments, string &error, bool &cast_parameters);
6431
6257
  DUCKDB_API static idx_t BindFunction(const string &name, vector<ScalarFunction> &functions,
6432
- vector<unique_ptr<Expression>> &arguments, string &error);
6258
+ vector<unique_ptr<Expression>> &arguments, string &error,
6259
+ bool &cast_parameters);
6433
6260
  //! Bind an aggregate function from the set of functions and input arguments. Returns the index of the chosen
6434
6261
  //! function, returns DConstants::INVALID_INDEX and sets error if none could be found
6262
+ DUCKDB_API static idx_t BindFunction(const string &name, vector<AggregateFunction> &functions,
6263
+ vector<LogicalType> &arguments, string &error, bool &cast_parameters);
6435
6264
  DUCKDB_API static idx_t BindFunction(const string &name, vector<AggregateFunction> &functions,
6436
6265
  vector<LogicalType> &arguments, string &error);
6437
6266
  DUCKDB_API static idx_t BindFunction(const string &name, vector<AggregateFunction> &functions,
@@ -6477,10 +6306,6 @@ public:
6477
6306
  public:
6478
6307
  DUCKDB_API string ToString() override;
6479
6308
  DUCKDB_API bool HasNamedParameters();
6480
-
6481
- DUCKDB_API void EvaluateInputParameters(vector<LogicalType> &arguments, vector<Value> &parameters,
6482
- named_parameter_map_t &named_parameters,
6483
- vector<unique_ptr<ParsedExpression>> &children);
6484
6309
  };
6485
6310
 
6486
6311
  class BaseScalarFunction : public SimpleFunction {
@@ -6502,7 +6327,8 @@ public:
6502
6327
  DUCKDB_API hash_t Hash() const;
6503
6328
 
6504
6329
  //! Cast a set of expressions to the arguments of this function
6505
- DUCKDB_API void CastToFunctionArguments(vector<unique_ptr<Expression>> &children);
6330
+ DUCKDB_API void CastToFunctionArguments(vector<unique_ptr<Expression>> &children,
6331
+ bool cast_parameter_expressions = true);
6506
6332
 
6507
6333
  DUCKDB_API string ToString() override;
6508
6334
  };
@@ -6574,6 +6400,7 @@ namespace duckdb {
6574
6400
  class Expression;
6575
6401
  class ExpressionExecutor;
6576
6402
  struct ExpressionExecutorState;
6403
+ struct FunctionLocalState;
6577
6404
 
6578
6405
  struct ExpressionState {
6579
6406
  ExpressionState(const Expression &expr, ExpressionExecutorState &root);
@@ -6594,13 +6421,13 @@ public:
6594
6421
  };
6595
6422
 
6596
6423
  struct ExecuteFunctionState : public ExpressionState {
6597
- ExecuteFunctionState(const Expression &expr, ExpressionExecutorState &root) : ExpressionState(expr, root) {
6598
- }
6424
+ ExecuteFunctionState(const Expression &expr, ExpressionExecutorState &root);
6425
+ ~ExecuteFunctionState();
6599
6426
 
6600
- unique_ptr<FunctionData> local_state;
6427
+ unique_ptr<FunctionLocalState> local_state;
6601
6428
 
6602
6429
  public:
6603
- static FunctionData *GetFunctionState(ExpressionState &state) {
6430
+ static FunctionLocalState *GetFunctionState(ExpressionState &state) {
6604
6431
  return ((ExecuteFunctionState &)state).local_state.get();
6605
6432
  }
6606
6433
  };
@@ -6651,56 +6478,201 @@ struct ExpressionExecutorState {
6651
6478
 
6652
6479
 
6653
6480
 
6481
+ //===----------------------------------------------------------------------===//
6482
+ // DuckDB
6483
+ //
6484
+ // duckdb/common/limits.hpp
6485
+ //
6486
+ //
6487
+ //===----------------------------------------------------------------------===//
6654
6488
 
6655
6489
 
6656
6490
 
6657
- namespace duckdb {
6658
-
6659
- //! The Hugeint class contains static operations for the INT128 type
6660
- class Hugeint {
6661
- public:
6662
- //! Convert a string to a hugeint object
6663
- static bool FromString(string str, hugeint_t &result);
6664
- //! Convert a string to a hugeint object
6665
- static bool FromCString(const char *str, idx_t len, hugeint_t &result);
6666
- //! Convert a hugeint object to a string
6667
- static string ToString(hugeint_t input);
6668
-
6669
- static hugeint_t FromString(string str) {
6670
- hugeint_t result;
6671
- FromString(str, result);
6672
- return result;
6673
- }
6674
6491
 
6675
- template <class T>
6676
- static bool TryCast(hugeint_t input, T &result);
6677
6492
 
6678
- template <class T>
6679
- static T Cast(hugeint_t input) {
6680
- T value;
6681
- TryCast(input, value);
6682
- return value;
6683
- }
6493
+ namespace duckdb {
6684
6494
 
6685
- template <class T>
6686
- static bool TryConvert(T value, hugeint_t &result);
6495
+ template <class T>
6496
+ struct NumericLimits {
6497
+ static T Minimum();
6498
+ static T Maximum();
6499
+ static bool IsSigned();
6500
+ static idx_t Digits();
6501
+ };
6687
6502
 
6688
- template <class T>
6689
- static hugeint_t Convert(T value) {
6690
- hugeint_t result;
6691
- if (!TryConvert(value, result)) { // LCOV_EXCL_START
6692
- throw ValueOutOfRangeException(double(value), GetTypeId<T>(), GetTypeId<hugeint_t>());
6693
- } // LCOV_EXCL_STOP
6694
- return result;
6503
+ template <>
6504
+ struct NumericLimits<int8_t> {
6505
+ static int8_t Minimum();
6506
+ static int8_t Maximum();
6507
+ static bool IsSigned() {
6508
+ return true;
6695
6509
  }
6696
-
6697
- static void NegateInPlace(hugeint_t &input) {
6698
- input.lower = NumericLimits<uint64_t>::Maximum() - input.lower + 1;
6699
- input.upper = -1 - input.upper + (input.lower == 0);
6510
+ static idx_t Digits() {
6511
+ return 3;
6700
6512
  }
6701
- static hugeint_t Negate(hugeint_t input) {
6702
- NegateInPlace(input);
6703
- return input;
6513
+ };
6514
+ template <>
6515
+ struct NumericLimits<int16_t> {
6516
+ static int16_t Minimum();
6517
+ static int16_t Maximum();
6518
+ static bool IsSigned() {
6519
+ return true;
6520
+ }
6521
+ static idx_t Digits() {
6522
+ return 5;
6523
+ }
6524
+ };
6525
+ template <>
6526
+ struct NumericLimits<int32_t> {
6527
+ static int32_t Minimum();
6528
+ static int32_t Maximum();
6529
+ static bool IsSigned() {
6530
+ return true;
6531
+ }
6532
+ static idx_t Digits() {
6533
+ return 10;
6534
+ }
6535
+ };
6536
+ template <>
6537
+ struct NumericLimits<int64_t> {
6538
+ static int64_t Minimum();
6539
+ static int64_t Maximum();
6540
+ static bool IsSigned() {
6541
+ return true;
6542
+ }
6543
+ static idx_t Digits() {
6544
+ return 19;
6545
+ }
6546
+ };
6547
+ template <>
6548
+ struct NumericLimits<hugeint_t> {
6549
+ static hugeint_t Minimum();
6550
+ static hugeint_t Maximum();
6551
+ static bool IsSigned() {
6552
+ return true;
6553
+ }
6554
+ static idx_t Digits() {
6555
+ return 39;
6556
+ }
6557
+ };
6558
+ template <>
6559
+ struct NumericLimits<uint8_t> {
6560
+ static uint8_t Minimum();
6561
+ static uint8_t Maximum();
6562
+ static bool IsSigned() {
6563
+ return false;
6564
+ }
6565
+ static idx_t Digits() {
6566
+ return 3;
6567
+ }
6568
+ };
6569
+ template <>
6570
+ struct NumericLimits<uint16_t> {
6571
+ static uint16_t Minimum();
6572
+ static uint16_t Maximum();
6573
+ static bool IsSigned() {
6574
+ return false;
6575
+ }
6576
+ static idx_t Digits() {
6577
+ return 5;
6578
+ }
6579
+ };
6580
+ template <>
6581
+ struct NumericLimits<uint32_t> {
6582
+ static uint32_t Minimum();
6583
+ static uint32_t Maximum();
6584
+ static bool IsSigned() {
6585
+ return false;
6586
+ }
6587
+ static idx_t Digits() {
6588
+ return 10;
6589
+ }
6590
+ };
6591
+ template <>
6592
+ struct NumericLimits<uint64_t> {
6593
+ static uint64_t Minimum();
6594
+ static uint64_t Maximum();
6595
+ static bool IsSigned() {
6596
+ return false;
6597
+ }
6598
+ static idx_t Digits() {
6599
+ return 20;
6600
+ }
6601
+ };
6602
+ template <>
6603
+ struct NumericLimits<float> {
6604
+ static float Minimum();
6605
+ static float Maximum();
6606
+ static bool IsSigned() {
6607
+ return true;
6608
+ }
6609
+ static idx_t Digits() {
6610
+ return 127;
6611
+ }
6612
+ };
6613
+ template <>
6614
+ struct NumericLimits<double> {
6615
+ static double Minimum();
6616
+ static double Maximum();
6617
+ static bool IsSigned() {
6618
+ return true;
6619
+ }
6620
+ static idx_t Digits() {
6621
+ return 250;
6622
+ }
6623
+ };
6624
+
6625
+ } // namespace duckdb
6626
+
6627
+
6628
+
6629
+ namespace duckdb {
6630
+
6631
+ //! The Hugeint class contains static operations for the INT128 type
6632
+ class Hugeint {
6633
+ public:
6634
+ //! Convert a string to a hugeint object
6635
+ static bool FromString(string str, hugeint_t &result);
6636
+ //! Convert a string to a hugeint object
6637
+ static bool FromCString(const char *str, idx_t len, hugeint_t &result);
6638
+ //! Convert a hugeint object to a string
6639
+ static string ToString(hugeint_t input);
6640
+
6641
+ static hugeint_t FromString(string str) {
6642
+ hugeint_t result;
6643
+ FromString(str, result);
6644
+ return result;
6645
+ }
6646
+
6647
+ template <class T>
6648
+ static bool TryCast(hugeint_t input, T &result);
6649
+
6650
+ template <class T>
6651
+ static T Cast(hugeint_t input) {
6652
+ T value;
6653
+ TryCast(input, value);
6654
+ return value;
6655
+ }
6656
+
6657
+ template <class T>
6658
+ static bool TryConvert(T value, hugeint_t &result);
6659
+
6660
+ template <class T>
6661
+ static hugeint_t Convert(T value) {
6662
+ hugeint_t result;
6663
+ if (!TryConvert(value, result)) { // LCOV_EXCL_START
6664
+ throw ValueOutOfRangeException(double(value), GetTypeId<T>(), GetTypeId<hugeint_t>());
6665
+ } // LCOV_EXCL_STOP
6666
+ return result;
6667
+ }
6668
+
6669
+ static void NegateInPlace(hugeint_t &input) {
6670
+ input.lower = NumericLimits<uint64_t>::Maximum() - input.lower + 1;
6671
+ input.upper = -1 - input.upper + (input.lower == 0);
6672
+ }
6673
+ static hugeint_t Negate(hugeint_t input) {
6674
+ NegateInPlace(input);
6675
+ return input;
6704
6676
  }
6705
6677
 
6706
6678
  static bool TryMultiply(hugeint_t lhs, hugeint_t rhs, hugeint_t &result);
@@ -7196,32 +7168,46 @@ class FieldWriter;
7196
7168
  class FieldReader;
7197
7169
  class Vector;
7198
7170
  class ValidityStatistics;
7171
+ class DistinctStatistics;
7172
+ struct VectorData;
7173
+
7174
+ enum StatisticsType { LOCAL_STATS = 0, GLOBAL_STATS = 1 };
7199
7175
 
7200
7176
  class BaseStatistics {
7201
7177
  public:
7202
- explicit BaseStatistics(LogicalType type);
7178
+ BaseStatistics(LogicalType type, StatisticsType stats_type);
7203
7179
  virtual ~BaseStatistics();
7204
7180
 
7205
7181
  //! The type of the logical segment
7206
7182
  LogicalType type;
7207
7183
  //! The validity stats of the column (if any)
7208
7184
  unique_ptr<BaseStatistics> validity_stats;
7185
+ //! The approximate count distinct stats of the column (if any)
7186
+ unique_ptr<BaseStatistics> distinct_stats;
7187
+ //! Whether these are 'global' stats, i.e., over a whole table, or just over a segment
7188
+ //! Some statistics are more expensive to keep, therefore we only keep them globally
7189
+ StatisticsType stats_type;
7209
7190
 
7210
7191
  public:
7192
+ static unique_ptr<BaseStatistics> CreateEmpty(LogicalType type, StatisticsType stats_type);
7193
+
7211
7194
  bool CanHaveNull() const;
7212
7195
  bool CanHaveNoNull() const;
7213
7196
 
7197
+ void UpdateDistinctStatistics(Vector &v, idx_t count);
7198
+
7214
7199
  virtual bool IsConstant() const {
7215
7200
  return false;
7216
7201
  }
7217
7202
 
7218
- static unique_ptr<BaseStatistics> CreateEmpty(LogicalType type);
7219
-
7220
7203
  virtual void Merge(const BaseStatistics &other);
7221
7204
 
7222
7205
  virtual unique_ptr<BaseStatistics> Copy() const;
7223
- void Serialize(Serializer &serializer) const;
7206
+ void CopyBase(const BaseStatistics &orig);
7207
+
7208
+ virtual void Serialize(Serializer &serializer) const;
7224
7209
  virtual void Serialize(FieldWriter &writer) const;
7210
+
7225
7211
  static unique_ptr<BaseStatistics> Deserialize(Deserializer &source, LogicalType type);
7226
7212
 
7227
7213
  //! Verify that a vector does not violate the statistics
@@ -7229,12 +7215,20 @@ public:
7229
7215
  void Verify(Vector &vector, idx_t count) const;
7230
7216
 
7231
7217
  virtual string ToString() const;
7218
+
7219
+ protected:
7220
+ void InitializeBase();
7232
7221
  };
7233
7222
 
7234
7223
  } // namespace duckdb
7235
7224
 
7236
7225
 
7237
7226
  namespace duckdb {
7227
+
7228
+ struct FunctionLocalState {
7229
+ DUCKDB_API virtual ~FunctionLocalState();
7230
+ };
7231
+
7238
7232
  class BoundFunctionExpression;
7239
7233
  class ScalarFunctionCatalogEntry;
7240
7234
 
@@ -7243,7 +7237,8 @@ typedef std::function<void(DataChunk &, ExpressionState &, Vector &)> scalar_fun
7243
7237
  //! Binds the scalar function and creates the function data
7244
7238
  typedef unique_ptr<FunctionData> (*bind_scalar_function_t)(ClientContext &context, ScalarFunction &bound_function,
7245
7239
  vector<unique_ptr<Expression>> &arguments);
7246
- typedef unique_ptr<FunctionData> (*init_local_state_t)(const BoundFunctionExpression &expr, FunctionData *bind_data);
7240
+ typedef unique_ptr<FunctionLocalState> (*init_local_state_t)(const BoundFunctionExpression &expr,
7241
+ FunctionData *bind_data);
7247
7242
  typedef unique_ptr<BaseStatistics> (*function_statistics_t)(ClientContext &context, BoundFunctionExpression &expr,
7248
7243
  FunctionData *bind_data,
7249
7244
  vector<unique_ptr<BaseStatistics>> &child_stats);
@@ -7285,10 +7280,9 @@ public:
7285
7280
  vector<unique_ptr<Expression>> children,
7286
7281
  string &error, bool is_operator = false);
7287
7282
 
7288
- DUCKDB_API static unique_ptr<BoundFunctionExpression> BindScalarFunction(ClientContext &context,
7289
- ScalarFunction bound_function,
7290
- vector<unique_ptr<Expression>> children,
7291
- bool is_operator = false);
7283
+ DUCKDB_API static unique_ptr<BoundFunctionExpression>
7284
+ BindScalarFunction(ClientContext &context, ScalarFunction bound_function, vector<unique_ptr<Expression>> children,
7285
+ bool is_operator = false, bool cast_parameters = true);
7292
7286
 
7293
7287
  DUCKDB_API bool operator==(const ScalarFunction &rhs) const;
7294
7288
  DUCKDB_API bool operator!=(const ScalarFunction &rhs) const;
@@ -7716,13 +7710,13 @@ public:
7716
7710
  }
7717
7711
 
7718
7712
  template <class STATE_TYPE, class OP>
7719
- static void Combine(Vector &source, Vector &target, idx_t count) {
7713
+ static void Combine(Vector &source, Vector &target, FunctionData *bind_data, idx_t count) {
7720
7714
  D_ASSERT(source.GetType().id() == LogicalTypeId::POINTER && target.GetType().id() == LogicalTypeId::POINTER);
7721
7715
  auto sdata = FlatVector::GetData<const STATE_TYPE *>(source);
7722
7716
  auto tdata = FlatVector::GetData<STATE_TYPE *>(target);
7723
7717
 
7724
7718
  for (idx_t i = 0; i < count; i++) {
7725
- OP::template Combine<STATE_TYPE, OP>(*sdata[i], tdata[i]);
7719
+ OP::template Combine<STATE_TYPE, OP>(*sdata[i], tdata[i], bind_data);
7726
7720
  }
7727
7721
  }
7728
7722
 
@@ -8953,8 +8947,8 @@ typedef void (*aggregate_initialize_t)(data_ptr_t state);
8953
8947
  //! The type used for updating hashed aggregate functions
8954
8948
  typedef void (*aggregate_update_t)(Vector inputs[], FunctionData *bind_data, idx_t input_count, Vector &state,
8955
8949
  idx_t count);
8956
- //! The type used for combining hashed aggregate states (optional)
8957
- typedef void (*aggregate_combine_t)(Vector &state, Vector &combined, idx_t count);
8950
+ //! The type used for combining hashed aggregate states
8951
+ typedef void (*aggregate_combine_t)(Vector &state, Vector &combined, FunctionData *bind_data, idx_t count);
8958
8952
  //! The type used for finalizing hashed aggregate function payloads
8959
8953
  typedef void (*aggregate_finalize_t)(Vector &state, FunctionData *bind_data, Vector &result, idx_t count, idx_t offset);
8960
8954
  //! The type used for propagating statistics in aggregate functions (optional)
@@ -9058,7 +9052,8 @@ public:
9058
9052
  DUCKDB_API static unique_ptr<BoundAggregateExpression>
9059
9053
  BindAggregateFunction(ClientContext &context, AggregateFunction bound_function,
9060
9054
  vector<unique_ptr<Expression>> children, unique_ptr<Expression> filter = nullptr,
9061
- bool is_distinct = false, unique_ptr<BoundOrderModifier> order_bys = nullptr);
9055
+ bool is_distinct = false, unique_ptr<BoundOrderModifier> order_bys = nullptr,
9056
+ bool cast_parameters = true);
9062
9057
 
9063
9058
  DUCKDB_API static unique_ptr<FunctionData> BindSortedAggregate(AggregateFunction &bound_function,
9064
9059
  vector<unique_ptr<Expression>> &children,
@@ -9164,8 +9159,8 @@ public:
9164
9159
  }
9165
9160
 
9166
9161
  template <class STATE, class OP>
9167
- static void StateCombine(Vector &source, Vector &target, idx_t count) {
9168
- AggregateExecutor::Combine<STATE, OP>(source, target, count);
9162
+ static void StateCombine(Vector &source, Vector &target, FunctionData *bind_data, idx_t count) {
9163
+ AggregateExecutor::Combine<STATE, OP>(source, target, bind_data, count);
9169
9164
  }
9170
9165
 
9171
9166
  template <class STATE, class RESULT_TYPE, class OP>
@@ -9748,7 +9743,32 @@ enum class StatementType : uint8_t {
9748
9743
  };
9749
9744
 
9750
9745
  string StatementTypeToString(StatementType type);
9751
- bool StatementTypeReturnChanges(StatementType type);
9746
+
9747
+ enum class StatementReturnType : uint8_t {
9748
+ QUERY_RESULT, // the statement returns a query result (e.g. for display to the user)
9749
+ CHANGED_ROWS, // the statement returns a single row containing the number of changed rows (e.g. an insert stmt)
9750
+ NOTHING // the statement returns nothing
9751
+ };
9752
+
9753
+ //! A struct containing various properties of a SQL statement
9754
+ struct StatementProperties {
9755
+ StatementProperties()
9756
+ : read_only(true), requires_valid_transaction(true), allow_stream_result(false), bound_all_parameters(true),
9757
+ return_type(StatementReturnType::QUERY_RESULT) {
9758
+ }
9759
+
9760
+ //! Whether or not the statement is a read-only statement, or whether it can result in changes to the database
9761
+ bool read_only;
9762
+ //! Whether or not the statement requires a valid transaction. Almost all statements require this, with the
9763
+ //! exception of
9764
+ bool requires_valid_transaction;
9765
+ //! Whether or not the result can be streamed to the client
9766
+ bool allow_stream_result;
9767
+ //! Whether or not all parameters have successfully had their types determined
9768
+ bool bound_all_parameters;
9769
+ //! What type of data the statement returns
9770
+ StatementReturnType return_type;
9771
+ };
9752
9772
 
9753
9773
  } // namespace duckdb
9754
9774
 
@@ -9763,11 +9783,9 @@ enum class QueryResultType : uint8_t { MATERIALIZED_RESULT, STREAM_RESULT, PENDI
9763
9783
 
9764
9784
  class BaseQueryResult {
9765
9785
  public:
9766
- //! Creates a successful empty query result
9767
- DUCKDB_API BaseQueryResult(QueryResultType type, StatementType statement_type);
9768
9786
  //! Creates a successful query result with the specified names and types
9769
- DUCKDB_API BaseQueryResult(QueryResultType type, StatementType statement_type, vector<LogicalType> types,
9770
- vector<string> names);
9787
+ DUCKDB_API BaseQueryResult(QueryResultType type, StatementType statement_type, StatementProperties properties,
9788
+ vector<LogicalType> types, vector<string> names);
9771
9789
  //! Creates an unsuccessful query result with error condition
9772
9790
  DUCKDB_API BaseQueryResult(QueryResultType type, string error);
9773
9791
  DUCKDB_API virtual ~BaseQueryResult();
@@ -9776,6 +9794,8 @@ public:
9776
9794
  QueryResultType type;
9777
9795
  //! The type of the statement that created this result
9778
9796
  StatementType statement_type;
9797
+ //! Properties of the statement
9798
+ StatementProperties properties;
9779
9799
  //! The SQL types of the result
9780
9800
  vector<LogicalType> types;
9781
9801
  //! The names of the result
@@ -9796,11 +9816,9 @@ public:
9796
9816
  //! incrementally fetch data from the database.
9797
9817
  class QueryResult : public BaseQueryResult {
9798
9818
  public:
9799
- //! Creates a successful empty query result
9800
- DUCKDB_API QueryResult(QueryResultType type, StatementType statement_type);
9801
9819
  //! Creates a successful query result with the specified names and types
9802
- DUCKDB_API QueryResult(QueryResultType type, StatementType statement_type, vector<LogicalType> types,
9803
- vector<string> names);
9820
+ DUCKDB_API QueryResult(QueryResultType type, StatementType statement_type, StatementProperties properties,
9821
+ vector<LogicalType> types, vector<string> names);
9804
9822
  //! Creates an unsuccessful query result with error condition
9805
9823
  DUCKDB_API QueryResult(QueryResultType type, string error);
9806
9824
  DUCKDB_API virtual ~QueryResult() override;
@@ -9836,7 +9854,10 @@ public:
9836
9854
  }
9837
9855
  }
9838
9856
 
9839
- DUCKDB_API static void ToArrowSchema(ArrowSchema *out_schema, vector<LogicalType> &types, vector<string> &names);
9857
+ DUCKDB_API static void ToArrowSchema(ArrowSchema *out_schema, vector<LogicalType> &types, vector<string> &names,
9858
+ string &config_timezone);
9859
+
9860
+ static string GetConfigTimezone(QueryResult &query_result);
9840
9861
 
9841
9862
  private:
9842
9863
  //! The current chunk used by the iterator
@@ -9914,17 +9935,25 @@ private:
9914
9935
 
9915
9936
  namespace duckdb {
9916
9937
 
9938
+ class ClientContext;
9939
+
9917
9940
  class MaterializedQueryResult : public QueryResult {
9918
9941
  public:
9942
+ friend class ClientContext;
9919
9943
  //! Creates an empty successful query result
9920
9944
  DUCKDB_API explicit MaterializedQueryResult(StatementType statement_type);
9921
9945
  //! Creates a successful query result with the specified names and types
9922
- DUCKDB_API MaterializedQueryResult(StatementType statement_type, vector<LogicalType> types, vector<string> names);
9946
+ DUCKDB_API MaterializedQueryResult(StatementType statement_type, StatementProperties properties,
9947
+ vector<LogicalType> types, vector<string> names,
9948
+ const shared_ptr<ClientContext> &context);
9923
9949
  //! Creates an unsuccessful query result with error condition
9924
9950
  DUCKDB_API explicit MaterializedQueryResult(string error);
9925
9951
 
9926
9952
  ChunkCollection collection;
9927
9953
 
9954
+ //! The client context this MaterializedQueryResult belongs to
9955
+ std::weak_ptr<ClientContext> context;
9956
+
9928
9957
  public:
9929
9958
  //! Fetches a DataChunk from the query result.
9930
9959
  //! This will consume the result (i.e. the chunks are taken directly from the ChunkCollection).
@@ -10352,9 +10381,12 @@ public:
10352
10381
 
10353
10382
 
10354
10383
 
10384
+
10385
+
10355
10386
  #include <functional>
10356
10387
 
10357
10388
  namespace duckdb {
10389
+
10358
10390
  class BaseStatistics;
10359
10391
  class LogicalGet;
10360
10392
  struct ParallelState;
@@ -10397,10 +10429,14 @@ typedef unique_ptr<FunctionOperatorData> (*table_function_init_t)(ClientContext
10397
10429
  typedef unique_ptr<BaseStatistics> (*table_statistics_t)(ClientContext &context, const FunctionData *bind_data,
10398
10430
  column_t column_index);
10399
10431
  typedef void (*table_function_t)(ClientContext &context, const FunctionData *bind_data,
10400
- FunctionOperatorData *operator_state, DataChunk *input, DataChunk &output);
10432
+ FunctionOperatorData *operator_state, DataChunk &output);
10433
+
10434
+ typedef OperatorResultType (*table_in_out_function_t)(ClientContext &context, const FunctionData *bind_data,
10435
+ FunctionOperatorData *operator_state, DataChunk &input,
10436
+ DataChunk &output);
10401
10437
 
10402
10438
  typedef void (*table_function_parallel_t)(ClientContext &context, const FunctionData *bind_data,
10403
- FunctionOperatorData *operator_state, DataChunk *input, DataChunk &output,
10439
+ FunctionOperatorData *operator_state, DataChunk &output,
10404
10440
  ParallelState *parallel_state);
10405
10441
 
10406
10442
  typedef void (*table_function_cleanup_t)(ClientContext &context, const FunctionData *bind_data,
@@ -10439,7 +10475,8 @@ public:
10439
10475
  table_function_parallel_t parallel_function = nullptr,
10440
10476
  table_function_init_parallel_t parallel_init = nullptr,
10441
10477
  table_function_parallel_state_next_t parallel_state_next = nullptr, bool projection_pushdown = false,
10442
- bool filter_pushdown = false, table_function_progress_t query_progress = nullptr);
10478
+ bool filter_pushdown = false, table_function_progress_t query_progress = nullptr,
10479
+ table_in_out_function_t in_out_function = nullptr);
10443
10480
  DUCKDB_API
10444
10481
  TableFunction(const vector<LogicalType> &arguments, table_function_t function, table_function_bind_t bind = nullptr,
10445
10482
  table_function_init_t init = nullptr, table_statistics_t statistics = nullptr,
@@ -10451,7 +10488,8 @@ public:
10451
10488
  table_function_parallel_t parallel_function = nullptr,
10452
10489
  table_function_init_parallel_t parallel_init = nullptr,
10453
10490
  table_function_parallel_state_next_t parallel_state_next = nullptr, bool projection_pushdown = false,
10454
- bool filter_pushdown = false, table_function_progress_t query_progress = nullptr);
10491
+ bool filter_pushdown = false, table_function_progress_t query_progress = nullptr,
10492
+ table_in_out_function_t in_out_function = nullptr);
10455
10493
  DUCKDB_API TableFunction();
10456
10494
 
10457
10495
  //! Bind function
@@ -10464,6 +10502,8 @@ public:
10464
10502
  table_function_init_t init;
10465
10503
  //! The main function
10466
10504
  table_function_t function;
10505
+ //! The table in-out function (if this is an in-out function)
10506
+ table_in_out_function_t in_out_function;
10467
10507
  //! (Optional) statistics function
10468
10508
  //! Returns the statistics of a specified column
10469
10509
  table_statistics_t statistics;
@@ -10611,11 +10651,11 @@ struct ProducerToken {
10611
10651
 
10612
10652
  //! The TaskScheduler is responsible for managing tasks and threads
10613
10653
  class TaskScheduler {
10614
- // timeout for semaphore wait, default 50ms
10615
- constexpr static int64_t TASK_TIMEOUT_USECS = 50000;
10654
+ // timeout for semaphore wait, default 5ms
10655
+ constexpr static int64_t TASK_TIMEOUT_USECS = 5000;
10616
10656
 
10617
10657
  public:
10618
- TaskScheduler();
10658
+ TaskScheduler(DatabaseInstance &db);
10619
10659
  ~TaskScheduler();
10620
10660
 
10621
10661
  static TaskScheduler &GetScheduler(ClientContext &context);
@@ -10628,6 +10668,8 @@ public:
10628
10668
  bool GetTaskFromProducer(ProducerToken &token, unique_ptr<Task> &task);
10629
10669
  //! Run tasks forever until "marker" is set to false, "marker" must remain valid until the thread is joined
10630
10670
  void ExecuteForever(atomic<bool> *marker);
10671
+ //! Run tasks until `max_tasks` have been completed, or until there are no more tasks available
10672
+ void ExecuteTasks(idx_t max_tasks);
10631
10673
 
10632
10674
  //! Sets the amount of active threads executing tasks for the system; n-1 background threads will be launched.
10633
10675
  //! The main thread will also be used for execution
@@ -10638,6 +10680,8 @@ public:
10638
10680
  private:
10639
10681
  void SetThreadsInternal(int32_t n);
10640
10682
 
10683
+ private:
10684
+ DatabaseInstance &db;
10641
10685
  //! The task queue
10642
10686
  unique_ptr<ConcurrentQueue> queue;
10643
10687
  //! The active background threads of the task scheduler
@@ -10968,6 +11012,8 @@ public:
10968
11012
  idx_t ColumnCount();
10969
11013
  //! Returns the statement type of the underlying prepared statement object
10970
11014
  StatementType GetStatementType();
11015
+ //! Returns the underlying statement properties
11016
+ StatementProperties GetStatementProperties();
10971
11017
  //! Returns the result SQL types of the prepared statement
10972
11018
  const vector<LogicalType> &GetTypes();
10973
11019
  //! Returns the result names of the prepared statement
@@ -13147,9 +13193,6 @@ public:
13147
13193
  static bool ContainsType(const LogicalType &type, LogicalTypeId target);
13148
13194
  static LogicalType ExchangeType(const LogicalType &type, LogicalTypeId target, LogicalType new_type);
13149
13195
 
13150
- static void ResolveParameterType(LogicalType &type);
13151
- static void ResolveParameterType(unique_ptr<Expression> &expr);
13152
-
13153
13196
  //! Bind the given expresion. Unlike Bind(), this does *not* mute the given ParsedExpression.
13154
13197
  //! Exposed to be used from sub-binders that aren't subclasses of ExpressionBinder.
13155
13198
  virtual BindResult BindExpression(unique_ptr<ParsedExpression> *expr_ptr, idx_t depth,
@@ -13171,7 +13214,6 @@ protected:
13171
13214
  BindResult BindExpression(OperatorExpression &expr, idx_t depth);
13172
13215
  BindResult BindExpression(ParameterExpression &expr, idx_t depth);
13173
13216
  BindResult BindExpression(PositionalReferenceExpression &ref, idx_t depth);
13174
- BindResult BindExpression(StarExpression &expr, idx_t depth);
13175
13217
  BindResult BindExpression(SubqueryExpression &expr, idx_t depth);
13176
13218
 
13177
13219
  protected:
@@ -13421,7 +13463,6 @@ private:
13421
13463
 
13422
13464
 
13423
13465
 
13424
- //#include "duckdb/catalog/catalog_entry/table_macro_catalog_entry.hpp"
13425
13466
 
13426
13467
  namespace duckdb {
13427
13468
  class BoundResultModifier;
@@ -13483,12 +13524,10 @@ public:
13483
13524
  vector<CorrelatedColumnInfo> correlated_columns;
13484
13525
  //! The set of parameter expressions bound by this binder
13485
13526
  vector<BoundParameterExpression *> *parameters;
13486
- //! Whether or not the bound statement is read-only
13487
- bool read_only;
13488
- //! Whether or not the statement requires a valid transaction to run
13489
- bool requires_valid_transaction;
13490
- //! Whether or not the statement can be streamed to the client
13491
- bool allow_stream_result;
13527
+ //! The types of the prepared statement parameters, if any
13528
+ vector<LogicalType> *parameter_types;
13529
+ //! Statement properties
13530
+ StatementProperties properties;
13492
13531
  //! The alias for the currently processing subquery, if it exists
13493
13532
  string alias;
13494
13533
  //! Macro parameter bindings (if any)
@@ -13641,9 +13680,12 @@ private:
13641
13680
  unique_ptr<BoundTableRef> Bind(EmptyTableRef &ref);
13642
13681
  unique_ptr<BoundTableRef> Bind(ExpressionListRef &ref);
13643
13682
 
13644
- bool BindFunctionParameters(vector<unique_ptr<ParsedExpression>> &expressions, vector<LogicalType> &arguments,
13645
- vector<Value> &parameters, named_parameter_map_t &named_parameters,
13646
- unique_ptr<BoundSubqueryRef> &subquery, string &error);
13683
+ bool BindTableFunctionParameters(TableFunctionCatalogEntry &table_function,
13684
+ vector<unique_ptr<ParsedExpression>> &expressions, vector<LogicalType> &arguments,
13685
+ vector<Value> &parameters, named_parameter_map_t &named_parameters,
13686
+ unique_ptr<BoundSubqueryRef> &subquery, string &error);
13687
+ bool BindTableInTableOutFunction(vector<unique_ptr<ParsedExpression>> &expressions,
13688
+ unique_ptr<BoundSubqueryRef> &subquery, string &error);
13647
13689
 
13648
13690
  unique_ptr<LogicalOperator> CreatePlan(BoundBaseTableRef &ref);
13649
13691
  unique_ptr<LogicalOperator> CreatePlan(BoundCrossProductRef &ref);
@@ -13781,6 +13823,7 @@ public:
13781
13823
 
13782
13824
 
13783
13825
  namespace duckdb {
13826
+
13784
13827
  //! SQLStatement is the base class of any type of SQL statement.
13785
13828
  class SQLStatement {
13786
13829
  public:
@@ -13803,6 +13846,9 @@ protected:
13803
13846
  SQLStatement(const SQLStatement &other) = default;
13804
13847
 
13805
13848
  public:
13849
+ virtual string ToString() const {
13850
+ throw InternalException("ToString not supported for this type of SQLStatement");
13851
+ }
13806
13852
  //! Create a copy of this SelectStatement
13807
13853
  virtual unique_ptr<SQLStatement> Copy() const = 0;
13808
13854
  };
@@ -13907,7 +13953,9 @@ public:
13907
13953
 
13908
13954
  public:
13909
13955
  //! Convert the object to a string
13910
- virtual string ToString() const;
13956
+ virtual string ToString() const = 0;
13957
+ string BaseToString(string result) const;
13958
+ string BaseToString(string result, const vector<string> &column_name_alias) const;
13911
13959
  void Print();
13912
13960
 
13913
13961
  virtual bool Equals(const TableRef *other) const;
@@ -13944,6 +13992,8 @@ protected:
13944
13992
  SelectStatement(const SelectStatement &other);
13945
13993
 
13946
13994
  public:
13995
+ //! Convert the SELECT statement to a string
13996
+ string ToString() const override;
13947
13997
  //! Create a copy of this SelectStatement
13948
13998
  unique_ptr<SQLStatement> Copy() const override;
13949
13999
  //! Serializes a SelectStatement to a stand-alone binary blob
@@ -13995,6 +14045,9 @@ public:
13995
14045
  virtual const vector<unique_ptr<ParsedExpression>> &GetSelectList() const = 0;
13996
14046
 
13997
14047
  public:
14048
+ //! Convert the query node to a string
14049
+ virtual string ToString() const = 0;
14050
+
13998
14051
  virtual bool Equals(const QueryNode *other) const;
13999
14052
 
14000
14053
  //! Create a copy of this QueryNode
@@ -14006,6 +14059,9 @@ public:
14006
14059
  //! Deserializes a blob back into a QueryNode
14007
14060
  DUCKDB_API static unique_ptr<QueryNode> Deserialize(Deserializer &source);
14008
14061
 
14062
+ string CTEToString() const;
14063
+ string ResultModifiersToString() const;
14064
+
14009
14065
  protected:
14010
14066
  //! Copy base QueryNode properties from another expression to this one,
14011
14067
  //! used in Copy method
@@ -16896,6 +16952,19 @@ Closes the result and de-allocates all memory allocated for the arrow result.
16896
16952
  */
16897
16953
  DUCKDB_API void duckdb_destroy_arrow(duckdb_arrow *result);
16898
16954
 
16955
+ //===--------------------------------------------------------------------===//
16956
+ // Threading Information
16957
+ //===--------------------------------------------------------------------===//
16958
+ /*!
16959
+ Execute DuckDB tasks on this thread.
16960
+
16961
+ Will return after `max_tasks` have been executed, or if there are no more tasks present.
16962
+
16963
+ * database: The database object to execute tasks for
16964
+ * max_tasks: The maximum amount of tasks to execute
16965
+ */
16966
+ DUCKDB_API void duckdb_execute_tasks(duckdb_database database, idx_t max_tasks);
16967
+
16899
16968
  #ifdef __cplusplus
16900
16969
  }
16901
16970
  #endif
@@ -17014,8 +17083,8 @@ class StreamQueryResult : public QueryResult {
17014
17083
  public:
17015
17084
  //! Create a successful StreamQueryResult. StreamQueryResults should always be successful initially (it makes no
17016
17085
  //! sense to stream an error).
17017
- DUCKDB_API StreamQueryResult(StatementType statement_type, shared_ptr<ClientContext> context,
17018
- vector<LogicalType> types, vector<string> names);
17086
+ DUCKDB_API StreamQueryResult(StatementType statement_type, StatementProperties properties,
17087
+ shared_ptr<ClientContext> context, vector<LogicalType> types, vector<string> names);
17019
17088
  DUCKDB_API ~StreamQueryResult() override;
17020
17089
 
17021
17090
  public:
@@ -17031,7 +17100,6 @@ public:
17031
17100
  //! Closes the StreamQueryResult
17032
17101
  DUCKDB_API void Close();
17033
17102
 
17034
- private:
17035
17103
  //! The client context this StreamQueryResult belongs to
17036
17104
  shared_ptr<ClientContext> context;
17037
17105
 
@@ -17128,7 +17196,6 @@ private:
17128
17196
  } // namespace duckdb
17129
17197
 
17130
17198
 
17131
- #include <random>
17132
17199
 
17133
17200
  //===----------------------------------------------------------------------===//
17134
17201
  // DuckDB
@@ -17187,6 +17254,8 @@ struct ClientConfig {
17187
17254
  //! Preserve identifier case while parsing.
17188
17255
  //! If false, all unquoted identifiers are lower-cased (e.g. "MyTable" -> "mytable").
17189
17256
  bool preserve_identifier_case = true;
17257
+ //! The maximum expression depth limit in the parser
17258
+ idx_t max_expression_depth = 1000;
17190
17259
 
17191
17260
  // Whether or not aggressive query verification is enabled
17192
17261
  bool query_verification_enabled = false;
@@ -17210,10 +17279,33 @@ struct ClientConfig {
17210
17279
 
17211
17280
  public:
17212
17281
  static ClientConfig &GetConfig(ClientContext &context);
17282
+
17283
+ static string ExtractTimezoneFromConfig(ClientConfig &config);
17213
17284
  };
17214
17285
 
17215
17286
  } // namespace duckdb
17216
17287
 
17288
+ //===----------------------------------------------------------------------===//
17289
+ // DuckDB
17290
+ //
17291
+ // duckdb/main/external_dependencies.hpp
17292
+ //
17293
+ //
17294
+ //===----------------------------------------------------------------------===//
17295
+
17296
+
17297
+
17298
+ namespace duckdb {
17299
+
17300
+ enum ExternalDependenciesType { PYTHON_DEPENDENCY };
17301
+ class ExternalDependency {
17302
+ public:
17303
+ explicit ExternalDependency(ExternalDependenciesType type_p) : type(type_p) {};
17304
+ virtual ~ExternalDependency() {};
17305
+ ExternalDependenciesType type;
17306
+ };
17307
+
17308
+ } // namespace duckdb
17217
17309
 
17218
17310
  namespace duckdb {
17219
17311
  class Appender;
@@ -17227,12 +17319,12 @@ class PreparedStatementData;
17227
17319
  class Relation;
17228
17320
  class BufferedFileWriter;
17229
17321
  class QueryProfiler;
17230
- class QueryProfilerHistory;
17231
17322
  class ClientContextLock;
17232
17323
  struct CreateScalarFunctionInfo;
17233
17324
  class ScalarFunctionCatalogEntry;
17234
17325
  struct ActiveQueryContext;
17235
17326
  struct ParserOptions;
17327
+ struct ClientData;
17236
17328
 
17237
17329
  //! The ClientContext holds information relevant to the current client session
17238
17330
  //! during execution
@@ -17245,31 +17337,19 @@ public:
17245
17337
  DUCKDB_API explicit ClientContext(shared_ptr<DatabaseInstance> db);
17246
17338
  DUCKDB_API ~ClientContext();
17247
17339
 
17248
- //! Query profiler
17249
- shared_ptr<QueryProfiler> profiler;
17250
- //! QueryProfiler History
17251
- unique_ptr<QueryProfilerHistory> query_profiler_history;
17252
17340
  //! The database that this client is connected to
17253
17341
  shared_ptr<DatabaseInstance> db;
17254
17342
  //! Data for the currently running transaction
17255
17343
  TransactionContext transaction;
17256
17344
  //! Whether or not the query is interrupted
17257
17345
  atomic<bool> interrupted;
17258
-
17259
- unique_ptr<SchemaCatalogEntry> temporary_objects;
17260
- unordered_map<string, shared_ptr<PreparedStatementData>> prepared_statements;
17261
-
17262
- //! The writer used to log queries (if logging is enabled)
17263
- unique_ptr<BufferedFileWriter> log_query_writer;
17264
- //! The random generator used by random(). Its seed value can be set by setseed().
17265
- std::mt19937 random_engine;
17266
-
17267
- const unique_ptr<CatalogSearchPath> catalog_search_path;
17268
-
17269
- unique_ptr<FileOpener> file_opener;
17346
+ //! External Objects (e.g., Python objects) that views depend of
17347
+ unordered_map<string, vector<shared_ptr<ExternalDependency>>> external_dependencies;
17270
17348
 
17271
17349
  //! The client configuration
17272
17350
  ClientConfig config;
17351
+ //! The set of client-specific data
17352
+ unique_ptr<ClientData> client_data;
17273
17353
 
17274
17354
  public:
17275
17355
  DUCKDB_API Transaction &ActiveTransaction() {
@@ -17398,7 +17478,8 @@ private:
17398
17478
 
17399
17479
  //! Internally prepare a SQL statement. Caller must hold the context_lock.
17400
17480
  shared_ptr<PreparedStatementData> CreatePreparedStatement(ClientContextLock &lock, const string &query,
17401
- unique_ptr<SQLStatement> statement);
17481
+ unique_ptr<SQLStatement> statement,
17482
+ vector<Value> *values = nullptr);
17402
17483
  unique_ptr<PendingQueryResult> PendingStatementInternal(ClientContextLock &lock, const string &query,
17403
17484
  unique_ptr<SQLStatement> statement);
17404
17485
  unique_ptr<QueryResult> RunStatementInternal(ClientContextLock &lock, const string &query,
@@ -17472,6 +17553,7 @@ private:
17472
17553
  } // namespace duckdb
17473
17554
 
17474
17555
 
17556
+
17475
17557
  #include <memory>
17476
17558
 
17477
17559
  namespace duckdb {
@@ -17483,8 +17565,6 @@ class LogicalOperator;
17483
17565
  class QueryNode;
17484
17566
  class TableRef;
17485
17567
 
17486
- class ExtraDependencies {};
17487
-
17488
17568
  class Relation : public std::enable_shared_from_this<Relation> {
17489
17569
  public:
17490
17570
  DUCKDB_API Relation(const std::shared_ptr<ClientContext> &context, RelationType type)
@@ -17499,7 +17579,7 @@ public:
17499
17579
 
17500
17580
  RelationType type;
17501
17581
 
17502
- unique_ptr<ExtraDependencies> extra_dependencies;
17582
+ shared_ptr<ExternalDependency> extra_dependencies;
17503
17583
 
17504
17584
  public:
17505
17585
  DUCKDB_API virtual const vector<ColumnDefinition> &Columns() = 0;
@@ -17599,6 +17679,7 @@ public:
17599
17679
  DUCKDB_API virtual Relation *ChildRelation() {
17600
17680
  return nullptr;
17601
17681
  }
17682
+ DUCKDB_API vector<shared_ptr<ExternalDependency>> GetAllDependencies();
17602
17683
 
17603
17684
  protected:
17604
17685
  DUCKDB_API string RenderWhitespace(idx_t depth);
@@ -18135,6 +18216,8 @@ public:
18135
18216
  idx_t maximum_memory = (idx_t)-1;
18136
18217
  //! The maximum amount of CPU threads used by the database system. Default: all available.
18137
18218
  idx_t maximum_threads = (idx_t)-1;
18219
+ //! The number of external threads that work on DuckDB tasks. Default: none.
18220
+ idx_t external_threads = 0;
18138
18221
  //! Whether or not to create and use a temporary directory to store intermediates that do not fit in memory
18139
18222
  bool use_temporary_directory = true;
18140
18223
  //! Directory to store temporary structures that do not fit in memory
@@ -21350,6 +21433,7 @@ namespace duckdb {
21350
21433
 
21351
21434
  struct ParserOptions {
21352
21435
  bool preserve_identifier_case = true;
21436
+ idx_t max_expression_depth = 1000;
21353
21437
  };
21354
21438
 
21355
21439
  //! The parser is responsible for parsing the query and converting it into a set
@@ -21593,7 +21677,7 @@ class Vector;
21593
21677
 
21594
21678
  class ValidityStatistics : public BaseStatistics {
21595
21679
  public:
21596
- ValidityStatistics(bool has_null = false, bool has_no_null = true);
21680
+ explicit ValidityStatistics(bool has_null = false, bool has_no_null = true);
21597
21681
 
21598
21682
  //! Whether or not the segment can contain NULL values
21599
21683
  bool has_null;
@@ -21606,8 +21690,10 @@ public:
21606
21690
  bool IsConstant() const override;
21607
21691
 
21608
21692
  unique_ptr<BaseStatistics> Copy() const override;
21693
+
21609
21694
  void Serialize(FieldWriter &writer) const override;
21610
- static unique_ptr<BaseStatistics> Deserialize(FieldReader &reader);
21695
+ static unique_ptr<ValidityStatistics> Deserialize(FieldReader &reader);
21696
+
21611
21697
  void Verify(Vector &vector, const SelectionVector &sel, idx_t count) const override;
21612
21698
 
21613
21699
  static unique_ptr<BaseStatistics> Combine(const unique_ptr<BaseStatistics> &lstats,
@@ -21626,7 +21712,7 @@ public:
21626
21712
  constexpr static uint32_t MAX_STRING_MINMAX_SIZE = 8;
21627
21713
 
21628
21714
  public:
21629
- explicit StringStatistics(LogicalType type);
21715
+ explicit StringStatistics(LogicalType type, StatisticsType stats_type);
21630
21716
 
21631
21717
  //! The minimum value of the segment, potentially truncated
21632
21718
  data_t min[MAX_STRING_MINMAX_SIZE];
@@ -21720,8 +21806,8 @@ namespace duckdb {
21720
21806
 
21721
21807
  class NumericStatistics : public BaseStatistics {
21722
21808
  public:
21723
- explicit NumericStatistics(LogicalType type);
21724
- NumericStatistics(LogicalType type, Value min, Value max);
21809
+ explicit NumericStatistics(LogicalType type, StatisticsType stats_type);
21810
+ NumericStatistics(LogicalType type, Value min, Value max, StatisticsType stats_type);
21725
21811
 
21726
21812
  //! The minimum value of the segment
21727
21813
  Value min;
@@ -21882,6 +21968,8 @@ public:
21882
21968
 
21883
21969
 
21884
21970
 
21971
+ #include <algorithm>
21972
+
21885
21973
  namespace duckdb {
21886
21974
 
21887
21975
  enum class StrTimeSpecifier : uint8_t {
@@ -21929,7 +22017,11 @@ public:
21929
22017
  virtual ~StrTimeFormat() {
21930
22018
  }
21931
22019
 
21932
- static string ParseFormatSpecifier(const string &format_string, StrTimeFormat &format);
22020
+ DUCKDB_API static string ParseFormatSpecifier(const string &format_string, StrTimeFormat &format);
22021
+
22022
+ inline bool HasFormatSpecifier(StrTimeSpecifier s) const {
22023
+ return std::find(specifiers.begin(), specifiers.end(), s) != specifiers.end();
22024
+ }
21933
22025
 
21934
22026
  protected:
21935
22027
  //! The format specifiers
@@ -21945,13 +22037,13 @@ protected:
21945
22037
 
21946
22038
  protected:
21947
22039
  void AddLiteral(string literal);
21948
- virtual void AddFormatSpecifier(string preceding_literal, StrTimeSpecifier specifier);
22040
+ DUCKDB_API virtual void AddFormatSpecifier(string preceding_literal, StrTimeSpecifier specifier);
21949
22041
  };
21950
22042
 
21951
22043
  struct StrfTimeFormat : public StrTimeFormat {
21952
- idx_t GetLength(date_t date, dtime_t time);
22044
+ DUCKDB_API idx_t GetLength(date_t date, dtime_t time, int32_t utc_offset, const char *tz_name);
21953
22045
 
21954
- void FormatString(date_t date, int32_t data[7], char *target);
22046
+ DUCKDB_API void FormatString(date_t date, int32_t data[8], const char *tz_name, char *target);
21955
22047
  void FormatString(date_t date, dtime_t time, char *target);
21956
22048
 
21957
22049
  DUCKDB_API static string Format(timestamp_t timestamp, const string &format);
@@ -21964,8 +22056,9 @@ protected:
21964
22056
  vector<bool> is_date_specifier;
21965
22057
 
21966
22058
  protected:
21967
- void AddFormatSpecifier(string preceding_literal, StrTimeSpecifier specifier) override;
21968
- static idx_t GetSpecifierLength(StrTimeSpecifier specifier, date_t date, dtime_t time);
22059
+ DUCKDB_API void AddFormatSpecifier(string preceding_literal, StrTimeSpecifier specifier) override;
22060
+ static idx_t GetSpecifierLength(StrTimeSpecifier specifier, date_t date, dtime_t time, int32_t utc_offset,
22061
+ const char *tz_name);
21969
22062
  char *WriteString(char *target, const string_t &str);
21970
22063
  char *Write2(char *target, uint8_t value);
21971
22064
  char *WritePadded2(char *target, uint32_t value);
@@ -21973,20 +22066,21 @@ protected:
21973
22066
  char *WritePadded(char *target, uint32_t value, size_t padding);
21974
22067
  bool IsDateSpecifier(StrTimeSpecifier specifier);
21975
22068
  char *WriteDateSpecifier(StrTimeSpecifier specifier, date_t date, char *target);
21976
- char *WriteStandardSpecifier(StrTimeSpecifier specifier, int32_t data[], char *target);
22069
+ char *WriteStandardSpecifier(StrTimeSpecifier specifier, int32_t data[], const char *tz_name, char *target);
21977
22070
  };
21978
22071
 
21979
22072
  struct StrpTimeFormat : public StrTimeFormat {
21980
22073
  public:
21981
22074
  //! Type-safe parsing argument
21982
22075
  struct ParseResult {
21983
- int32_t data[7];
22076
+ int32_t data[8]; // year, month, day, hour, min, sec, µs, offset
22077
+ string tz;
21984
22078
  string error_message;
21985
22079
  idx_t error_position = DConstants::INVALID_INDEX;
21986
22080
 
21987
22081
  date_t ToDate();
21988
22082
  timestamp_t ToTimestamp();
21989
- string FormatError(string_t input, const string &format_specifier);
22083
+ DUCKDB_API string FormatError(string_t input, const string &format_specifier);
21990
22084
  };
21991
22085
 
21992
22086
  public:
@@ -21996,7 +22090,7 @@ public:
21996
22090
  public:
21997
22091
  DUCKDB_API static ParseResult Parse(const string &format, const string &text);
21998
22092
 
21999
- bool Parse(string_t str, ParseResult &result);
22093
+ DUCKDB_API bool Parse(string_t str, ParseResult &result);
22000
22094
 
22001
22095
  bool TryParseDate(string_t str, date_t &result, string &error_message);
22002
22096
  bool TryParseTimestamp(string_t str, timestamp_t &result, string &error_message);
@@ -22006,7 +22100,7 @@ public:
22006
22100
 
22007
22101
  protected:
22008
22102
  static string FormatStrpTimeError(const string &input, idx_t position);
22009
- void AddFormatSpecifier(string preceding_literal, StrTimeSpecifier specifier) override;
22103
+ DUCKDB_API void AddFormatSpecifier(string preceding_literal, StrTimeSpecifier specifier) override;
22010
22104
  int NumericSpecifierWidth(StrTimeSpecifier specifier);
22011
22105
  int32_t TryParseCollection(const char *data, idx_t &pos, idx_t size, const string_t collection[],
22012
22106
  idx_t collection_count);
@@ -22057,13 +22151,10 @@ struct TextSearchShiftArray {
22057
22151
  };
22058
22152
 
22059
22153
  struct BufferedCSVReaderOptions {
22060
- //! The file path of the CSV file to read
22061
- string file_path;
22062
- //! Whether file is compressed or not, and if so which compression type
22063
- //! AUTO_DETECT (default; infer from file extension)
22064
- FileCompressionType compression = FileCompressionType::AUTO_DETECT;
22065
- //! Whether or not to automatically detect dialect and datatypes
22066
- bool auto_detect = false;
22154
+ //===--------------------------------------------------------------------===//
22155
+ // CommonCSVOptions
22156
+ //===--------------------------------------------------------------------===//
22157
+
22067
22158
  //! Whether or not a delimiter was defined by the user
22068
22159
  bool has_delimiter = false;
22069
22160
  //! Delimiter to separate columns within each line
@@ -22080,26 +22171,51 @@ struct BufferedCSVReaderOptions {
22080
22171
  bool has_header = false;
22081
22172
  //! Whether or not the file has a header line
22082
22173
  bool header = false;
22083
- //! Whether or not header names shall be normalized
22084
- bool normalize_names = false;
22085
- //! How many leading rows to skip
22086
- idx_t skip_rows = 0;
22174
+ //! Whether or not we should ignore InvalidInput errors
22175
+ bool ignore_errors = false;
22087
22176
  //! Expected number of columns
22088
22177
  idx_t num_cols = 0;
22178
+ //! Number of samples to buffer
22179
+ idx_t buffer_size = STANDARD_VECTOR_SIZE * 100;
22089
22180
  //! Specifies the string that represents a null value
22090
22181
  string null_str;
22182
+ //! Whether file is compressed or not, and if so which compression type
22183
+ //! AUTO_DETECT (default; infer from file extension)
22184
+ FileCompressionType compression = FileCompressionType::AUTO_DETECT;
22185
+
22186
+ //===--------------------------------------------------------------------===//
22187
+ // ReadCSVOptions
22188
+ //===--------------------------------------------------------------------===//
22189
+
22190
+ //! How many leading rows to skip
22191
+ idx_t skip_rows = 0;
22192
+ //! Maximum CSV line size: specified because if we reach this amount, we likely have wrong delimiters (default: 2MB)
22193
+ idx_t maximum_line_size = 2097152;
22194
+ //! Whether or not header names shall be normalized
22195
+ bool normalize_names = false;
22091
22196
  //! True, if column with that index must skip null check
22092
22197
  vector<bool> force_not_null;
22198
+ //! Consider all columns to be of type varchar
22199
+ bool all_varchar = false;
22093
22200
  //! Size of sample chunk used for dialect and type detection
22094
22201
  idx_t sample_chunk_size = STANDARD_VECTOR_SIZE;
22095
22202
  //! Number of sample chunks used for type detection
22096
22203
  idx_t sample_chunks = 10;
22097
- //! Number of samples to buffer
22098
- idx_t buffer_size = STANDARD_VECTOR_SIZE * 100;
22099
- //! Consider all columns to be of type varchar
22100
- bool all_varchar = false;
22101
- //! Maximum CSV line size: specified because if we reach this amount, we likely have wrong delimiters (default: 2MB)
22102
- idx_t maximum_line_size = 2097152;
22204
+ //! Whether or not to automatically detect dialect and datatypes
22205
+ bool auto_detect = false;
22206
+ //! The file path of the CSV file to read
22207
+ string file_path;
22208
+ //! Whether or not to include a file name column
22209
+ bool include_file_name = false;
22210
+
22211
+ //===--------------------------------------------------------------------===//
22212
+ // WriteCSVOptions
22213
+ //===--------------------------------------------------------------------===//
22214
+
22215
+ //! The column names of the columns to write
22216
+ vector<string> names;
22217
+ //! True, if column with that index must be quoted
22218
+ vector<bool> force_quote;
22103
22219
 
22104
22220
  //! The date format to use (if any is specified)
22105
22221
  std::map<LogicalTypeId, StrpTimeFormat> date_format = {{LogicalTypeId::DATE, {}}, {LogicalTypeId::TIMESTAMP, {}}};
@@ -22107,6 +22223,16 @@ struct BufferedCSVReaderOptions {
22107
22223
  std::map<LogicalTypeId, bool> has_format = {{LogicalTypeId::DATE, false}, {LogicalTypeId::TIMESTAMP, false}};
22108
22224
 
22109
22225
  void SetDelimiter(const string &delimiter);
22226
+ //! Set an option that is supported by both reading and writing functions, called by
22227
+ //! the SetReadOption and SetWriteOption methods
22228
+ bool SetBaseOption(const string &loption, const Value &value);
22229
+
22230
+ //! loption - lowercase string
22231
+ //! set - argument(s) to the option
22232
+ //! expected_names - names expected if the option is "columns"
22233
+ void SetReadOption(const string &loption, const Value &value, vector<string> &expected_names);
22234
+
22235
+ void SetWriteOption(const string &loption, const Value &value);
22110
22236
 
22111
22237
  std::string ToString() const;
22112
22238
  };
@@ -22232,6 +22358,10 @@ private:
22232
22358
  const vector<LogicalType> &requested_types,
22233
22359
  vector<vector<LogicalType>> &best_sql_types_candidates,
22234
22360
  map<LogicalTypeId, vector<string>> &best_format_candidates);
22361
+
22362
+ private:
22363
+ //! Whether or not the current row's columns have overflown sql_types.size()
22364
+ bool error_column_overflow = false;
22235
22365
  };
22236
22366
 
22237
22367
  } // namespace duckdb
@@ -22382,46 +22512,7 @@ private:
22382
22512
  //===----------------------------------------------------------------------===//
22383
22513
  // DuckDB
22384
22514
  //
22385
- // duckdb/parser/expression/lambda_expression.hpp
22386
- //
22387
- //
22388
- //===----------------------------------------------------------------------===//
22389
-
22390
-
22391
-
22392
-
22393
-
22394
-
22395
- namespace duckdb {
22396
-
22397
- //! LambdaExpression represents either:
22398
- //! 1. A lambda operator that can be used for e.g. mapping an expression to a list
22399
- //! 2. An OperatorExpression with the "->" operator
22400
- //! Lambda expressions are written in the form of "capture -> expr", e.g. "x -> x + 1"
22401
- class LambdaExpression : public ParsedExpression {
22402
- public:
22403
- LambdaExpression(unique_ptr<ParsedExpression> lhs, unique_ptr<ParsedExpression> rhs);
22404
-
22405
- unique_ptr<ParsedExpression> lhs;
22406
- unique_ptr<ParsedExpression> rhs;
22407
-
22408
- public:
22409
- string ToString() const override;
22410
-
22411
- static bool Equals(const LambdaExpression *a, const LambdaExpression *b);
22412
- hash_t Hash() const override;
22413
-
22414
- unique_ptr<ParsedExpression> Copy() const override;
22415
-
22416
- void Serialize(FieldWriter &writer) const override;
22417
- static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
22418
- };
22419
-
22420
- } // namespace duckdb
22421
- //===----------------------------------------------------------------------===//
22422
- // DuckDB
22423
- //
22424
- // duckdb/parser/expression/collate_expression.hpp
22515
+ // duckdb/parser/expression/operator_expression.hpp
22425
22516
  //
22426
22517
  //
22427
22518
  //===----------------------------------------------------------------------===//
@@ -22430,56 +22521,23 @@ public:
22430
22521
 
22431
22522
 
22432
22523
 
22433
- namespace duckdb {
22434
-
22435
- //! CollateExpression represents a COLLATE statement
22436
- class CollateExpression : public ParsedExpression {
22437
- public:
22438
- CollateExpression(string collation, unique_ptr<ParsedExpression> child);
22439
-
22440
- //! The child of the cast expression
22441
- unique_ptr<ParsedExpression> child;
22442
- //! The collation clause
22443
- string collation;
22444
-
22445
- public:
22446
- string ToString() const override;
22447
-
22448
- static bool Equals(const CollateExpression *a, const CollateExpression *b);
22449
-
22450
- unique_ptr<ParsedExpression> Copy() const override;
22451
-
22452
- void Serialize(FieldWriter &writer) const override;
22453
- static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
22454
- };
22455
- } // namespace duckdb
22456
- //===----------------------------------------------------------------------===//
22457
- // DuckDB
22458
- //
22459
- // duckdb/parser/expression/between_expression.hpp
22460
- //
22461
- //
22462
- //===----------------------------------------------------------------------===//
22463
-
22464
-
22465
22524
 
22466
22525
 
22467
22526
 
22468
22527
  namespace duckdb {
22469
-
22470
- class BetweenExpression : public ParsedExpression {
22528
+ //! Represents a built-in operator expression
22529
+ class OperatorExpression : public ParsedExpression {
22471
22530
  public:
22472
- BetweenExpression(unique_ptr<ParsedExpression> input, unique_ptr<ParsedExpression> lower,
22473
- unique_ptr<ParsedExpression> upper);
22531
+ DUCKDB_API explicit OperatorExpression(ExpressionType type, unique_ptr<ParsedExpression> left = nullptr,
22532
+ unique_ptr<ParsedExpression> right = nullptr);
22533
+ DUCKDB_API OperatorExpression(ExpressionType type, vector<unique_ptr<ParsedExpression>> children);
22474
22534
 
22475
- unique_ptr<ParsedExpression> input;
22476
- unique_ptr<ParsedExpression> lower;
22477
- unique_ptr<ParsedExpression> upper;
22535
+ vector<unique_ptr<ParsedExpression>> children;
22478
22536
 
22479
22537
  public:
22480
22538
  string ToString() const override;
22481
22539
 
22482
- static bool Equals(const BetweenExpression *a, const BetweenExpression *b);
22540
+ static bool Equals(const OperatorExpression *a, const OperatorExpression *b);
22483
22541
 
22484
22542
  unique_ptr<ParsedExpression> Copy() const override;
22485
22543
 
@@ -22489,16 +22547,72 @@ public:
22489
22547
  public:
22490
22548
  template <class T, class BASE>
22491
22549
  static string ToString(const T &entry) {
22492
- return entry.input->ToString() + " BETWEEN " + entry.lower->ToString() + " AND " + entry.upper->ToString();
22550
+ auto op = ExpressionTypeToOperator(entry.type);
22551
+ if (!op.empty()) {
22552
+ // use the operator string to represent the operator
22553
+ D_ASSERT(entry.children.size() == 2);
22554
+ return entry.children[0]->ToString() + " " + op + " " + entry.children[1]->ToString();
22555
+ }
22556
+ switch (entry.type) {
22557
+ case ExpressionType::COMPARE_IN:
22558
+ case ExpressionType::COMPARE_NOT_IN: {
22559
+ string op_type = entry.type == ExpressionType::COMPARE_IN ? " IN " : " NOT IN ";
22560
+ string in_child = entry.children[0]->ToString();
22561
+ string child_list = "(";
22562
+ for (idx_t i = 1; i < entry.children.size(); i++) {
22563
+ if (i > 1) {
22564
+ child_list += ", ";
22565
+ }
22566
+ child_list += entry.children[i]->ToString();
22567
+ }
22568
+ child_list += ")";
22569
+ return "(" + in_child + op_type + child_list + ")";
22570
+ }
22571
+ case ExpressionType::OPERATOR_NOT:
22572
+ case ExpressionType::GROUPING_FUNCTION:
22573
+ case ExpressionType::OPERATOR_COALESCE: {
22574
+ string result = ExpressionTypeToString(entry.type);
22575
+ result += "(";
22576
+ result += StringUtil::Join(entry.children, entry.children.size(), ", ",
22577
+ [](const unique_ptr<BASE> &child) { return child->ToString(); });
22578
+ result += ")";
22579
+ return result;
22580
+ }
22581
+ case ExpressionType::OPERATOR_IS_NULL:
22582
+ return "(" + entry.children[0]->ToString() + " IS NULL)";
22583
+ case ExpressionType::OPERATOR_IS_NOT_NULL:
22584
+ return "(" + entry.children[0]->ToString() + " IS NOT NULL)";
22585
+ case ExpressionType::ARRAY_EXTRACT:
22586
+ return entry.children[0]->ToString() + "[" + entry.children[1]->ToString() + "]";
22587
+ case ExpressionType::ARRAY_SLICE:
22588
+ return entry.children[0]->ToString() + "[" + entry.children[1]->ToString() + ":" +
22589
+ entry.children[2]->ToString() + "]";
22590
+ case ExpressionType::STRUCT_EXTRACT: {
22591
+ D_ASSERT(entry.children[1]->type == ExpressionType::VALUE_CONSTANT);
22592
+ auto child_string = entry.children[1]->ToString();
22593
+ D_ASSERT(child_string.size() >= 3);
22594
+ D_ASSERT(child_string[0] == '\'' && child_string[child_string.size() - 1] == '\'');
22595
+ return "(" + entry.children[0]->ToString() + ")." +
22596
+ KeywordHelper::WriteOptionallyQuoted(child_string.substr(1, child_string.size() - 2));
22597
+ }
22598
+ case ExpressionType::ARRAY_CONSTRUCTOR: {
22599
+ string result = "(ARRAY[";
22600
+ result += StringUtil::Join(entry.children, entry.children.size(), ", ",
22601
+ [](const unique_ptr<BASE> &child) { return child->ToString(); });
22602
+ result += "])";
22603
+ return result;
22604
+ }
22605
+ default:
22606
+ throw InternalException("Unrecognized operator type");
22607
+ }
22493
22608
  }
22494
22609
  };
22495
- } // namespace duckdb
22496
-
22497
22610
 
22611
+ } // namespace duckdb
22498
22612
  //===----------------------------------------------------------------------===//
22499
22613
  // DuckDB
22500
22614
  //
22501
- // duckdb/parser/expression/case_expression.hpp
22615
+ // duckdb/parser/expression/star_expression.hpp
22502
22616
  //
22503
22617
  //
22504
22618
  //===----------------------------------------------------------------------===//
@@ -22510,44 +22624,29 @@ public:
22510
22624
 
22511
22625
  namespace duckdb {
22512
22626
 
22513
- struct CaseCheck {
22514
- unique_ptr<ParsedExpression> when_expr;
22515
- unique_ptr<ParsedExpression> then_expr;
22516
- };
22517
-
22518
- //! The CaseExpression represents a CASE expression in the query
22519
- class CaseExpression : public ParsedExpression {
22627
+ //! Represents a * expression in the SELECT clause
22628
+ class StarExpression : public ParsedExpression {
22520
22629
  public:
22521
- DUCKDB_API CaseExpression();
22630
+ StarExpression(string relation_name = string());
22522
22631
 
22523
- vector<CaseCheck> case_checks;
22524
- unique_ptr<ParsedExpression> else_expr;
22632
+ //! The relation name in case of tbl.*, or empty if this is a normal *
22633
+ string relation_name;
22634
+ //! List of columns to exclude from the STAR expression
22635
+ case_insensitive_set_t exclude_list;
22636
+ //! List of columns to replace with another expression
22637
+ case_insensitive_map_t<unique_ptr<ParsedExpression>> replace_list;
22525
22638
 
22526
22639
  public:
22527
22640
  string ToString() const override;
22528
22641
 
22529
- static bool Equals(const CaseExpression *a, const CaseExpression *b);
22642
+ static bool Equals(const StarExpression *a, const StarExpression *b);
22530
22643
 
22531
22644
  unique_ptr<ParsedExpression> Copy() const override;
22532
22645
 
22533
22646
  void Serialize(FieldWriter &writer) const override;
22534
22647
  static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
22535
-
22536
- public:
22537
- template <class T, class BASE>
22538
- static string ToString(const T &entry) {
22539
- string case_str = "CASE ";
22540
- for (auto &check : entry.case_checks) {
22541
- case_str += " WHEN (" + check.when_expr->ToString() + ")";
22542
- case_str += " THEN (" + check.then_expr->ToString() + ")";
22543
- }
22544
- case_str += " ELSE " + entry.else_expr->ToString();
22545
- case_str += " END";
22546
- return case_str;
22547
- }
22548
22648
  };
22549
22649
  } // namespace duckdb
22550
-
22551
22650
  //===----------------------------------------------------------------------===//
22552
22651
  // DuckDB
22553
22652
  //
@@ -22593,13 +22692,10 @@ public:
22593
22692
  }
22594
22693
  };
22595
22694
  } // namespace duckdb
22596
-
22597
-
22598
-
22599
22695
  //===----------------------------------------------------------------------===//
22600
22696
  // DuckDB
22601
22697
  //
22602
- // duckdb/parser/expression/comparison_expression.hpp
22698
+ // duckdb/parser/expression/positional_reference_expression.hpp
22603
22699
  //
22604
22700
  //
22605
22701
  //===----------------------------------------------------------------------===//
@@ -22609,34 +22705,27 @@ public:
22609
22705
 
22610
22706
 
22611
22707
  namespace duckdb {
22612
- //! ComparisonExpression represents a boolean comparison (e.g. =, >=, <>). Always returns a boolean
22613
- //! and has two children.
22614
- class ComparisonExpression : public ParsedExpression {
22708
+ class PositionalReferenceExpression : public ParsedExpression {
22615
22709
  public:
22616
- DUCKDB_API ComparisonExpression(ExpressionType type, unique_ptr<ParsedExpression> left,
22617
- unique_ptr<ParsedExpression> right);
22710
+ DUCKDB_API PositionalReferenceExpression(idx_t index);
22618
22711
 
22619
- unique_ptr<ParsedExpression> left;
22620
- unique_ptr<ParsedExpression> right;
22712
+ idx_t index;
22621
22713
 
22622
22714
  public:
22623
- string ToString() const override;
22715
+ bool IsScalar() const override {
22716
+ return false;
22717
+ }
22624
22718
 
22625
- static bool Equals(const ComparisonExpression *a, const ComparisonExpression *b);
22719
+ string ToString() const override;
22626
22720
 
22721
+ static bool Equals(const PositionalReferenceExpression *a, const PositionalReferenceExpression *b);
22627
22722
  unique_ptr<ParsedExpression> Copy() const override;
22723
+ hash_t Hash() const override;
22628
22724
 
22629
22725
  void Serialize(FieldWriter &writer) const override;
22630
22726
  static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
22631
-
22632
- public:
22633
- template <class T, class BASE>
22634
- static string ToString(const T &entry) {
22635
- return entry.left->ToString() + " " + ExpressionTypeToOperator(entry.type) + " " + entry.right->ToString();
22636
- }
22637
22727
  };
22638
22728
  } // namespace duckdb
22639
-
22640
22729
  //===----------------------------------------------------------------------===//
22641
22730
  // DuckDB
22642
22731
  //
@@ -22677,19 +22766,18 @@ public:
22677
22766
  public:
22678
22767
  template <class T, class BASE>
22679
22768
  static string ToString(const T &entry) {
22680
- string result = entry.children[0]->ToString();
22769
+ string result = "(" + entry.children[0]->ToString();
22681
22770
  for (idx_t i = 1; i < entry.children.size(); i++) {
22682
22771
  result += " " + ExpressionTypeToOperator(entry.type) + " " + entry.children[i]->ToString();
22683
22772
  }
22684
- return result;
22773
+ return result + ")";
22685
22774
  }
22686
22775
  };
22687
22776
  } // namespace duckdb
22688
-
22689
22777
  //===----------------------------------------------------------------------===//
22690
22778
  // DuckDB
22691
22779
  //
22692
- // duckdb/parser/expression/constant_expression.hpp
22780
+ // duckdb/parser/expression/parameter_expression.hpp
22693
22781
  //
22694
22782
  //
22695
22783
  //===----------------------------------------------------------------------===//
@@ -22698,35 +22786,69 @@ public:
22698
22786
 
22699
22787
 
22700
22788
 
22701
-
22702
22789
  namespace duckdb {
22703
-
22704
- //! ConstantExpression represents a constant value in the query
22705
- class ConstantExpression : public ParsedExpression {
22790
+ class ParameterExpression : public ParsedExpression {
22706
22791
  public:
22707
- DUCKDB_API explicit ConstantExpression(Value val);
22792
+ ParameterExpression();
22708
22793
 
22709
- //! The constant value referenced
22710
- Value value;
22794
+ idx_t parameter_nr;
22711
22795
 
22712
22796
  public:
22797
+ bool IsScalar() const override {
22798
+ return true;
22799
+ }
22800
+ bool HasParameter() const override {
22801
+ return true;
22802
+ }
22803
+
22713
22804
  string ToString() const override;
22714
22805
 
22715
- static bool Equals(const ConstantExpression *a, const ConstantExpression *b);
22806
+ unique_ptr<ParsedExpression> Copy() const override;
22716
22807
  hash_t Hash() const override;
22717
22808
 
22809
+ void Serialize(FieldWriter &writer) const override;
22810
+ static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
22811
+ };
22812
+ } // namespace duckdb
22813
+ //===----------------------------------------------------------------------===//
22814
+ // DuckDB
22815
+ //
22816
+ // duckdb/parser/expression/collate_expression.hpp
22817
+ //
22818
+ //
22819
+ //===----------------------------------------------------------------------===//
22820
+
22821
+
22822
+
22823
+
22824
+
22825
+ namespace duckdb {
22826
+
22827
+ //! CollateExpression represents a COLLATE statement
22828
+ class CollateExpression : public ParsedExpression {
22829
+ public:
22830
+ CollateExpression(string collation, unique_ptr<ParsedExpression> child);
22831
+
22832
+ //! The child of the cast expression
22833
+ unique_ptr<ParsedExpression> child;
22834
+ //! The collation clause
22835
+ string collation;
22836
+
22837
+ public:
22838
+ string ToString() const override;
22839
+
22840
+ static bool Equals(const CollateExpression *a, const CollateExpression *b);
22841
+
22718
22842
  unique_ptr<ParsedExpression> Copy() const override;
22719
22843
 
22720
22844
  void Serialize(FieldWriter &writer) const override;
22721
22845
  static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
22722
22846
  };
22723
-
22724
22847
  } // namespace duckdb
22725
-
22726
22848
  //===----------------------------------------------------------------------===//
22727
22849
  // DuckDB
22728
22850
  //
22729
- // duckdb/parser/expression/default_expression.hpp
22851
+ // duckdb/parser/expression/subquery_expression.hpp
22730
22852
  //
22731
22853
  //
22732
22854
  //===----------------------------------------------------------------------===//
@@ -22735,26 +22857,171 @@ public:
22735
22857
 
22736
22858
 
22737
22859
 
22860
+
22861
+
22738
22862
  namespace duckdb {
22739
- //! Represents the default value of a column
22740
- class DefaultExpression : public ParsedExpression {
22863
+
22864
+ //! Represents a subquery
22865
+ class SubqueryExpression : public ParsedExpression {
22741
22866
  public:
22742
- DefaultExpression();
22867
+ SubqueryExpression();
22868
+
22869
+ //! The actual subquery
22870
+ unique_ptr<SelectStatement> subquery;
22871
+ //! The subquery type
22872
+ SubqueryType subquery_type;
22873
+ //! the child expression to compare with (in case of IN, ANY, ALL operators, empty for EXISTS queries and scalar
22874
+ //! subquery)
22875
+ unique_ptr<ParsedExpression> child;
22876
+ //! The comparison type of the child expression with the subquery (in case of ANY, ALL operators), empty otherwise
22877
+ ExpressionType comparison_type;
22743
22878
 
22744
22879
  public:
22880
+ bool HasSubquery() const override {
22881
+ return true;
22882
+ }
22745
22883
  bool IsScalar() const override {
22746
22884
  return false;
22747
22885
  }
22748
22886
 
22749
22887
  string ToString() const override;
22750
22888
 
22889
+ static bool Equals(const SubqueryExpression *a, const SubqueryExpression *b);
22890
+
22751
22891
  unique_ptr<ParsedExpression> Copy() const override;
22752
22892
 
22753
22893
  void Serialize(FieldWriter &writer) const override;
22754
22894
  static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
22755
22895
  };
22756
22896
  } // namespace duckdb
22897
+ //===----------------------------------------------------------------------===//
22898
+ // DuckDB
22899
+ //
22900
+ // duckdb/parser/expression/between_expression.hpp
22901
+ //
22902
+ //
22903
+ //===----------------------------------------------------------------------===//
22904
+
22905
+
22906
+
22907
+
22908
+
22909
+ namespace duckdb {
22910
+
22911
+ class BetweenExpression : public ParsedExpression {
22912
+ public:
22913
+ DUCKDB_API BetweenExpression(unique_ptr<ParsedExpression> input, unique_ptr<ParsedExpression> lower,
22914
+ unique_ptr<ParsedExpression> upper);
22915
+
22916
+ unique_ptr<ParsedExpression> input;
22917
+ unique_ptr<ParsedExpression> lower;
22918
+ unique_ptr<ParsedExpression> upper;
22757
22919
 
22920
+ public:
22921
+ string ToString() const override;
22922
+
22923
+ static bool Equals(const BetweenExpression *a, const BetweenExpression *b);
22924
+
22925
+ unique_ptr<ParsedExpression> Copy() const override;
22926
+
22927
+ void Serialize(FieldWriter &writer) const override;
22928
+ static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
22929
+
22930
+ public:
22931
+ template <class T, class BASE>
22932
+ static string ToString(const T &entry) {
22933
+ return entry.input->ToString() + " BETWEEN " + entry.lower->ToString() + " AND " + entry.upper->ToString();
22934
+ }
22935
+ };
22936
+ } // namespace duckdb
22937
+ //===----------------------------------------------------------------------===//
22938
+ // DuckDB
22939
+ //
22940
+ // duckdb/parser/expression/case_expression.hpp
22941
+ //
22942
+ //
22943
+ //===----------------------------------------------------------------------===//
22944
+
22945
+
22946
+
22947
+
22948
+
22949
+
22950
+ namespace duckdb {
22951
+
22952
+ struct CaseCheck {
22953
+ unique_ptr<ParsedExpression> when_expr;
22954
+ unique_ptr<ParsedExpression> then_expr;
22955
+ };
22956
+
22957
+ //! The CaseExpression represents a CASE expression in the query
22958
+ class CaseExpression : public ParsedExpression {
22959
+ public:
22960
+ DUCKDB_API CaseExpression();
22961
+
22962
+ vector<CaseCheck> case_checks;
22963
+ unique_ptr<ParsedExpression> else_expr;
22964
+
22965
+ public:
22966
+ string ToString() const override;
22967
+
22968
+ static bool Equals(const CaseExpression *a, const CaseExpression *b);
22969
+
22970
+ unique_ptr<ParsedExpression> Copy() const override;
22971
+
22972
+ void Serialize(FieldWriter &writer) const override;
22973
+ static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
22974
+
22975
+ public:
22976
+ template <class T, class BASE>
22977
+ static string ToString(const T &entry) {
22978
+ string case_str = "CASE ";
22979
+ for (auto &check : entry.case_checks) {
22980
+ case_str += " WHEN (" + check.when_expr->ToString() + ")";
22981
+ case_str += " THEN (" + check.then_expr->ToString() + ")";
22982
+ }
22983
+ case_str += " ELSE " + entry.else_expr->ToString();
22984
+ case_str += " END";
22985
+ return case_str;
22986
+ }
22987
+ };
22988
+ } // namespace duckdb
22989
+ //===----------------------------------------------------------------------===//
22990
+ // DuckDB
22991
+ //
22992
+ // duckdb/parser/expression/constant_expression.hpp
22993
+ //
22994
+ //
22995
+ //===----------------------------------------------------------------------===//
22996
+
22997
+
22998
+
22999
+
23000
+
23001
+
23002
+ namespace duckdb {
23003
+
23004
+ //! ConstantExpression represents a constant value in the query
23005
+ class ConstantExpression : public ParsedExpression {
23006
+ public:
23007
+ DUCKDB_API explicit ConstantExpression(Value val);
23008
+
23009
+ //! The constant value referenced
23010
+ Value value;
23011
+
23012
+ public:
23013
+ string ToString() const override;
23014
+
23015
+ static bool Equals(const ConstantExpression *a, const ConstantExpression *b);
23016
+ hash_t Hash() const override;
23017
+
23018
+ unique_ptr<ParsedExpression> Copy() const override;
23019
+
23020
+ void Serialize(FieldWriter &writer) const override;
23021
+ static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
23022
+ };
23023
+
23024
+ } // namespace duckdb
22758
23025
  //===----------------------------------------------------------------------===//
22759
23026
  // DuckDB
22760
23027
  //
@@ -22817,7 +23084,7 @@ public:
22817
23084
  template <class T, class BASE>
22818
23085
  static string ToString(const T &entry, const string &schema, const string &function_name, bool is_operator = false,
22819
23086
  bool distinct = false, BASE *filter = nullptr, OrderModifier *order_bys = nullptr,
22820
- bool export_state = false) {
23087
+ bool export_state = false, bool add_alias = false) {
22821
23088
  if (is_operator) {
22822
23089
  // built-in operator
22823
23090
  D_ASSERT(!distinct);
@@ -22839,8 +23106,11 @@ public:
22839
23106
  if (distinct) {
22840
23107
  result += "DISTINCT ";
22841
23108
  }
22842
- result += StringUtil::Join(entry.children, entry.children.size(), ", ",
22843
- [](const unique_ptr<BASE> &child) { return child->ToString(); });
23109
+ result += StringUtil::Join(entry.children, entry.children.size(), ", ", [&](const unique_ptr<BASE> &child) {
23110
+ return child->alias.empty() || !add_alias
23111
+ ? child->ToString()
23112
+ : KeywordHelper::WriteOptionallyQuoted(child->alias) + " := " + child->ToString();
23113
+ });
22844
23114
  // ordered aggregate
22845
23115
  if (order_bys && !order_bys->orders.empty()) {
22846
23116
  if (entry.children.empty()) {
@@ -22871,10 +23141,14 @@ public:
22871
23141
  } // namespace duckdb
22872
23142
 
22873
23143
 
23144
+
23145
+
23146
+
23147
+
22874
23148
  //===----------------------------------------------------------------------===//
22875
23149
  // DuckDB
22876
23150
  //
22877
- // duckdb/parser/expression/operator_expression.hpp
23151
+ // duckdb/parser/expression/comparison_expression.hpp
22878
23152
  //
22879
23153
  //
22880
23154
  //===----------------------------------------------------------------------===//
@@ -22883,23 +23157,21 @@ public:
22883
23157
 
22884
23158
 
22885
23159
 
22886
-
22887
-
22888
-
22889
23160
  namespace duckdb {
22890
- //! Represents a built-in operator expression
22891
- class OperatorExpression : public ParsedExpression {
23161
+ //! ComparisonExpression represents a boolean comparison (e.g. =, >=, <>). Always returns a boolean
23162
+ //! and has two children.
23163
+ class ComparisonExpression : public ParsedExpression {
22892
23164
  public:
22893
- DUCKDB_API explicit OperatorExpression(ExpressionType type, unique_ptr<ParsedExpression> left = nullptr,
22894
- unique_ptr<ParsedExpression> right = nullptr);
22895
- DUCKDB_API OperatorExpression(ExpressionType type, vector<unique_ptr<ParsedExpression>> children);
23165
+ DUCKDB_API ComparisonExpression(ExpressionType type, unique_ptr<ParsedExpression> left,
23166
+ unique_ptr<ParsedExpression> right);
22896
23167
 
22897
- vector<unique_ptr<ParsedExpression>> children;
23168
+ unique_ptr<ParsedExpression> left;
23169
+ unique_ptr<ParsedExpression> right;
22898
23170
 
22899
23171
  public:
22900
23172
  string ToString() const override;
22901
23173
 
22902
- static bool Equals(const OperatorExpression *a, const OperatorExpression *b);
23174
+ static bool Equals(const ComparisonExpression *a, const ComparisonExpression *b);
22903
23175
 
22904
23176
  unique_ptr<ParsedExpression> Copy() const override;
22905
23177
 
@@ -22909,73 +23181,17 @@ public:
22909
23181
  public:
22910
23182
  template <class T, class BASE>
22911
23183
  static string ToString(const T &entry) {
22912
- auto op = ExpressionTypeToOperator(entry.type);
22913
- if (!op.empty()) {
22914
- // use the operator string to represent the operator
22915
- D_ASSERT(entry.children.size() == 2);
22916
- return entry.children[0]->ToString() + " " + op + " " + entry.children[1]->ToString();
22917
- }
22918
- switch (entry.type) {
22919
- case ExpressionType::COMPARE_IN:
22920
- case ExpressionType::COMPARE_NOT_IN: {
22921
- string op_type = entry.type == ExpressionType::COMPARE_IN ? " IN " : " NOT IN ";
22922
- string in_child = entry.children[0]->ToString();
22923
- string child_list = "(";
22924
- for (idx_t i = 1; i < entry.children.size(); i++) {
22925
- if (i > 1) {
22926
- child_list += ", ";
22927
- }
22928
- child_list += entry.children[i]->ToString();
22929
- }
22930
- child_list += ")";
22931
- return "(" + in_child + op_type + child_list + ")";
22932
- }
22933
- case ExpressionType::OPERATOR_NOT:
22934
- case ExpressionType::GROUPING_FUNCTION:
22935
- case ExpressionType::OPERATOR_COALESCE: {
22936
- string result = ExpressionTypeToString(entry.type);
22937
- result += "(";
22938
- result += StringUtil::Join(entry.children, entry.children.size(), ", ",
22939
- [](const unique_ptr<BASE> &child) { return child->ToString(); });
22940
- result += ")";
22941
- return result;
22942
- }
22943
- case ExpressionType::OPERATOR_IS_NULL:
22944
- return "(" + entry.children[0]->ToString() + " IS NULL)";
22945
- case ExpressionType::OPERATOR_IS_NOT_NULL:
22946
- return "(" + entry.children[0]->ToString() + " IS NOT NULL)";
22947
- case ExpressionType::ARRAY_EXTRACT:
22948
- return entry.children[0]->ToString() + "[" + entry.children[1]->ToString() + "]";
22949
- case ExpressionType::ARRAY_SLICE:
22950
- return entry.children[0]->ToString() + "[" + entry.children[1]->ToString() + ":" +
22951
- entry.children[2]->ToString() + "]";
22952
- case ExpressionType::STRUCT_EXTRACT: {
22953
- D_ASSERT(entry.children[1]->type == ExpressionType::VALUE_CONSTANT);
22954
- auto child_string = entry.children[1]->ToString();
22955
- D_ASSERT(child_string.size() >= 3);
22956
- D_ASSERT(child_string[0] == '\'' && child_string[child_string.size() - 1] == '\'');
22957
- return "(" + entry.children[0]->ToString() + ")." +
22958
- KeywordHelper::WriteOptionallyQuoted(child_string.substr(1, child_string.size() - 2));
22959
- }
22960
- case ExpressionType::ARRAY_CONSTRUCTOR: {
22961
- string result = "ARRAY[";
22962
- result += StringUtil::Join(entry.children, entry.children.size(), ", ",
22963
- [](const unique_ptr<BASE> &child) { return child->ToString(); });
22964
- result += "]";
22965
- return result;
22966
- }
22967
- default:
22968
- throw InternalException("Unrecognized operator type");
22969
- }
23184
+ return entry.left->ToString() + " " + ExpressionTypeToOperator(entry.type) + " " + entry.right->ToString();
22970
23185
  }
22971
23186
  };
22972
-
22973
23187
  } // namespace duckdb
22974
23188
 
23189
+
23190
+
22975
23191
  //===----------------------------------------------------------------------===//
22976
23192
  // DuckDB
22977
23193
  //
22978
- // duckdb/parser/expression/parameter_expression.hpp
23194
+ // duckdb/parser/expression/default_expression.hpp
22979
23195
  //
22980
23196
  //
22981
23197
  //===----------------------------------------------------------------------===//
@@ -22985,34 +23201,30 @@ public:
22985
23201
 
22986
23202
 
22987
23203
  namespace duckdb {
22988
- class ParameterExpression : public ParsedExpression {
23204
+ //! Represents the default value of a column
23205
+ class DefaultExpression : public ParsedExpression {
22989
23206
  public:
22990
- ParameterExpression();
22991
-
22992
- idx_t parameter_nr;
23207
+ DefaultExpression();
22993
23208
 
22994
23209
  public:
22995
23210
  bool IsScalar() const override {
22996
- return true;
22997
- }
22998
- bool HasParameter() const override {
22999
- return true;
23211
+ return false;
23000
23212
  }
23001
23213
 
23002
23214
  string ToString() const override;
23003
23215
 
23004
23216
  unique_ptr<ParsedExpression> Copy() const override;
23005
- hash_t Hash() const override;
23006
23217
 
23007
23218
  void Serialize(FieldWriter &writer) const override;
23008
23219
  static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
23009
23220
  };
23010
23221
  } // namespace duckdb
23011
23222
 
23223
+
23012
23224
  //===----------------------------------------------------------------------===//
23013
23225
  // DuckDB
23014
23226
  //
23015
- // duckdb/parser/expression/positional_reference_expression.hpp
23227
+ // duckdb/parser/expression/lambda_expression.hpp
23016
23228
  //
23017
23229
  //
23018
23230
  //===----------------------------------------------------------------------===//
@@ -23021,33 +23233,44 @@ public:
23021
23233
 
23022
23234
 
23023
23235
 
23236
+
23024
23237
  namespace duckdb {
23025
- class PositionalReferenceExpression : public ParsedExpression {
23238
+
23239
+ //! LambdaExpression represents either:
23240
+ //! 1. A lambda operator that can be used for e.g. mapping an expression to a list
23241
+ //! 2. An OperatorExpression with the "->" operator
23242
+ //! Lambda expressions are written in the form of "capture -> expr", e.g. "x -> x + 1"
23243
+ class LambdaExpression : public ParsedExpression {
23026
23244
  public:
23027
- DUCKDB_API PositionalReferenceExpression(idx_t index);
23245
+ LambdaExpression(unique_ptr<ParsedExpression> lhs, unique_ptr<ParsedExpression> rhs);
23028
23246
 
23029
- idx_t index;
23247
+ unique_ptr<ParsedExpression> lhs;
23248
+ unique_ptr<ParsedExpression> rhs;
23030
23249
 
23031
23250
  public:
23032
- bool IsScalar() const override {
23033
- return false;
23034
- }
23035
-
23036
23251
  string ToString() const override;
23037
23252
 
23038
- static bool Equals(const PositionalReferenceExpression *a, const PositionalReferenceExpression *b);
23039
- unique_ptr<ParsedExpression> Copy() const override;
23253
+ static bool Equals(const LambdaExpression *a, const LambdaExpression *b);
23040
23254
  hash_t Hash() const override;
23041
23255
 
23256
+ unique_ptr<ParsedExpression> Copy() const override;
23257
+
23042
23258
  void Serialize(FieldWriter &writer) const override;
23043
23259
  static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
23044
23260
  };
23261
+
23045
23262
  } // namespace duckdb
23046
23263
 
23264
+
23265
+
23266
+
23267
+
23268
+
23269
+
23047
23270
  //===----------------------------------------------------------------------===//
23048
23271
  // DuckDB
23049
23272
  //
23050
- // duckdb/parser/expression/star_expression.hpp
23273
+ // duckdb/parser/parsed_data/create_aggregate_function_info.hpp
23051
23274
  //
23052
23275
  //
23053
23276
  //===----------------------------------------------------------------------===//
@@ -23059,34 +23282,36 @@ public:
23059
23282
 
23060
23283
  namespace duckdb {
23061
23284
 
23062
- //! Represents a * expression in the SELECT clause
23063
- class StarExpression : public ParsedExpression {
23064
- public:
23065
- StarExpression(string relation_name = string());
23066
-
23067
- //! The relation name in case of tbl.*, or empty if this is a normal *
23068
- string relation_name;
23069
- //! List of columns to exclude from the STAR expression
23070
- case_insensitive_set_t exclude_list;
23071
- //! List of columns to replace with another expression
23072
- case_insensitive_map_t<unique_ptr<ParsedExpression>> replace_list;
23073
-
23074
- public:
23075
- string ToString() const override;
23285
+ struct CreateAggregateFunctionInfo : public CreateFunctionInfo {
23286
+ explicit CreateAggregateFunctionInfo(AggregateFunction function)
23287
+ : CreateFunctionInfo(CatalogType::AGGREGATE_FUNCTION_ENTRY), functions(function.name) {
23288
+ this->name = function.name;
23289
+ functions.AddFunction(move(function));
23290
+ }
23076
23291
 
23077
- static bool Equals(const StarExpression *a, const StarExpression *b);
23292
+ explicit CreateAggregateFunctionInfo(AggregateFunctionSet set)
23293
+ : CreateFunctionInfo(CatalogType::AGGREGATE_FUNCTION_ENTRY), functions(move(set)) {
23294
+ this->name = functions.name;
23295
+ for (auto &func : functions.functions) {
23296
+ func.name = functions.name;
23297
+ }
23298
+ }
23078
23299
 
23079
- unique_ptr<ParsedExpression> Copy() const override;
23300
+ AggregateFunctionSet functions;
23080
23301
 
23081
- void Serialize(FieldWriter &writer) const override;
23082
- static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
23302
+ public:
23303
+ unique_ptr<CreateInfo> Copy() const override {
23304
+ auto result = make_unique<CreateAggregateFunctionInfo>(functions);
23305
+ CopyProperties(*result);
23306
+ return move(result);
23307
+ }
23083
23308
  };
23084
- } // namespace duckdb
23085
23309
 
23310
+ } // namespace duckdb
23086
23311
  //===----------------------------------------------------------------------===//
23087
23312
  // DuckDB
23088
23313
  //
23089
- // duckdb/parser/expression/subquery_expression.hpp
23314
+ // duckdb/parser/parsed_data/drop_info.hpp
23090
23315
  //
23091
23316
  //
23092
23317
  //===----------------------------------------------------------------------===//
@@ -23096,44 +23321,37 @@ public:
23096
23321
 
23097
23322
 
23098
23323
 
23099
-
23100
23324
  namespace duckdb {
23101
23325
 
23102
- //! Represents a subquery
23103
- class SubqueryExpression : public ParsedExpression {
23104
- public:
23105
- SubqueryExpression();
23326
+ struct DropInfo : public ParseInfo {
23327
+ DropInfo() : schema(INVALID_SCHEMA), if_exists(false), cascade(false) {
23328
+ }
23106
23329
 
23107
- //! The actual subquery
23108
- unique_ptr<SelectStatement> subquery;
23109
- //! The subquery type
23110
- SubqueryType subquery_type;
23111
- //! the child expression to compare with (in case of IN, ANY, ALL operators, empty for EXISTS queries and scalar
23112
- //! subquery)
23113
- unique_ptr<ParsedExpression> child;
23114
- //! The comparison type of the child expression with the subquery (in case of ANY, ALL operators), empty otherwise
23115
- ExpressionType comparison_type;
23330
+ //! The catalog type to drop
23331
+ CatalogType type;
23332
+ //! Schema name to drop from, if any
23333
+ string schema;
23334
+ //! Element name to drop
23335
+ string name;
23336
+ //! Ignore if the entry does not exist instead of failing
23337
+ bool if_exists = false;
23338
+ //! Cascade drop (drop all dependents instead of throwing an error if there
23339
+ //! are any)
23340
+ bool cascade = false;
23116
23341
 
23117
23342
  public:
23118
- bool HasSubquery() const override {
23119
- return true;
23120
- }
23121
- bool IsScalar() const override {
23122
- return false;
23343
+ unique_ptr<DropInfo> Copy() const {
23344
+ auto result = make_unique<DropInfo>();
23345
+ result->type = type;
23346
+ result->schema = schema;
23347
+ result->name = name;
23348
+ result->if_exists = if_exists;
23349
+ result->cascade = cascade;
23350
+ return result;
23123
23351
  }
23124
-
23125
- string ToString() const override;
23126
-
23127
- static bool Equals(const SubqueryExpression *a, const SubqueryExpression *b);
23128
-
23129
- unique_ptr<ParsedExpression> Copy() const override;
23130
-
23131
- void Serialize(FieldWriter &writer) const override;
23132
- static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
23133
23352
  };
23134
- } // namespace duckdb
23135
-
23136
23353
 
23354
+ } // namespace duckdb
23137
23355
  //===----------------------------------------------------------------------===//
23138
23356
  // DuckDB
23139
23357
  //
@@ -23175,33 +23393,6 @@ public:
23175
23393
  }
23176
23394
  };
23177
23395
 
23178
- } // namespace duckdb
23179
- //===----------------------------------------------------------------------===//
23180
- // DuckDB
23181
- //
23182
- // duckdb/parser/parsed_data/create_schema_info.hpp
23183
- //
23184
- //
23185
- //===----------------------------------------------------------------------===//
23186
-
23187
-
23188
-
23189
-
23190
-
23191
- namespace duckdb {
23192
-
23193
- struct CreateSchemaInfo : public CreateInfo {
23194
- CreateSchemaInfo() : CreateInfo(CatalogType::SCHEMA_ENTRY) {
23195
- }
23196
-
23197
- public:
23198
- unique_ptr<CreateInfo> Copy() const override {
23199
- auto result = make_unique<CreateSchemaInfo>();
23200
- CopyProperties(*result);
23201
- return move(result);
23202
- }
23203
- };
23204
-
23205
23396
  } // namespace duckdb
23206
23397
  //===----------------------------------------------------------------------===//
23207
23398
  // DuckDB
@@ -23225,56 +23416,24 @@ struct ShowSelectInfo : public ParseInfo {
23225
23416
  unique_ptr<QueryNode> query;
23226
23417
  //! Aliases of projected columns
23227
23418
  vector<string> aliases;
23228
- //! Whether or not we are requesting a summary or a describe
23229
- bool is_summary;
23230
-
23231
- unique_ptr<ShowSelectInfo> Copy() {
23232
- auto result = make_unique<ShowSelectInfo>();
23233
- result->types = types;
23234
- result->query = query->Copy();
23235
- result->aliases = aliases;
23236
- result->is_summary = is_summary;
23237
- return result;
23238
- }
23239
- };
23240
-
23241
- } // namespace duckdb
23242
- //===----------------------------------------------------------------------===//
23243
- // DuckDB
23244
- //
23245
- // duckdb/parser/parsed_data/vacuum_info.hpp
23246
- //
23247
- //
23248
- //===----------------------------------------------------------------------===//
23249
-
23250
-
23251
-
23252
-
23253
-
23254
- namespace duckdb {
23255
-
23256
- struct VacuumInfo : public ParseInfo {
23257
- // nothing for now
23258
- };
23259
-
23260
- } // namespace duckdb
23261
- //===----------------------------------------------------------------------===//
23262
- // DuckDB
23263
- //
23264
- // duckdb/parser/parsed_data/create_index_info.hpp
23265
- //
23266
- //
23267
- //===----------------------------------------------------------------------===//
23268
-
23269
-
23270
-
23271
-
23419
+ //! Whether or not we are requesting a summary or a describe
23420
+ bool is_summary;
23272
23421
 
23422
+ unique_ptr<ShowSelectInfo> Copy() {
23423
+ auto result = make_unique<ShowSelectInfo>();
23424
+ result->types = types;
23425
+ result->query = query->Copy();
23426
+ result->aliases = aliases;
23427
+ result->is_summary = is_summary;
23428
+ return result;
23429
+ }
23430
+ };
23273
23431
 
23432
+ } // namespace duckdb
23274
23433
  //===----------------------------------------------------------------------===//
23275
23434
  // DuckDB
23276
23435
  //
23277
- // duckdb/parser/tableref/basetableref.hpp
23436
+ // duckdb/parser/parsed_data/transaction_info.hpp
23278
23437
  //
23279
23438
  //
23280
23439
  //===----------------------------------------------------------------------===//
@@ -23283,73 +23442,23 @@ struct VacuumInfo : public ParseInfo {
23283
23442
 
23284
23443
 
23285
23444
 
23286
-
23287
23445
  namespace duckdb {
23288
- //! Represents a TableReference to a base table in the schema
23289
- class BaseTableRef : public TableRef {
23290
- public:
23291
- BaseTableRef() : TableRef(TableReferenceType::BASE_TABLE), schema_name(INVALID_SCHEMA) {
23292
- }
23293
-
23294
- //! Schema name
23295
- string schema_name;
23296
- //! Table name
23297
- string table_name;
23298
- //! Aliases for the column names
23299
- vector<string> column_name_alias;
23300
-
23301
- public:
23302
- string ToString() const override;
23303
- bool Equals(const TableRef *other_p) const override;
23304
-
23305
- unique_ptr<TableRef> Copy() override;
23306
-
23307
- //! Serializes a blob into a BaseTableRef
23308
- void Serialize(FieldWriter &serializer) const override;
23309
- //! Deserializes a blob back into a BaseTableRef
23310
- static unique_ptr<TableRef> Deserialize(FieldReader &source);
23311
- };
23312
- } // namespace duckdb
23313
23446
 
23447
+ enum class TransactionType : uint8_t { INVALID, BEGIN_TRANSACTION, COMMIT, ROLLBACK };
23314
23448
 
23315
-
23316
- namespace duckdb {
23317
-
23318
- struct CreateIndexInfo : public CreateInfo {
23319
- CreateIndexInfo() : CreateInfo(CatalogType::INDEX_ENTRY) {
23449
+ struct TransactionInfo : public ParseInfo {
23450
+ explicit TransactionInfo(TransactionType type) : type(type) {
23320
23451
  }
23321
23452
 
23322
- //! Index Type (e.g., B+-tree, Skip-List, ...)
23323
- IndexType index_type;
23324
- //! Name of the Index
23325
- string index_name;
23326
- //! If it is an unique index
23327
- bool unique = false;
23328
- //! The table to create the index on
23329
- unique_ptr<BaseTableRef> table;
23330
- //! Set of expressions to index by
23331
- vector<unique_ptr<ParsedExpression>> expressions;
23332
-
23333
- public:
23334
- unique_ptr<CreateInfo> Copy() const override {
23335
- auto result = make_unique<CreateIndexInfo>();
23336
- CopyProperties(*result);
23337
- result->index_type = index_type;
23338
- result->index_name = index_name;
23339
- result->unique = unique;
23340
- result->table = unique_ptr_cast<TableRef, BaseTableRef>(table->Copy());
23341
- for (auto &expr : expressions) {
23342
- result->expressions.push_back(expr->Copy());
23343
- }
23344
- return move(result);
23345
- }
23453
+ //! The type of transaction statement
23454
+ TransactionType type;
23346
23455
  };
23347
23456
 
23348
23457
  } // namespace duckdb
23349
23458
  //===----------------------------------------------------------------------===//
23350
23459
  // DuckDB
23351
23460
  //
23352
- // duckdb/parser/parsed_data/transaction_info.hpp
23461
+ // duckdb/parser/parsed_data/vacuum_info.hpp
23353
23462
  //
23354
23463
  //
23355
23464
  //===----------------------------------------------------------------------===//
@@ -23360,14 +23469,19 @@ public:
23360
23469
 
23361
23470
  namespace duckdb {
23362
23471
 
23363
- enum class TransactionType : uint8_t { INVALID, BEGIN_TRANSACTION, COMMIT, ROLLBACK };
23472
+ enum class LoadType { LOAD, INSTALL, FORCE_INSTALL };
23364
23473
 
23365
- struct TransactionInfo : public ParseInfo {
23366
- explicit TransactionInfo(TransactionType type) : type(type) {
23367
- }
23474
+ struct LoadInfo : public ParseInfo {
23475
+ std::string filename;
23476
+ LoadType load_type;
23368
23477
 
23369
- //! The type of transaction statement
23370
- TransactionType type;
23478
+ public:
23479
+ unique_ptr<LoadInfo> Copy() const {
23480
+ auto result = make_unique<LoadInfo>();
23481
+ result->filename = filename;
23482
+ result->load_type = load_type;
23483
+ return result;
23484
+ }
23371
23485
  };
23372
23486
 
23373
23487
  } // namespace duckdb
@@ -23412,7 +23526,7 @@ public:
23412
23526
  //===----------------------------------------------------------------------===//
23413
23527
  // DuckDB
23414
23528
  //
23415
- // duckdb/parser/parsed_data/create_view_info.hpp
23529
+ // duckdb/parser/parsed_data/create_schema_info.hpp
23416
23530
  //
23417
23531
  //
23418
23532
  //===----------------------------------------------------------------------===//
@@ -23421,32 +23535,16 @@ public:
23421
23535
 
23422
23536
 
23423
23537
 
23424
-
23425
23538
  namespace duckdb {
23426
23539
 
23427
- struct CreateViewInfo : public CreateInfo {
23428
- CreateViewInfo() : CreateInfo(CatalogType::VIEW_ENTRY, INVALID_SCHEMA) {
23429
- }
23430
- CreateViewInfo(string schema, string view_name)
23431
- : CreateInfo(CatalogType::VIEW_ENTRY, schema), view_name(view_name) {
23540
+ struct CreateSchemaInfo : public CreateInfo {
23541
+ CreateSchemaInfo() : CreateInfo(CatalogType::SCHEMA_ENTRY) {
23432
23542
  }
23433
23543
 
23434
- //! Table name to insert to
23435
- string view_name;
23436
- //! Aliases of the view
23437
- vector<string> aliases;
23438
- //! Return types
23439
- vector<LogicalType> types;
23440
- //! The SelectStatement of the view
23441
- unique_ptr<SelectStatement> query;
23442
-
23443
23544
  public:
23444
23545
  unique_ptr<CreateInfo> Copy() const override {
23445
- auto result = make_unique<CreateViewInfo>(schema, view_name);
23546
+ auto result = make_unique<CreateSchemaInfo>();
23446
23547
  CopyProperties(*result);
23447
- result->aliases = aliases;
23448
- result->types = types;
23449
- result->query = unique_ptr_cast<SQLStatement, SelectStatement>(query->Copy());
23450
23548
  return move(result);
23451
23549
  }
23452
23550
  };
@@ -23455,7 +23553,7 @@ public:
23455
23553
  //===----------------------------------------------------------------------===//
23456
23554
  // DuckDB
23457
23555
  //
23458
- // duckdb/parser/parsed_data/create_macro_info.hpp
23556
+ // duckdb/parser/parsed_data/create_index_info.hpp
23459
23557
  //
23460
23558
  //
23461
23559
  //===----------------------------------------------------------------------===//
@@ -23463,74 +23561,78 @@ public:
23463
23561
 
23464
23562
 
23465
23563
 
23564
+
23565
+
23466
23566
  //===----------------------------------------------------------------------===//
23467
23567
  // DuckDB
23468
23568
  //
23469
- // duckdb/function/macro_function.hpp
23569
+ // duckdb/parser/tableref/basetableref.hpp
23470
23570
  //
23471
23571
  //
23472
23572
  //===----------------------------------------------------------------------===//
23473
23573
 
23474
23574
 
23475
- //! The SelectStatement of the view
23476
-
23477
-
23478
-
23479
23575
 
23480
23576
 
23481
23577
 
23482
23578
 
23483
23579
  namespace duckdb {
23484
-
23485
- enum class MacroType : uint8_t { VOID_MACRO = 0, TABLE_MACRO = 1, SCALAR_MACRO = 2 };
23486
-
23487
- class MacroFunction {
23580
+ //! Represents a TableReference to a base table in the schema
23581
+ class BaseTableRef : public TableRef {
23488
23582
  public:
23489
- // explicit MacroFunction(unique_ptr<ParsedExpression> expression);
23490
- MacroFunction(MacroType type);
23583
+ BaseTableRef() : TableRef(TableReferenceType::BASE_TABLE), schema_name(INVALID_SCHEMA) {
23584
+ }
23491
23585
 
23492
- // MacroFunction(void);
23493
- // The type
23494
- MacroType type;
23495
- //! The positional parameters
23496
- vector<unique_ptr<ParsedExpression>> parameters;
23497
- //! The default parameters and their associated values
23498
- unordered_map<string, unique_ptr<ParsedExpression>> default_parameters;
23586
+ //! Schema name
23587
+ string schema_name;
23588
+ //! Table name
23589
+ string table_name;
23590
+ //! Aliases for the column names
23591
+ vector<string> column_name_alias;
23499
23592
 
23500
23593
  public:
23501
- virtual ~MacroFunction() {
23502
- }
23503
-
23504
- void CopyProperties(MacroFunction &other);
23594
+ string ToString() const override;
23595
+ bool Equals(const TableRef *other_p) const override;
23505
23596
 
23506
- virtual unique_ptr<MacroFunction> Copy() = 0;
23597
+ unique_ptr<TableRef> Copy() override;
23507
23598
 
23508
- static string ValidateArguments(MacroFunction &macro_function, const string &name,
23509
- FunctionExpression &function_expr,
23510
- vector<unique_ptr<ParsedExpression>> &positionals,
23511
- unordered_map<string, unique_ptr<ParsedExpression>> &defaults);
23599
+ //! Serializes a blob into a BaseTableRef
23600
+ void Serialize(FieldWriter &serializer) const override;
23601
+ //! Deserializes a blob back into a BaseTableRef
23602
+ static unique_ptr<TableRef> Deserialize(FieldReader &source);
23512
23603
  };
23513
-
23514
23604
  } // namespace duckdb
23515
23605
 
23516
23606
 
23517
- namespace duckdb {
23518
23607
 
23519
- struct CreateMacroInfo : public CreateFunctionInfo {
23520
- CreateMacroInfo() : CreateFunctionInfo(CatalogType::MACRO_ENTRY, INVALID_SCHEMA) {
23521
- }
23608
+ namespace duckdb {
23522
23609
 
23523
- CreateMacroInfo(CatalogType type) : CreateFunctionInfo(type, INVALID_SCHEMA) {
23610
+ struct CreateIndexInfo : public CreateInfo {
23611
+ CreateIndexInfo() : CreateInfo(CatalogType::INDEX_ENTRY) {
23524
23612
  }
23525
23613
 
23526
- unique_ptr<MacroFunction> function;
23614
+ //! Index Type (e.g., B+-tree, Skip-List, ...)
23615
+ IndexType index_type;
23616
+ //! Name of the Index
23617
+ string index_name;
23618
+ //! If it is an unique index
23619
+ bool unique = false;
23620
+ //! The table to create the index on
23621
+ unique_ptr<BaseTableRef> table;
23622
+ //! Set of expressions to index by
23623
+ vector<unique_ptr<ParsedExpression>> expressions;
23527
23624
 
23528
23625
  public:
23529
23626
  unique_ptr<CreateInfo> Copy() const override {
23530
- auto result = make_unique<CreateMacroInfo>();
23531
- result->function = function->Copy();
23532
- result->name = name;
23627
+ auto result = make_unique<CreateIndexInfo>();
23533
23628
  CopyProperties(*result);
23629
+ result->index_type = index_type;
23630
+ result->index_name = index_name;
23631
+ result->unique = unique;
23632
+ result->table = unique_ptr_cast<TableRef, BaseTableRef>(table->Copy());
23633
+ for (auto &expr : expressions) {
23634
+ result->expressions.push_back(expr->Copy());
23635
+ }
23534
23636
  return move(result);
23535
23637
  }
23536
23638
  };
@@ -23575,7 +23677,7 @@ struct BoundExportData : public ParseInfo {
23575
23677
  //===----------------------------------------------------------------------===//
23576
23678
  // DuckDB
23577
23679
  //
23578
- // duckdb/parser/parsed_data/vacuum_info.hpp
23680
+ // duckdb/parser/parsed_data/create_macro_info.hpp
23579
23681
  //
23580
23682
  //
23581
23683
  //===----------------------------------------------------------------------===//
@@ -23583,106 +23685,75 @@ struct BoundExportData : public ParseInfo {
23583
23685
 
23584
23686
 
23585
23687
 
23586
-
23587
- namespace duckdb {
23588
-
23589
- enum class LoadType { LOAD, INSTALL, FORCE_INSTALL };
23590
-
23591
- struct LoadInfo : public ParseInfo {
23592
- std::string filename;
23593
- LoadType load_type;
23594
-
23595
- public:
23596
- unique_ptr<LoadInfo> Copy() const {
23597
- auto result = make_unique<LoadInfo>();
23598
- result->filename = filename;
23599
- result->load_type = load_type;
23600
- return result;
23601
- }
23602
- };
23603
-
23604
- } // namespace duckdb
23605
23688
  //===----------------------------------------------------------------------===//
23606
23689
  // DuckDB
23607
23690
  //
23608
- // duckdb/parser/parsed_data/create_aggregate_function_info.hpp
23691
+ // duckdb/function/macro_function.hpp
23609
23692
  //
23610
23693
  //
23611
23694
  //===----------------------------------------------------------------------===//
23612
23695
 
23613
23696
 
23697
+ //! The SelectStatement of the view
23614
23698
 
23615
23699
 
23616
23700
 
23617
23701
 
23618
- namespace duckdb {
23619
23702
 
23620
- struct CreateAggregateFunctionInfo : public CreateFunctionInfo {
23621
- explicit CreateAggregateFunctionInfo(AggregateFunction function)
23622
- : CreateFunctionInfo(CatalogType::AGGREGATE_FUNCTION_ENTRY), functions(function.name) {
23623
- this->name = function.name;
23624
- functions.AddFunction(move(function));
23625
- }
23626
23703
 
23627
- explicit CreateAggregateFunctionInfo(AggregateFunctionSet set)
23628
- : CreateFunctionInfo(CatalogType::AGGREGATE_FUNCTION_ENTRY), functions(move(set)) {
23629
- this->name = functions.name;
23630
- for (auto &func : functions.functions) {
23631
- func.name = functions.name;
23632
- }
23633
- }
23634
23704
 
23635
- AggregateFunctionSet functions;
23705
+ namespace duckdb {
23706
+
23707
+ enum class MacroType : uint8_t { VOID_MACRO = 0, TABLE_MACRO = 1, SCALAR_MACRO = 2 };
23636
23708
 
23709
+ class MacroFunction {
23637
23710
  public:
23638
- unique_ptr<CreateInfo> Copy() const override {
23639
- auto result = make_unique<CreateAggregateFunctionInfo>(functions);
23640
- CopyProperties(*result);
23641
- return move(result);
23642
- }
23643
- };
23711
+ // explicit MacroFunction(unique_ptr<ParsedExpression> expression);
23712
+ MacroFunction(MacroType type);
23713
+
23714
+ // MacroFunction(void);
23715
+ // The type
23716
+ MacroType type;
23717
+ //! The positional parameters
23718
+ vector<unique_ptr<ParsedExpression>> parameters;
23719
+ //! The default parameters and their associated values
23720
+ unordered_map<string, unique_ptr<ParsedExpression>> default_parameters;
23644
23721
 
23645
- } // namespace duckdb
23646
- //===----------------------------------------------------------------------===//
23647
- // DuckDB
23648
- //
23649
- // duckdb/parser/parsed_data/drop_info.hpp
23650
- //
23651
- //
23652
- //===----------------------------------------------------------------------===//
23722
+ public:
23723
+ virtual ~MacroFunction() {
23724
+ }
23653
23725
 
23726
+ void CopyProperties(MacroFunction &other);
23654
23727
 
23728
+ virtual unique_ptr<MacroFunction> Copy() = 0;
23655
23729
 
23730
+ static string ValidateArguments(MacroFunction &macro_function, const string &name,
23731
+ FunctionExpression &function_expr,
23732
+ vector<unique_ptr<ParsedExpression>> &positionals,
23733
+ unordered_map<string, unique_ptr<ParsedExpression>> &defaults);
23734
+ };
23656
23735
 
23736
+ } // namespace duckdb
23657
23737
 
23658
23738
 
23659
23739
  namespace duckdb {
23660
23740
 
23661
- struct DropInfo : public ParseInfo {
23662
- DropInfo() : schema(INVALID_SCHEMA), if_exists(false), cascade(false) {
23741
+ struct CreateMacroInfo : public CreateFunctionInfo {
23742
+ CreateMacroInfo() : CreateFunctionInfo(CatalogType::MACRO_ENTRY, INVALID_SCHEMA) {
23663
23743
  }
23664
23744
 
23665
- //! The catalog type to drop
23666
- CatalogType type;
23667
- //! Schema name to drop from, if any
23668
- string schema;
23669
- //! Element name to drop
23670
- string name;
23671
- //! Ignore if the entry does not exist instead of failing
23672
- bool if_exists = false;
23673
- //! Cascade drop (drop all dependents instead of throwing an error if there
23674
- //! are any)
23675
- bool cascade = false;
23745
+ CreateMacroInfo(CatalogType type) : CreateFunctionInfo(type, INVALID_SCHEMA) {
23746
+ }
23747
+
23748
+ unique_ptr<MacroFunction> function;
23676
23749
 
23677
23750
  public:
23678
- unique_ptr<DropInfo> Copy() const {
23679
- auto result = make_unique<DropInfo>();
23680
- result->type = type;
23681
- result->schema = schema;
23751
+ unique_ptr<CreateInfo> Copy() const override {
23752
+ auto result = make_unique<CreateMacroInfo>();
23753
+ result->function = function->Copy();
23682
23754
  result->name = name;
23683
- result->if_exists = if_exists;
23684
- result->cascade = cascade;
23685
- return result;
23755
+ CopyProperties(*result);
23756
+ return move(result);
23686
23757
  }
23687
23758
  };
23688
23759
 
@@ -23730,7 +23801,7 @@ public:
23730
23801
  //===----------------------------------------------------------------------===//
23731
23802
  // DuckDB
23732
23803
  //
23733
- // duckdb/parser/tableref/expressionlistref.hpp
23804
+ // duckdb/parser/parsed_data/create_view_info.hpp
23734
23805
  //
23735
23806
  //
23736
23807
  //===----------------------------------------------------------------------===//
@@ -23740,38 +23811,59 @@ public:
23740
23811
 
23741
23812
 
23742
23813
 
23814
+ namespace duckdb {
23743
23815
 
23816
+ struct CreateViewInfo : public CreateInfo {
23817
+ CreateViewInfo() : CreateInfo(CatalogType::VIEW_ENTRY, INVALID_SCHEMA) {
23818
+ }
23819
+ CreateViewInfo(string schema, string view_name)
23820
+ : CreateInfo(CatalogType::VIEW_ENTRY, schema), view_name(view_name) {
23821
+ }
23822
+
23823
+ //! Table name to insert to
23824
+ string view_name;
23825
+ //! Aliases of the view
23826
+ vector<string> aliases;
23827
+ //! Return types
23828
+ vector<LogicalType> types;
23829
+ //! The SelectStatement of the view
23830
+ unique_ptr<SelectStatement> query;
23744
23831
 
23745
- namespace duckdb {
23746
- //! Represents an expression list as generated by a VALUES statement
23747
- class ExpressionListRef : public TableRef {
23748
23832
  public:
23749
- ExpressionListRef() : TableRef(TableReferenceType::EXPRESSION_LIST) {
23833
+ unique_ptr<CreateInfo> Copy() const override {
23834
+ auto result = make_unique<CreateViewInfo>(schema, view_name);
23835
+ CopyProperties(*result);
23836
+ result->aliases = aliases;
23837
+ result->types = types;
23838
+ result->query = unique_ptr_cast<SQLStatement, SelectStatement>(query->Copy());
23839
+ return move(result);
23750
23840
  }
23841
+ };
23751
23842
 
23752
- //! Value list, only used for VALUES statement
23753
- vector<vector<unique_ptr<ParsedExpression>>> values;
23754
- //! Expected SQL types
23755
- vector<LogicalType> expected_types;
23756
- //! The set of expected names
23757
- vector<string> expected_names;
23843
+ } // namespace duckdb
23844
+ //===----------------------------------------------------------------------===//
23845
+ // DuckDB
23846
+ //
23847
+ // duckdb/parser/parsed_data/vacuum_info.hpp
23848
+ //
23849
+ //
23850
+ //===----------------------------------------------------------------------===//
23758
23851
 
23759
- public:
23760
- bool Equals(const TableRef *other_p) const override;
23761
23852
 
23762
- unique_ptr<TableRef> Copy() override;
23763
23853
 
23764
- //! Serializes a blob into a ExpressionListRef
23765
- void Serialize(FieldWriter &serializer) const override;
23766
- //! Deserializes a blob back into a ExpressionListRef
23767
- static unique_ptr<TableRef> Deserialize(FieldReader &source);
23854
+
23855
+
23856
+ namespace duckdb {
23857
+
23858
+ struct VacuumInfo : public ParseInfo {
23859
+ // nothing for now
23768
23860
  };
23769
- } // namespace duckdb
23770
23861
 
23862
+ } // namespace duckdb
23771
23863
  //===----------------------------------------------------------------------===//
23772
23864
  // DuckDB
23773
23865
  //
23774
- // duckdb/parser/tableref/crossproductref.hpp
23866
+ // duckdb/parser/tableref/emptytableref.hpp
23775
23867
  //
23776
23868
  //
23777
23869
  //===----------------------------------------------------------------------===//
@@ -23782,32 +23874,27 @@ public:
23782
23874
 
23783
23875
  namespace duckdb {
23784
23876
  //! Represents a cross product
23785
- class CrossProductRef : public TableRef {
23877
+ class EmptyTableRef : public TableRef {
23786
23878
  public:
23787
- CrossProductRef() : TableRef(TableReferenceType::CROSS_PRODUCT) {
23879
+ EmptyTableRef() : TableRef(TableReferenceType::EMPTY) {
23788
23880
  }
23789
23881
 
23790
- //! The left hand side of the cross product
23791
- unique_ptr<TableRef> left;
23792
- //! The right hand side of the cross product
23793
- unique_ptr<TableRef> right;
23794
-
23795
23882
  public:
23883
+ string ToString() const override;
23796
23884
  bool Equals(const TableRef *other_p) const override;
23797
23885
 
23798
23886
  unique_ptr<TableRef> Copy() override;
23799
23887
 
23800
- //! Serializes a blob into a CrossProductRef
23888
+ //! Serializes a blob into a DummyTableRef
23801
23889
  void Serialize(FieldWriter &serializer) const override;
23802
- //! Deserializes a blob back into a CrossProductRef
23890
+ //! Deserializes a blob back into a DummyTableRef
23803
23891
  static unique_ptr<TableRef> Deserialize(FieldReader &source);
23804
23892
  };
23805
23893
  } // namespace duckdb
23806
-
23807
23894
  //===----------------------------------------------------------------------===//
23808
23895
  // DuckDB
23809
23896
  //
23810
- // duckdb/parser/tableref/emptytableref.hpp
23897
+ // duckdb/parser/tableref/table_function_ref.hpp
23811
23898
  //
23812
23899
  //
23813
23900
  //===----------------------------------------------------------------------===//
@@ -23816,30 +23903,38 @@ public:
23816
23903
 
23817
23904
 
23818
23905
 
23906
+
23907
+
23908
+
23819
23909
  namespace duckdb {
23820
- //! Represents a cross product
23821
- class EmptyTableRef : public TableRef {
23910
+ //! Represents a Table producing function
23911
+ class TableFunctionRef : public TableRef {
23822
23912
  public:
23823
- EmptyTableRef() : TableRef(TableReferenceType::EMPTY) {
23824
- }
23913
+ DUCKDB_API TableFunctionRef();
23914
+
23915
+ unique_ptr<ParsedExpression> function;
23916
+ vector<string> column_name_alias;
23917
+
23918
+ // if the function takes a subquery as argument its in here
23919
+ unique_ptr<SelectStatement> subquery;
23825
23920
 
23826
23921
  public:
23922
+ string ToString() const override;
23923
+
23827
23924
  bool Equals(const TableRef *other_p) const override;
23828
23925
 
23829
23926
  unique_ptr<TableRef> Copy() override;
23830
23927
 
23831
- //! Serializes a blob into a DummyTableRef
23928
+ //! Serializes a blob into a BaseTableRef
23832
23929
  void Serialize(FieldWriter &serializer) const override;
23833
- //! Deserializes a blob back into a DummyTableRef
23930
+ //! Deserializes a blob back into a BaseTableRef
23834
23931
  static unique_ptr<TableRef> Deserialize(FieldReader &source);
23835
23932
  };
23836
23933
  } // namespace duckdb
23837
-
23838
-
23839
23934
  //===----------------------------------------------------------------------===//
23840
23935
  // DuckDB
23841
23936
  //
23842
- // duckdb/parser/tableref/joinref.hpp
23937
+ // duckdb/parser/tableref/expressionlistref.hpp
23843
23938
  //
23844
23939
  //
23845
23940
  //===----------------------------------------------------------------------===//
@@ -23851,39 +23946,32 @@ public:
23851
23946
 
23852
23947
 
23853
23948
 
23854
-
23855
23949
  namespace duckdb {
23856
- //! Represents a JOIN between two expressions
23857
- class JoinRef : public TableRef {
23950
+ //! Represents an expression list as generated by a VALUES statement
23951
+ class ExpressionListRef : public TableRef {
23858
23952
  public:
23859
- JoinRef() : TableRef(TableReferenceType::JOIN), is_natural(false) {
23953
+ ExpressionListRef() : TableRef(TableReferenceType::EXPRESSION_LIST) {
23860
23954
  }
23861
23955
 
23862
- //! The left hand side of the join
23863
- unique_ptr<TableRef> left;
23864
- //! The right hand side of the join
23865
- unique_ptr<TableRef> right;
23866
- //! The join condition
23867
- unique_ptr<ParsedExpression> condition;
23868
- //! The join type
23869
- JoinType type;
23870
- //! Natural join
23871
- bool is_natural;
23872
- //! The set of USING columns (if any)
23873
- vector<string> using_columns;
23956
+ //! Value list, only used for VALUES statement
23957
+ vector<vector<unique_ptr<ParsedExpression>>> values;
23958
+ //! Expected SQL types
23959
+ vector<LogicalType> expected_types;
23960
+ //! The set of expected names
23961
+ vector<string> expected_names;
23874
23962
 
23875
23963
  public:
23964
+ string ToString() const override;
23876
23965
  bool Equals(const TableRef *other_p) const override;
23877
23966
 
23878
23967
  unique_ptr<TableRef> Copy() override;
23879
23968
 
23880
- //! Serializes a blob into a JoinRef
23969
+ //! Serializes a blob into a ExpressionListRef
23881
23970
  void Serialize(FieldWriter &serializer) const override;
23882
- //! Deserializes a blob back into a JoinRef
23971
+ //! Deserializes a blob back into a ExpressionListRef
23883
23972
  static unique_ptr<TableRef> Deserialize(FieldReader &source);
23884
23973
  };
23885
23974
  } // namespace duckdb
23886
-
23887
23975
  //===----------------------------------------------------------------------===//
23888
23976
  // DuckDB
23889
23977
  //
@@ -23909,6 +23997,7 @@ public:
23909
23997
  vector<string> column_name_alias;
23910
23998
 
23911
23999
  public:
24000
+ string ToString() const override;
23912
24001
  bool Equals(const TableRef *other_p) const override;
23913
24002
 
23914
24003
  unique_ptr<TableRef> Copy() override;
@@ -23923,7 +24012,46 @@ public:
23923
24012
  //===----------------------------------------------------------------------===//
23924
24013
  // DuckDB
23925
24014
  //
23926
- // duckdb/parser/tableref/table_function_ref.hpp
24015
+ // duckdb/parser/tableref/crossproductref.hpp
24016
+ //
24017
+ //
24018
+ //===----------------------------------------------------------------------===//
24019
+
24020
+
24021
+
24022
+
24023
+
24024
+ namespace duckdb {
24025
+ //! Represents a cross product
24026
+ class CrossProductRef : public TableRef {
24027
+ public:
24028
+ CrossProductRef() : TableRef(TableReferenceType::CROSS_PRODUCT) {
24029
+ }
24030
+
24031
+ //! The left hand side of the cross product
24032
+ unique_ptr<TableRef> left;
24033
+ //! The right hand side of the cross product
24034
+ unique_ptr<TableRef> right;
24035
+
24036
+ public:
24037
+ string ToString() const override;
24038
+ bool Equals(const TableRef *other_p) const override;
24039
+
24040
+ unique_ptr<TableRef> Copy() override;
24041
+
24042
+ //! Serializes a blob into a CrossProductRef
24043
+ void Serialize(FieldWriter &serializer) const override;
24044
+ //! Deserializes a blob back into a CrossProductRef
24045
+ static unique_ptr<TableRef> Deserialize(FieldReader &source);
24046
+ };
24047
+ } // namespace duckdb
24048
+
24049
+
24050
+
24051
+ //===----------------------------------------------------------------------===//
24052
+ // DuckDB
24053
+ //
24054
+ // duckdb/parser/tableref/joinref.hpp
23927
24055
  //
23928
24056
  //
23929
24057
  //===----------------------------------------------------------------------===//
@@ -23935,30 +24063,39 @@ public:
23935
24063
 
23936
24064
 
23937
24065
 
24066
+
23938
24067
  namespace duckdb {
23939
- //! Represents a Table producing function
23940
- class TableFunctionRef : public TableRef {
24068
+ //! Represents a JOIN between two expressions
24069
+ class JoinRef : public TableRef {
23941
24070
  public:
23942
- TableFunctionRef() : TableRef(TableReferenceType::TABLE_FUNCTION) {
24071
+ JoinRef() : TableRef(TableReferenceType::JOIN), is_natural(false) {
23943
24072
  }
23944
24073
 
23945
- unique_ptr<ParsedExpression> function;
23946
- vector<string> column_name_alias;
23947
-
23948
- // if the function takes a subquery as argument its in here
23949
- unique_ptr<SelectStatement> subquery;
24074
+ //! The left hand side of the join
24075
+ unique_ptr<TableRef> left;
24076
+ //! The right hand side of the join
24077
+ unique_ptr<TableRef> right;
24078
+ //! The join condition
24079
+ unique_ptr<ParsedExpression> condition;
24080
+ //! The join type
24081
+ JoinType type;
24082
+ //! Natural join
24083
+ bool is_natural;
24084
+ //! The set of USING columns (if any)
24085
+ vector<string> using_columns;
23950
24086
 
23951
24087
  public:
23952
24088
  string ToString() const override;
23953
-
23954
24089
  bool Equals(const TableRef *other_p) const override;
23955
24090
 
23956
24091
  unique_ptr<TableRef> Copy() override;
23957
24092
 
23958
- //! Serializes a blob into a BaseTableRef
24093
+ //! Serializes a blob into a JoinRef
23959
24094
  void Serialize(FieldWriter &serializer) const override;
23960
- //! Deserializes a blob back into a BaseTableRef
24095
+ //! Deserializes a blob back into a JoinRef
23961
24096
  static unique_ptr<TableRef> Deserialize(FieldReader &source);
23962
24097
  };
23963
24098
  } // namespace duckdb
23964
24099
 
24100
+
24101
+