Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::PivotColumn Struct Reference
Collaboration diagram for duckdb::PivotColumn:

Public Member Functions

string ToString () const
bool Equals (const PivotColumn &other) const
PivotColumn Copy () const
void Serialize (Serializer &serializer) const
vector< PivotColumnEntry > GetEntriesForSerialization (Serializer &serializer) const

Static Public Member Functions

static PivotColumn Deserialize (Deserializer &source)

Public Attributes

vector< unique_ptr< ParsedExpression > > pivot_expressions
 The set of expressions to pivot on.
vector< string > unpivot_names
 The set of unpivot names.
vector< PivotColumnEntry > entries
 The set of values to pivot on.
string pivot_enum
 The enum to read pivot values from (if any).
unique_ptr< QueryNode > subquery
 Subquery (if any) - used during transform only.

Member Function Documentation

◆ ToString()

string duckdb::PivotColumn::ToString ( ) const
350612 {
350613 string result;
350614 if (!unpivot_names.empty()) {
350615 D_ASSERT(pivot_expressions.empty());
350616 // unpivot
350617 if (unpivot_names.size() == 1) {
350619 } else {
350620 result += "(";
350621 for (idx_t n = 0; n < unpivot_names.size(); n++) {
350622 if (n > 0) {
350623 result += ", ";
350624 }
350626 }
350627 result += ")";
350628 }
350629 } else if (!pivot_expressions.empty()) {
350630 // pivot
350631 result += "(";
350632 for (idx_t n = 0; n < pivot_expressions.size(); n++) {
350633 if (n > 0) {
350634 result += ", ";
350635 }
350636 result += pivot_expressions[n]->ToString();
350637 }
350638 result += ")";
350639 }
350640 result += " IN ";
350641 if (pivot_enum.empty()) {
350642 result += "(";
350643 for (idx_t e = 0; e < entries.size(); e++) {
350644 auto &entry = entries[e];
350645 if (e > 0) {
350646 result += ", ";
350647 }
350648 if (entry.expr) {
350649 D_ASSERT(entry.values.empty());
350650 result += entry.expr->ToString();
350651 } else if (entry.values.size() == 1) {
350652 result += entry.values[0].ToSQLString();
350653 } else {
350654 result += "(";
350655 for (idx_t v = 0; v < entry.values.size(); v++) {
350656 if (v > 0) {
350657 result += ", ";
350658 }
350659 result += entry.values[v].ToSQLString();
350660 }
350661 result += ")";
350662 }
350663 if (!entry.alias.empty()) {
350664 result += " AS " + KeywordHelper::WriteOptionallyQuoted(entry.alias);
350665 }
350666 }
350667 result += ")";
350668 } else {
350670 }
350671 return result;
350672}
static string WriteOptionallyQuoted(const string &text, char quote='"', bool allow_caps = true, KeywordCategory category = KeywordCategory::KEYWORD_NONE)
Writes a string that is optionally quoted + escaped so it can be used as an identifier.
Definition duckdb.cpp:338034
uint32_t v
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
vector< unique_ptr< ParsedExpression > > pivot_expressions
The set of expressions to pivot on.
Definition duckdb.cpp:197314
vector< PivotColumnEntry > entries
The set of values to pivot on.
Definition duckdb.cpp:197318
string pivot_enum
The enum to read pivot values from (if any).
Definition duckdb.cpp:197320
vector< string > unpivot_names
The set of unpivot names.
Definition duckdb.cpp:197316

◆ Equals()

bool duckdb::PivotColumn::Equals ( const PivotColumn & other) const
350689 {
350690 if (!ExpressionUtil::ListEquals(pivot_expressions, other.pivot_expressions)) {
350691 return false;
350692 }
350693 if (other.unpivot_names != unpivot_names) {
350694 return false;
350695 }
350696 if (other.pivot_enum != pivot_enum) {
350697 return false;
350698 }
350699 if (other.entries.size() != entries.size()) {
350700 return false;
350701 }
350702 for (idx_t i = 0; i < entries.size(); i++) {
350703 if (!entries[i].Equals(other.entries[i])) {
350704 return false;
350705 }
350706 }
350707 return true;
350708}
static bool ListEquals(const vector< unique_ptr< ParsedExpression > > &a, const vector< unique_ptr< ParsedExpression > > &b)
ListEquals: check if a list of two expressions is equal (order is important).
Definition duckdb.cpp:337970

