//===----------------------------------------------------------------------===// // DuckDB // // duckdb/parser/tableref/pivotref.hpp // // //===----------------------------------------------------------------------===// #pragma once #include "duckdb/parser/tableref.hpp" #include "duckdb/parser/query_node/select_node.hpp" namespace duckdb { struct PivotColumnEntry { //! The set of values to match on vector values; //! The star expression (UNPIVOT only) unique_ptr star_expr; //! The alias of the pivot column entry string alias; bool Equals(const PivotColumnEntry &other) const; void Serialize(Serializer &serializer) const; PivotColumnEntry Copy() const; static PivotColumnEntry Deserialize(Deserializer &source); void FormatSerialize(FormatSerializer &serializer) const; static PivotColumnEntry FormatDeserialize(FormatDeserializer &source); }; struct PivotValueElement { vector values; string name; }; struct PivotColumn { //! The set of expressions to pivot on vector> pivot_expressions; //! The set of unpivot names vector unpivot_names; //! The set of values to pivot on vector entries; //! The enum to read pivot values from (if any) string pivot_enum; //! Subquery (if any) - used during transform only unique_ptr subquery; string ToString() const; bool Equals(const PivotColumn &other) const; void Serialize(Serializer &serializer) const; PivotColumn Copy() const; static PivotColumn Deserialize(Deserializer &source); void FormatSerialize(FormatSerializer &serializer) const; static PivotColumn FormatDeserialize(FormatDeserializer &source); }; //! Represents a PIVOT or UNPIVOT expression class PivotRef : public TableRef { public: static constexpr const TableReferenceType TYPE = TableReferenceType::PIVOT; public: explicit PivotRef() : TableRef(TableReferenceType::PIVOT), include_nulls(false) { } //! The source table of the pivot unique_ptr source; //! The aggregates to compute over the pivot (PIVOT only) vector> aggregates; //! The names of the unpivot expressions (UNPIVOT only) vector unpivot_names; //! The set of pivots vector pivots; //! The groups to pivot over. If none are specified all columns not included in the pivots/aggregate are chosen. vector groups; //! Aliases for the column names vector column_name_alias; //! Whether or not to include nulls in the result (UNPIVOT only) bool include_nulls; //! The set of values to pivot on (bound pivot only) vector bound_pivot_values; //! The set of bound group names (bound pivot only) vector bound_group_names; //! The set of bound aggregate names (bound pivot only) vector bound_aggregate_names; public: string ToString() const override; bool Equals(const TableRef &other_p) const override; unique_ptr Copy() override; //! Serializes a blob into a PivotRef void Serialize(FieldWriter &serializer) const override; //! Deserializes a blob back into a PivotRef static unique_ptr Deserialize(FieldReader &source); void FormatSerialize(FormatSerializer &serializer) const override; static unique_ptr FormatDeserialize(FormatDeserializer &source); }; } // namespace duckdb