duckdb 0.3.5-dev22.0 → 0.3.5-dev250.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 "339bd4003"
15
- #define DUCKDB_VERSION "v0.3.5-dev22"
14
+ #define DUCKDB_SOURCE_ID "91d3928b6"
15
+ #define DUCKDB_VERSION "v0.3.5-dev250"
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;
@@ -5315,195 +5319,6 @@ using std::chrono::system_clock;
5315
5319
  using std::chrono::time_point;
5316
5320
  } // namespace duckdb
5317
5321
 
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
5322
 
5508
5323
  namespace duckdb {
5509
5324
 
@@ -5561,7 +5376,6 @@ private:
5561
5376
 
5562
5377
  } // namespace duckdb
5563
5378
 
5564
-
5565
5379
  //===----------------------------------------------------------------------===//
5566
5380
  // DuckDB
5567
5381
  //
@@ -6137,7 +5951,7 @@ public:
6137
5951
  static bool RequiresQuotes(const string &text);
6138
5952
 
6139
5953
  //! Writes a string that is optionally quoted + escaped so it can be used as an identifier
6140
- static string WriteOptionallyQuoted(const string &text);
5954
+ static string WriteOptionallyQuoted(const string &text, char quote = '"');
6141
5955
  };
6142
5956
 
6143
5957
  } // namespace duckdb
@@ -6390,14 +6204,19 @@ struct PragmaInfo;
6390
6204
  struct FunctionData {
6391
6205
  DUCKDB_API virtual ~FunctionData();
6392
6206
 
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);
6207
+ DUCKDB_API virtual unique_ptr<FunctionData> Copy() const = 0;
6208
+ DUCKDB_API virtual bool Equals(const FunctionData &other) const = 0;
6209
+ DUCKDB_API static bool Equals(const FunctionData *left, const FunctionData *right);
6396
6210
  };
6397
6211
 
6398
6212
  struct TableFunctionData : public FunctionData {
6399
6213
  // used to pass on projections to table functions that support them. NB, can contain COLUMN_IDENTIFIER_ROW_ID
6400
6214
  vector<idx_t> column_ids;
6215
+
6216
+ DUCKDB_API virtual ~TableFunctionData();
6217
+
6218
+ DUCKDB_API unique_ptr<FunctionData> Copy() const override;
6219
+ DUCKDB_API bool Equals(const FunctionData &other) const override;
6401
6220
  };
6402
6221
 
6403
6222
  struct FunctionParameters {
@@ -6427,11 +6246,14 @@ public:
6427
6246
  //! Bind a scalar function from the set of functions and input arguments. Returns the index of the chosen function,
6428
6247
  //! returns DConstants::INVALID_INDEX and sets error if none could be found
6429
6248
  DUCKDB_API static idx_t BindFunction(const string &name, vector<ScalarFunction> &functions,
6430
- vector<LogicalType> &arguments, string &error);
6249
+ vector<LogicalType> &arguments, string &error, bool &cast_parameters);
6431
6250
  DUCKDB_API static idx_t BindFunction(const string &name, vector<ScalarFunction> &functions,
6432
- vector<unique_ptr<Expression>> &arguments, string &error);
6251
+ vector<unique_ptr<Expression>> &arguments, string &error,
6252
+ bool &cast_parameters);
6433
6253
  //! Bind an aggregate function from the set of functions and input arguments. Returns the index of the chosen
6434
6254
  //! function, returns DConstants::INVALID_INDEX and sets error if none could be found
6255
+ DUCKDB_API static idx_t BindFunction(const string &name, vector<AggregateFunction> &functions,
6256
+ vector<LogicalType> &arguments, string &error, bool &cast_parameters);
6435
6257
  DUCKDB_API static idx_t BindFunction(const string &name, vector<AggregateFunction> &functions,
6436
6258
  vector<LogicalType> &arguments, string &error);
6437
6259
  DUCKDB_API static idx_t BindFunction(const string &name, vector<AggregateFunction> &functions,
@@ -6477,10 +6299,6 @@ public:
6477
6299
  public:
6478
6300
  DUCKDB_API string ToString() override;
6479
6301
  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
6302
  };
6485
6303
 
6486
6304
  class BaseScalarFunction : public SimpleFunction {
@@ -6502,7 +6320,8 @@ public:
6502
6320
  DUCKDB_API hash_t Hash() const;
6503
6321
 
6504
6322
  //! Cast a set of expressions to the arguments of this function
6505
- DUCKDB_API void CastToFunctionArguments(vector<unique_ptr<Expression>> &children);
6323
+ DUCKDB_API void CastToFunctionArguments(vector<unique_ptr<Expression>> &children,
6324
+ bool cast_parameter_expressions = true);
6506
6325
 
6507
6326
  DUCKDB_API string ToString() override;
6508
6327
  };
