duckdb 0.3.5-dev992.0 → 0.4.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 "710a969ca"
15
- #define DUCKDB_VERSION "v0.3.5-dev992"
14
+ #define DUCKDB_SOURCE_ID "da9ee490d"
15
+ #define DUCKDB_VERSION "v0.4.0"
16
16
  //===----------------------------------------------------------------------===//
17
17
  // DuckDB
18
18
  //
@@ -102,7 +102,7 @@ using std::string;
102
102
  #define DUCKDB_EXTENSION_API
103
103
  #endif
104
104
  #else
105
- #define DUCKDB_EXTENSION_API
105
+ #define DUCKDB_EXTENSION_API __attribute__((visibility("default")))
106
106
  #endif
107
107
  #endif
108
108
 
@@ -1047,8 +1047,12 @@ struct LogicalType {
1047
1047
  DUCKDB_API bool IsIntegral() const;
1048
1048
  DUCKDB_API bool IsNumeric() const;
1049
1049
  DUCKDB_API hash_t Hash() const;
1050
+ DUCKDB_API void SetAlias(string &alias);
1051
+ DUCKDB_API string GetAlias() const;
1050
1052
 
1051
1053
  DUCKDB_API static LogicalType MaxLogicalType(const LogicalType &left, const LogicalType &right);
1054
+ DUCKDB_API static void SetCatalog(LogicalType &type, TypeCatalogEntry* catalog_entry);
1055
+ DUCKDB_API static TypeCatalogEntry* GetCatalog(const LogicalType &type);
1052
1056
 
1053
1057
  //! Gets the decimal properties of a numeric type. Fails if the type is not numeric.
1054
1058
  DUCKDB_API bool GetDecimalProperties(uint8_t &width, uint8_t &scale) const;
@@ -1106,6 +1110,7 @@ public:
1106
1110
  DUCKDB_API static LogicalType MAP( child_list_t<LogicalType> children); // NOLINT
1107
1111
  DUCKDB_API static LogicalType MAP(LogicalType key, LogicalType value); // NOLINT
1108
1112
  DUCKDB_API static LogicalType ENUM(const string &enum_name, Vector &ordered_data, idx_t size); // NOLINT
1113
+ DUCKDB_API static LogicalType DEDUP_POINTER_ENUM(); // NOLINT
1109
1114
  DUCKDB_API static LogicalType USER(const string &user_type_name); // NOLINT
1110
1115
  //! A list of all NUMERIC types (integral and floating point types)
1111
1116
  DUCKDB_API static const vector<LogicalType> Numeric();
@@ -1140,7 +1145,7 @@ struct EnumType{
1140
1145
  DUCKDB_API static const string GetValue(const Value &val);
1141
1146
  DUCKDB_API static void SetCatalog(LogicalType &type, TypeCatalogEntry* catalog_entry);
1142
1147
  DUCKDB_API static TypeCatalogEntry* GetCatalog(const LogicalType &type);
1143
- DUCKDB_API static PhysicalType GetPhysicalType(idx_t size);
1148
+ DUCKDB_API static PhysicalType GetPhysicalType(const LogicalType &type);
1144
1149
  };
1145
1150
 
1146
1151
  struct StructType {
@@ -1265,8 +1270,8 @@ struct ExceptionFormatValue {
1265
1270
 
1266
1271
  ExceptionFormatValueType type;
1267
1272
 
1268
- double dbl_val;
1269
- int64_t int_val;
1273
+ double dbl_val = 0;
1274
+ int64_t int_val = 0;
1270
1275
  string str_val;
1271
1276
 
1272
1277
  public:
@@ -2189,9 +2194,8 @@ namespace duckdb {
2189
2194
  class VectorBuffer;
2190
2195
 
2191
2196
  struct SelectionData {
2192
- explicit SelectionData(idx_t count) {
2193
- owned_data = unique_ptr<sel_t[]>(new sel_t[count]);
2194
- }
2197
+ explicit SelectionData(idx_t count);
2198
+
2195
2199
  unique_ptr<sel_t[]> owned_data;
2196
2200
  };
2197
2201
 
@@ -3552,6 +3556,7 @@ class VectorStructBuffer : public VectorBuffer {
3552
3556
  public:
3553
3557
  VectorStructBuffer();
3554
3558
  VectorStructBuffer(const LogicalType &struct_type, idx_t capacity = STANDARD_VECTOR_SIZE);
3559
+ VectorStructBuffer(Vector &other, const SelectionVector &sel, idx_t count);
3555
3560
  ~VectorStructBuffer() override;
3556
3561
 
3557
3562
  public:
@@ -3713,7 +3718,9 @@ public:
3713
3718
  //! Verify that the Vector is in a consistent, not corrupt state. DEBUG
3714
3719
  //! FUNCTION ONLY!
3715
3720
  DUCKDB_API void Verify(idx_t count);
3716
- DUCKDB_API void Verify(const SelectionVector &sel, idx_t count);
3721
+ //! Asserts that the CheckMapValidity returns MapInvalidReason::VALID
3722
+ DUCKDB_API static void VerifyMap(Vector &map, const SelectionVector &sel, idx_t count);
3723
+ DUCKDB_API static void Verify(Vector &vector, const SelectionVector &sel, idx_t count);
3717
3724
  DUCKDB_API void UTFVerify(idx_t count);
3718
3725
  DUCKDB_API void UTFVerify(const SelectionVector &sel, idx_t count);
3719
3726
 
@@ -3756,6 +3763,10 @@ public:
3756
3763
  // Setters
3757
3764
  DUCKDB_API void SetVectorType(VectorType vector_type);
3758
3765
 
3766
+ private:
3767
+ //! Returns the [index] element of the Vector as a Value.
3768
+ DUCKDB_API static Value GetValue(const Vector &v, idx_t index);
3769
+
3759
3770
  protected:
3760
3771
  //! The vector type specifies how the data of the vector is physically stored (i.e. if it is a single repeated
3761
3772
  //! constant, if it is compressed)
@@ -5881,6 +5892,9 @@ enum class ExpressionClass : uint8_t {
5881
5892
  DUCKDB_API string ExpressionTypeToString(ExpressionType type);
5882
5893
  string ExpressionTypeToOperator(ExpressionType type);
5883
5894
 
5895
+ // Operator String to ExpressionType (e.g. + => OPERATOR_ADD)
5896
+ ExpressionType OperatorToExpressionType(const string &op);
5897
+
5884
5898
  //! Negate a comparison expression, turning e.g. = into !=, or < into >=
5885
5899
  ExpressionType NegateComparisionExpression(ExpressionType type);
5886
5900
  //! Flip a comparison expression, turning e.g. < into >, or = into =
@@ -7352,6 +7366,18 @@ struct FunctionLocalState {
7352
7366
  class BoundFunctionExpression;
7353
7367
  class ScalarFunctionCatalogEntry;
7354
7368
 
7369
+ struct FunctionStatisticsInput {
7370
+ FunctionStatisticsInput(BoundFunctionExpression &expr_p, FunctionData *bind_data_p,
7371
+ vector<unique_ptr<BaseStatistics>> &child_stats_p, unique_ptr<Expression> *expr_ptr_p)
7372
+ : expr(expr_p), bind_data(bind_data_p), child_stats(child_stats_p), expr_ptr(expr_ptr_p) {
7373
+ }
7374
+
7375
+ BoundFunctionExpression &expr;
7376
+ FunctionData *bind_data;
7377
+ vector<unique_ptr<BaseStatistics>> &child_stats;
7378
+ unique_ptr<Expression> *expr_ptr;
7379
+ };
7380
+
7355
7381
  //! The type used for scalar functions
7356
7382
  typedef std::function<void(DataChunk &, ExpressionState &, Vector &)> scalar_function_t;
7357
7383
  //! Binds the scalar function and creates the function data
@@ -7359,9 +7385,7 @@ typedef unique_ptr<FunctionData> (*bind_scalar_function_t)(ClientContext &contex
7359
7385
  vector<unique_ptr<Expression>> &arguments);
7360
7386
  typedef unique_ptr<FunctionLocalState> (*init_local_state_t)(const BoundFunctionExpression &expr,
7361
7387
  FunctionData *bind_data);
7362
- typedef unique_ptr<BaseStatistics> (*function_statistics_t)(ClientContext &context, BoundFunctionExpression &expr,
7363
- FunctionData *bind_data,
7364
- vector<unique_ptr<BaseStatistics>> &child_stats);
7388
+ typedef unique_ptr<BaseStatistics> (*function_statistics_t)(ClientContext &context, FunctionStatisticsInput &input);
7365
7389
  //! Adds the dependencies of this BoundFunctionExpression to the set of dependencies
7366
7390
  typedef void (*dependency_function_t)(BoundFunctionExpression &expr, unordered_set<CatalogEntry *> &dependencies);
7367
7391
 
@@ -9875,11 +9899,13 @@ enum class StatementReturnType : uint8_t {
9875
9899
  NOTHING // the statement returns nothing
9876
9900
  };
9877
9901
 
9902
+ string StatementReturnTypeToString(StatementReturnType type);
9903
+
9878
9904
  //! A struct containing various properties of a SQL statement
9879
9905
  struct StatementProperties {
9880
9906
  StatementProperties()
9881
9907
  : read_only(true), requires_valid_transaction(true), allow_stream_result(false), bound_all_parameters(true),
9882
- return_type(StatementReturnType::QUERY_RESULT) {
9908
+ return_type(StatementReturnType::QUERY_RESULT), parameter_count(0) {
9883
9909
  }
9884
9910
 
9885
9911
  //! Whether or not the statement is a read-only statement, or whether it can result in changes to the database
@@ -9893,6 +9919,8 @@ struct StatementProperties {
9893
9919
  bool bound_all_parameters;
9894
9920
  //! What type of data the statement returns
9895
9921
  StatementReturnType return_type;
9922
+ //! The number of prepared statement parameters
9923
+ idx_t parameter_count;
9896
9924
  };
9897
9925
 
9898
9926
  } // namespace duckdb
@@ -13539,8 +13567,9 @@ class LogicalGet;
13539
13567
  class TableCatalogEntry;
13540
13568
  class TableFunctionCatalogEntry;
13541
13569
  class BoundTableFunction;
13570
+ class StandardEntry;
13542
13571
 
13543
- enum class BindingType { BASE, TABLE, MACRO };
13572
+ enum class BindingType { BASE, TABLE, MACRO, CATALOG_ENTRY };
13544
13573
 
13545
13574
  //! A Binding represents a binding to a table, table-producing function or subquery with a specified table index.
13546
13575
  struct Binding {
@@ -13566,7 +13595,17 @@ public:
13566
13595
  bool HasMatchingBinding(const string &column_name);
13567
13596
  virtual string ColumnNotFoundError(const string &column_name) const;
13568
13597
  virtual BindResult Bind(ColumnRefExpression &colref, idx_t depth);
13569
- virtual TableCatalogEntry *GetTableEntry();
13598
+ virtual StandardEntry *GetStandardEntry();
13599
+ };
13600
+
13601
+ struct EntryBinding : public Binding {
13602
+ public:
13603
+ EntryBinding(const string &alias, vector<LogicalType> types, vector<string> names, idx_t index,
13604
+ StandardEntry &entry);
13605
+ StandardEntry &entry;
13606
+
13607
+ public:
13608
+ StandardEntry *GetStandardEntry() override;
13570
13609
  };
13571
13610
 
13572
13611
  //! TableBinding is exactly like the Binding, except it keeps track of which columns were bound in the linked LogicalGet
@@ -13581,7 +13620,7 @@ struct TableBinding : public Binding {
13581
13620
  public:
13582
13621
  unique_ptr<ParsedExpression> ExpandGeneratedColumn(const string &column_name);
13583
13622
  BindResult Bind(ColumnRefExpression &colref, idx_t depth) override;
13584
- TableCatalogEntry *GetTableEntry() override;
13623
+ StandardEntry *GetStandardEntry() override;
13585
13624
  string ColumnNotFoundError(const string &column_name) const override;
13586
13625
  };
13587
13626
 
@@ -13671,10 +13710,15 @@ public:
13671
13710
  //! Adds a call to a table function with the given alias to the BindContext.
13672
13711
  void AddTableFunction(idx_t index, const string &alias, const vector<string> &names,
13673
13712
  const vector<LogicalType> &types, LogicalGet &get);
13713
+ //! Adds a table view with a given alias to the BindContext.
13714
+ void AddView(idx_t index, const string &alias, SubqueryRef &ref, BoundQueryNode &subquery, ViewCatalogEntry *view);
13674
13715
  //! Adds a subquery with a given alias to the BindContext.
13675
13716
  void AddSubquery(idx_t index, const string &alias, SubqueryRef &ref, BoundQueryNode &subquery);
13676
13717
  //! Adds a subquery with a given alias to the BindContext.
13677
13718
  void AddSubquery(idx_t index, const string &alias, TableFunctionRef &ref, BoundQueryNode &subquery);
13719
+ //! Adds a binding to a catalog entry with a given alias to the BindContext.
13720
+ void AddEntryBinding(idx_t index, const string &alias, const vector<string> &names,
13721
+ const vector<LogicalType> &types, StandardEntry *entry);
13678
13722
  //! Adds a base table with the given alias to the BindContext.
13679
13723
  void AddGenericBinding(idx_t index, const string &alias, const vector<string> &names,
13680
13724
  const vector<LogicalType> &types);
@@ -14123,11 +14167,11 @@ public:
14123
14167
  //! The statement type
14124
14168
  StatementType type;
14125
14169
  //! The statement location within the query string
14126
- idx_t stmt_location;
14170
+ idx_t stmt_location = 0;
14127
14171
  //! The statement length within the query string
14128
- idx_t stmt_length;
14172
+ idx_t stmt_length = 0;
14129
14173
  //! The number of prepared statement parameters (if any)
14130
- idx_t n_param;
14174
+ idx_t n_param = 0;
14131
14175
  //! The query text that corresponds to this SQL statement
14132
14176
  string query;
14133
14177
 
@@ -15149,8 +15193,8 @@ private:
15149
15193
  void AdjustTableDependencies(CatalogEntry *entry);
15150
15194
  //! Adjust one dependency
15151
15195
  void AdjustDependency(CatalogEntry *entry, TableCatalogEntry *table, ColumnDefinition &column, bool remove);
15152
- //! Adjust Enum dependency
15153
- void AdjustEnumDependency(CatalogEntry *entry, ColumnDefinition &column, bool remove);
15196
+ //! Adjust User dependency
15197
+ void AdjustUserDependency(CatalogEntry *entry, ColumnDefinition &column, bool remove);
15154
15198
  //! Given a root entry, gets the entry valid for this transaction
15155
15199
  CatalogEntry *GetEntryForTransaction(ClientContext &context, CatalogEntry *current);
15156
15200
  CatalogEntry *GetCommittedEntry(CatalogEntry *current);
@@ -15348,6 +15392,19 @@ using std::deque;
15348
15392
  #endif
15349
15393
  #endif
15350
15394
 
15395
+ // duplicate of duckdb/main/winapi.hpp
15396
+ #ifndef DUCKDB_EXTENSION_API
15397
+ #ifdef _WIN32
15398
+ #ifdef DUCKDB_BUILD_LOADABLE_EXTENSION
15399
+ #define DUCKDB_EXTENSION_API __declspec(dllexport)
15400
+ #else
15401
+ #define DUCKDB_EXTENSION_API
15402
+ #endif
15403
+ #else
15404
+ #define DUCKDB_EXTENSION_API __attribute__((visibility("default")))
15405
+ #endif
15406
+ #endif
15407
+
15351
15408
  // duplicate of duckdb/common/constants.hpp
15352
15409
  #ifndef DUCKDB_API_0_3_1
15353
15410
  #define DUCKDB_API_0_3_1 1
@@ -18304,9 +18361,12 @@ private:
18304
18361
 
18305
18362
  class Allocator {
18306
18363
  public:
18307
- Allocator();
18308
- Allocator(allocate_function_ptr_t allocate_function_p, free_function_ptr_t free_function_p,
18309
- reallocate_function_ptr_t reallocate_function_p, unique_ptr<PrivateAllocatorData> private_data);
18364
+ DUCKDB_API Allocator();
18365
+ DUCKDB_API Allocator(allocate_function_ptr_t allocate_function_p, free_function_ptr_t free_function_p,
18366
+ reallocate_function_ptr_t reallocate_function_p,
18367
+ unique_ptr<PrivateAllocatorData> private_data);
18368
+
18369
+ DUCKDB_API Allocator &operator=(Allocator &&allocator) noexcept = default;
18310
18370
 
18311
18371
  data_ptr_t AllocateData(idx_t size);
18312
18372
  void FreeData(data_ptr_t pointer, idx_t size);
@@ -22567,6 +22627,7 @@ struct BufferedCSVReaderOptions {
22567
22627
  //! How many leading rows to skip
22568
22628
  idx_t skip_rows = 0;
22569
22629
  //! Maximum CSV line size: specified because if we reach this amount, we likely have wrong delimiters (default: 2MB)
22630
+ //! note that this is the guaranteed line length that will succeed, longer lines may be accepted if slightly above
22570
22631
  idx_t maximum_line_size = 2097152;
22571
22632
  //! Whether or not header names shall be normalized
22572
22633
  bool normalize_names = false;
@@ -22620,6 +22681,8 @@ enum class ParserMode : uint8_t { PARSING = 0, SNIFFING_DIALECT = 1, SNIFFING_DA
22620
22681
  class BufferedCSVReader {
22621
22682
  //! Initial buffer read size; can be extended for long lines
22622
22683
  static constexpr idx_t INITIAL_BUFFER_SIZE = 16384;
22684
+ //! Larger buffer size for non disk files
22685
+ static constexpr idx_t INITIAL_BUFFER_SIZE_LARGE = 10000000; // 10MB
22623
22686
  ParserMode mode;
22624
22687
 
22625
22688
  public:
@@ -22889,7 +22952,7 @@ private:
22889
22952
  //===----------------------------------------------------------------------===//
22890
22953
  // DuckDB
22891
22954
  //
22892
- // duckdb/parser/expression/comparison_expression.hpp
22955
+ // duckdb/parser/expression/conjunction_expression.hpp
22893
22956
  //
22894
22957
  //
22895
22958
  //===----------------------------------------------------------------------===//
@@ -22898,21 +22961,25 @@ private:
22898
22961
 
22899
22962
 
22900
22963
 
22964
+
22901
22965
  namespace duckdb {
22902
- //! ComparisonExpression represents a boolean comparison (e.g. =, >=, <>). Always returns a boolean
22903
- //! and has two children.
22904
- class ComparisonExpression : public ParsedExpression {
22966
+
22967
+ //! Represents a conjunction (AND/OR)
22968
+ class ConjunctionExpression : public ParsedExpression {
22905
22969
  public:
22906
- DUCKDB_API ComparisonExpression(ExpressionType type, unique_ptr<ParsedExpression> left,
22907
- unique_ptr<ParsedExpression> right);
22970
+ DUCKDB_API explicit ConjunctionExpression(ExpressionType type);
22971
+ DUCKDB_API ConjunctionExpression(ExpressionType type, vector<unique_ptr<ParsedExpression>> children);
22972
+ DUCKDB_API ConjunctionExpression(ExpressionType type, unique_ptr<ParsedExpression> left,
22973
+ unique_ptr<ParsedExpression> right);
22908
22974
 
22909
- unique_ptr<ParsedExpression> left;
22910
- unique_ptr<ParsedExpression> right;
22975
+ vector<unique_ptr<ParsedExpression>> children;
22911
22976
 
22912
22977
  public:
22978
+ void AddExpression(unique_ptr<ParsedExpression> expr);
22979
+
22913
22980
  string ToString() const override;
22914
22981
 
22915
- static bool Equals(const ComparisonExpression *a, const ComparisonExpression *b);
22982
+ static bool Equals(const ConjunctionExpression *a, const ConjunctionExpression *b);
22916
22983
 
22917
22984
  unique_ptr<ParsedExpression> Copy() const override;
22918
22985
 
@@ -22922,14 +22989,18 @@ public:
22922
22989
  public:
22923
22990
  template <class T, class BASE>
22924
22991
  static string ToString(const T &entry) {
22925
- return entry.left->ToString() + " " + ExpressionTypeToOperator(entry.type) + " " + entry.right->ToString();
22992
+ string result = "(" + entry.children[0]->ToString();
22993
+ for (idx_t i = 1; i < entry.children.size(); i++) {
22994
+ result += " " + ExpressionTypeToOperator(entry.type) + " " + entry.children[i]->ToString();
22995
+ }
22996
+ return result + ")";
22926
22997
  }
22927
22998
  };
22928
22999
  } // namespace duckdb
22929
23000
  //===----------------------------------------------------------------------===//
22930
23001
  // DuckDB
22931
23002
  //
22932
- // duckdb/parser/expression/default_expression.hpp
23003
+ // duckdb/parser/expression/positional_reference_expression.hpp
22933
23004
  //
22934
23005
  //
22935
23006
  //===----------------------------------------------------------------------===//
@@ -22939,10 +23010,11 @@ public:
22939
23010
 
22940
23011
 
22941
23012
  namespace duckdb {
22942
- //! Represents the default value of a column
22943
- class DefaultExpression : public ParsedExpression {
23013
+ class PositionalReferenceExpression : public ParsedExpression {
22944
23014
  public:
22945
- DefaultExpression();
23015
+ DUCKDB_API PositionalReferenceExpression(idx_t index);
23016
+
23017
+ idx_t index;
22946
23018
 
22947
23019
  public:
22948
23020
  bool IsScalar() const override {
@@ -22951,7 +23023,9 @@ public:
22951
23023
 
22952
23024
  string ToString() const override;
22953
23025
 
23026
+ static bool Equals(const PositionalReferenceExpression *a, const PositionalReferenceExpression *b);
22954
23027
  unique_ptr<ParsedExpression> Copy() const override;
23028
+ hash_t Hash() const override;
22955
23029
 
22956
23030
  void Serialize(FieldWriter &writer) const override;
22957
23031
  static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
@@ -22960,7 +23034,7 @@ public:
22960
23034
  //===----------------------------------------------------------------------===//
22961
23035
  // DuckDB
22962
23036
  //
22963
- // duckdb/parser/expression/case_expression.hpp
23037
+ // duckdb/parser/expression/star_expression.hpp
22964
23038
  //
22965
23039
  //
22966
23040
  //===----------------------------------------------------------------------===//
@@ -22972,47 +23046,33 @@ public:
22972
23046
 
22973
23047
  namespace duckdb {
22974
23048
 
22975
- struct CaseCheck {
22976
- unique_ptr<ParsedExpression> when_expr;
22977
- unique_ptr<ParsedExpression> then_expr;
22978
- };
22979
-
22980
- //! The CaseExpression represents a CASE expression in the query
22981
- class CaseExpression : public ParsedExpression {
23049
+ //! Represents a * expression in the SELECT clause
23050
+ class StarExpression : public ParsedExpression {
22982
23051
  public:
22983
- DUCKDB_API CaseExpression();
23052
+ StarExpression(string relation_name = string());
22984
23053
 
22985
- vector<CaseCheck> case_checks;
22986
- unique_ptr<ParsedExpression> else_expr;
23054
+ //! The relation name in case of tbl.*, or empty if this is a normal *
23055
+ string relation_name;
23056
+ //! List of columns to exclude from the STAR expression
23057
+ case_insensitive_set_t exclude_list;
23058
+ //! List of columns to replace with another expression
23059
+ case_insensitive_map_t<unique_ptr<ParsedExpression>> replace_list;
22987
23060
 
22988
23061
  public:
22989
23062
  string ToString() const override;
22990
23063
 
22991
- static bool Equals(const CaseExpression *a, const CaseExpression *b);
23064
+ static bool Equals(const StarExpression *a, const StarExpression *b);
22992
23065
 
22993
23066
  unique_ptr<ParsedExpression> Copy() const override;
22994
23067
 
22995
23068
  void Serialize(FieldWriter &writer) const override;
22996
23069
  static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
22997
-
22998
- public:
22999
- template <class T, class BASE>
23000
- static string ToString(const T &entry) {
23001
- string case_str = "CASE ";
23002
- for (auto &check : entry.case_checks) {
23003
- case_str += " WHEN (" + check.when_expr->ToString() + ")";
23004
- case_str += " THEN (" + check.then_expr->ToString() + ")";
23005
- }
23006
- case_str += " ELSE " + entry.else_expr->ToString();
23007
- case_str += " END";
23008
- return case_str;
23009
- }
23010
23070
  };
23011
23071
  } // namespace duckdb
23012
23072
  //===----------------------------------------------------------------------===//
23013
23073
  // DuckDB
23014
23074
  //
23015
- // duckdb/parser/expression/positional_reference_expression.hpp
23075
+ // duckdb/parser/expression/operator_expression.hpp
23016
23076
  //
23017
23077
  //
23018
23078
  //===----------------------------------------------------------------------===//
@@ -23021,32 +23081,98 @@ public:
23021
23081
 
23022
23082
 
23023
23083
 
23084
+
23085
+
23086
+
23024
23087
  namespace duckdb {
23025
- class PositionalReferenceExpression : public ParsedExpression {
23088
+ //! Represents a built-in operator expression
23089
+ class OperatorExpression : public ParsedExpression {
23026
23090
  public:
23027
- DUCKDB_API PositionalReferenceExpression(idx_t index);
23091
+ DUCKDB_API explicit OperatorExpression(ExpressionType type, unique_ptr<ParsedExpression> left = nullptr,
23092
+ unique_ptr<ParsedExpression> right = nullptr);
23093
+ DUCKDB_API OperatorExpression(ExpressionType type, vector<unique_ptr<ParsedExpression>> children);
23028
23094
 
23029
- idx_t index;
23095
+ vector<unique_ptr<ParsedExpression>> children;
23030
23096
 
23031
23097
  public:
23032
- bool IsScalar() const override {
23033
- return false;
23034
- }
23035
-
23036
23098
  string ToString() const override;
23037
23099
 
23038
- static bool Equals(const PositionalReferenceExpression *a, const PositionalReferenceExpression *b);
23100
+ static bool Equals(const OperatorExpression *a, const OperatorExpression *b);
23101
+
23039
23102
  unique_ptr<ParsedExpression> Copy() const override;
23040
- hash_t Hash() const override;
23041
23103
 
23042
23104
  void Serialize(FieldWriter &writer) const override;
23043
23105
  static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
23106
+
23107
+ public:
23108
+ template <class T, class BASE>
23109
+ static string ToString(const T &entry) {
23110
+ auto op = ExpressionTypeToOperator(entry.type);
23111
+ if (!op.empty()) {
23112
+ // use the operator string to represent the operator
23113
+ D_ASSERT(entry.children.size() == 2);
23114
+ return entry.children[0]->ToString() + " " + op + " " + entry.children[1]->ToString();
23115
+ }
23116
+ switch (entry.type) {
23117
+ case ExpressionType::COMPARE_IN:
23118
+ case ExpressionType::COMPARE_NOT_IN: {
23119
+ string op_type = entry.type == ExpressionType::COMPARE_IN ? " IN " : " NOT IN ";
23120
+ string in_child = entry.children[0]->ToString();
23121
+ string child_list = "(";
23122
+ for (idx_t i = 1; i < entry.children.size(); i++) {
23123
+ if (i > 1) {
23124
+ child_list += ", ";
23125
+ }
23126
+ child_list += entry.children[i]->ToString();
23127
+ }
23128
+ child_list += ")";
23129
+ return "(" + in_child + op_type + child_list + ")";
23130
+ }
23131
+ case ExpressionType::OPERATOR_NOT:
23132
+ case ExpressionType::GROUPING_FUNCTION:
23133
+ case ExpressionType::OPERATOR_COALESCE: {
23134
+ string result = ExpressionTypeToString(entry.type);
23135
+ result += "(";
23136
+ result += StringUtil::Join(entry.children, entry.children.size(), ", ",
23137
+ [](const unique_ptr<BASE> &child) { return child->ToString(); });
23138
+ result += ")";
23139
+ return result;
23140
+ }
23141
+ case ExpressionType::OPERATOR_IS_NULL:
23142
+ return "(" + entry.children[0]->ToString() + " IS NULL)";
23143
+ case ExpressionType::OPERATOR_IS_NOT_NULL:
23144
+ return "(" + entry.children[0]->ToString() + " IS NOT NULL)";
23145
+ case ExpressionType::ARRAY_EXTRACT:
23146
+ return entry.children[0]->ToString() + "[" + entry.children[1]->ToString() + "]";
23147
+ case ExpressionType::ARRAY_SLICE:
23148
+ return entry.children[0]->ToString() + "[" + entry.children[1]->ToString() + ":" +
23149
+ entry.children[2]->ToString() + "]";
23150
+ case ExpressionType::STRUCT_EXTRACT: {
23151
+ D_ASSERT(entry.children[1]->type == ExpressionType::VALUE_CONSTANT);
23152
+ auto child_string = entry.children[1]->ToString();
23153
+ D_ASSERT(child_string.size() >= 3);
23154
+ D_ASSERT(child_string[0] == '\'' && child_string[child_string.size() - 1] == '\'');
23155
+ return "(" + entry.children[0]->ToString() + ")." +
23156
+ KeywordHelper::WriteOptionallyQuoted(child_string.substr(1, child_string.size() - 2));
23157
+ }
23158
+ case ExpressionType::ARRAY_CONSTRUCTOR: {
23159
+ string result = "(ARRAY[";
23160
+ result += StringUtil::Join(entry.children, entry.children.size(), ", ",
23161
+ [](const unique_ptr<BASE> &child) { return child->ToString(); });
23162
+ result += "])";
23163
+ return result;
23164
+ }
23165
+ default:
23166
+ throw InternalException("Unrecognized operator type");
23167
+ }
23168
+ }
23044
23169
  };
23170
+
23045
23171
  } // namespace duckdb
23046
23172
  //===----------------------------------------------------------------------===//
23047
23173
  // DuckDB
23048
23174
  //
23049
- // duckdb/parser/expression/conjunction_expression.hpp
23175
+ // duckdb/parser/expression/constant_expression.hpp
23050
23176
  //
23051
23177
  //
23052
23178
  //===----------------------------------------------------------------------===//
@@ -23058,38 +23184,26 @@ public:
23058
23184
 
23059
23185
  namespace duckdb {
23060
23186
 
23061
- //! Represents a conjunction (AND/OR)
23062
- class ConjunctionExpression : public ParsedExpression {
23187
+ //! ConstantExpression represents a constant value in the query
23188
+ class ConstantExpression : public ParsedExpression {
23063
23189
  public:
23064
- DUCKDB_API explicit ConjunctionExpression(ExpressionType type);
23065
- DUCKDB_API ConjunctionExpression(ExpressionType type, vector<unique_ptr<ParsedExpression>> children);
23066
- DUCKDB_API ConjunctionExpression(ExpressionType type, unique_ptr<ParsedExpression> left,
23067
- unique_ptr<ParsedExpression> right);
23190
+ DUCKDB_API explicit ConstantExpression(Value val);
23068
23191
 
23069
- vector<unique_ptr<ParsedExpression>> children;
23192
+ //! The constant value referenced
23193
+ Value value;
23070
23194
 
23071
23195
  public:
23072
- void AddExpression(unique_ptr<ParsedExpression> expr);
23073
-
23074
23196
  string ToString() const override;
23075
23197
 
23076
- static bool Equals(const ConjunctionExpression *a, const ConjunctionExpression *b);
23198
+ static bool Equals(const ConstantExpression *a, const ConstantExpression *b);
23199
+ hash_t Hash() const override;
23077
23200
 
23078
23201
  unique_ptr<ParsedExpression> Copy() const override;
23079
23202
 
23080
23203
  void Serialize(FieldWriter &writer) const override;
23081
23204
  static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
23082
-
23083
- public:
23084
- template <class T, class BASE>
23085
- static string ToString(const T &entry) {
23086
- string result = "(" + entry.children[0]->ToString();
23087
- for (idx_t i = 1; i < entry.children.size(); i++) {
23088
- result += " " + ExpressionTypeToOperator(entry.type) + " " + entry.children[i]->ToString();
23089
- }
23090
- return result + ")";
23091
- }
23092
23205
  };
23206
+
23093
23207
  } // namespace duckdb
23094
23208
  //===----------------------------------------------------------------------===//
23095
23209
  // DuckDB
@@ -23143,7 +23257,7 @@ public:
23143
23257
  //===----------------------------------------------------------------------===//
23144
23258
  // DuckDB
23145
23259
  //
23146
- // duckdb/parser/expression/cast_expression.hpp
23260
+ // duckdb/parser/expression/parameter_expression.hpp
23147
23261
  //
23148
23262
  //
23149
23263
  //===----------------------------------------------------------------------===//
@@ -23152,43 +23266,34 @@ public:
23152
23266
 
23153
23267
 
23154
23268
 
23155
-
23156
23269
  namespace duckdb {
23157
-
23158
- //! CastExpression represents a type cast from one SQL type to another SQL type
23159
- class CastExpression : public ParsedExpression {
23270
+ class ParameterExpression : public ParsedExpression {
23160
23271
  public:
23161
- DUCKDB_API CastExpression(LogicalType target, unique_ptr<ParsedExpression> child, bool try_cast = false);
23272
+ ParameterExpression();
23162
23273
 
23163
- //! The child of the cast expression
23164
- unique_ptr<ParsedExpression> child;
23165
- //! The type to cast to
23166
- LogicalType cast_type;
23167
- //! Whether or not this is a try_cast expression
23168
- bool try_cast;
23274
+ idx_t parameter_nr;
23169
23275
 
23170
23276
  public:
23171
- string ToString() const override;
23277
+ bool IsScalar() const override {
23278
+ return true;
23279
+ }
23280
+ bool HasParameter() const override {
23281
+ return true;
23282
+ }
23172
23283
 
23173
- static bool Equals(const CastExpression *a, const CastExpression *b);
23284
+ string ToString() const override;
23174
23285
 
23175
23286
  unique_ptr<ParsedExpression> Copy() const override;
23287
+ hash_t Hash() const override;
23176
23288
 
23177
23289
  void Serialize(FieldWriter &writer) const override;
23178
23290
  static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
23179
-
23180
- public:
23181
- template <class T, class BASE>
23182
- static string ToString(const T &entry) {
23183
- return (entry.try_cast ? "TRY_CAST(" : "CAST(") + entry.child->ToString() + " AS " +
23184
- entry.cast_type.ToString() + ")";
23185
- }
23186
23291
  };
23187
23292
  } // namespace duckdb
23188
23293
  //===----------------------------------------------------------------------===//
23189
23294
  // DuckDB
23190
23295
  //
23191
- // duckdb/parser/expression/lambda_expression.hpp
23296
+ // duckdb/parser/expression/between_expression.hpp
23192
23297
  //
23193
23298
  //
23194
23299
  //===----------------------------------------------------------------------===//
@@ -23197,37 +23302,38 @@ public:
23197
23302
 
23198
23303
 
23199
23304
 
23200
-
23201
23305
  namespace duckdb {
23202
23306
 
23203
- //! LambdaExpression represents either:
23204
- //! 1. A lambda operator that can be used for e.g. mapping an expression to a list
23205
- //! 2. An OperatorExpression with the "->" operator
23206
- //! Lambda expressions are written in the form of "capture -> expr", e.g. "x -> x + 1"
23207
- class LambdaExpression : public ParsedExpression {
23307
+ class BetweenExpression : public ParsedExpression {
23208
23308
  public:
23209
- LambdaExpression(unique_ptr<ParsedExpression> lhs, unique_ptr<ParsedExpression> rhs);
23309
+ DUCKDB_API BetweenExpression(unique_ptr<ParsedExpression> input, unique_ptr<ParsedExpression> lower,
23310
+ unique_ptr<ParsedExpression> upper);
23210
23311
 
23211
- unique_ptr<ParsedExpression> lhs;
23212
- unique_ptr<ParsedExpression> rhs;
23312
+ unique_ptr<ParsedExpression> input;
23313
+ unique_ptr<ParsedExpression> lower;
23314
+ unique_ptr<ParsedExpression> upper;
23213
23315
 
23214
23316
  public:
23215
23317
  string ToString() const override;
23216
23318
 
23217
- static bool Equals(const LambdaExpression *a, const LambdaExpression *b);
23218
- hash_t Hash() const override;
23319
+ static bool Equals(const BetweenExpression *a, const BetweenExpression *b);
23219
23320
 
23220
23321
  unique_ptr<ParsedExpression> Copy() const override;
23221
23322
 
23222
23323
  void Serialize(FieldWriter &writer) const override;
23223
23324
  static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
23224
- };
23225
23325
 
23326
+ public:
23327
+ template <class T, class BASE>
23328
+ static string ToString(const T &entry) {
23329
+ return entry.input->ToString() + " BETWEEN " + entry.lower->ToString() + " AND " + entry.upper->ToString();
23330
+ }
23331
+ };
23226
23332
  } // namespace duckdb
23227
23333
  //===----------------------------------------------------------------------===//
23228
23334
  // DuckDB
23229
23335
  //
23230
- // duckdb/parser/expression/function_expression.hpp
23336
+ // duckdb/parser/expression/default_expression.hpp
23231
23337
  //
23232
23338
  //
23233
23339
  //===----------------------------------------------------------------------===//
@@ -23236,115 +23342,31 @@ public:
23236
23342
 
23237
23343
 
23238
23344
 
23239
-
23240
-
23241
23345
  namespace duckdb {
23242
- //! Represents a function call
23243
- class FunctionExpression : public ParsedExpression {
23346
+ //! Represents the default value of a column
23347
+ class DefaultExpression : public ParsedExpression {
23244
23348
  public:
23245
- DUCKDB_API FunctionExpression(string schema_name, const string &function_name,
23246
- vector<unique_ptr<ParsedExpression>> children,
23247
- unique_ptr<ParsedExpression> filter = nullptr,
23248
- unique_ptr<OrderModifier> order_bys = nullptr, bool distinct = false,
23249
- bool is_operator = false, bool export_state = false);
23250
- DUCKDB_API FunctionExpression(const string &function_name, vector<unique_ptr<ParsedExpression>> children,
23251
- unique_ptr<ParsedExpression> filter = nullptr,
23252
- unique_ptr<OrderModifier> order_bys = nullptr, bool distinct = false,
23253
- bool is_operator = false, bool export_state = false);
23254
-
23255
- //! Schema of the function
23256
- string schema;
23257
- //! Function name
23258
- string function_name;
23259
- //! Whether or not the function is an operator, only used for rendering
23260
- bool is_operator;
23261
- //! List of arguments to the function
23262
- vector<unique_ptr<ParsedExpression>> children;
23263
- //! Whether or not the aggregate function is distinct, only used for aggregates
23264
- bool distinct;
23265
- //! Expression representing a filter, only used for aggregates
23266
- unique_ptr<ParsedExpression> filter;
23267
- //! Modifier representing an ORDER BY, only used for aggregates
23268
- unique_ptr<OrderModifier> order_bys;
23269
- //! whether this function should export its state or not
23270
- bool export_state;
23349
+ DefaultExpression();
23271
23350
 
23272
23351
  public:
23352
+ bool IsScalar() const override {
23353
+ return false;
23354
+ }
23355
+
23273
23356
  string ToString() const override;
23274
23357
 
23275
23358
  unique_ptr<ParsedExpression> Copy() const override;
23276
23359
 
23277
- static bool Equals(const FunctionExpression *a, const FunctionExpression *b);
23278
- hash_t Hash() const override;
23279
-
23280
23360
  void Serialize(FieldWriter &writer) const override;
23281
23361
  static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
23282
-
23283
- void Verify() const override;
23284
-
23285
- public:
23286
- template <class T, class BASE>
23287
- static string ToString(const T &entry, const string &schema, const string &function_name, bool is_operator = false,
23288
- bool distinct = false, BASE *filter = nullptr, OrderModifier *order_bys = nullptr,
23289
- bool export_state = false, bool add_alias = false) {
23290
- if (is_operator) {
23291
- // built-in operator
23292
- D_ASSERT(!distinct);
23293
- if (entry.children.size() == 1) {
23294
- if (StringUtil::Contains(function_name, "__postfix")) {
23295
- return "(" + entry.children[0]->ToString() + ")" +
23296
- StringUtil::Replace(function_name, "__postfix", "");
23297
- } else {
23298
- return function_name + "(" + entry.children[0]->ToString() + ")";
23299
- }
23300
- } else if (entry.children.size() == 2) {
23301
- return "(" + entry.children[0]->ToString() + " " + function_name + " " + entry.children[1]->ToString() +
23302
- ")";
23303
- }
23304
- }
23305
- // standard function call
23306
- string result = schema.empty() ? function_name : schema + "." + function_name;
23307
- result += "(";
23308
- if (distinct) {
23309
- result += "DISTINCT ";
23310
- }
23311
- result += StringUtil::Join(entry.children, entry.children.size(), ", ", [&](const unique_ptr<BASE> &child) {
23312
- return child->alias.empty() || !add_alias
23313
- ? child->ToString()
23314
- : KeywordHelper::WriteOptionallyQuoted(child->alias) + " := " + child->ToString();
23315
- });
23316
- // ordered aggregate
23317
- if (order_bys && !order_bys->orders.empty()) {
23318
- if (entry.children.empty()) {
23319
- result += ") WITHIN GROUP (";
23320
- }
23321
- result += " ORDER BY ";
23322
- for (idx_t i = 0; i < order_bys->orders.size(); i++) {
23323
- if (i > 0) {
23324
- result += ", ";
23325
- }
23326
- result += order_bys->orders[i].ToString();
23327
- }
23328
- }
23329
- result += ")";
23330
-
23331
- // filtered aggregate
23332
- if (filter) {
23333
- result += " FILTER (WHERE " + filter->ToString() + ")";
23334
- }
23335
-
23336
- if (export_state) {
23337
- result += " EXPORT_STATE";
23338
- }
23339
-
23340
- return result;
23341
- }
23342
23362
  };
23343
23363
  } // namespace duckdb
23364
+
23365
+
23344
23366
  //===----------------------------------------------------------------------===//
23345
23367
  // DuckDB
23346
23368
  //
23347
- // duckdb/parser/expression/star_expression.hpp
23369
+ // duckdb/parser/expression/case_expression.hpp
23348
23370
  //
23349
23371
  //
23350
23372
  //===----------------------------------------------------------------------===//
@@ -23356,69 +23378,48 @@ public:
23356
23378
 
23357
23379
  namespace duckdb {
23358
23380
 
23359
- //! Represents a * expression in the SELECT clause
23360
- class StarExpression : public ParsedExpression {
23381
+ struct CaseCheck {
23382
+ unique_ptr<ParsedExpression> when_expr;
23383
+ unique_ptr<ParsedExpression> then_expr;
23384
+ };
23385
+
23386
+ //! The CaseExpression represents a CASE expression in the query
23387
+ class CaseExpression : public ParsedExpression {
23361
23388
  public:
23362
- StarExpression(string relation_name = string());
23389
+ DUCKDB_API CaseExpression();
23363
23390
 
23364
- //! The relation name in case of tbl.*, or empty if this is a normal *
23365
- string relation_name;
23366
- //! List of columns to exclude from the STAR expression
23367
- case_insensitive_set_t exclude_list;
23368
- //! List of columns to replace with another expression
23369
- case_insensitive_map_t<unique_ptr<ParsedExpression>> replace_list;
23391
+ vector<CaseCheck> case_checks;
23392
+ unique_ptr<ParsedExpression> else_expr;
23370
23393
 
23371
23394
  public:
23372
23395
  string ToString() const override;
23373
23396
 
23374
- static bool Equals(const StarExpression *a, const StarExpression *b);
23397
+ static bool Equals(const CaseExpression *a, const CaseExpression *b);
23375
23398
 
23376
23399
  unique_ptr<ParsedExpression> Copy() const override;
23377
23400
 
23378
23401
  void Serialize(FieldWriter &writer) const override;
23379
23402
  static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
23380
- };
23381
- } // namespace duckdb
23382
- //===----------------------------------------------------------------------===//
23383
- // DuckDB
23384
- //
23385
- // duckdb/parser/expression/parameter_expression.hpp
23386
- //
23387
- //
23388
- //===----------------------------------------------------------------------===//
23389
-
23390
-
23391
-
23392
23403
 
23393
-
23394
- namespace duckdb {
23395
- class ParameterExpression : public ParsedExpression {
23396
23404
  public:
23397
- ParameterExpression();
23398
-
23399
- idx_t parameter_nr;
23400
-
23401
- public:
23402
- bool IsScalar() const override {
23403
- return true;
23404
- }
23405
- bool HasParameter() const override {
23406
- return true;
23405
+ template <class T, class BASE>
23406
+ static string ToString(const T &entry) {
23407
+ string case_str = "CASE ";
23408
+ for (auto &check : entry.case_checks) {
23409
+ case_str += " WHEN (" + check.when_expr->ToString() + ")";
23410
+ case_str += " THEN (" + check.then_expr->ToString() + ")";
23411
+ }
23412
+ case_str += " ELSE " + entry.else_expr->ToString();
23413
+ case_str += " END";
23414
+ return case_str;
23407
23415
  }
23408
-
23409
- string ToString() const override;
23410
-
23411
- unique_ptr<ParsedExpression> Copy() const override;
23412
- hash_t Hash() const override;
23413
-
23414
- void Serialize(FieldWriter &writer) const override;
23415
- static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
23416
23416
  };
23417
23417
  } // namespace duckdb
23418
+
23418
23419
  //===----------------------------------------------------------------------===//
23419
23420
  // DuckDB
23420
23421
  //
23421
- // duckdb/parser/expression/between_expression.hpp
23422
+ // duckdb/parser/expression/cast_expression.hpp
23422
23423
  //
23423
23424
  //
23424
23425
  //===----------------------------------------------------------------------===//
@@ -23427,21 +23428,25 @@ public:
23427
23428
 
23428
23429
 
23429
23430
 
23431
+
23430
23432
  namespace duckdb {
23431
23433
 
23432
- class BetweenExpression : public ParsedExpression {
23434
+ //! CastExpression represents a type cast from one SQL type to another SQL type
23435
+ class CastExpression : public ParsedExpression {
23433
23436
  public:
23434
- DUCKDB_API BetweenExpression(unique_ptr<ParsedExpression> input, unique_ptr<ParsedExpression> lower,
23435
- unique_ptr<ParsedExpression> upper);
23437
+ DUCKDB_API CastExpression(LogicalType target, unique_ptr<ParsedExpression> child, bool try_cast = false);
23436
23438
 
23437
- unique_ptr<ParsedExpression> input;
23438
- unique_ptr<ParsedExpression> lower;
23439
- unique_ptr<ParsedExpression> upper;
23439
+ //! The child of the cast expression
23440
+ unique_ptr<ParsedExpression> child;
23441
+ //! The type to cast to
23442
+ LogicalType cast_type;
23443
+ //! Whether or not this is a try_cast expression
23444
+ bool try_cast;
23440
23445
 
23441
23446
  public:
23442
23447
  string ToString() const override;
23443
23448
 
23444
- static bool Equals(const BetweenExpression *a, const BetweenExpression *b);
23449
+ static bool Equals(const CastExpression *a, const CastExpression *b);
23445
23450
 
23446
23451
  unique_ptr<ParsedExpression> Copy() const override;
23447
23452
 
@@ -23451,14 +23456,12 @@ public:
23451
23456
  public:
23452
23457
  template <class T, class BASE>
23453
23458
  static string ToString(const T &entry) {
23454
- return entry.input->ToString() + " BETWEEN " + entry.lower->ToString() + " AND " + entry.upper->ToString();
23459
+ return (entry.try_cast ? "TRY_CAST(" : "CAST(") + entry.child->ToString() + " AS " +
23460
+ entry.cast_type.ToString() + ")";
23455
23461
  }
23456
23462
  };
23457
23463
  } // namespace duckdb
23458
23464
 
23459
-
23460
-
23461
-
23462
23465
  //===----------------------------------------------------------------------===//
23463
23466
  // DuckDB
23464
23467
  //
@@ -23496,12 +23499,10 @@ public:
23496
23499
  } // namespace duckdb
23497
23500
 
23498
23501
 
23499
-
23500
-
23501
23502
  //===----------------------------------------------------------------------===//
23502
23503
  // DuckDB
23503
23504
  //
23504
- // duckdb/parser/expression/constant_expression.hpp
23505
+ // duckdb/parser/expression/comparison_expression.hpp
23505
23506
  //
23506
23507
  //
23507
23508
  //===----------------------------------------------------------------------===//
@@ -23510,29 +23511,33 @@ public:
23510
23511
 
23511
23512
 
23512
23513
 
23513
-
23514
23514
  namespace duckdb {
23515
-
23516
- //! ConstantExpression represents a constant value in the query
23517
- class ConstantExpression : public ParsedExpression {
23515
+ //! ComparisonExpression represents a boolean comparison (e.g. =, >=, <>). Always returns a boolean
23516
+ //! and has two children.
23517
+ class ComparisonExpression : public ParsedExpression {
23518
23518
  public:
23519
- DUCKDB_API explicit ConstantExpression(Value val);
23519
+ DUCKDB_API ComparisonExpression(ExpressionType type, unique_ptr<ParsedExpression> left,
23520
+ unique_ptr<ParsedExpression> right);
23520
23521
 
23521
- //! The constant value referenced
23522
- Value value;
23522
+ unique_ptr<ParsedExpression> left;
23523
+ unique_ptr<ParsedExpression> right;
23523
23524
 
23524
23525
  public:
23525
23526
  string ToString() const override;
23526
23527
 
23527
- static bool Equals(const ConstantExpression *a, const ConstantExpression *b);
23528
- hash_t Hash() const override;
23528
+ static bool Equals(const ComparisonExpression *a, const ComparisonExpression *b);
23529
23529
 
23530
23530
  unique_ptr<ParsedExpression> Copy() const override;
23531
23531
 
23532
23532
  void Serialize(FieldWriter &writer) const override;
23533
23533
  static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
23534
- };
23535
23534
 
23535
+ public:
23536
+ template <class T, class BASE>
23537
+ static string ToString(const T &entry) {
23538
+ return entry.left->ToString() + " " + ExpressionTypeToOperator(entry.type) + " " + entry.right->ToString();
23539
+ }
23540
+ };
23536
23541
  } // namespace duckdb
23537
23542
 
23538
23543
 
@@ -23541,7 +23546,7 @@ public:
23541
23546
  //===----------------------------------------------------------------------===//
23542
23547
  // DuckDB
23543
23548
  //
23544
- // duckdb/parser/expression/operator_expression.hpp
23549
+ // duckdb/parser/expression/function_expression.hpp
23545
23550
  //
23546
23551
  //
23547
23552
  //===----------------------------------------------------------------------===//
@@ -23552,102 +23557,114 @@ public:
23552
23557
 
23553
23558
 
23554
23559
 
23555
-
23556
23560
  namespace duckdb {
23557
- //! Represents a built-in operator expression
23558
- class OperatorExpression : public ParsedExpression {
23561
+ //! Represents a function call
23562
+ class FunctionExpression : public ParsedExpression {
23559
23563
  public:
23560
- DUCKDB_API explicit OperatorExpression(ExpressionType type, unique_ptr<ParsedExpression> left = nullptr,
23561
- unique_ptr<ParsedExpression> right = nullptr);
23562
- DUCKDB_API OperatorExpression(ExpressionType type, vector<unique_ptr<ParsedExpression>> children);
23564
+ DUCKDB_API FunctionExpression(string schema_name, const string &function_name,
23565
+ vector<unique_ptr<ParsedExpression>> children,
23566
+ unique_ptr<ParsedExpression> filter = nullptr,
23567
+ unique_ptr<OrderModifier> order_bys = nullptr, bool distinct = false,
23568
+ bool is_operator = false, bool export_state = false);
23569
+ DUCKDB_API FunctionExpression(const string &function_name, vector<unique_ptr<ParsedExpression>> children,
23570
+ unique_ptr<ParsedExpression> filter = nullptr,
23571
+ unique_ptr<OrderModifier> order_bys = nullptr, bool distinct = false,
23572
+ bool is_operator = false, bool export_state = false);
23563
23573
 
23574
+ //! Schema of the function
23575
+ string schema;
23576
+ //! Function name
23577
+ string function_name;
23578
+ //! Whether or not the function is an operator, only used for rendering
23579
+ bool is_operator;
23580
+ //! List of arguments to the function
23564
23581
  vector<unique_ptr<ParsedExpression>> children;
23582
+ //! Whether or not the aggregate function is distinct, only used for aggregates
23583
+ bool distinct;
23584
+ //! Expression representing a filter, only used for aggregates
23585
+ unique_ptr<ParsedExpression> filter;
23586
+ //! Modifier representing an ORDER BY, only used for aggregates
23587
+ unique_ptr<OrderModifier> order_bys;
23588
+ //! whether this function should export its state or not
23589
+ bool export_state;
23565
23590
 
23566
23591
  public:
23567
23592
  string ToString() const override;
23568
23593
 
23569
- static bool Equals(const OperatorExpression *a, const OperatorExpression *b);
23570
-
23571
23594
  unique_ptr<ParsedExpression> Copy() const override;
23572
23595
 
23596
+ static bool Equals(const FunctionExpression *a, const FunctionExpression *b);
23597
+ hash_t Hash() const override;
23598
+
23573
23599
  void Serialize(FieldWriter &writer) const override;
23574
23600
  static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
23575
23601
 
23602
+ void Verify() const override;
23603
+
23576
23604
  public:
23577
23605
  template <class T, class BASE>
23578
- static string ToString(const T &entry) {
23579
- auto op = ExpressionTypeToOperator(entry.type);
23580
- if (!op.empty()) {
23581
- // use the operator string to represent the operator
23582
- D_ASSERT(entry.children.size() == 2);
23583
- return entry.children[0]->ToString() + " " + op + " " + entry.children[1]->ToString();
23584
- }
23585
- switch (entry.type) {
23586
- case ExpressionType::COMPARE_IN:
23587
- case ExpressionType::COMPARE_NOT_IN: {
23588
- string op_type = entry.type == ExpressionType::COMPARE_IN ? " IN " : " NOT IN ";
23589
- string in_child = entry.children[0]->ToString();
23590
- string child_list = "(";
23591
- for (idx_t i = 1; i < entry.children.size(); i++) {
23592
- if (i > 1) {
23593
- child_list += ", ";
23606
+ static string ToString(const T &entry, const string &schema, const string &function_name, bool is_operator = false,
23607
+ bool distinct = false, BASE *filter = nullptr, OrderModifier *order_bys = nullptr,
23608
+ bool export_state = false, bool add_alias = false) {
23609
+ if (is_operator) {
23610
+ // built-in operator
23611
+ D_ASSERT(!distinct);
23612
+ if (entry.children.size() == 1) {
23613
+ if (StringUtil::Contains(function_name, "__postfix")) {
23614
+ return "(" + entry.children[0]->ToString() + ")" +
23615
+ StringUtil::Replace(function_name, "__postfix", "");
23616
+ } else {
23617
+ return function_name + "(" + entry.children[0]->ToString() + ")";
23594
23618
  }
23595
- child_list += entry.children[i]->ToString();
23619
+ } else if (entry.children.size() == 2) {
23620
+ return "(" + entry.children[0]->ToString() + " " + function_name + " " + entry.children[1]->ToString() +
23621
+ ")";
23596
23622
  }
23597
- child_list += ")";
23598
- return "(" + in_child + op_type + child_list + ")";
23599
23623
  }
23600
- case ExpressionType::OPERATOR_NOT:
23601
- case ExpressionType::GROUPING_FUNCTION:
23602
- case ExpressionType::OPERATOR_COALESCE: {
23603
- string result = ExpressionTypeToString(entry.type);
23604
- result += "(";
23605
- result += StringUtil::Join(entry.children, entry.children.size(), ", ",
23606
- [](const unique_ptr<BASE> &child) { return child->ToString(); });
23607
- result += ")";
23608
- return result;
23624
+ // standard function call
23625
+ string result = schema.empty() ? function_name : schema + "." + function_name;
23626
+ result += "(";
23627
+ if (distinct) {
23628
+ result += "DISTINCT ";
23609
23629
  }
23610
- case ExpressionType::OPERATOR_IS_NULL:
23611
- return "(" + entry.children[0]->ToString() + " IS NULL)";
23612
- case ExpressionType::OPERATOR_IS_NOT_NULL:
23613
- return "(" + entry.children[0]->ToString() + " IS NOT NULL)";
23614
- case ExpressionType::ARRAY_EXTRACT:
23615
- return entry.children[0]->ToString() + "[" + entry.children[1]->ToString() + "]";
23616
- case ExpressionType::ARRAY_SLICE:
23617
- return entry.children[0]->ToString() + "[" + entry.children[1]->ToString() + ":" +
23618
- entry.children[2]->ToString() + "]";
23619
- case ExpressionType::STRUCT_EXTRACT: {
23620
- D_ASSERT(entry.children[1]->type == ExpressionType::VALUE_CONSTANT);
23621
- auto child_string = entry.children[1]->ToString();
23622
- D_ASSERT(child_string.size() >= 3);
23623
- D_ASSERT(child_string[0] == '\'' && child_string[child_string.size() - 1] == '\'');
23624
- return "(" + entry.children[0]->ToString() + ")." +
23625
- KeywordHelper::WriteOptionallyQuoted(child_string.substr(1, child_string.size() - 2));
23630
+ result += StringUtil::Join(entry.children, entry.children.size(), ", ", [&](const unique_ptr<BASE> &child) {
23631
+ return child->alias.empty() || !add_alias
23632
+ ? child->ToString()
23633
+ : KeywordHelper::WriteOptionallyQuoted(child->alias) + " := " + child->ToString();
23634
+ });
23635
+ // ordered aggregate
23636
+ if (order_bys && !order_bys->orders.empty()) {
23637
+ if (entry.children.empty()) {
23638
+ result += ") WITHIN GROUP (";
23639
+ }
23640
+ result += " ORDER BY ";
23641
+ for (idx_t i = 0; i < order_bys->orders.size(); i++) {
23642
+ if (i > 0) {
23643
+ result += ", ";
23644
+ }
23645
+ result += order_bys->orders[i].ToString();
23646
+ }
23626
23647
  }
23627
- case ExpressionType::ARRAY_CONSTRUCTOR: {
23628
- string result = "(ARRAY[";
23629
- result += StringUtil::Join(entry.children, entry.children.size(), ", ",
23630
- [](const unique_ptr<BASE> &child) { return child->ToString(); });
23631
- result += "])";
23632
- return result;
23648
+ result += ")";
23649
+
23650
+ // filtered aggregate
23651
+ if (filter) {
23652
+ result += " FILTER (WHERE " + filter->ToString() + ")";
23633
23653
  }
23634
- default:
23635
- throw InternalException("Unrecognized operator type");
23654
+
23655
+ if (export_state) {
23656
+ result += " EXPORT_STATE";
23636
23657
  }
23658
+
23659
+ return result;
23637
23660
  }
23638
23661
  };
23639
-
23640
23662
  } // namespace duckdb
23641
23663
 
23642
-
23643
-
23644
-
23645
-
23646
-
23647
23664
  //===----------------------------------------------------------------------===//
23648
23665
  // DuckDB
23649
23666
  //
23650
- // duckdb/parser/parsed_data/create_view_info.hpp
23667
+ // duckdb/parser/expression/lambda_expression.hpp
23651
23668
  //
23652
23669
  //
23653
23670
  //===----------------------------------------------------------------------===//
@@ -23659,38 +23676,41 @@ public:
23659
23676
 
23660
23677
  namespace duckdb {
23661
23678
 
23662
- struct CreateViewInfo : public CreateInfo {
23663
- CreateViewInfo() : CreateInfo(CatalogType::VIEW_ENTRY, INVALID_SCHEMA) {
23664
- }
23665
- CreateViewInfo(string schema, string view_name)
23666
- : CreateInfo(CatalogType::VIEW_ENTRY, schema), view_name(view_name) {
23667
- }
23679
+ //! LambdaExpression represents either:
23680
+ //! 1. A lambda operator that can be used for e.g. mapping an expression to a list
23681
+ //! 2. An OperatorExpression with the "->" operator
23682
+ //! Lambda expressions are written in the form of "capture -> expr", e.g. "x -> x + 1"
23683
+ class LambdaExpression : public ParsedExpression {
23684
+ public:
23685
+ LambdaExpression(unique_ptr<ParsedExpression> lhs, unique_ptr<ParsedExpression> rhs);
23668
23686
 
23669
- //! Table name to insert to
23670
- string view_name;
23671
- //! Aliases of the view
23672
- vector<string> aliases;
23673
- //! Return types
23674
- vector<LogicalType> types;
23675
- //! The SelectStatement of the view
23676
- unique_ptr<SelectStatement> query;
23687
+ unique_ptr<ParsedExpression> lhs;
23688
+ unique_ptr<ParsedExpression> rhs;
23677
23689
 
23678
23690
  public:
23679
- unique_ptr<CreateInfo> Copy() const override {
23680
- auto result = make_unique<CreateViewInfo>(schema, view_name);
23681
- CopyProperties(*result);
23682
- result->aliases = aliases;
23683
- result->types = types;
23684
- result->query = unique_ptr_cast<SQLStatement, SelectStatement>(query->Copy());
23685
- return move(result);
23686
- }
23691
+ string ToString() const override;
23692
+
23693
+ static bool Equals(const LambdaExpression *a, const LambdaExpression *b);
23694
+ hash_t Hash() const override;
23695
+
23696
+ unique_ptr<ParsedExpression> Copy() const override;
23697
+
23698
+ void Serialize(FieldWriter &writer) const override;
23699
+ static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
23687
23700
  };
23688
23701
 
23689
23702
  } // namespace duckdb
23703
+
23704
+
23705
+
23706
+
23707
+
23708
+
23709
+
23690
23710
  //===----------------------------------------------------------------------===//
23691
23711
  // DuckDB
23692
23712
  //
23693
- // duckdb/parser/parsed_data/transaction_info.hpp
23713
+ // duckdb/parser/parsed_data/vacuum_info.hpp
23694
23714
  //
23695
23715
  //
23696
23716
  //===----------------------------------------------------------------------===//
@@ -23701,14 +23721,19 @@ public:
23701
23721
 
23702
23722
  namespace duckdb {
23703
23723
 
23704
- enum class TransactionType : uint8_t { INVALID, BEGIN_TRANSACTION, COMMIT, ROLLBACK };
23724
+ enum class LoadType { LOAD, INSTALL, FORCE_INSTALL };
23725
+
23726
+ struct LoadInfo : public ParseInfo {
23727
+ std::string filename;
23728
+ LoadType load_type;
23705
23729
 
23706
- struct TransactionInfo : public ParseInfo {
23707
- explicit TransactionInfo(TransactionType type) : type(type) {
23730
+ public:
23731
+ unique_ptr<LoadInfo> Copy() const {
23732
+ auto result = make_unique<LoadInfo>();
23733
+ result->filename = filename;
23734
+ result->load_type = load_type;
23735
+ return result;
23708
23736
  }
23709
-
23710
- //! The type of transaction statement
23711
- TransactionType type;
23712
23737
  };
23713
23738
 
23714
23739
  } // namespace duckdb
@@ -23755,7 +23780,7 @@ public:
23755
23780
  //===----------------------------------------------------------------------===//
23756
23781
  // DuckDB
23757
23782
  //
23758
- // duckdb/parser/parsed_data/create_schema_info.hpp
23783
+ // duckdb/parser/parsed_data/drop_info.hpp
23759
23784
  //
23760
23785
  //
23761
23786
  //===----------------------------------------------------------------------===//
@@ -23764,18 +23789,60 @@ public:
23764
23789
 
23765
23790
 
23766
23791
 
23792
+
23767
23793
  namespace duckdb {
23768
23794
 
23769
- struct CreateSchemaInfo : public CreateInfo {
23770
- CreateSchemaInfo() : CreateInfo(CatalogType::SCHEMA_ENTRY) {
23795
+ struct DropInfo : public ParseInfo {
23796
+ DropInfo() : schema(INVALID_SCHEMA), if_exists(false), cascade(false) {
23771
23797
  }
23772
23798
 
23799
+ //! The catalog type to drop
23800
+ CatalogType type;
23801
+ //! Schema name to drop from, if any
23802
+ string schema;
23803
+ //! Element name to drop
23804
+ string name;
23805
+ //! Ignore if the entry does not exist instead of failing
23806
+ bool if_exists = false;
23807
+ //! Cascade drop (drop all dependents instead of throwing an error if there
23808
+ //! are any)
23809
+ bool cascade = false;
23810
+
23773
23811
  public:
23774
- unique_ptr<CreateInfo> Copy() const override {
23775
- auto result = make_unique<CreateSchemaInfo>();
23776
- CopyProperties(*result);
23777
- return move(result);
23812
+ unique_ptr<DropInfo> Copy() const {
23813
+ auto result = make_unique<DropInfo>();
23814
+ result->type = type;
23815
+ result->schema = schema;
23816
+ result->name = name;
23817
+ result->if_exists = if_exists;
23818
+ result->cascade = cascade;
23819
+ return result;
23820
+ }
23821
+ };
23822
+
23823
+ } // namespace duckdb
23824
+ //===----------------------------------------------------------------------===//
23825
+ // DuckDB
23826
+ //
23827
+ // duckdb/parser/parsed_data/transaction_info.hpp
23828
+ //
23829
+ //
23830
+ //===----------------------------------------------------------------------===//
23831
+
23832
+
23833
+
23834
+
23835
+
23836
+ namespace duckdb {
23837
+
23838
+ enum class TransactionType : uint8_t { INVALID, BEGIN_TRANSACTION, COMMIT, ROLLBACK };
23839
+
23840
+ struct TransactionInfo : public ParseInfo {
23841
+ explicit TransactionInfo(TransactionType type) : type(type) {
23778
23842
  }
23843
+
23844
+ //! The type of transaction statement
23845
+ TransactionType type;
23779
23846
  };
23780
23847
 
23781
23848
  } // namespace duckdb
@@ -23866,7 +23933,7 @@ public:
23866
23933
  //===----------------------------------------------------------------------===//
23867
23934
  // DuckDB
23868
23935
  //
23869
- // duckdb/parser/parsed_data/create_aggregate_function_info.hpp
23936
+ // duckdb/parser/parsed_data/show_select_info.hpp
23870
23937
  //
23871
23938
  //
23872
23939
  //===----------------------------------------------------------------------===//
@@ -23878,36 +23945,63 @@ public:
23878
23945
 
23879
23946
  namespace duckdb {
23880
23947
 
23881
- struct CreateAggregateFunctionInfo : public CreateFunctionInfo {
23882
- explicit CreateAggregateFunctionInfo(AggregateFunction function)
23883
- : CreateFunctionInfo(CatalogType::AGGREGATE_FUNCTION_ENTRY), functions(function.name) {
23884
- this->name = function.name;
23885
- functions.AddFunction(move(function));
23886
- }
23948
+ struct ShowSelectInfo : public ParseInfo {
23949
+ //! Types of projected columns
23950
+ vector<LogicalType> types;
23951
+ //! The QueryNode of select query
23952
+ unique_ptr<QueryNode> query;
23953
+ //! Aliases of projected columns
23954
+ vector<string> aliases;
23955
+ //! Whether or not we are requesting a summary or a describe
23956
+ bool is_summary;
23887
23957
 
23888
- explicit CreateAggregateFunctionInfo(AggregateFunctionSet set)
23889
- : CreateFunctionInfo(CatalogType::AGGREGATE_FUNCTION_ENTRY), functions(move(set)) {
23890
- this->name = functions.name;
23891
- for (auto &func : functions.functions) {
23892
- func.name = functions.name;
23893
- }
23958
+ unique_ptr<ShowSelectInfo> Copy() {
23959
+ auto result = make_unique<ShowSelectInfo>();
23960
+ result->types = types;
23961
+ result->query = query->Copy();
23962
+ result->aliases = aliases;
23963
+ result->is_summary = is_summary;
23964
+ return result;
23894
23965
  }
23966
+ };
23895
23967
 
23896
- AggregateFunctionSet functions;
23968
+ } // namespace duckdb
23969
+ //===----------------------------------------------------------------------===//
23970
+ // DuckDB
23971
+ //
23972
+ // duckdb/parser/parsed_data/vacuum_info.hpp
23973
+ //
23974
+ //
23975
+ //===----------------------------------------------------------------------===//
23897
23976
 
23898
- public:
23899
- unique_ptr<CreateInfo> Copy() const override {
23900
- auto result = make_unique<CreateAggregateFunctionInfo>(functions);
23901
- CopyProperties(*result);
23902
- return move(result);
23903
- }
23977
+
23978
+
23979
+
23980
+
23981
+ namespace duckdb {
23982
+
23983
+ struct VacuumInfo : public ParseInfo {
23984
+ // nothing for now
23904
23985
  };
23905
23986
 
23906
23987
  } // namespace duckdb
23907
23988
  //===----------------------------------------------------------------------===//
23908
23989
  // DuckDB
23909
23990
  //
23910
- // duckdb/parser/parsed_data/show_select_info.hpp
23991
+ // duckdb/parser/parsed_data/create_index_info.hpp
23992
+ //
23993
+ //
23994
+ //===----------------------------------------------------------------------===//
23995
+
23996
+
23997
+
23998
+
23999
+
24000
+
24001
+ //===----------------------------------------------------------------------===//
24002
+ // DuckDB
24003
+ //
24004
+ // duckdb/parser/tableref/basetableref.hpp
23911
24005
  //
23912
24006
  //
23913
24007
  //===----------------------------------------------------------------------===//
@@ -23918,24 +24012,63 @@ public:
23918
24012
 
23919
24013
 
23920
24014
  namespace duckdb {
24015
+ //! Represents a TableReference to a base table in the schema
24016
+ class BaseTableRef : public TableRef {
24017
+ public:
24018
+ BaseTableRef() : TableRef(TableReferenceType::BASE_TABLE), schema_name(INVALID_SCHEMA) {
24019
+ }
23921
24020
 
23922
- struct ShowSelectInfo : public ParseInfo {
23923
- //! Types of projected columns
23924
- vector<LogicalType> types;
23925
- //! The QueryNode of select query
23926
- unique_ptr<QueryNode> query;
23927
- //! Aliases of projected columns
23928
- vector<string> aliases;
23929
- //! Whether or not we are requesting a summary or a describe
23930
- bool is_summary;
24021
+ //! Schema name
24022
+ string schema_name;
24023
+ //! Table name
24024
+ string table_name;
24025
+ //! Aliases for the column names
24026
+ vector<string> column_name_alias;
23931
24027
 
23932
- unique_ptr<ShowSelectInfo> Copy() {
23933
- auto result = make_unique<ShowSelectInfo>();
23934
- result->types = types;
23935
- result->query = query->Copy();
23936
- result->aliases = aliases;
23937
- result->is_summary = is_summary;
23938
- return result;
24028
+ public:
24029
+ string ToString() const override;
24030
+ bool Equals(const TableRef *other_p) const override;
24031
+
24032
+ unique_ptr<TableRef> Copy() override;
24033
+
24034
+ //! Serializes a blob into a BaseTableRef
24035
+ void Serialize(FieldWriter &serializer) const override;
24036
+ //! Deserializes a blob back into a BaseTableRef
24037
+ static unique_ptr<TableRef> Deserialize(FieldReader &source);
24038
+ };
24039
+ } // namespace duckdb
24040
+
24041
+
24042
+
24043
+ namespace duckdb {
24044
+
24045
+ struct CreateIndexInfo : public CreateInfo {
24046
+ CreateIndexInfo() : CreateInfo(CatalogType::INDEX_ENTRY) {
24047
+ }
24048
+
24049
+ //! Index Type (e.g., B+-tree, Skip-List, ...)
24050
+ IndexType index_type;
24051
+ //! Name of the Index
24052
+ string index_name;
24053
+ //! If it is an unique index
24054
+ bool unique = false;
24055
+ //! The table to create the index on
24056
+ unique_ptr<BaseTableRef> table;
24057
+ //! Set of expressions to index by
24058
+ vector<unique_ptr<ParsedExpression>> expressions;
24059
+
24060
+ public:
24061
+ unique_ptr<CreateInfo> Copy() const override {
24062
+ auto result = make_unique<CreateIndexInfo>();
24063
+ CopyProperties(*result);
24064
+ result->index_type = index_type;
24065
+ result->index_name = index_name;
24066
+ result->unique = unique;
24067
+ result->table = unique_ptr_cast<TableRef, BaseTableRef>(table->Copy());
24068
+ for (auto &expr : expressions) {
24069
+ result->expressions.push_back(expr->Copy());
24070
+ }
24071
+ return move(result);
23939
24072
  }
23940
24073
  };
23941
24074
 
@@ -23979,7 +24112,7 @@ struct BoundExportData : public ParseInfo {
23979
24112
  //===----------------------------------------------------------------------===//
23980
24113
  // DuckDB
23981
24114
  //
23982
- // duckdb/parser/parsed_data/drop_info.hpp
24115
+ // duckdb/parser/parsed_data/create_schema_info.hpp
23983
24116
  //
23984
24117
  //
23985
24118
  //===----------------------------------------------------------------------===//
@@ -23988,34 +24121,17 @@ struct BoundExportData : public ParseInfo {
23988
24121
 
23989
24122
 
23990
24123
 
23991
-
23992
24124
  namespace duckdb {
23993
24125
 
23994
- struct DropInfo : public ParseInfo {
23995
- DropInfo() : schema(INVALID_SCHEMA), if_exists(false), cascade(false) {
24126
+ struct CreateSchemaInfo : public CreateInfo {
24127
+ CreateSchemaInfo() : CreateInfo(CatalogType::SCHEMA_ENTRY) {
23996
24128
  }
23997
24129
 
23998
- //! The catalog type to drop
23999
- CatalogType type;
24000
- //! Schema name to drop from, if any
24001
- string schema;
24002
- //! Element name to drop
24003
- string name;
24004
- //! Ignore if the entry does not exist instead of failing
24005
- bool if_exists = false;
24006
- //! Cascade drop (drop all dependents instead of throwing an error if there
24007
- //! are any)
24008
- bool cascade = false;
24009
-
24010
24130
  public:
24011
- unique_ptr<DropInfo> Copy() const {
24012
- auto result = make_unique<DropInfo>();
24013
- result->type = type;
24014
- result->schema = schema;
24015
- result->name = name;
24016
- result->if_exists = if_exists;
24017
- result->cascade = cascade;
24018
- return result;
24131
+ unique_ptr<CreateInfo> Copy() const override {
24132
+ auto result = make_unique<CreateSchemaInfo>();
24133
+ CopyProperties(*result);
24134
+ return move(result);
24019
24135
  }
24020
24136
  };
24021
24137
 
@@ -24023,20 +24139,7 @@ public:
24023
24139
  //===----------------------------------------------------------------------===//
24024
24140
  // DuckDB
24025
24141
  //
24026
- // duckdb/parser/parsed_data/create_index_info.hpp
24027
- //
24028
- //
24029
- //===----------------------------------------------------------------------===//
24030
-
24031
-
24032
-
24033
-
24034
-
24035
-
24036
- //===----------------------------------------------------------------------===//
24037
- // DuckDB
24038
- //
24039
- // duckdb/parser/tableref/basetableref.hpp
24142
+ // duckdb/parser/parsed_data/create_aggregate_function_info.hpp
24040
24143
  //
24041
24144
  //
24042
24145
  //===----------------------------------------------------------------------===//
@@ -24047,62 +24150,28 @@ public:
24047
24150
 
24048
24151
 
24049
24152
  namespace duckdb {
24050
- //! Represents a TableReference to a base table in the schema
24051
- class BaseTableRef : public TableRef {
24052
- public:
24053
- BaseTableRef() : TableRef(TableReferenceType::BASE_TABLE), schema_name(INVALID_SCHEMA) {
24054
- }
24055
-
24056
- //! Schema name
24057
- string schema_name;
24058
- //! Table name
24059
- string table_name;
24060
- //! Aliases for the column names
24061
- vector<string> column_name_alias;
24062
-
24063
- public:
24064
- string ToString() const override;
24065
- bool Equals(const TableRef *other_p) const override;
24066
24153
 
24067
- unique_ptr<TableRef> Copy() override;
24068
-
24069
- //! Serializes a blob into a BaseTableRef
24070
- void Serialize(FieldWriter &serializer) const override;
24071
- //! Deserializes a blob back into a BaseTableRef
24072
- static unique_ptr<TableRef> Deserialize(FieldReader &source);
24073
- };
24074
- } // namespace duckdb
24075
-
24076
-
24077
-
24078
- namespace duckdb {
24154
+ struct CreateAggregateFunctionInfo : public CreateFunctionInfo {
24155
+ explicit CreateAggregateFunctionInfo(AggregateFunction function)
24156
+ : CreateFunctionInfo(CatalogType::AGGREGATE_FUNCTION_ENTRY), functions(function.name) {
24157
+ this->name = function.name;
24158
+ functions.AddFunction(move(function));
24159
+ }
24079
24160
 
24080
- struct CreateIndexInfo : public CreateInfo {
24081
- CreateIndexInfo() : CreateInfo(CatalogType::INDEX_ENTRY) {
24161
+ explicit CreateAggregateFunctionInfo(AggregateFunctionSet set)
24162
+ : CreateFunctionInfo(CatalogType::AGGREGATE_FUNCTION_ENTRY), functions(move(set)) {
24163
+ this->name = functions.name;
24164
+ for (auto &func : functions.functions) {
24165
+ func.name = functions.name;
24166
+ }
24082
24167
  }
24083
24168
 
24084
- //! Index Type (e.g., B+-tree, Skip-List, ...)
24085
- IndexType index_type;
24086
- //! Name of the Index
24087
- string index_name;
24088
- //! If it is an unique index
24089
- bool unique = false;
24090
- //! The table to create the index on
24091
- unique_ptr<BaseTableRef> table;
24092
- //! Set of expressions to index by
24093
- vector<unique_ptr<ParsedExpression>> expressions;
24169
+ AggregateFunctionSet functions;
24094
24170
 
24095
24171
  public:
24096
24172
  unique_ptr<CreateInfo> Copy() const override {
24097
- auto result = make_unique<CreateIndexInfo>();
24173
+ auto result = make_unique<CreateAggregateFunctionInfo>(functions);
24098
24174
  CopyProperties(*result);
24099
- result->index_type = index_type;
24100
- result->index_name = index_name;
24101
- result->unique = unique;
24102
- result->table = unique_ptr_cast<TableRef, BaseTableRef>(table->Copy());
24103
- for (auto &expr : expressions) {
24104
- result->expressions.push_back(expr->Copy());
24105
- }
24106
24175
  return move(result);
24107
24176
  }
24108
24177
  };
@@ -24111,7 +24180,7 @@ public:
24111
24180
  //===----------------------------------------------------------------------===//
24112
24181
  // DuckDB
24113
24182
  //
24114
- // duckdb/parser/parsed_data/vacuum_info.hpp
24183
+ // duckdb/parser/parsed_data/create_type_info.hpp
24115
24184
  //
24116
24185
  //
24117
24186
  //===----------------------------------------------------------------------===//
@@ -24120,10 +24189,29 @@ public:
24120
24189
 
24121
24190
 
24122
24191
 
24192
+
24193
+
24194
+
24123
24195
  namespace duckdb {
24124
24196
 
24125
- struct VacuumInfo : public ParseInfo {
24126
- // nothing for now
24197
+ struct CreateTypeInfo : public CreateInfo {
24198
+
24199
+ CreateTypeInfo() : CreateInfo(CatalogType::TYPE_ENTRY) {
24200
+ }
24201
+
24202
+ //! Name of the Type
24203
+ string name;
24204
+ //! Logical Type
24205
+ LogicalType type;
24206
+
24207
+ public:
24208
+ unique_ptr<CreateInfo> Copy() const override {
24209
+ auto result = make_unique<CreateTypeInfo>();
24210
+ CopyProperties(*result);
24211
+ result->name = name;
24212
+ result->type = type;
24213
+ return move(result);
24214
+ }
24127
24215
  };
24128
24216
 
24129
24217
  } // namespace duckdb
@@ -24172,37 +24260,7 @@ public:
24172
24260
  //===----------------------------------------------------------------------===//
24173
24261
  // DuckDB
24174
24262
  //
24175
- // duckdb/parser/parsed_data/vacuum_info.hpp
24176
- //
24177
- //
24178
- //===----------------------------------------------------------------------===//
24179
-
24180
-
24181
-
24182
-
24183
-
24184
- namespace duckdb {
24185
-
24186
- enum class LoadType { LOAD, INSTALL, FORCE_INSTALL };
24187
-
24188
- struct LoadInfo : public ParseInfo {
24189
- std::string filename;
24190
- LoadType load_type;
24191
-
24192
- public:
24193
- unique_ptr<LoadInfo> Copy() const {
24194
- auto result = make_unique<LoadInfo>();
24195
- result->filename = filename;
24196
- result->load_type = load_type;
24197
- return result;
24198
- }
24199
- };
24200
-
24201
- } // namespace duckdb
24202
- //===----------------------------------------------------------------------===//
24203
- // DuckDB
24204
- //
24205
- // duckdb/parser/parsed_data/create_type_info.hpp
24263
+ // duckdb/parser/parsed_data/create_view_info.hpp
24206
24264
  //
24207
24265
  //
24208
24266
  //===----------------------------------------------------------------------===//
@@ -24212,26 +24270,31 @@ public:
24212
24270
 
24213
24271
 
24214
24272
 
24215
-
24216
-
24217
24273
  namespace duckdb {
24218
24274
 
24219
- struct CreateTypeInfo : public CreateInfo {
24220
-
24221
- CreateTypeInfo() : CreateInfo(CatalogType::TYPE_ENTRY) {
24275
+ struct CreateViewInfo : public CreateInfo {
24276
+ CreateViewInfo() : CreateInfo(CatalogType::VIEW_ENTRY, INVALID_SCHEMA) {
24277
+ }
24278
+ CreateViewInfo(string schema, string view_name)
24279
+ : CreateInfo(CatalogType::VIEW_ENTRY, schema), view_name(view_name) {
24222
24280
  }
24223
24281
 
24224
- //! Name of the Type
24225
- string name;
24226
- //! Logical Type
24227
- LogicalType type;
24282
+ //! Table name to insert to
24283
+ string view_name;
24284
+ //! Aliases of the view
24285
+ vector<string> aliases;
24286
+ //! Return types
24287
+ vector<LogicalType> types;
24288
+ //! The SelectStatement of the view
24289
+ unique_ptr<SelectStatement> query;
24228
24290
 
24229
24291
  public:
24230
24292
  unique_ptr<CreateInfo> Copy() const override {
24231
- auto result = make_unique<CreateTypeInfo>();
24293
+ auto result = make_unique<CreateViewInfo>(schema, view_name);
24232
24294
  CopyProperties(*result);
24233
- result->name = name;
24234
- result->type = type;
24295
+ result->aliases = aliases;
24296
+ result->types = types;
24297
+ result->query = unique_ptr_cast<SQLStatement, SelectStatement>(query->Copy());
24235
24298
  return move(result);
24236
24299
  }
24237
24300
  };
@@ -24240,7 +24303,7 @@ public:
24240
24303
  //===----------------------------------------------------------------------===//
24241
24304
  // DuckDB
24242
24305
  //
24243
- // duckdb/parser/tableref/subqueryref.hpp
24306
+ // duckdb/parser/tableref/emptytableref.hpp
24244
24307
  //
24245
24308
  //
24246
24309
  //===----------------------------------------------------------------------===//
@@ -24249,17 +24312,12 @@ public:
24249
24312
 
24250
24313
 
24251
24314
 
24252
-
24253
24315
  namespace duckdb {
24254
- //! Represents a subquery
24255
- class SubqueryRef : public TableRef {
24316
+ //! Represents a cross product
24317
+ class EmptyTableRef : public TableRef {
24256
24318
  public:
24257
- explicit SubqueryRef(unique_ptr<SelectStatement> subquery, string alias = string());
24258
-
24259
- //! The subquery
24260
- unique_ptr<SelectStatement> subquery;
24261
- //! Aliases for the column names
24262
- vector<string> column_name_alias;
24319
+ EmptyTableRef() : TableRef(TableReferenceType::EMPTY) {
24320
+ }
24263
24321
 
24264
24322
  public:
24265
24323
  string ToString() const override;
@@ -24267,16 +24325,16 @@ public:
24267
24325
 
24268
24326
  unique_ptr<TableRef> Copy() override;
24269
24327
 
24270
- //! Serializes a blob into a SubqueryRef
24328
+ //! Serializes a blob into a DummyTableRef
24271
24329
  void Serialize(FieldWriter &serializer) const override;
24272
- //! Deserializes a blob back into a SubqueryRef
24330
+ //! Deserializes a blob back into a DummyTableRef
24273
24331
  static unique_ptr<TableRef> Deserialize(FieldReader &source);
24274
24332
  };
24275
24333
  } // namespace duckdb
24276
24334
  //===----------------------------------------------------------------------===//
24277
24335
  // DuckDB
24278
24336
  //
24279
- // duckdb/parser/tableref/expressionlistref.hpp
24337
+ // duckdb/parser/tableref/joinref.hpp
24280
24338
  //
24281
24339
  //
24282
24340
  //===----------------------------------------------------------------------===//
@@ -24288,19 +24346,26 @@ public:
24288
24346
 
24289
24347
 
24290
24348
 
24349
+
24291
24350
  namespace duckdb {
24292
- //! Represents an expression list as generated by a VALUES statement
24293
- class ExpressionListRef : public TableRef {
24351
+ //! Represents a JOIN between two expressions
24352
+ class JoinRef : public TableRef {
24294
24353
  public:
24295
- ExpressionListRef() : TableRef(TableReferenceType::EXPRESSION_LIST) {
24354
+ JoinRef() : TableRef(TableReferenceType::JOIN), is_natural(false) {
24296
24355
  }
24297
24356
 
24298
- //! Value list, only used for VALUES statement
24299
- vector<vector<unique_ptr<ParsedExpression>>> values;
24300
- //! Expected SQL types
24301
- vector<LogicalType> expected_types;
24302
- //! The set of expected names
24303
- vector<string> expected_names;
24357
+ //! The left hand side of the join
24358
+ unique_ptr<TableRef> left;
24359
+ //! The right hand side of the join
24360
+ unique_ptr<TableRef> right;
24361
+ //! The join condition
24362
+ unique_ptr<ParsedExpression> condition;
24363
+ //! The join type
24364
+ JoinType type;
24365
+ //! Natural join
24366
+ bool is_natural;
24367
+ //! The set of USING columns (if any)
24368
+ vector<string> using_columns;
24304
24369
 
24305
24370
  public:
24306
24371
  string ToString() const override;
@@ -24308,13 +24373,12 @@ public:
24308
24373
 
24309
24374
  unique_ptr<TableRef> Copy() override;
24310
24375
 
24311
- //! Serializes a blob into a ExpressionListRef
24376
+ //! Serializes a blob into a JoinRef
24312
24377
  void Serialize(FieldWriter &serializer) const override;
24313
- //! Deserializes a blob back into a ExpressionListRef
24378
+ //! Deserializes a blob back into a JoinRef
24314
24379
  static unique_ptr<TableRef> Deserialize(FieldReader &source);
24315
24380
  };
24316
24381
  } // namespace duckdb
24317
-
24318
24382
  //===----------------------------------------------------------------------===//
24319
24383
  // DuckDB
24320
24384
  //
@@ -24352,10 +24416,12 @@ public:
24352
24416
  };
24353
24417
  } // namespace duckdb
24354
24418
 
24419
+
24420
+
24355
24421
  //===----------------------------------------------------------------------===//
24356
24422
  // DuckDB
24357
24423
  //
24358
- // duckdb/parser/tableref/emptytableref.hpp
24424
+ // duckdb/parser/tableref/expressionlistref.hpp
24359
24425
  //
24360
24426
  //
24361
24427
  //===----------------------------------------------------------------------===//
@@ -24364,22 +24430,32 @@ public:
24364
24430
 
24365
24431
 
24366
24432
 
24433
+
24434
+
24435
+
24367
24436
  namespace duckdb {
24368
- //! Represents a cross product
24369
- class EmptyTableRef : public TableRef {
24437
+ //! Represents an expression list as generated by a VALUES statement
24438
+ class ExpressionListRef : public TableRef {
24370
24439
  public:
24371
- EmptyTableRef() : TableRef(TableReferenceType::EMPTY) {
24440
+ ExpressionListRef() : TableRef(TableReferenceType::EXPRESSION_LIST) {
24372
24441
  }
24373
24442
 
24443
+ //! Value list, only used for VALUES statement
24444
+ vector<vector<unique_ptr<ParsedExpression>>> values;
24445
+ //! Expected SQL types
24446
+ vector<LogicalType> expected_types;
24447
+ //! The set of expected names
24448
+ vector<string> expected_names;
24449
+
24374
24450
  public:
24375
24451
  string ToString() const override;
24376
24452
  bool Equals(const TableRef *other_p) const override;
24377
24453
 
24378
24454
  unique_ptr<TableRef> Copy() override;
24379
24455
 
24380
- //! Serializes a blob into a DummyTableRef
24456
+ //! Serializes a blob into a ExpressionListRef
24381
24457
  void Serialize(FieldWriter &serializer) const override;
24382
- //! Deserializes a blob back into a DummyTableRef
24458
+ //! Deserializes a blob back into a ExpressionListRef
24383
24459
  static unique_ptr<TableRef> Deserialize(FieldReader &source);
24384
24460
  };
24385
24461
  } // namespace duckdb
@@ -24388,7 +24464,7 @@ public:
24388
24464
  //===----------------------------------------------------------------------===//
24389
24465
  // DuckDB
24390
24466
  //
24391
- // duckdb/parser/tableref/joinref.hpp
24467
+ // duckdb/parser/tableref/subqueryref.hpp
24392
24468
  //
24393
24469
  //
24394
24470
  //===----------------------------------------------------------------------===//
@@ -24398,28 +24474,16 @@ public:
24398
24474
 
24399
24475
 
24400
24476
 
24401
-
24402
-
24403
-
24404
24477
  namespace duckdb {
24405
- //! Represents a JOIN between two expressions
24406
- class JoinRef : public TableRef {
24478
+ //! Represents a subquery
24479
+ class SubqueryRef : public TableRef {
24407
24480
  public:
24408
- JoinRef() : TableRef(TableReferenceType::JOIN), is_natural(false) {
24409
- }
24481
+ explicit SubqueryRef(unique_ptr<SelectStatement> subquery, string alias = string());
24410
24482
 
24411
- //! The left hand side of the join
24412
- unique_ptr<TableRef> left;
24413
- //! The right hand side of the join
24414
- unique_ptr<TableRef> right;
24415
- //! The join condition
24416
- unique_ptr<ParsedExpression> condition;
24417
- //! The join type
24418
- JoinType type;
24419
- //! Natural join
24420
- bool is_natural;
24421
- //! The set of USING columns (if any)
24422
- vector<string> using_columns;
24483
+ //! The subquery
24484
+ unique_ptr<SelectStatement> subquery;
24485
+ //! Aliases for the column names
24486
+ vector<string> column_name_alias;
24423
24487
 
24424
24488
  public:
24425
24489
  string ToString() const override;
@@ -24427,14 +24491,13 @@ public:
24427
24491
 
24428
24492
  unique_ptr<TableRef> Copy() override;
24429
24493
 
24430
- //! Serializes a blob into a JoinRef
24494
+ //! Serializes a blob into a SubqueryRef
24431
24495
  void Serialize(FieldWriter &serializer) const override;
24432
- //! Deserializes a blob back into a JoinRef
24496
+ //! Deserializes a blob back into a SubqueryRef
24433
24497
  static unique_ptr<TableRef> Deserialize(FieldReader &source);
24434
24498
  };
24435
24499
  } // namespace duckdb
24436
24500
 
24437
-
24438
24501
  //===----------------------------------------------------------------------===//
24439
24502
  // DuckDB
24440
24503
  //