◆ Copy()

PivotColumn duckdb::PivotColumn::Copy ( ) const
350710 {
350711 PivotColumn result;
350712 for (auto &expr : pivot_expressions) {
350713 result.pivot_expressions.push_back(expr->Copy());
350714 }
350715 result.unpivot_names = unpivot_names;
350716 for (auto &entry : entries) {
350717 result.entries.push_back(entry.Copy());
350718 }
350719 result.pivot_enum = pivot_enum;
350720 return result;
350721}

◆ Serialize()

void duckdb::PivotColumn::Serialize ( Serializer & serializer) const
417580 {
417581 serializer.WritePropertyWithDefault<vector<unique_ptr<ParsedExpression>>>(100, "pivot_expressions", pivot_expressions);
417582 serializer.WritePropertyWithDefault<vector<string>>(101, "unpivot_names", unpivot_names);
417583 serializer.WritePropertyWithDefault<vector<PivotColumnEntry>>(102, "entries", GetEntriesForSerialization(serializer));
417584 serializer.WritePropertyWithDefault<string>(103, "pivot_enum", pivot_enum);
417585}

◆ Deserialize()

PivotColumn duckdb::PivotColumn::Deserialize ( Deserializer & source)
static
417587 {
417588 PivotColumn result;
417589 deserializer.ReadPropertyWithDefault<vector<unique_ptr<ParsedExpression>>>(100, "pivot_expressions", result.pivot_expressions);
417590 deserializer.ReadPropertyWithDefault<vector<string>>(101, "unpivot_names", result.unpivot_names);
417591 deserializer.ReadPropertyWithDefault<vector<PivotColumnEntry>>(102, "entries", result.entries);
417592 deserializer.ReadPropertyWithDefault<string>(103, "pivot_enum", result.pivot_enum);
417593 return result;
417594}

◆ GetEntriesForSerialization()

vector< PivotColumnEntry > duckdb::PivotColumn::GetEntriesForSerialization ( Serializer & serializer) const
350867 {
350868 vector<PivotColumnEntry> result;
350869
350870 if (serializer.ShouldSerialize(7)) {
350871 // Latest version, serialize as is.
350872 // Unfortunately, we have to make a deep copy to return vector by value.
350873 for (auto &entry : entries) {
350874 result.push_back(entry.Copy());
350875 }
350876 return result;
350877 }
350878
350879 // For PIVOT, We need to potentially transform entries to deal with older serialization versions.
350880 const auto is_unpivot = !unpivot_names.empty();
350881
350882 for (auto &entry : entries) {
350883 auto result_entry = entry.Copy();
350884 if (!entry.expr) {
350885 // No expression, just values, so we can serialize as-is
350886 result.push_back(std::move(result_entry));
350887 continue;
350888 }
350889
350890 // Try to constant-fold the expression back into values
350891 vector<Value> folded_values;
350892 if (TryFoldForBackwardsCompatibility(result_entry.expr, folded_values)) {
350893 // Set the folded values and clear the expression for serialization
350894 result_entry.values = std::move(folded_values);
350895 result_entry.expr.reset();
350896 result.push_back(std::move(result_entry));
350897 continue;
350898 }
350899
350900 // UNPIVOT always supported expressions, so if we didn't fold, that's fine, we can serialize the expr as-is
350901 if (is_unpivot) {
350902 result.push_back(std::move(result_entry));
350903 continue;
350904 }
350905
350906 // Otherwise this is a PIVOT with an expression we could not fold.
350907 // Older versions of DuckDB do not support this, so throw an exception.
350908 const auto target_version = serializer.GetOptions().serialization_compatibility.duckdb_version;
350909
350910 throw SerializationException(
350911 "Cannot serialize non-constant expression '%s' in pivot list when targeting database storage version '%s'",
350912 entry.expr->ToString(), target_version);
350913 }
350914
350915 return result;
350916}

The documentation for this struct was generated from the following file: