Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
ParquetFormatter.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2012-2026 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
18// Output formatter for Parquet output
19/****************************************************************************/
20#pragma once
21#include <config.h>
22
23#include <memory>
24#include <ostream>
26#include "OutputFormatter.h"
27
28
29// ===========================================================================
30// class definitions
31// ===========================================================================
40public:
42 // for some motivation on the default batch size see https://stackoverflow.com/questions/76782018/what-is-actually-meant-when-referring-to-parquet-row-group-size
43 ParquetFormatter(const std::string& columnNames, const std::string& compression = "", const int batchSize = 1000000);
44
47
57 bool writeXMLHeader(std::ostream& into, const std::string& rootElement,
58 const std::map<SumoXMLAttr, std::string>& attrs, bool /* writeMetadata */,
59 bool /* includeConfig */) override;
60
66 void openTag(std::ostream& into, const std::string& xmlElement) override;
67
73 void openTag(std::ostream& into, const SumoXMLTag& xmlElement) override;
74
83 bool closeTag(std::ostream& into, const std::string& comment = "") override;
84
92 template <class T>
93 void writeAttr(std::ostream& /* into */, const SumoXMLAttr attr, const T& val, const bool isNull, const bool /* escape */) {
94 if (isNull) {
95 writeNullAttr(attr);
96 } else {
97 writeStringAttr(attr, toString(val));
98 }
99 }
100
108 template <class T>
109 void writeAttr(std::ostream& /* into */, const std::string& attr, const T& val, const bool isNull, const bool /* escape */) {
110 if (isNull) {
111 writeNullAttr(attr);
112 } else {
113 writeStringAttr(attr, toString(val));
114 }
115 }
116
118 void writeAttr(std::ostream& into, const SumoXMLAttr attr, const double& val, const bool isNull, const bool escape);
119 void writeAttr(std::ostream& into, const SumoXMLAttr attr, const int& val, const bool isNull, const bool escape);
120 void writeAttr(std::ostream& into, const std::string& attr, const double& val, const bool isNull, const bool escape);
121 void writeAttr(std::ostream& into, const std::string& attr, const int& val, const bool isNull, const bool escape);
122
132 void writeTime(std::ostream& into, const SumoXMLAttr attr, const SUMOTime val) override;
133
138 bool wroteHeader() const override;
139
154 void setExpectedAttributes(const SumoXMLAttrMask& expected, const int depth) override;
155
156private:
158 void writeStringAttr(const SumoXMLAttr attr, const std::string& val);
159 void writeStringAttr(const std::string& attr, const std::string& val);
160 void writeNullAttr(const SumoXMLAttr attr);
161 void writeNullAttr(const std::string& attr);
162
164 struct Impl;
165 std::unique_ptr<Impl> myImpl;
166};
long long int SUMOTime
Definition GUI.h:36
SumoXMLTag
Numbers representing SUMO-XML - element names.
std::bitset< 96 > SumoXMLAttrMask
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:49
Abstract base class for output formatters.
Output formatter for Parquet output.
void writeNullAttr(const SumoXMLAttr attr)
void setExpectedAttributes(const SumoXMLAttrMask &expected, const int depth) override
Which elements are expected and which maximum depth the XML tree has.
void openTag(std::ostream &into, const std::string &xmlElement) override
Keeps track of an open XML tag by adding a new element to the stack.
~ParquetFormatter() override
Destructor (out-of-line: Impl is incomplete here)
bool writeXMLHeader(std::ostream &into, const std::string &rootElement, const std::map< SumoXMLAttr, std::string > &attrs, bool, bool) override
Writes an "XML header".
void writeAttr(std::ostream &, const std::string &attr, const T &val, const bool isNull, const bool)
Writes a named attribute.
bool wroteHeader() const override
Whether a complete row has been encountered and triggered writing.
std::unique_ptr< Impl > myImpl
void writeStringAttr(const SumoXMLAttr attr, const std::string &val)
non-template helpers; defined in the .cpp where arrow/parquet are available
bool closeTag(std::ostream &into, const std::string &comment="") override
Closes the most recently opened tag.
void writeAttr(std::ostream &, const SumoXMLAttr attr, const T &val, const bool isNull, const bool)
Writes a named attribute.
void writeTime(std::ostream &into, const SumoXMLAttr attr, const SUMOTime val) override
Writes a time value.