@@ -6574,6 +6393,7 @@ namespace duckdb {
6574
6393
  class Expression;
6575
6394
  class ExpressionExecutor;
6576
6395
  struct ExpressionExecutorState;
6396
+ struct FunctionLocalState;
6577
6397
 
6578
6398
  struct ExpressionState {
6579
6399
  ExpressionState(const Expression &expr, ExpressionExecutorState &root);
@@ -6594,13 +6414,13 @@ public:
6594
6414
  };
6595
6415
 
6596
6416
  struct ExecuteFunctionState : public ExpressionState {
6597
- ExecuteFunctionState(const Expression &expr, ExpressionExecutorState &root) : ExpressionState(expr, root) {
6598
- }
6417
+ ExecuteFunctionState(const Expression &expr, ExpressionExecutorState &root);
6418
+ ~ExecuteFunctionState();
6599
6419
 
6600
- unique_ptr<FunctionData> local_state;
6420
+ unique_ptr<FunctionLocalState> local_state;
6601
6421
 
6602
6422
  public:
6603
- static FunctionData *GetFunctionState(ExpressionState &state) {
6423
+ static FunctionLocalState *GetFunctionState(ExpressionState &state) {
6604
6424
  return ((ExecuteFunctionState &)state).local_state.get();
6605
6425
  }
6606
6426
  };
@@ -6651,61 +6471,206 @@ struct ExpressionExecutorState {
6651
6471
 
6652
6472
 
6653
6473
 
6474
+ //===----------------------------------------------------------------------===//
6475
+ // DuckDB
6476
+ //
6477
+ // duckdb/common/limits.hpp
6478
+ //
6479
+ //
6480
+ //===----------------------------------------------------------------------===//
6654
6481
 
6655
6482
 
6656
6483
 
6657
- namespace duckdb {
6658
6484
 
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
6485
 
6669
- static hugeint_t FromString(string str) {
6670
- hugeint_t result;
6671
- FromString(str, result);
6672
- return result;
6673
- }
6486
+ namespace duckdb {
6674
6487
 
6675
- template <class T>
6676
- static bool TryCast(hugeint_t input, T &result);
6488
+ template <class T>
6489
+ struct NumericLimits {
6490
+ static T Minimum();
6491
+ static T Maximum();
6492
+ static bool IsSigned();
6493
+ static idx_t Digits();
6494
+ };
6677
6495
 
6678
- template <class T>
6679
- static T Cast(hugeint_t input) {
6680
- T value;
6681
- TryCast(input, value);
6682
- return value;
6496
+ template <>
6497
+ struct NumericLimits<int8_t> {
6498
+ static int8_t Minimum();
6499
+ static int8_t Maximum();
6500
+ static bool IsSigned() {
6501
+ return true;
6683
6502
  }
6684
-
6685
- template <class T>
6686
- static bool TryConvert(T value, hugeint_t &result);
6687
-
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
+ static idx_t Digits() {
6504
+ return 3;
6695
6505
  }
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);
6506
+ };
6507
+ template <>
6508
+ struct NumericLimits<int16_t> {
6509
+ static int16_t Minimum();
6510
+ static int16_t Maximum();
6511
+ static bool IsSigned() {
6512
+ return true;
6700
6513
  }
6701
- static hugeint_t Negate(hugeint_t input) {
6702
- NegateInPlace(input);
6703
- return input;
6514
+ static idx_t Digits() {
6515
+ return 5;
6704
6516
  }
6705
-
6706
- static bool TryMultiply(hugeint_t lhs, hugeint_t rhs, hugeint_t &result);
6707
-
6708
- static hugeint_t Add(hugeint_t lhs, hugeint_t rhs);
6517
+ };
6518
+ template <>
6519
+ struct NumericLimits<int32_t> {
6520
+ static int32_t Minimum();
6521
+ static int32_t Maximum();
6522
+ static bool IsSigned() {
6523
+ return true;
6524
+ }
6525
+ static idx_t Digits() {
6526
+ return 10;
6527
+ }
6528
+ };
6529
+ template <>
6530
+ struct NumericLimits<int64_t> {
6531
+ static int64_t Minimum();
6532
+ static int64_t Maximum();
6533
+ static bool IsSigned() {
6534
+ return true;
6535
+ }
6536
+ static idx_t Digits() {
6537
+ return 19;
6538
+ }
6539
+ };
6540
+ template <>
6541
+ struct NumericLimits<hugeint_t> {
6542
+ static hugeint_t Minimum();
6543
+ static hugeint_t Maximum();
6544
+ static bool IsSigned() {
6545
+ return true;
6546
+ }
6547
+ static idx_t Digits() {
6548
+ return 39;
6549
+ }
6550
+ };
6551
+ template <>
6552
+ struct NumericLimits<uint8_t> {
6553
+ static uint8_t Minimum();
6554
+ static uint8_t Maximum();
6555
+ static bool IsSigned() {
6556
+ return false;
6557
+ }
6558
+ static idx_t Digits() {
6559
+ return 3;
6560
+ }
6561
+ };
6562
+ template <>
6563
+ struct NumericLimits<uint16_t> {
6564
+ static uint16_t Minimum();
6565
+ static uint16_t Maximum();
6566
+ static bool IsSigned() {
6567
+ return false;
6568
+ }
6569
+ static idx_t Digits() {
6570
+ return 5;
6571
+ }
6572
+ };
6573
+ template <>
6574
+ struct NumericLimits<uint32_t> {
6575
+ static uint32_t Minimum();
6576
+ static uint32_t Maximum();
6577
+ static bool IsSigned() {
6578
+ return false;
6579
+ }
6580
+ static idx_t Digits() {
6581
+ return 10;
6582
+ }
6583
+ };
6584
+ template <>
6585
+ struct NumericLimits<uint64_t> {
6586
+ static uint64_t Minimum();
6587
+ static uint64_t Maximum();
6588
+ static bool IsSigned() {
6589
+ return false;
6590
+ }
6591
+ static idx_t Digits() {
6592
+ return 20;
6593
+ }
6594
+ };
6595
+ template <>
6596
+ struct NumericLimits<float> {
6597
+ static float Minimum();
6598
+ static float Maximum();
6599
+ static bool IsSigned() {
6600
+ return true;
6601
+ }
6602
+ static idx_t Digits() {
6603
+ return 127;
6604
+ }
6605
+ };
6606
+ template <>
6607
+ struct NumericLimits<double> {
6608
+ static double Minimum();
6609
+ static double Maximum();
6610
+ static bool IsSigned() {
6611
+ return true;
6612
+ }
6613
+ static idx_t Digits() {
6614
+ return 250;
6615
+ }
6616
+ };
6617
+
6618
+ } // namespace duckdb
6619
+
6620
+
6621
+
6622
+ namespace duckdb {
6623
+
6624
+ //! The Hugeint class contains static operations for the INT128 type
6625
+ class Hugeint {
6626
+ public:
6627
+ //! Convert a string to a hugeint object
6628
+ static bool FromString(string str, hugeint_t &result);
6629
+ //! Convert a string to a hugeint object
6630
+ static bool FromCString(const char *str, idx_t len, hugeint_t &result);
6631
+ //! Convert a hugeint object to a string
6632
+ static string ToString(hugeint_t input);
6633
+
6634
+ static hugeint_t FromString(string str) {
6635
+ hugeint_t result;
6636
+ FromString(str, result);
6637
+ return result;
6638
+ }
6639
+
6640
+ template <class T>
6641
+ static bool TryCast(hugeint_t input, T &result);
6642
+
6643
+ template <class T>
6644
+ static T Cast(hugeint_t input) {
6645
+ T value;
6646
+ TryCast(input, value);
6647
+ return value;
6648
+ }
6649
+
6650
+ template <class T>
6651
+ static bool TryConvert(T value, hugeint_t &result);
6652
+
6653
+ template <class T>
6654
+ static hugeint_t Convert(T value) {
6655
+ hugeint_t result;
6656
+ if (!TryConvert(value, result)) { // LCOV_EXCL_START
6657
+ throw ValueOutOfRangeException(double(value), GetTypeId<T>(), GetTypeId<hugeint_t>());
6658
+ } // LCOV_EXCL_STOP
6659
+ return result;
6660
+ }
6661
+
6662
+ static void NegateInPlace(hugeint_t &input) {
6663
+ input.lower = NumericLimits<uint64_t>::Maximum() - input.lower + 1;
6664
+ input.upper = -1 - input.upper + (input.lower == 0);
6665
+ }
6666
+ static hugeint_t Negate(hugeint_t input) {
6667
+ NegateInPlace(input);
6668
+ return input;
6669
+ }
6670
+
6671
+ static bool TryMultiply(hugeint_t lhs, hugeint_t rhs, hugeint_t &result);
6672
+
6673
+ static hugeint_t Add(hugeint_t lhs, hugeint_t rhs);
6709
6674
  static hugeint_t Subtract(hugeint_t lhs, hugeint_t rhs);
6710
6675
  static hugeint_t Multiply(hugeint_t lhs, hugeint_t rhs);
6711
6676
  static hugeint_t Divide(hugeint_t lhs, hugeint_t rhs);
@@ -7235,6 +7200,11 @@ public:
7235
7200
 
7236
7201
 
7237
7202
  namespace duckdb {
7203
+
7204
+ struct FunctionLocalState {
7205
+ DUCKDB_API virtual ~FunctionLocalState();
7206
+ };
7207
+
7238
7208
  class BoundFunctionExpression;
7239
7209
  class ScalarFunctionCatalogEntry;
7240
7210
 
@@ -7243,7 +7213,8 @@ typedef std::function<void(DataChunk &, ExpressionState &, Vector &)> scalar_fun
7243
7213
  //! Binds the scalar function and creates the function data
7244
7214
  typedef unique_ptr<FunctionData> (*bind_scalar_function_t)(ClientContext &context, ScalarFunction &bound_function,
7245
7215
  vector<unique_ptr<Expression>> &arguments);
7246
- typedef unique_ptr<FunctionData> (*init_local_state_t)(const BoundFunctionExpression &expr, FunctionData *bind_data);
7216
+ typedef unique_ptr<FunctionLocalState> (*init_local_state_t)(const BoundFunctionExpression &expr,
7217
+ FunctionData *bind_data);
7247
7218
  typedef unique_ptr<BaseStatistics> (*function_statistics_t)(ClientContext &context, BoundFunctionExpression &expr,
7248
7219
  FunctionData *bind_data,
7249
7220
  vector<unique_ptr<BaseStatistics>> &child_stats);
@@ -7285,10 +7256,9 @@ public:
7285
7256
  vector<unique_ptr<Expression>> children,
7286
7257
  string &error, bool is_operator = false);
7287
7258
 
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);
7259
+ DUCKDB_API static unique_ptr<BoundFunctionExpression>
7260
+ BindScalarFunction(ClientContext &context, ScalarFunction bound_function, vector<unique_ptr<Expression>> children,
7261
+ bool is_operator = false, bool cast_parameters = true);
7292
7262
 
7293
7263
  DUCKDB_API bool operator==(const ScalarFunction &rhs) const;
7294
7264
  DUCKDB_API bool operator!=(const ScalarFunction &rhs) const;
@@ -7716,13 +7686,13 @@ public:
7716
7686
  }
7717
7687
 
7718
7688
  template <class STATE_TYPE, class OP>
7719
- static void Combine(Vector &source, Vector &target, idx_t count) {
7689
+ static void Combine(Vector &source, Vector &target, FunctionData *bind_data, idx_t count) {
7720
7690
  D_ASSERT(source.GetType().id() == LogicalTypeId::POINTER && target.GetType().id() == LogicalTypeId::POINTER);
7721
7691
  auto sdata = FlatVector::GetData<const STATE_TYPE *>(source);
7722
7692
  auto tdata = FlatVector::GetData<STATE_TYPE *>(target);
7723
7693
 
7724
7694
  for (idx_t i = 0; i < count; i++) {
7725
- OP::template Combine<STATE_TYPE, OP>(*sdata[i], tdata[i]);
7695
+ OP::template Combine<STATE_TYPE, OP>(*sdata[i], tdata[i], bind_data);
7726
7696
  }
7727
7697
  }
7728
7698
 
@@ -8953,8 +8923,8 @@ typedef void (*aggregate_initialize_t)(data_ptr_t state);
8953
8923
  //! The type used for updating hashed aggregate functions
8954
8924
  typedef void (*aggregate_update_t)(Vector inputs[], FunctionData *bind_data, idx_t input_count, Vector &state,
8955
8925
  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);
8926
+ //! The type used for combining hashed aggregate states
8927
+ typedef void (*aggregate_combine_t)(Vector &state, Vector &combined, FunctionData *bind_data, idx_t count);
8958
8928
  //! The type used for finalizing hashed aggregate function payloads
8959
8929
  typedef void (*aggregate_finalize_t)(Vector &state, FunctionData *bind_data, Vector &result, idx_t count, idx_t offset);
8960
8930
  //! The type used for propagating statistics in aggregate functions (optional)
@@ -9058,7 +9028,8 @@ public:
9058
9028
  DUCKDB_API static unique_ptr<BoundAggregateExpression>
9059
9029
  BindAggregateFunction(ClientContext &context, AggregateFunction bound_function,
9060
9030
  vector<unique_ptr<Expression>> children, unique_ptr<Expression> filter = nullptr,
9061
- bool is_distinct = false, unique_ptr<BoundOrderModifier> order_bys = nullptr);
9031
+ bool is_distinct = false, unique_ptr<BoundOrderModifier> order_bys = nullptr,
9032
+ bool cast_parameters = true);
9062
9033
 
9063
9034
  DUCKDB_API static unique_ptr<FunctionData> BindSortedAggregate(AggregateFunction &bound_function,
9064
9035
  vector<unique_ptr<Expression>> &children,
@@ -9164,8 +9135,8 @@ public:
9164
9135
  }
9165
9136
 
9166
9137
  template <class STATE, class OP>
9167
- static void StateCombine(Vector &source, Vector &target, idx_t count) {
9168
- AggregateExecutor::Combine<STATE, OP>(source, target, count);
9138
+ static void StateCombine(Vector &source, Vector &target, FunctionData *bind_data, idx_t count) {
9139
+ AggregateExecutor::Combine<STATE, OP>(source, target, bind_data, count);
9169
9140
  }
9170
9141
 
9171
9142
  template <class STATE, class RESULT_TYPE, class OP>
@@ -10352,9 +10323,12 @@ public:
10352
10323
 
10353
10324
 
10354
10325
 
10326
+
10327
+
10355
10328
  #include <functional>
10356
10329
 
10357
10330
  namespace duckdb {
10331
+
10358
10332
  class BaseStatistics;
10359
10333
  class LogicalGet;
10360
10334
  struct ParallelState;
@@ -10397,10 +10371,14 @@ typedef unique_ptr<FunctionOperatorData> (*table_function_init_t)(ClientContext
10397
10371
  typedef unique_ptr<BaseStatistics> (*table_statistics_t)(ClientContext &context, const FunctionData *bind_data,
10398
10372
  column_t column_index);
10399
10373
  typedef void (*table_function_t)(ClientContext &context, const FunctionData *bind_data,
10400
- FunctionOperatorData *operator_state, DataChunk *input, DataChunk &output);
10374
+ FunctionOperatorData *operator_state, DataChunk &output);
10375
+
10376
+ typedef OperatorResultType (*table_in_out_function_t)(ClientContext &context, const FunctionData *bind_data,
10377
+ FunctionOperatorData *operator_state, DataChunk &input,
10378
+ DataChunk &output);
10401
10379
 
10402
10380
  typedef void (*table_function_parallel_t)(ClientContext &context, const FunctionData *bind_data,
10403
- FunctionOperatorData *operator_state, DataChunk *input, DataChunk &output,
10381
+ FunctionOperatorData *operator_state, DataChunk &output,
10404
10382
  ParallelState *parallel_state);
10405
10383
 
10406
10384
  typedef void (*table_function_cleanup_t)(ClientContext &context, const FunctionData *bind_data,
@@ -10439,7 +10417,8 @@ public:
10439
10417
  table_function_parallel_t parallel_function = nullptr,
10440
10418
  table_function_init_parallel_t parallel_init = nullptr,
10441
10419
  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);
10420
+ bool filter_pushdown = false, table_function_progress_t query_progress = nullptr,
10421
+ table_in_out_function_t in_out_function = nullptr);
10443
10422
  DUCKDB_API
10444
10423
  TableFunction(const vector<LogicalType> &arguments, table_function_t function, table_function_bind_t bind = nullptr,
10445
10424
  table_function_init_t init = nullptr, table_statistics_t statistics = nullptr,
@@ -10451,7 +10430,8 @@ public:
10451
10430
  table_function_parallel_t parallel_function = nullptr,
10452
10431
  table_function_init_parallel_t parallel_init = nullptr,
10453
10432
  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);
10433
+ bool filter_pushdown = false, table_function_progress_t query_progress = nullptr,
10434
+ table_in_out_function_t in_out_function = nullptr);
10455
10435
  DUCKDB_API TableFunction();
10456
10436
 
10457
10437
  //! Bind function
@@ -10464,6 +10444,8 @@ public:
10464
10444
  table_function_init_t init;
10465
10445
  //! The main function
10466
10446
  table_function_t function;
10447
+ //! The table in-out function (if this is an in-out function)
10448
+ table_in_out_function_t in_out_function;
10467
10449
  //! (Optional) statistics function
10468
10450
  //! Returns the statistics of a specified column
10469
10451
  table_statistics_t statistics;
@@ -10611,11 +10593,11 @@ struct ProducerToken {
10611
10593
 
10612
10594
  //! The TaskScheduler is responsible for managing tasks and threads
10613
10595
  class TaskScheduler {
10614
- // timeout for semaphore wait, default 50ms
10615
- constexpr static int64_t TASK_TIMEOUT_USECS = 50000;
10596
+ // timeout for semaphore wait, default 5ms
10597
+ constexpr static int64_t TASK_TIMEOUT_USECS = 5000;
10616
10598
 
10617
10599
  public:
10618
- TaskScheduler();
10600
+ TaskScheduler(DatabaseInstance &db);
10619
10601
  ~TaskScheduler();
10620
10602
 
10621
10603
  static TaskScheduler &GetScheduler(ClientContext &context);
@@ -10628,6 +10610,8 @@ public:
10628
10610
  bool GetTaskFromProducer(ProducerToken &token, unique_ptr<Task> &task);
10629
10611
  //! Run tasks forever until "marker" is set to false, "marker" must remain valid until the thread is joined
10630
10612
  void ExecuteForever(atomic<bool> *marker);
10613
+ //! Run tasks until `max_tasks` have been completed, or until there are no more tasks available
10614
+ void ExecuteTasks(idx_t max_tasks);
10631
10615
 
10632
10616
  //! Sets the amount of active threads executing tasks for the system; n-1 background threads will be launched.
10633
10617
  //! The main thread will also be used for execution
@@ -10638,6 +10622,8 @@ public:
10638
10622
  private:
10639
10623
  void SetThreadsInternal(int32_t n);
10640
10624
 
10625
+ private:
10626
+ DatabaseInstance &db;
10641
10627
  //! The task queue
10642
10628
  unique_ptr<ConcurrentQueue> queue;
10643
10629
  //! The active background threads of the task scheduler
@@ -13147,9 +13133,6 @@ public:
13147
13133
  static bool ContainsType(const LogicalType &type, LogicalTypeId target);
13148
13134
  static LogicalType ExchangeType(const LogicalType &type, LogicalTypeId target, LogicalType new_type);
13149
13135
 
13150
- static void ResolveParameterType(LogicalType &type);
13151
- static void ResolveParameterType(unique_ptr<Expression> &expr);
13152
-
13153
13136
  //! Bind the given expresion. Unlike Bind(), this does *not* mute the given ParsedExpression.
13154
13137
  //! Exposed to be used from sub-binders that aren't subclasses of ExpressionBinder.
13155
13138
  virtual BindResult BindExpression(unique_ptr<ParsedExpression> *expr_ptr, idx_t depth,
@@ -13171,7 +13154,6 @@ protected:
13171
13154
  BindResult BindExpression(OperatorExpression &expr, idx_t depth);
13172
13155
  BindResult BindExpression(ParameterExpression &expr, idx_t depth);
13173
13156
  BindResult BindExpression(PositionalReferenceExpression &ref, idx_t depth);
13174
- BindResult BindExpression(StarExpression &expr, idx_t depth);
13175
13157
  BindResult BindExpression(SubqueryExpression &expr, idx_t depth);
13176
13158
 
13177
13159
  protected:
@@ -13483,6 +13465,8 @@ public:
13483
13465
  vector<CorrelatedColumnInfo> correlated_columns;
13484
13466
  //! The set of parameter expressions bound by this binder
13485
13467
  vector<BoundParameterExpression *> *parameters;
13468
+ //! The types of the prepared statement parameters, if any
13469
+ vector<LogicalType> *parameter_types;
13486
13470
  //! Whether or not the bound statement is read-only
13487
13471
  bool read_only;
13488
13472
  //! Whether or not the statement requires a valid transaction to run
@@ -13641,9 +13625,12 @@ private:
13641
13625
  unique_ptr<BoundTableRef> Bind(EmptyTableRef &ref);
13642
13626
  unique_ptr<BoundTableRef> Bind(ExpressionListRef &ref);
13643
13627
 
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);
13628
+ bool BindTableFunctionParameters(TableFunctionCatalogEntry &table_function,
13629
+ vector<unique_ptr<ParsedExpression>> &expressions, vector<LogicalType> &arguments,
13630
+ vector<Value> &parameters, named_parameter_map_t &named_parameters,
13631
+ unique_ptr<BoundSubqueryRef> &subquery, string &error);
13632
+ bool BindTableInTableOutFunction(vector<unique_ptr<ParsedExpression>> &expressions,
13633
+ unique_ptr<BoundSubqueryRef> &subquery, string &error);
13647
13634
 
13648
13635
  unique_ptr<LogicalOperator> CreatePlan(BoundBaseTableRef &ref);
13649
13636
  unique_ptr<LogicalOperator> CreatePlan(BoundCrossProductRef &ref);
@@ -13781,6 +13768,7 @@ public:
13781
13768
 
13782
13769
 
13783
13770
  namespace duckdb {
13771
+
13784
13772
  //! SQLStatement is the base class of any type of SQL statement.
13785
13773
  class SQLStatement {
13786
13774
  public:
@@ -13803,6 +13791,9 @@ protected:
13803
13791
  SQLStatement(const SQLStatement &other) = default;
13804
13792
 
13805
13793
  public:
13794
+ virtual string ToString() const {
13795
+ throw InternalException("ToString not supported for this type of SQLStatement");
13796
+ }
13806
13797
  //! Create a copy of this SelectStatement
13807
13798
  virtual unique_ptr<SQLStatement> Copy() const = 0;
13808
13799
  };
@@ -13907,7 +13898,9 @@ public:
13907
13898
 
13908
13899
  public:
13909
13900
  //! Convert the object to a string
13910
- virtual string ToString() const;
13901
+ virtual string ToString() const = 0;
13902
+ string BaseToString(string result) const;
13903
+ string BaseToString(string result, const vector<string> &column_name_alias) const;
13911
13904
  void Print();
13912
13905
 
13913
13906
  virtual bool Equals(const TableRef *other) const;
@@ -13944,6 +13937,8 @@ protected:
13944
13937
  SelectStatement(const SelectStatement &other);
13945
13938
 
13946
13939
  public:
13940
+ //! Convert the SELECT statement to a string
13941
+ string ToString() const override;
13947
13942
  //! Create a copy of this SelectStatement
13948
13943
  unique_ptr<SQLStatement> Copy() const override;
13949
13944
  //! Serializes a SelectStatement to a stand-alone binary blob
@@ -13995,6 +13990,9 @@ public:
13995
13990
  virtual const vector<unique_ptr<ParsedExpression>> &GetSelectList() const = 0;
13996
13991
 
13997
13992
  public:
13993
+ //! Convert the query node to a string
13994
+ virtual string ToString() const = 0;
13995
+
13998
13996
  virtual bool Equals(const QueryNode *other) const;
13999
13997
 
14000
13998
  //! Create a copy of this QueryNode
@@ -14006,6 +14004,9 @@ public:
14006
14004
  //! Deserializes a blob back into a QueryNode
14007
14005
  DUCKDB_API static unique_ptr<QueryNode> Deserialize(Deserializer &source);
14008
14006
 
14007
+ string CTEToString() const;
14008
+ string ResultModifiersToString() const;
14009
+
14009
14010
  protected:
14010
14011
  //! Copy base QueryNode properties from another expression to this one,
14011
14012
  //! used in Copy method
@@ -16896,6 +16897,19 @@ Closes the result and de-allocates all memory allocated for the arrow result.
16896
16897
  */
16897
16898
  DUCKDB_API void duckdb_destroy_arrow(duckdb_arrow *result);
16898
16899
 
16900
+ //===--------------------------------------------------------------------===//
16901
+ // Threading Information
16902
+ //===--------------------------------------------------------------------===//
16903
+ /*!
16904
+ Execute DuckDB tasks on this thread.
16905
+
16906
+ Will return after `max_tasks` have been executed, or if there are no more tasks present.
16907
+
16908
+ * database: The database object to execute tasks for
16909
+ * max_tasks: The maximum amount of tasks to execute
16910
+ */
16911
+ DUCKDB_API void duckdb_execute_tasks(duckdb_database database, idx_t max_tasks);
16912
+
16899
16913
  #ifdef __cplusplus
16900
16914
  }
16901
16915
  #endif
@@ -17128,7 +17142,6 @@ private:
17128
17142
  } // namespace duckdb
17129
17143
 
17130
17144
 
17131
- #include <random>
17132
17145
 
17133
17146
  //===----------------------------------------------------------------------===//
17134
17147
  // DuckDB
@@ -17214,6 +17227,27 @@ public:
17214
17227
 
17215
17228
  } // namespace duckdb
17216
17229
 
17230
+ //===----------------------------------------------------------------------===//
17231
+ // DuckDB
17232
+ //
17233
+ // duckdb/main/external_dependencies.hpp
17234
+ //
17235
+ //
17236
+ //===----------------------------------------------------------------------===//
17237
+
17238
+
17239
+
17240
+ namespace duckdb {
17241
+
17242
+ enum ExternalDependenciesType { PYTHON_DEPENDENCY };
17243
+ class ExternalDependency {
17244
+ public:
17245
+ explicit ExternalDependency(ExternalDependenciesType type_p) : type(type_p) {};
17246
+ virtual ~ExternalDependency() {};
17247
+ ExternalDependenciesType type;
17248
+ };
17249
+
17250
+ } // namespace duckdb
17217
17251
 
17218
17252
  namespace duckdb {
17219
17253
  class Appender;
@@ -17227,12 +17261,12 @@ class PreparedStatementData;
17227
17261
  class Relation;
17228
17262
  class BufferedFileWriter;
17229
17263
  class QueryProfiler;
17230
- class QueryProfilerHistory;
17231
17264
  class ClientContextLock;
17232
17265
  struct CreateScalarFunctionInfo;
17233
17266
  class ScalarFunctionCatalogEntry;
17234
17267
  struct ActiveQueryContext;
17235
17268
  struct ParserOptions;
17269
+ struct ClientData;
17236
17270
 
17237
17271
  //! The ClientContext holds information relevant to the current client session
17238
17272
  //! during execution
@@ -17245,31 +17279,19 @@ public:
17245
17279
  DUCKDB_API explicit ClientContext(shared_ptr<DatabaseInstance> db);
17246
17280
  DUCKDB_API ~ClientContext();
17247
17281
 
17248
- //! Query profiler
17249
- shared_ptr<QueryProfiler> profiler;
17250
- //! QueryProfiler History
17251
- unique_ptr<QueryProfilerHistory> query_profiler_history;
17252
17282
  //! The database that this client is connected to
17253
17283
  shared_ptr<DatabaseInstance> db;
17254
17284
  //! Data for the currently running transaction
17255
17285
  TransactionContext transaction;
17256
17286
  //! Whether or not the query is interrupted
17257
17287
  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;
17288
+ //! External Objects (e.g., Python objects) that views depend of
17289
+ unordered_map<string, vector<shared_ptr<ExternalDependency>>> external_dependencies;
17270
17290
 
17271
17291
  //! The client configuration
17272
17292
  ClientConfig config;
17293
+ //! The set of client-specific data
17294
+ unique_ptr<ClientData> client_data;
17273
17295
 
17274
17296
  public:
17275
17297
  DUCKDB_API Transaction &ActiveTransaction() {
@@ -17398,7 +17420,8 @@ private:
17398
17420
 
17399
17421
  //! Internally prepare a SQL statement. Caller must hold the context_lock.
17400
17422
  shared_ptr<PreparedStatementData> CreatePreparedStatement(ClientContextLock &lock, const string &query,
17401
- unique_ptr<SQLStatement> statement);
17423
+ unique_ptr<SQLStatement> statement,
17424
+ vector<Value> *values = nullptr);
17402
17425
  unique_ptr<PendingQueryResult> PendingStatementInternal(ClientContextLock &lock, const string &query,
17403
17426
  unique_ptr<SQLStatement> statement);
17404
17427
  unique_ptr<QueryResult> RunStatementInternal(ClientContextLock &lock, const string &query,
@@ -17472,6 +17495,7 @@ private:
17472
17495
  } // namespace duckdb
17473
17496
 
17474
17497
 
17498
+
17475
17499
  #include <memory>
17476
17500
 
17477
17501
  namespace duckdb {
@@ -17483,8 +17507,6 @@ class LogicalOperator;
17483
17507
  class QueryNode;
17484
17508
  class TableRef;
17485
17509
 
17486
- class ExtraDependencies {};
17487
-
17488
17510
  class Relation : public std::enable_shared_from_this<Relation> {
17489
17511
  public:
17490
17512
  DUCKDB_API Relation(const std::shared_ptr<ClientContext> &context, RelationType type)
@@ -17499,7 +17521,7 @@ public:
17499
17521
 
17500
17522
  RelationType type;
17501
17523
 
17502
- unique_ptr<ExtraDependencies> extra_dependencies;
17524
+ shared_ptr<ExternalDependency> extra_dependencies;
17503
17525
 
17504
17526
  public:
17505
17527
  DUCKDB_API virtual const vector<ColumnDefinition> &Columns() = 0;
@@ -17599,6 +17621,7 @@ public:
17599
17621
  DUCKDB_API virtual Relation *ChildRelation() {
17600
17622
  return nullptr;
17601
17623
  }
17624
+ DUCKDB_API vector<shared_ptr<ExternalDependency>> GetAllDependencies();
17602
17625
 
17603
17626
  protected:
17604
17627
  DUCKDB_API string RenderWhitespace(idx_t depth);
@@ -18135,6 +18158,8 @@ public:
18135
18158
  idx_t maximum_memory = (idx_t)-1;
18136
18159
  //! The maximum amount of CPU threads used by the database system. Default: all available.
18137
18160
  idx_t maximum_threads = (idx_t)-1;
18161
+ //! The number of external threads that work on DuckDB tasks. Default: none.
18162
+ idx_t external_threads = 0;
18138
18163
  //! Whether or not to create and use a temporary directory to store intermediates that do not fit in memory
18139
18164
  bool use_temporary_directory = true;
18140
18165
  //! Directory to store temporary structures that do not fit in memory
@@ -21882,6 +21907,8 @@ public:
21882
21907
 
21883
21908
 
21884
21909
 
21910
+ #include <algorithm>
21911
+
21885
21912
  namespace duckdb {
21886
21913
 
21887
21914
  enum class StrTimeSpecifier : uint8_t {
@@ -21929,7 +21956,11 @@ public:
21929
21956
  virtual ~StrTimeFormat() {
21930
21957
  }
21931
21958
 
21932
- static string ParseFormatSpecifier(const string &format_string, StrTimeFormat &format);
21959
+ DUCKDB_API static string ParseFormatSpecifier(const string &format_string, StrTimeFormat &format);
21960
+
21961
+ inline bool HasFormatSpecifier(StrTimeSpecifier s) const {
21962
+ return std::find(specifiers.begin(), specifiers.end(), s) != specifiers.end();
21963
+ }
21933
21964
 
21934
21965
  protected:
21935
21966
  //! The format specifiers
@@ -21945,13 +21976,13 @@ protected:
21945
21976
 
21946
21977
  protected:
21947
21978
  void AddLiteral(string literal);
21948
- virtual void AddFormatSpecifier(string preceding_literal, StrTimeSpecifier specifier);
21979
+ DUCKDB_API virtual void AddFormatSpecifier(string preceding_literal, StrTimeSpecifier specifier);
21949
21980
  };
21950
21981
 
21951
21982
  struct StrfTimeFormat : public StrTimeFormat {
21952
- idx_t GetLength(date_t date, dtime_t time);
21983
+ DUCKDB_API idx_t GetLength(date_t date, dtime_t time, int32_t utc_offset, const char *tz_name);
21953
21984
 
21954
- void FormatString(date_t date, int32_t data[7], char *target);
21985
+ DUCKDB_API void FormatString(date_t date, int32_t data[8], const char *tz_name, char *target);
21955
21986
  void FormatString(date_t date, dtime_t time, char *target);
21956
21987
 
21957
21988
  DUCKDB_API static string Format(timestamp_t timestamp, const string &format);
@@ -21964,8 +21995,9 @@ protected:
21964
21995
  vector<bool> is_date_specifier;
21965
21996
 
21966
21997
  protected:
21967
- void AddFormatSpecifier(string preceding_literal, StrTimeSpecifier specifier) override;
21968
- static idx_t GetSpecifierLength(StrTimeSpecifier specifier, date_t date, dtime_t time);
21998
+ DUCKDB_API void AddFormatSpecifier(string preceding_literal, StrTimeSpecifier specifier) override;
21999
+ static idx_t GetSpecifierLength(StrTimeSpecifier specifier, date_t date, dtime_t time, int32_t utc_offset,
22000
+ const char *tz_name);
21969
22001
  char *WriteString(char *target, const string_t &str);
21970
22002
  char *Write2(char *target, uint8_t value);
21971
22003
  char *WritePadded2(char *target, uint32_t value);
@@ -21973,20 +22005,21 @@ protected:
21973
22005
  char *WritePadded(char *target, uint32_t value, size_t padding);
21974
22006
  bool IsDateSpecifier(StrTimeSpecifier specifier);
21975
22007
  char *WriteDateSpecifier(StrTimeSpecifier specifier, date_t date, char *target);
21976
- char *WriteStandardSpecifier(StrTimeSpecifier specifier, int32_t data[], char *target);
22008
+ char *WriteStandardSpecifier(StrTimeSpecifier specifier, int32_t data[], const char *tz_name, char *target);
21977
22009
  };
21978
22010
 
21979
22011
  struct StrpTimeFormat : public StrTimeFormat {
21980
22012
  public:
21981
22013
  //! Type-safe parsing argument
21982
22014
  struct ParseResult {
21983
- int32_t data[7];
22015
+ int32_t data[8]; // year, month, day, hour, min, sec, µs, offset
22016
+ string tz;
21984
22017
  string error_message;
21985
22018
  idx_t error_position = DConstants::INVALID_INDEX;
21986
22019
 
21987
22020
  date_t ToDate();
21988
22021
  timestamp_t ToTimestamp();
21989
- string FormatError(string_t input, const string &format_specifier);
22022
+ DUCKDB_API string FormatError(string_t input, const string &format_specifier);
21990
22023
  };
21991
22024
 
21992
22025
  public:
@@ -21996,7 +22029,7 @@ public:
21996
22029
  public:
21997
22030
  DUCKDB_API static ParseResult Parse(const string &format, const string &text);
21998
22031
 
21999
- bool Parse(string_t str, ParseResult &result);
22032
+ DUCKDB_API bool Parse(string_t str, ParseResult &result);
22000
22033
 
22001
22034
  bool TryParseDate(string_t str, date_t &result, string &error_message);
22002
22035
  bool TryParseTimestamp(string_t str, timestamp_t &result, string &error_message);
@@ -22006,7 +22039,7 @@ public:
22006
22039
 
22007
22040
  protected:
22008
22041
  static string FormatStrpTimeError(const string &input, idx_t position);
22009
- void AddFormatSpecifier(string preceding_literal, StrTimeSpecifier specifier) override;
22042
+ DUCKDB_API void AddFormatSpecifier(string preceding_literal, StrTimeSpecifier specifier) override;
22010
22043
  int NumericSpecifierWidth(StrTimeSpecifier specifier);
22011
22044
  int32_t TryParseCollection(const char *data, idx_t &pos, idx_t size, const string_t collection[],
22012
22045
  idx_t collection_count);
@@ -22057,13 +22090,10 @@ struct TextSearchShiftArray {
22057
22090
  };
22058
22091
 
22059
22092
  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;
22093
+ //===--------------------------------------------------------------------===//
22094
+ // CommonCSVOptions
22095
+ //===--------------------------------------------------------------------===//
22096
+
22067
22097
  //! Whether or not a delimiter was defined by the user
22068
22098
  bool has_delimiter = false;
22069
22099
  //! Delimiter to separate columns within each line
@@ -22080,33 +22110,68 @@ struct BufferedCSVReaderOptions {
22080
22110
  bool has_header = false;
22081
22111
  //! Whether or not the file has a header line
22082
22112
  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;
22113
+ //! Whether or not we should ignore InvalidInput errors
22114
+ bool ignore_errors = false;
22087
22115
  //! Expected number of columns
22088
22116
  idx_t num_cols = 0;
22117
+ //! Number of samples to buffer
22118
+ idx_t buffer_size = STANDARD_VECTOR_SIZE * 100;
22089
22119
  //! Specifies the string that represents a null value
22090
22120
  string null_str;
22121
+ //! Whether file is compressed or not, and if so which compression type
22122
+ //! AUTO_DETECT (default; infer from file extension)
22123
+ FileCompressionType compression = FileCompressionType::AUTO_DETECT;
22124
+
22125
+ //===--------------------------------------------------------------------===//
22126
+ // ReadCSVOptions
22127
+ //===--------------------------------------------------------------------===//
22128
+
22129
+ //! How many leading rows to skip
22130
+ idx_t skip_rows = 0;
22131
+ //! Maximum CSV line size: specified because if we reach this amount, we likely have wrong delimiters (default: 2MB)
22132
+ idx_t maximum_line_size = 2097152;
22133
+ //! Whether or not header names shall be normalized
22134
+ bool normalize_names = false;
22091
22135
  //! True, if column with that index must skip null check
22092
22136
  vector<bool> force_not_null;
22137
+ //! Consider all columns to be of type varchar
22138
+ bool all_varchar = false;
22093
22139
  //! Size of sample chunk used for dialect and type detection
22094
22140
  idx_t sample_chunk_size = STANDARD_VECTOR_SIZE;
22095
22141
  //! Number of sample chunks used for type detection
22096
22142
  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;
22143
+ //! Whether or not to automatically detect dialect and datatypes
22144
+ bool auto_detect = false;
22145
+ //! The file path of the CSV file to read
22146
+ string file_path;
22147
+ //! Whether or not to include a file name column
22148
+ bool include_file_name = false;
22103
22149
 
22104
- //! The date format to use (if any is specified)
22105
- std::map<LogicalTypeId, StrpTimeFormat> date_format = {{LogicalTypeId::DATE, {}}, {LogicalTypeId::TIMESTAMP, {}}};
22106
- //! Whether or not a type format is specified
22107
- std::map<LogicalTypeId, bool> has_format = {{LogicalTypeId::DATE, false}, {LogicalTypeId::TIMESTAMP, false}};
22150
+ //===--------------------------------------------------------------------===//
22151
+ // WriteCSVOptions
22152
+ //===--------------------------------------------------------------------===//
22153
+
22154
+ //! The column names of the columns to write
22155
+ vector<string> names;
22156
+ //! True, if column with that index must be quoted
22157
+ vector<bool> force_quote;
22158
+
22159
+ //! The date format to use (if any is specified)
22160
+ std::map<LogicalTypeId, StrpTimeFormat> date_format = {{LogicalTypeId::DATE, {}}, {LogicalTypeId::TIMESTAMP, {}}};
22161
+ //! Whether or not a type format is specified
22162
+ std::map<LogicalTypeId, bool> has_format = {{LogicalTypeId::DATE, false}, {LogicalTypeId::TIMESTAMP, false}};
22108
22163
 
22109
22164
  void SetDelimiter(const string &delimiter);
22165
+ //! Set an option that is supported by both reading and writing functions, called by
22166
+ //! the SetReadOption and SetWriteOption methods
22167
+ bool SetBaseOption(const string &loption, const Value &value);
22168
+
22169
+ //! loption - lowercase string
22170
+ //! set - argument(s) to the option
22171
+ //! expected_names - names expected if the option is "columns"
22172
+ void SetReadOption(const string &loption, const Value &value, vector<string> &expected_names);
22173
+
22174
+ void SetWriteOption(const string &loption, const Value &value);
22110
22175
 
22111
22176
  std::string ToString() const;
22112
22177
  };
@@ -22232,6 +22297,10 @@ private:
22232
22297
  const vector<LogicalType> &requested_types,
22233
22298
  vector<vector<LogicalType>> &best_sql_types_candidates,
22234
22299
  map<LogicalTypeId, vector<string>> &best_format_candidates);
22300
+
22301
+ private:
22302
+ //! Whether or not the current row's columns have overflown sql_types.size()
22303
+ bool error_column_overflow = false;
22235
22304
  };
22236
22305
 
22237
22306
  } // namespace duckdb
@@ -22421,7 +22490,7 @@ public:
22421
22490
  //===----------------------------------------------------------------------===//
22422
22491
  // DuckDB
22423
22492
  //
22424
- // duckdb/parser/expression/collate_expression.hpp
22493
+ // duckdb/parser/expression/star_expression.hpp
22425
22494
  //
22426
22495
  //
22427
22496
  //===----------------------------------------------------------------------===//
@@ -22430,22 +22499,25 @@ public:
22430
22499
 
22431
22500
 
22432
22501
 
22502
+
22433
22503
  namespace duckdb {
22434
22504
 
22435
- //! CollateExpression represents a COLLATE statement
22436
- class CollateExpression : public ParsedExpression {
22505
+ //! Represents a * expression in the SELECT clause
22506
+ class StarExpression : public ParsedExpression {
22437
22507
  public:
22438
- CollateExpression(string collation, unique_ptr<ParsedExpression> child);
22508
+ StarExpression(string relation_name = string());
22439
22509
 
22440
- //! The child of the cast expression
22441
- unique_ptr<ParsedExpression> child;
22442
- //! The collation clause
22443
- string collation;
22510
+ //! The relation name in case of tbl.*, or empty if this is a normal *
22511
+ string relation_name;
22512
+ //! List of columns to exclude from the STAR expression
22513
+ case_insensitive_set_t exclude_list;
22514
+ //! List of columns to replace with another expression
22515
+ case_insensitive_map_t<unique_ptr<ParsedExpression>> replace_list;
22444
22516
 
22445
22517
  public:
22446
22518
  string ToString() const override;
22447
22519
 
22448
- static bool Equals(const CollateExpression *a, const CollateExpression *b);
22520
+ static bool Equals(const StarExpression *a, const StarExpression *b);
22449
22521
 
22450
22522
  unique_ptr<ParsedExpression> Copy() const override;
22451
22523
 
@@ -22456,7 +22528,7 @@ public:
22456
22528
  //===----------------------------------------------------------------------===//
22457
22529
  // DuckDB
22458
22530
  //
22459
- // duckdb/parser/expression/between_expression.hpp
22531
+ // duckdb/parser/expression/default_expression.hpp
22460
22532
  //
22461
22533
  //
22462
22534
  //===----------------------------------------------------------------------===//
@@ -22466,39 +22538,28 @@ public:
22466
22538
 
22467
22539
 
22468
22540
  namespace duckdb {
22469
-
22470
- class BetweenExpression : public ParsedExpression {
22541
+ //! Represents the default value of a column
22542
+ class DefaultExpression : public ParsedExpression {
22471
22543
  public:
22472
- BetweenExpression(unique_ptr<ParsedExpression> input, unique_ptr<ParsedExpression> lower,
22473
- unique_ptr<ParsedExpression> upper);
22474
-
22475
- unique_ptr<ParsedExpression> input;
22476
- unique_ptr<ParsedExpression> lower;
22477
- unique_ptr<ParsedExpression> upper;
22544
+ DefaultExpression();
22478
22545
 
22479
22546
  public:
22480
- string ToString() const override;
22547
+ bool IsScalar() const override {
22548
+ return false;
22549
+ }
22481
22550
 
22482
- static bool Equals(const BetweenExpression *a, const BetweenExpression *b);
22551
+ string ToString() const override;
22483
22552
 
22484
22553
  unique_ptr<ParsedExpression> Copy() const override;
22485
22554
 
22486
22555
  void Serialize(FieldWriter &writer) const override;
22487
22556
  static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
22488
-
22489
- public:
22490
- template <class T, class BASE>
22491
- static string ToString(const T &entry) {
22492
- return entry.input->ToString() + " BETWEEN " + entry.lower->ToString() + " AND " + entry.upper->ToString();
22493
- }
22494
22557
  };
22495
22558
  } // namespace duckdb
22496
-
22497
-
22498
22559
  //===----------------------------------------------------------------------===//
22499
22560
  // DuckDB
22500
22561
  //
22501
- // duckdb/parser/expression/case_expression.hpp
22562
+ // duckdb/parser/expression/operator_expression.hpp
22502
22563
  //
22503
22564
  //
22504
22565
  //===----------------------------------------------------------------------===//
@@ -22508,25 +22569,22 @@ public:
22508
22569
 
22509
22570
 
22510
22571
 
22511
- namespace duckdb {
22512
22572
 
22513
- struct CaseCheck {
22514
- unique_ptr<ParsedExpression> when_expr;
22515
- unique_ptr<ParsedExpression> then_expr;
22516
- };
22517
22573
 
22518
- //! The CaseExpression represents a CASE expression in the query
22519
- class CaseExpression : public ParsedExpression {
22574
+ namespace duckdb {
22575
+ //! Represents a built-in operator expression
22576
+ class OperatorExpression : public ParsedExpression {
22520
22577
  public:
22521
- DUCKDB_API CaseExpression();
22578
+ DUCKDB_API explicit OperatorExpression(ExpressionType type, unique_ptr<ParsedExpression> left = nullptr,
22579
+ unique_ptr<ParsedExpression> right = nullptr);
22580
+ DUCKDB_API OperatorExpression(ExpressionType type, vector<unique_ptr<ParsedExpression>> children);
22522
22581
 
22523
- vector<CaseCheck> case_checks;
22524
- unique_ptr<ParsedExpression> else_expr;
22582
+ vector<unique_ptr<ParsedExpression>> children;
22525
22583
 
22526
22584
  public:
22527
22585
  string ToString() const override;
22528
22586
 
22529
- static bool Equals(const CaseExpression *a, const CaseExpression *b);
22587
+ static bool Equals(const OperatorExpression *a, const OperatorExpression *b);
22530
22588
 
22531
22589
  unique_ptr<ParsedExpression> Copy() const override;
22532
22590
 
@@ -22536,22 +22594,72 @@ public:
22536
22594
  public:
22537
22595
  template <class T, class BASE>
22538
22596
  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() + ")";
22597
+ auto op = ExpressionTypeToOperator(entry.type);
22598
+ if (!op.empty()) {
22599
+ // use the operator string to represent the operator
22600
+ D_ASSERT(entry.children.size() == 2);
22601
+ return entry.children[0]->ToString() + " " + op + " " + entry.children[1]->ToString();
22602
+ }
22603
+ switch (entry.type) {
22604
+ case ExpressionType::COMPARE_IN:
22605
+ case ExpressionType::COMPARE_NOT_IN: {
22606
+ string op_type = entry.type == ExpressionType::COMPARE_IN ? " IN " : " NOT IN ";
22607
+ string in_child = entry.children[0]->ToString();
22608
+ string child_list = "(";
22609
+ for (idx_t i = 1; i < entry.children.size(); i++) {
22610
+ if (i > 1) {
22611
+ child_list += ", ";
22612
+ }
22613
+ child_list += entry.children[i]->ToString();
22614
+ }
22615
+ child_list += ")";
22616
+ return "(" + in_child + op_type + child_list + ")";
22617
+ }
22618
+ case ExpressionType::OPERATOR_NOT:
22619
+ case ExpressionType::GROUPING_FUNCTION:
22620
+ case ExpressionType::OPERATOR_COALESCE: {
22621
+ string result = ExpressionTypeToString(entry.type);
22622
+ result += "(";
22623
+ result += StringUtil::Join(entry.children, entry.children.size(), ", ",
22624
+ [](const unique_ptr<BASE> &child) { return child->ToString(); });
22625
+ result += ")";
22626
+ return result;
22627
+ }
22628
+ case ExpressionType::OPERATOR_IS_NULL:
22629
+ return "(" + entry.children[0]->ToString() + " IS NULL)";
22630
+ case ExpressionType::OPERATOR_IS_NOT_NULL:
22631
+ return "(" + entry.children[0]->ToString() + " IS NOT NULL)";
22632
+ case ExpressionType::ARRAY_EXTRACT:
22633
+ return entry.children[0]->ToString() + "[" + entry.children[1]->ToString() + "]";
22634
+ case ExpressionType::ARRAY_SLICE:
22635
+ return entry.children[0]->ToString() + "[" + entry.children[1]->ToString() + ":" +
22636
+ entry.children[2]->ToString() + "]";
22637
+ case ExpressionType::STRUCT_EXTRACT: {
22638
+ D_ASSERT(entry.children[1]->type == ExpressionType::VALUE_CONSTANT);
22639
+ auto child_string = entry.children[1]->ToString();
22640
+ D_ASSERT(child_string.size() >= 3);
22641
+ D_ASSERT(child_string[0] == '\'' && child_string[child_string.size() - 1] == '\'');
22642
+ return "(" + entry.children[0]->ToString() + ")." +
22643
+ KeywordHelper::WriteOptionallyQuoted(child_string.substr(1, child_string.size() - 2));
22644
+ }
22645
+ case ExpressionType::ARRAY_CONSTRUCTOR: {
22646
+ string result = "(ARRAY[";
22647
+ result += StringUtil::Join(entry.children, entry.children.size(), ", ",
22648
+ [](const unique_ptr<BASE> &child) { return child->ToString(); });
22649
+ result += "])";
22650
+ return result;
22651
+ }
22652
+ default:
22653
+ throw InternalException("Unrecognized operator type");
22543
22654
  }
22544
- case_str += " ELSE " + entry.else_expr->ToString();
22545
- case_str += " END";
22546
- return case_str;
22547
22655
  }
22548
22656
  };
22549
- } // namespace duckdb
22550
22657
 
22658
+ } // namespace duckdb
22551
22659
  //===----------------------------------------------------------------------===//
22552
22660
  // DuckDB
22553
22661
  //
22554
- // duckdb/parser/expression/cast_expression.hpp
22662
+ // duckdb/parser/expression/conjunction_expression.hpp
22555
22663
  //
22556
22664
  //
22557
22665
  //===----------------------------------------------------------------------===//
@@ -22563,22 +22671,22 @@ public:
22563
22671
 
22564
22672
  namespace duckdb {
22565
22673
 
22566
- //! CastExpression represents a type cast from one SQL type to another SQL type
22567
- class CastExpression : public ParsedExpression {
22674
+ //! Represents a conjunction (AND/OR)
22675
+ class ConjunctionExpression : public ParsedExpression {
22568
22676
  public:
22569
- DUCKDB_API CastExpression(LogicalType target, unique_ptr<ParsedExpression> child, bool try_cast = false);
22677
+ DUCKDB_API explicit ConjunctionExpression(ExpressionType type);
22678
+ DUCKDB_API ConjunctionExpression(ExpressionType type, vector<unique_ptr<ParsedExpression>> children);
22679
+ DUCKDB_API ConjunctionExpression(ExpressionType type, unique_ptr<ParsedExpression> left,
22680
+ unique_ptr<ParsedExpression> right);
22570
22681
 
22571
- //! The child of the cast expression
22572
- unique_ptr<ParsedExpression> child;
22573
- //! The type to cast to
22574
- LogicalType cast_type;
22575
- //! Whether or not this is a try_cast expression
22576
- bool try_cast;
22682
+ vector<unique_ptr<ParsedExpression>> children;
22577
22683
 
22578
22684
  public:
22685
+ void AddExpression(unique_ptr<ParsedExpression> expr);
22686
+
22579
22687
  string ToString() const override;
22580
22688
 
22581
- static bool Equals(const CastExpression *a, const CastExpression *b);
22689
+ static bool Equals(const ConjunctionExpression *a, const ConjunctionExpression *b);
22582
22690
 
22583
22691
  unique_ptr<ParsedExpression> Copy() const override;
22584
22692
 
@@ -22588,18 +22696,18 @@ public:
22588
22696
  public:
22589
22697
  template <class T, class BASE>
22590
22698
  static string ToString(const T &entry) {
22591
- return (entry.try_cast ? "TRY_CAST(" : "CAST(") + entry.child->ToString() + " AS " +
22592
- entry.cast_type.ToString() + ")";
22699
+ string result = "(" + entry.children[0]->ToString();
22700
+ for (idx_t i = 1; i < entry.children.size(); i++) {
22701
+ result += " " + ExpressionTypeToOperator(entry.type) + " " + entry.children[i]->ToString();
22702
+ }
22703
+ return result + ")";
22593
22704
  }
22594
22705
  };
22595
22706
  } // namespace duckdb
22596
-
22597
-
22598
-
22599
22707
  //===----------------------------------------------------------------------===//
22600
22708
  // DuckDB
22601
22709
  //
22602
- // duckdb/parser/expression/comparison_expression.hpp
22710
+ // duckdb/parser/expression/constant_expression.hpp
22603
22711
  //
22604
22712
  //
22605
22713
  //===----------------------------------------------------------------------===//
@@ -22608,39 +22716,34 @@ public:
22608
22716
 
22609
22717
 
22610
22718
 
22719
+
22611
22720
  namespace duckdb {
22612
- //! ComparisonExpression represents a boolean comparison (e.g. =, >=, <>). Always returns a boolean
22613
- //! and has two children.
22614
- class ComparisonExpression : public ParsedExpression {
22721
+
22722
+ //! ConstantExpression represents a constant value in the query
22723
+ class ConstantExpression : public ParsedExpression {
22615
22724
  public:
22616
- DUCKDB_API ComparisonExpression(ExpressionType type, unique_ptr<ParsedExpression> left,
22617
- unique_ptr<ParsedExpression> right);
22725
+ DUCKDB_API explicit ConstantExpression(Value val);
22618
22726
 
22619
- unique_ptr<ParsedExpression> left;
22620
- unique_ptr<ParsedExpression> right;
22727
+ //! The constant value referenced
22728
+ Value value;
22621
22729
 
22622
22730
  public:
22623
22731
  string ToString() const override;
22624
22732
 
22625
- static bool Equals(const ComparisonExpression *a, const ComparisonExpression *b);
22733
+ static bool Equals(const ConstantExpression *a, const ConstantExpression *b);
22734
+ hash_t Hash() const override;
22626
22735
 
22627
22736
  unique_ptr<ParsedExpression> Copy() const override;
22628
22737
 
22629
22738
  void Serialize(FieldWriter &writer) const override;
22630
22739
  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
22740
  };
22638
- } // namespace duckdb
22639
22741
 
22742
+ } // namespace duckdb
22640
22743
  //===----------------------------------------------------------------------===//
22641
22744
  // DuckDB
22642
22745
  //
22643
- // duckdb/parser/expression/conjunction_expression.hpp
22746
+ // duckdb/parser/expression/case_expression.hpp
22644
22747
  //
22645
22748
  //
22646
22749
  //===----------------------------------------------------------------------===//
@@ -22652,22 +22755,23 @@ public:
22652
22755
 
22653
22756
  namespace duckdb {
22654
22757
 
22655
- //! Represents a conjunction (AND/OR)
22656
- class ConjunctionExpression : public ParsedExpression {
22758
+ struct CaseCheck {
22759
+ unique_ptr<ParsedExpression> when_expr;
22760
+ unique_ptr<ParsedExpression> then_expr;
22761
+ };
22762
+
22763
+ //! The CaseExpression represents a CASE expression in the query
22764
+ class CaseExpression : public ParsedExpression {
22657
22765
  public:
22658
- DUCKDB_API explicit ConjunctionExpression(ExpressionType type);
22659
- DUCKDB_API ConjunctionExpression(ExpressionType type, vector<unique_ptr<ParsedExpression>> children);
22660
- DUCKDB_API ConjunctionExpression(ExpressionType type, unique_ptr<ParsedExpression> left,
22661
- unique_ptr<ParsedExpression> right);
22766
+ DUCKDB_API CaseExpression();
22662
22767
 
22663
- vector<unique_ptr<ParsedExpression>> children;
22768
+ vector<CaseCheck> case_checks;
22769
+ unique_ptr<ParsedExpression> else_expr;
22664
22770
 
22665
22771
  public:
22666
- void AddExpression(unique_ptr<ParsedExpression> expr);
22667
-
22668
22772
  string ToString() const override;
22669
22773
 
22670
- static bool Equals(const ConjunctionExpression *a, const ConjunctionExpression *b);
22774
+ static bool Equals(const CaseExpression *a, const CaseExpression *b);
22671
22775
 
22672
22776
  unique_ptr<ParsedExpression> Copy() const override;
22673
22777
 
@@ -22677,19 +22781,21 @@ public:
22677
22781
  public:
22678
22782
  template <class T, class BASE>
22679
22783
  static string ToString(const T &entry) {
22680
- string result = entry.children[0]->ToString();
22681
- for (idx_t i = 1; i < entry.children.size(); i++) {
22682
- result += " " + ExpressionTypeToOperator(entry.type) + " " + entry.children[i]->ToString();
22784
+ string case_str = "CASE ";
22785
+ for (auto &check : entry.case_checks) {
22786
+ case_str += " WHEN (" + check.when_expr->ToString() + ")";
22787
+ case_str += " THEN (" + check.then_expr->ToString() + ")";
22683
22788
  }
22684
- return result;
22789
+ case_str += " ELSE " + entry.else_expr->ToString();
22790
+ case_str += " END";
22791
+ return case_str;
22685
22792
  }
22686
22793
  };
22687
22794
  } // namespace duckdb
22688
-
22689
22795
  //===----------------------------------------------------------------------===//
22690
22796
  // DuckDB
22691
22797
  //
22692
- // duckdb/parser/expression/constant_expression.hpp
22798
+ // duckdb/parser/expression/between_expression.hpp
22693
22799
  //
22694
22800
  //
22695
22801
  //===----------------------------------------------------------------------===//
@@ -22698,35 +22804,41 @@ public:
22698
22804
 
22699
22805
 
22700
22806
 
22701
-
22702
22807
  namespace duckdb {
22703
22808
 
22704
- //! ConstantExpression represents a constant value in the query
22705
- class ConstantExpression : public ParsedExpression {
22809
+ class BetweenExpression : public ParsedExpression {
22706
22810
  public:
22707
- DUCKDB_API explicit ConstantExpression(Value val);
22811
+ BetweenExpression(unique_ptr<ParsedExpression> input, unique_ptr<ParsedExpression> lower,
22812
+ unique_ptr<ParsedExpression> upper);
22708
22813
 
22709
- //! The constant value referenced
22710
- Value value;
22814
+ unique_ptr<ParsedExpression> input;
22815
+ unique_ptr<ParsedExpression> lower;
22816
+ unique_ptr<ParsedExpression> upper;
22711
22817
 
22712
22818
  public:
22713
22819
  string ToString() const override;
22714
22820
 
22715
- static bool Equals(const ConstantExpression *a, const ConstantExpression *b);
22716
- hash_t Hash() const override;
22821
+ static bool Equals(const BetweenExpression *a, const BetweenExpression *b);
22717
22822
 
22718
22823
  unique_ptr<ParsedExpression> Copy() const override;
22719
22824
 
22720
22825
  void Serialize(FieldWriter &writer) const override;
22721
22826
  static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
22722
- };
22723
22827
 
22724
- } // namespace duckdb
22828
+ public:
22829
+ template <class T, class BASE>
22830
+ static string ToString(const T &entry) {
22831
+ return entry.input->ToString() + " BETWEEN " + entry.lower->ToString() + " AND " + entry.upper->ToString();
22832
+ }
22833
+ };
22834
+ } // namespace duckdb
22835
+
22836
+
22725
22837
 
22726
22838
  //===----------------------------------------------------------------------===//
22727
22839
  // DuckDB
22728
22840
  //
22729
- // duckdb/parser/expression/default_expression.hpp
22841
+ // duckdb/parser/expression/cast_expression.hpp
22730
22842
  //
22731
22843
  //
22732
22844
  //===----------------------------------------------------------------------===//
@@ -22735,19 +22847,69 @@ public:
22735
22847
 
22736
22848
 
22737
22849
 
22850
+
22738
22851
  namespace duckdb {
22739
- //! Represents the default value of a column
22740
- class DefaultExpression : public ParsedExpression {
22852
+
22853
+ //! CastExpression represents a type cast from one SQL type to another SQL type
22854
+ class CastExpression : public ParsedExpression {
22741
22855
  public:
22742
- DefaultExpression();
22856
+ DUCKDB_API CastExpression(LogicalType target, unique_ptr<ParsedExpression> child, bool try_cast = false);
22857
+
22858
+ //! The child of the cast expression
22859
+ unique_ptr<ParsedExpression> child;
22860
+ //! The type to cast to
22861
+ LogicalType cast_type;
22862
+ //! Whether or not this is a try_cast expression
22863
+ bool try_cast;
22743
22864
 
22744
22865
  public:
22745
- bool IsScalar() const override {
22746
- return false;
22866
+ string ToString() const override;
22867
+
22868
+ static bool Equals(const CastExpression *a, const CastExpression *b);
22869
+
22870
+ unique_ptr<ParsedExpression> Copy() const override;
22871
+
22872
+ void Serialize(FieldWriter &writer) const override;
22873
+ static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
22874
+
22875
+ public:
22876
+ template <class T, class BASE>
22877
+ static string ToString(const T &entry) {
22878
+ return (entry.try_cast ? "TRY_CAST(" : "CAST(") + entry.child->ToString() + " AS " +
22879
+ entry.cast_type.ToString() + ")";
22747
22880
  }
22881
+ };
22882
+ } // namespace duckdb
22883
+
22884
+ //===----------------------------------------------------------------------===//
22885
+ // DuckDB
22886
+ //
22887
+ // duckdb/parser/expression/collate_expression.hpp
22888
+ //
22889
+ //
22890
+ //===----------------------------------------------------------------------===//
22891
+
22892
+
22893
+
22894
+
22748
22895
 
22896
+ namespace duckdb {
22897
+
22898
+ //! CollateExpression represents a COLLATE statement
22899
+ class CollateExpression : public ParsedExpression {
22900
+ public:
22901
+ CollateExpression(string collation, unique_ptr<ParsedExpression> child);
22902
+
22903
+ //! The child of the cast expression
22904
+ unique_ptr<ParsedExpression> child;
22905
+ //! The collation clause
22906
+ string collation;
22907
+
22908
+ public:
22749
22909
  string ToString() const override;
22750
22910
 
22911
+ static bool Equals(const CollateExpression *a, const CollateExpression *b);
22912
+
22751
22913
  unique_ptr<ParsedExpression> Copy() const override;
22752
22914
 
22753
22915
  void Serialize(FieldWriter &writer) const override;
@@ -22755,6 +22917,51 @@ public:
22755
22917
  };
22756
22918
  } // namespace duckdb
22757
22919
 
22920
+
22921
+ //===----------------------------------------------------------------------===//
22922
+ // DuckDB
22923
+ //
22924
+ // duckdb/parser/expression/comparison_expression.hpp
22925
+ //
22926
+ //
22927
+ //===----------------------------------------------------------------------===//
22928
+
22929
+
22930
+
22931
+
22932
+
22933
+ namespace duckdb {
22934
+ //! ComparisonExpression represents a boolean comparison (e.g. =, >=, <>). Always returns a boolean
22935
+ //! and has two children.
22936
+ class ComparisonExpression : public ParsedExpression {
22937
+ public:
22938
+ DUCKDB_API ComparisonExpression(ExpressionType type, unique_ptr<ParsedExpression> left,
22939
+ unique_ptr<ParsedExpression> right);
22940
+
22941
+ unique_ptr<ParsedExpression> left;
22942
+ unique_ptr<ParsedExpression> right;
22943
+
22944
+ public:
22945
+ string ToString() const override;
22946
+
22947
+ static bool Equals(const ComparisonExpression *a, const ComparisonExpression *b);
22948
+
22949
+ unique_ptr<ParsedExpression> Copy() const override;
22950
+
22951
+ void Serialize(FieldWriter &writer) const override;
22952
+ static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
22953
+
22954
+ public:
22955
+ template <class T, class BASE>
22956
+ static string ToString(const T &entry) {
22957
+ return entry.left->ToString() + " " + ExpressionTypeToOperator(entry.type) + " " + entry.right->ToString();
22958
+ }
22959
+ };
22960
+ } // namespace duckdb
22961
+
22962
+
22963
+
22964
+
22758
22965
  //===----------------------------------------------------------------------===//
22759
22966
  // DuckDB
22760
22967
  //
@@ -22817,7 +23024,7 @@ public:
22817
23024
  template <class T, class BASE>
22818
23025
  static string ToString(const T &entry, const string &schema, const string &function_name, bool is_operator = false,
22819
23026
  bool distinct = false, BASE *filter = nullptr, OrderModifier *order_bys = nullptr,
22820
- bool export_state = false) {
23027
+ bool export_state = false, bool add_alias = false) {
22821
23028
  if (is_operator) {
22822
23029
  // built-in operator
22823
23030
  D_ASSERT(!distinct);
@@ -22839,8 +23046,11 @@ public:
22839
23046
  if (distinct) {
22840
23047
  result += "DISTINCT ";
22841
23048
  }
22842
- result += StringUtil::Join(entry.children, entry.children.size(), ", ",
22843
- [](const unique_ptr<BASE> &child) { return child->ToString(); });
23049
+ result += StringUtil::Join(entry.children, entry.children.size(), ", ", [&](const unique_ptr<BASE> &child) {
23050
+ return child->alias.empty() || !add_alias
23051
+ ? child->ToString()
23052
+ : KeywordHelper::WriteOptionallyQuoted(child->alias) + " := " + child->ToString();
23053
+ });
22844
23054
  // ordered aggregate
22845
23055
  if (order_bys && !order_bys->orders.empty()) {
22846
23056
  if (entry.children.empty()) {
@@ -22871,106 +23081,6 @@ public:
22871
23081
  } // namespace duckdb
22872
23082
 
22873
23083
 
22874
- //===----------------------------------------------------------------------===//
22875
- // DuckDB
22876
- //
22877
- // duckdb/parser/expression/operator_expression.hpp
22878
- //
22879
- //
22880
- //===----------------------------------------------------------------------===//
22881
-
22882
-
22883
-
22884
-
22885
-
22886
-
22887
-
22888
-
22889
- namespace duckdb {
22890
- //! Represents a built-in operator expression
22891
- class OperatorExpression : public ParsedExpression {
22892
- 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);
22896
-
22897
- vector<unique_ptr<ParsedExpression>> children;
22898
-
22899
- public:
22900
- string ToString() const override;
22901
-
22902
- static bool Equals(const OperatorExpression *a, const OperatorExpression *b);
22903
-
22904
- unique_ptr<ParsedExpression> Copy() const override;
22905
-
22906
- void Serialize(FieldWriter &writer) const override;
22907
- static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
22908
-
22909
- public:
22910
- template <class T, class BASE>
22911
- 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
- }
22970
- }
22971
- };
22972
-
22973
- } // namespace duckdb
22974
23084
 
22975
23085
  //===----------------------------------------------------------------------===//
22976
23086
  // DuckDB
@@ -23044,44 +23154,6 @@ public:
23044
23154
  };
23045
23155
  } // namespace duckdb
23046
23156
 
23047
- //===----------------------------------------------------------------------===//
23048
- // DuckDB
23049
- //
23050
- // duckdb/parser/expression/star_expression.hpp
23051
- //
23052
- //
23053
- //===----------------------------------------------------------------------===//
23054
-
23055
-
23056
-
23057
-
23058
-
23059
-
23060
- namespace duckdb {
23061
-
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;
23076
-
23077
- static bool Equals(const StarExpression *a, const StarExpression *b);
23078
-
23079
- unique_ptr<ParsedExpression> Copy() const override;
23080
-
23081
- void Serialize(FieldWriter &writer) const override;
23082
- static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
23083
- };
23084
- } // namespace duckdb
23085
23157
 
23086
23158
  //===----------------------------------------------------------------------===//
23087
23159
  // DuckDB
@@ -23137,7 +23209,7 @@ public:
23137
23209
  //===----------------------------------------------------------------------===//
23138
23210
  // DuckDB
23139
23211
  //
23140
- // duckdb/parser/parsed_data/create_collation_info.hpp
23212
+ // duckdb/parser/parsed_data/export_table_data.hpp
23141
23213
  //
23142
23214
  //
23143
23215
  //===----------------------------------------------------------------------===//
@@ -23149,112 +23221,24 @@ public:
23149
23221
 
23150
23222
  namespace duckdb {
23151
23223
 
23152
- struct CreateCollationInfo : public CreateInfo {
23153
- CreateCollationInfo(string name_p, ScalarFunction function_p, bool combinable_p, bool not_required_for_equality_p)
23154
- : CreateInfo(CatalogType::COLLATION_ENTRY), function(move(function_p)), combinable(combinable_p),
23155
- not_required_for_equality(not_required_for_equality_p) {
23156
- this->name = move(name_p);
23157
- }
23158
-
23159
- //! The name of the collation
23160
- string name;
23161
- //! The collation function to push in case collation is required
23162
- ScalarFunction function;
23163
- //! Whether or not the collation can be combined with other collations.
23164
- bool combinable;
23165
- //! Whether or not the collation is required for equality comparisons or not. For many collations a binary
23166
- //! comparison for equality comparisons is correct, allowing us to skip the collation in these cases which greatly
23167
- //! speeds up processing.
23168
- bool not_required_for_equality;
23169
-
23170
- public:
23171
- unique_ptr<CreateInfo> Copy() const override {
23172
- auto result = make_unique<CreateCollationInfo>(name, function, combinable, not_required_for_equality);
23173
- CopyProperties(*result);
23174
- return move(result);
23175
- }
23176
- };
23177
-
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 {
23224
+ struct ExportedTableData {
23225
+ //! Name of the exported table
23226
+ string table_name;
23192
23227
 
23193
- struct CreateSchemaInfo : public CreateInfo {
23194
- CreateSchemaInfo() : CreateInfo(CatalogType::SCHEMA_ENTRY) {
23195
- }
23228
+ //! Name of the schema
23229
+ string schema_name;
23196
23230
 
23197
- public:
23198
- unique_ptr<CreateInfo> Copy() const override {
23199
- auto result = make_unique<CreateSchemaInfo>();
23200
- CopyProperties(*result);
23201
- return move(result);
23202
- }
23231
+ //! Path to be exported
23232
+ string file_path;
23203
23233
  };
23204
23234
 
23205
- } // namespace duckdb
23206
- //===----------------------------------------------------------------------===//
23207
- // DuckDB
23208
- //
23209
- // duckdb/parser/parsed_data/show_select_info.hpp
23210
- //
23211
- //
23212
- //===----------------------------------------------------------------------===//
23213
-
23214
-
23215
-
23216
-
23217
-
23218
-
23219
- namespace duckdb {
23220
-
23221
- struct ShowSelectInfo : public ParseInfo {
23222
- //! Types of projected columns
23223
- vector<LogicalType> types;
23224
- //! The QueryNode of select query
23225
- unique_ptr<QueryNode> query;
23226
- //! Aliases of projected columns
23227
- 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
- }
23235
+ struct ExportedTableInfo {
23236
+ TableCatalogEntry *entry;
23237
+ ExportedTableData table_data;
23239
23238
  };
23240
23239
 
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
23240
+ struct BoundExportData : public ParseInfo {
23241
+ std::vector<ExportedTableInfo> data;
23258
23242
  };
23259
23243
 
23260
23244
  } // namespace duckdb
@@ -23345,6 +23329,129 @@ public:
23345
23329
  }
23346
23330
  };
23347
23331
 
23332
+ } // namespace duckdb
23333
+ //===----------------------------------------------------------------------===//
23334
+ // DuckDB
23335
+ //
23336
+ // duckdb/parser/parsed_data/create_aggregate_function_info.hpp
23337
+ //
23338
+ //
23339
+ //===----------------------------------------------------------------------===//
23340
+
23341
+
23342
+
23343
+
23344
+
23345
+
23346
+ namespace duckdb {
23347
+
23348
+ struct CreateAggregateFunctionInfo : public CreateFunctionInfo {
23349
+ explicit CreateAggregateFunctionInfo(AggregateFunction function)
23350
+ : CreateFunctionInfo(CatalogType::AGGREGATE_FUNCTION_ENTRY), functions(function.name) {
23351
+ this->name = function.name;
23352
+ functions.AddFunction(move(function));
23353
+ }
23354
+
23355
+ explicit CreateAggregateFunctionInfo(AggregateFunctionSet set)
23356
+ : CreateFunctionInfo(CatalogType::AGGREGATE_FUNCTION_ENTRY), functions(move(set)) {
23357
+ this->name = functions.name;
23358
+ for (auto &func : functions.functions) {
23359
+ func.name = functions.name;
23360
+ }
23361
+ }
23362
+
23363
+ AggregateFunctionSet functions;
23364
+
23365
+ public:
23366
+ unique_ptr<CreateInfo> Copy() const override {
23367
+ auto result = make_unique<CreateAggregateFunctionInfo>(functions);
23368
+ CopyProperties(*result);
23369
+ return move(result);
23370
+ }
23371
+ };
23372
+
23373
+ } // namespace duckdb
23374
+ //===----------------------------------------------------------------------===//
23375
+ // DuckDB
23376
+ //
23377
+ // duckdb/parser/parsed_data/create_collation_info.hpp
23378
+ //
23379
+ //
23380
+ //===----------------------------------------------------------------------===//
23381
+
23382
+
23383
+
23384
+
23385
+
23386
+
23387
+ namespace duckdb {
23388
+
23389
+ struct CreateCollationInfo : public CreateInfo {
23390
+ CreateCollationInfo(string name_p, ScalarFunction function_p, bool combinable_p, bool not_required_for_equality_p)
23391
+ : CreateInfo(CatalogType::COLLATION_ENTRY), function(move(function_p)), combinable(combinable_p),
23392
+ not_required_for_equality(not_required_for_equality_p) {
23393
+ this->name = move(name_p);
23394
+ }
23395
+
23396
+ //! The name of the collation
23397
+ string name;
23398
+ //! The collation function to push in case collation is required
23399
+ ScalarFunction function;
23400
+ //! Whether or not the collation can be combined with other collations.
23401
+ bool combinable;
23402
+ //! Whether or not the collation is required for equality comparisons or not. For many collations a binary
23403
+ //! comparison for equality comparisons is correct, allowing us to skip the collation in these cases which greatly
23404
+ //! speeds up processing.
23405
+ bool not_required_for_equality;
23406
+
23407
+ public:
23408
+ unique_ptr<CreateInfo> Copy() const override {
23409
+ auto result = make_unique<CreateCollationInfo>(name, function, combinable, not_required_for_equality);
23410
+ CopyProperties(*result);
23411
+ return move(result);
23412
+ }
23413
+ };
23414
+
23415
+ } // namespace duckdb
23416
+ //===----------------------------------------------------------------------===//
23417
+ // DuckDB
23418
+ //
23419
+ // duckdb/parser/parsed_data/create_pragma_function_info.hpp
23420
+ //
23421
+ //
23422
+ //===----------------------------------------------------------------------===//
23423
+
23424
+
23425
+
23426
+
23427
+
23428
+
23429
+ namespace duckdb {
23430
+
23431
+ struct CreatePragmaFunctionInfo : public CreateFunctionInfo {
23432
+ explicit CreatePragmaFunctionInfo(PragmaFunction function)
23433
+ : CreateFunctionInfo(CatalogType::PRAGMA_FUNCTION_ENTRY) {
23434
+ functions.push_back(move(function));
23435
+ this->name = function.name;
23436
+ }
23437
+ CreatePragmaFunctionInfo(string name, vector<PragmaFunction> functions_)
23438
+ : CreateFunctionInfo(CatalogType::PRAGMA_FUNCTION_ENTRY), functions(move(functions_)) {
23439
+ this->name = name;
23440
+ for (auto &function : functions) {
23441
+ function.name = name;
23442
+ }
23443
+ }
23444
+
23445
+ vector<PragmaFunction> functions;
23446
+
23447
+ public:
23448
+ unique_ptr<CreateInfo> Copy() const override {
23449
+ auto result = make_unique<CreatePragmaFunctionInfo>(functions[0].name, functions);
23450
+ CopyProperties(*result);
23451
+ return move(result);
23452
+ }
23453
+ };
23454
+
23348
23455
  } // namespace duckdb
23349
23456
  //===----------------------------------------------------------------------===//
23350
23457
  // DuckDB
@@ -23374,7 +23481,7 @@ struct TransactionInfo : public ParseInfo {
23374
23481
  //===----------------------------------------------------------------------===//
23375
23482
  // DuckDB
23376
23483
  //
23377
- // duckdb/parser/parsed_data/create_type_info.hpp
23484
+ // duckdb/parser/parsed_data/drop_info.hpp
23378
23485
  //
23379
23486
  //
23380
23487
  //===----------------------------------------------------------------------===//
@@ -23384,27 +23491,33 @@ struct TransactionInfo : public ParseInfo {
23384
23491
 
23385
23492
 
23386
23493
 
23387
-
23388
-
23389
23494
  namespace duckdb {
23390
23495
 
23391
- struct CreateTypeInfo : public CreateInfo {
23392
-
23393
- CreateTypeInfo() : CreateInfo(CatalogType::TYPE_ENTRY) {
23496
+ struct DropInfo : public ParseInfo {
23497
+ DropInfo() : schema(INVALID_SCHEMA), if_exists(false), cascade(false) {
23394
23498
  }
23395
23499
 
23396
- //! Name of the Type
23500
+ //! The catalog type to drop
23501
+ CatalogType type;
23502
+ //! Schema name to drop from, if any
23503
+ string schema;
23504
+ //! Element name to drop
23397
23505
  string name;
23398
- //! Logical Type
23399
- LogicalType type;
23506
+ //! Ignore if the entry does not exist instead of failing
23507
+ bool if_exists = false;
23508
+ //! Cascade drop (drop all dependents instead of throwing an error if there
23509
+ //! are any)
23510
+ bool cascade = false;
23400
23511
 
23401
23512
  public:
23402
- unique_ptr<CreateInfo> Copy() const override {
23403
- auto result = make_unique<CreateTypeInfo>();
23404
- CopyProperties(*result);
23405
- result->name = name;
23513
+ unique_ptr<DropInfo> Copy() const {
23514
+ auto result = make_unique<DropInfo>();
23406
23515
  result->type = type;
23407
- return move(result);
23516
+ result->schema = schema;
23517
+ result->name = name;
23518
+ result->if_exists = if_exists;
23519
+ result->cascade = cascade;
23520
+ return result;
23408
23521
  }
23409
23522
  };
23410
23523
 
@@ -23412,7 +23525,7 @@ public:
23412
23525
  //===----------------------------------------------------------------------===//
23413
23526
  // DuckDB
23414
23527
  //
23415
- // duckdb/parser/parsed_data/create_view_info.hpp
23528
+ // duckdb/parser/parsed_data/create_schema_info.hpp
23416
23529
  //
23417
23530
  //
23418
23531
  //===----------------------------------------------------------------------===//
@@ -23421,32 +23534,16 @@ public:
23421
23534
 
23422
23535
 
23423
23536
 
23424
-
23425
23537
  namespace duckdb {
23426
23538
 
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) {
23539
+ struct CreateSchemaInfo : public CreateInfo {
23540
+ CreateSchemaInfo() : CreateInfo(CatalogType::SCHEMA_ENTRY) {
23432
23541
  }
23433
23542
 
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
23543
  public:
23444
23544
  unique_ptr<CreateInfo> Copy() const override {
23445
- auto result = make_unique<CreateViewInfo>(schema, view_name);
23545
+ auto result = make_unique<CreateSchemaInfo>();
23446
23546
  CopyProperties(*result);
23447
- result->aliases = aliases;
23448
- result->types = types;
23449
- result->query = unique_ptr_cast<SQLStatement, SelectStatement>(query->Copy());
23450
23547
  return move(result);
23451
23548
  }
23452
23549
  };
@@ -23539,7 +23636,7 @@ public:
23539
23636
  //===----------------------------------------------------------------------===//
23540
23637
  // DuckDB
23541
23638
  //
23542
- // duckdb/parser/parsed_data/export_table_data.hpp
23639
+ // duckdb/parser/parsed_data/vacuum_info.hpp
23543
23640
  //
23544
23641
  //
23545
23642
  //===----------------------------------------------------------------------===//
@@ -23548,34 +23645,28 @@ public:
23548
23645
 
23549
23646
 
23550
23647
 
23551
-
23552
23648
  namespace duckdb {
23553
23649
 
23554
- struct ExportedTableData {
23555
- //! Name of the exported table
23556
- string table_name;
23557
-
23558
- //! Name of the schema
23559
- string schema_name;
23560
-
23561
- //! Path to be exported
23562
- string file_path;
23563
- };
23650
+ enum class LoadType { LOAD, INSTALL, FORCE_INSTALL };
23564
23651
 
23565
- struct ExportedTableInfo {
23566
- TableCatalogEntry *entry;
23567
- ExportedTableData table_data;
23568
- };
23652
+ struct LoadInfo : public ParseInfo {
23653
+ std::string filename;
23654
+ LoadType load_type;
23569
23655
 
23570
- struct BoundExportData : public ParseInfo {
23571
- std::vector<ExportedTableInfo> data;
23656
+ public:
23657
+ unique_ptr<LoadInfo> Copy() const {
23658
+ auto result = make_unique<LoadInfo>();
23659
+ result->filename = filename;
23660
+ result->load_type = load_type;
23661
+ return result;
23662
+ }
23572
23663
  };
23573
23664
 
23574
23665
  } // namespace duckdb
23575
23666
  //===----------------------------------------------------------------------===//
23576
23667
  // DuckDB
23577
23668
  //
23578
- // duckdb/parser/parsed_data/vacuum_info.hpp
23669
+ // duckdb/parser/parsed_data/create_type_info.hpp
23579
23670
  //
23580
23671
  //
23581
23672
  //===----------------------------------------------------------------------===//
@@ -23584,20 +23675,28 @@ struct BoundExportData : public ParseInfo {
23584
23675
 
23585
23676
 
23586
23677
 
23678
+
23679
+
23680
+
23587
23681
  namespace duckdb {
23588
23682
 
23589
- enum class LoadType { LOAD, INSTALL, FORCE_INSTALL };
23683
+ struct CreateTypeInfo : public CreateInfo {
23590
23684
 
23591
- struct LoadInfo : public ParseInfo {
23592
- std::string filename;
23593
- LoadType load_type;
23685
+ CreateTypeInfo() : CreateInfo(CatalogType::TYPE_ENTRY) {
23686
+ }
23687
+
23688
+ //! Name of the Type
23689
+ string name;
23690
+ //! Logical Type
23691
+ LogicalType type;
23594
23692
 
23595
23693
  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;
23694
+ unique_ptr<CreateInfo> Copy() const override {
23695
+ auto result = make_unique<CreateTypeInfo>();
23696
+ CopyProperties(*result);
23697
+ result->name = name;
23698
+ result->type = type;
23699
+ return move(result);
23601
23700
  }
23602
23701
  };
23603
23702
 
@@ -23605,7 +23704,7 @@ public:
23605
23704
  //===----------------------------------------------------------------------===//
23606
23705
  // DuckDB
23607
23706
  //
23608
- // duckdb/parser/parsed_data/create_aggregate_function_info.hpp
23707
+ // duckdb/parser/parsed_data/create_view_info.hpp
23609
23708
  //
23610
23709
  //
23611
23710
  //===----------------------------------------------------------------------===//
@@ -23617,27 +23716,29 @@ public:
23617
23716
 
23618
23717
  namespace duckdb {
23619
23718
 
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));
23719
+ struct CreateViewInfo : public CreateInfo {
23720
+ CreateViewInfo() : CreateInfo(CatalogType::VIEW_ENTRY, INVALID_SCHEMA) {
23625
23721
  }
23626
-
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
- }
23722
+ CreateViewInfo(string schema, string view_name)
23723
+ : CreateInfo(CatalogType::VIEW_ENTRY, schema), view_name(view_name) {
23633
23724
  }
23634
23725
 
23635
- AggregateFunctionSet functions;
23726
+ //! Table name to insert to
23727
+ string view_name;
23728
+ //! Aliases of the view
23729
+ vector<string> aliases;
23730
+ //! Return types
23731
+ vector<LogicalType> types;
23732
+ //! The SelectStatement of the view
23733
+ unique_ptr<SelectStatement> query;
23636
23734
 
23637
23735
  public:
23638
23736
  unique_ptr<CreateInfo> Copy() const override {
23639
- auto result = make_unique<CreateAggregateFunctionInfo>(functions);
23737
+ auto result = make_unique<CreateViewInfo>(schema, view_name);
23640
23738
  CopyProperties(*result);
23739
+ result->aliases = aliases;
23740
+ result->types = types;
23741
+ result->query = unique_ptr_cast<SQLStatement, SelectStatement>(query->Copy());
23641
23742
  return move(result);
23642
23743
  }
23643
23744
  };
@@ -23646,7 +23747,7 @@ public:
23646
23747
  //===----------------------------------------------------------------------===//
23647
23748
  // DuckDB
23648
23749
  //
23649
- // duckdb/parser/parsed_data/drop_info.hpp
23750
+ // duckdb/parser/parsed_data/vacuum_info.hpp
23650
23751
  //
23651
23752
  //
23652
23753
  //===----------------------------------------------------------------------===//
@@ -23655,42 +23756,17 @@ public:
23655
23756
 
23656
23757
 
23657
23758
 
23658
-
23659
23759
  namespace duckdb {
23660
23760
 
23661
- struct DropInfo : public ParseInfo {
23662
- DropInfo() : schema(INVALID_SCHEMA), if_exists(false), cascade(false) {
23663
- }
23664
-
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;
23676
-
23677
- public:
23678
- unique_ptr<DropInfo> Copy() const {
23679
- auto result = make_unique<DropInfo>();
23680
- result->type = type;
23681
- result->schema = schema;
23682
- result->name = name;
23683
- result->if_exists = if_exists;
23684
- result->cascade = cascade;
23685
- return result;
23686
- }
23761
+ struct VacuumInfo : public ParseInfo {
23762
+ // nothing for now
23687
23763
  };
23688
23764
 
23689
23765
  } // namespace duckdb
23690
23766
  //===----------------------------------------------------------------------===//
23691
23767
  // DuckDB
23692
23768
  //
23693
- // duckdb/parser/parsed_data/create_pragma_function_info.hpp
23769
+ // duckdb/parser/parsed_data/show_select_info.hpp
23694
23770
  //
23695
23771
  //
23696
23772
  //===----------------------------------------------------------------------===//
@@ -23702,27 +23778,23 @@ public:
23702
23778
 
23703
23779
  namespace duckdb {
23704
23780
 
23705
- struct CreatePragmaFunctionInfo : public CreateFunctionInfo {
23706
- explicit CreatePragmaFunctionInfo(PragmaFunction function)
23707
- : CreateFunctionInfo(CatalogType::PRAGMA_FUNCTION_ENTRY) {
23708
- functions.push_back(move(function));
23709
- this->name = function.name;
23710
- }
23711
- CreatePragmaFunctionInfo(string name, vector<PragmaFunction> functions_)
23712
- : CreateFunctionInfo(CatalogType::PRAGMA_FUNCTION_ENTRY), functions(move(functions_)) {
23713
- this->name = name;
23714
- for (auto &function : functions) {
23715
- function.name = name;
23716
- }
23717
- }
23718
-
23719
- vector<PragmaFunction> functions;
23781
+ struct ShowSelectInfo : public ParseInfo {
23782
+ //! Types of projected columns
23783
+ vector<LogicalType> types;
23784
+ //! The QueryNode of select query
23785
+ unique_ptr<QueryNode> query;
23786
+ //! Aliases of projected columns
23787
+ vector<string> aliases;
23788
+ //! Whether or not we are requesting a summary or a describe
23789
+ bool is_summary;
23720
23790
 
23721
- public:
23722
- unique_ptr<CreateInfo> Copy() const override {
23723
- auto result = make_unique<CreatePragmaFunctionInfo>(functions[0].name, functions);
23724
- CopyProperties(*result);
23725
- return move(result);
23791
+ unique_ptr<ShowSelectInfo> Copy() {
23792
+ auto result = make_unique<ShowSelectInfo>();
23793
+ result->types = types;
23794
+ result->query = query->Copy();
23795
+ result->aliases = aliases;
23796
+ result->is_summary = is_summary;
23797
+ return result;
23726
23798
  }
23727
23799
  };
23728
23800
 
@@ -23730,7 +23802,7 @@ public:
23730
23802
  //===----------------------------------------------------------------------===//
23731
23803
  // DuckDB
23732
23804
  //
23733
- // duckdb/parser/tableref/expressionlistref.hpp
23805
+ // duckdb/parser/tableref/emptytableref.hpp
23734
23806
  //
23735
23807
  //
23736
23808
  //===----------------------------------------------------------------------===//
@@ -23739,35 +23811,25 @@ public:
23739
23811
 
23740
23812
 
23741
23813
 
23742
-
23743
-
23744
-
23745
23814
  namespace duckdb {
23746
- //! Represents an expression list as generated by a VALUES statement
23747
- class ExpressionListRef : public TableRef {
23815
+ //! Represents a cross product
23816
+ class EmptyTableRef : public TableRef {
23748
23817
  public:
23749
- ExpressionListRef() : TableRef(TableReferenceType::EXPRESSION_LIST) {
23818
+ EmptyTableRef() : TableRef(TableReferenceType::EMPTY) {
23750
23819
  }
23751
23820
 
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;
23758
-
23759
23821
  public:
23822
+ string ToString() const override;
23760
23823
  bool Equals(const TableRef *other_p) const override;
23761
23824
 
23762
23825
  unique_ptr<TableRef> Copy() override;
23763
23826
 
23764
- //! Serializes a blob into a ExpressionListRef
23827
+ //! Serializes a blob into a DummyTableRef
23765
23828
  void Serialize(FieldWriter &serializer) const override;
23766
- //! Deserializes a blob back into a ExpressionListRef
23829
+ //! Deserializes a blob back into a DummyTableRef
23767
23830
  static unique_ptr<TableRef> Deserialize(FieldReader &source);
23768
23831
  };
23769
23832
  } // namespace duckdb
23770
-
23771
23833
  //===----------------------------------------------------------------------===//
23772
23834
  // DuckDB
23773
23835
  //
@@ -23793,6 +23855,7 @@ public:
23793
23855
  unique_ptr<TableRef> right;
23794
23856
 
23795
23857
  public:
23858
+ string ToString() const override;
23796
23859
  bool Equals(const TableRef *other_p) const override;
23797
23860
 
23798
23861
  unique_ptr<TableRef> Copy() override;
@@ -23804,10 +23867,12 @@ public:
23804
23867
  };
23805
23868
  } // namespace duckdb
23806
23869
 
23870
+
23871
+
23807
23872
  //===----------------------------------------------------------------------===//
23808
23873
  // DuckDB
23809
23874
  //
23810
- // duckdb/parser/tableref/emptytableref.hpp
23875
+ // duckdb/parser/tableref/expressionlistref.hpp
23811
23876
  //
23812
23877
  //
23813
23878
  //===----------------------------------------------------------------------===//
@@ -23816,26 +23881,36 @@ public:
23816
23881
 
23817
23882
 
23818
23883
 
23884
+
23885
+
23886
+
23819
23887
  namespace duckdb {
23820
- //! Represents a cross product
23821
- class EmptyTableRef : public TableRef {
23888
+ //! Represents an expression list as generated by a VALUES statement
23889
+ class ExpressionListRef : public TableRef {
23822
23890
  public:
23823
- EmptyTableRef() : TableRef(TableReferenceType::EMPTY) {
23891
+ ExpressionListRef() : TableRef(TableReferenceType::EXPRESSION_LIST) {
23824
23892
  }
23825
23893
 
23894
+ //! Value list, only used for VALUES statement
23895
+ vector<vector<unique_ptr<ParsedExpression>>> values;
23896
+ //! Expected SQL types
23897
+ vector<LogicalType> expected_types;
23898
+ //! The set of expected names
23899
+ vector<string> expected_names;
23900
+
23826
23901
  public:
23902
+ string ToString() const override;
23827
23903
  bool Equals(const TableRef *other_p) const override;
23828
23904
 
23829
23905
  unique_ptr<TableRef> Copy() override;
23830
23906
 
23831
- //! Serializes a blob into a DummyTableRef
23907
+ //! Serializes a blob into a ExpressionListRef
23832
23908
  void Serialize(FieldWriter &serializer) const override;
23833
- //! Deserializes a blob back into a DummyTableRef
23909
+ //! Deserializes a blob back into a ExpressionListRef
23834
23910
  static unique_ptr<TableRef> Deserialize(FieldReader &source);
23835
23911
  };
23836
23912
  } // namespace duckdb
23837
23913
 
23838
-
23839
23914
  //===----------------------------------------------------------------------===//
23840
23915
  // DuckDB
23841
23916
  //
@@ -23873,6 +23948,7 @@ public:
23873
23948
  vector<string> using_columns;
23874
23949
 
23875
23950
  public:
23951
+ string ToString() const override;
23876
23952
  bool Equals(const TableRef *other_p) const override;
23877
23953
 
23878
23954
  unique_ptr<TableRef> Copy() override;
@@ -23909,6 +23985,7 @@ public:
23909
23985
  vector<string> column_name_alias;
23910
23986
 
23911
23987
  public:
23988
+ string ToString() const override;
23912
23989
  bool Equals(const TableRef *other_p) const override;
23913
23990
 
23914
23991
  unique_ptr<TableRef> Copy() override;
@@ -23939,8 +24016,7 @@ namespace duckdb {
23939
24016
  //! Represents a Table producing function
23940
24017
  class TableFunctionRef : public TableRef {
23941
24018
  public:
23942
- TableFunctionRef() : TableRef(TableReferenceType::TABLE_FUNCTION) {
23943
- }
24019
+ DUCKDB_API TableFunctionRef();
23944
24020
 
23945
24021
  unique_ptr<ParsedExpression> function;
23946
24022
  vector<string> column_name_alias;