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
48 void openTag(std::ostream& into, const std::string& xmlElement) override;
49 void openTag(std::ostream& into, const SumoXMLTag& xmlElement) override;
50 bool closeTag(std::ostream& into, const std::string& comment = "") override;
51
58 template <class T>
59 void writeAttr(std::ostream& /* into */, const SumoXMLAttr attr, const T& val, const bool isNull) {
60 if (isNull) {
61 writeNullAttr(attr);
62 } else {
63 writeStringAttr(attr, toString(val));
64 }
65 }
66
67 template <class T>
68 void writeAttr(std::ostream& /* into */, const std::string& attr, const T& val, const bool isNull) {
69 if (isNull) {
70 writeNullAttr(attr);
71 } else {
72 writeStringAttr(attr, toString(val));
73 }
74 }
75
77 void writeAttr(std::ostream& into, const SumoXMLAttr attr, const double& val, const bool isNull);
78 void writeAttr(std::ostream& into, const SumoXMLAttr attr, const int& val, const bool isNull);
79 void writeAttr(std::ostream& into, const std::string& attr, const double& val, const bool isNull);
80 void writeAttr(std::ostream& into, const std::string& attr, const int& val, const bool isNull);
81
82 void writeTime(std::ostream& into, const SumoXMLAttr attr, const SUMOTime val) override;
83
84 bool wroteHeader() const override;
85
86 void setExpectedAttributes(const SumoXMLAttrMask& expected, const int depth = 2) override;
87
88private:
90 void writeStringAttr(const SumoXMLAttr attr, const std::string& val);
91 void writeStringAttr(const std::string& attr, const std::string& val);
92 void writeNullAttr(const SumoXMLAttr attr);
93 void writeNullAttr(const std::string& attr);
94
96 struct Impl;
97 std::unique_ptr<Impl> myImpl;
98};
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 openTag(std::ostream &into, const std::string &xmlElement) override
Opens an XML tag.
void setExpectedAttributes(const SumoXMLAttrMask &expected, const int depth=2) override
Set the expected attributes to write. This is used for tracking which attributes are expected in tabl...
~ParquetFormatter() override
Destructor (out-of-line: Impl is incomplete here)
bool wroteHeader() const override
Returns whether a header has been written. Useful to detect whether a file is being used by multiple ...
void writeAttr(std::ostream &, const SumoXMLAttr attr, const T &val, const bool isNull)
writes a named attribute
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 and optinally add a comment.
void writeAttr(std::ostream &, const std::string &attr, const T &val, const bool isNull)
void writeTime(std::ostream &into, const SumoXMLAttr attr, const SUMOTime val) override