# HG changeset patch # User František Kučera # Date 1661630212 -7200 # Node ID af4cb72127c1d0876ba783d66241111d9deda846 # Parent 56aeec532d4f675cc6765c201510fb0498f94dba do UNION ALL if multiple relations have same number of attributes of same types diff -r 56aeec532d4f -r af4cb72127c1 src/CSVHandler.h --- a/src/CSVHandler.h Sat Dec 04 21:14:51 2021 +0100 +++ b/src/CSVHandler.h Sat Aug 27 21:56:52 2022 +0200 @@ -48,6 +48,17 @@ std::wstring_convert> convertor; // TODO: local system encoding or generate CSV always in UTF-8 like XML? std::vector firstAttributes; integer_t valueCount = 0; + + /** + * @param a + * @param b + * @return true if relations have same number and types of attributes (names may differ) + */ + bool matches(const std::vector& a, const std::vector& b) { + if (a.size() != b.size()) return false; + for (int i = 0, limit = a.size(); i < limit; i++) if (a[i].getTypeId() != b[i].getTypeId()) return false; + return true; + } public: CSVHandler(std::ostream& output, Configuration& configuration) : output(output), configuration(configuration) { @@ -57,9 +68,10 @@ if (firstAttributes.empty()) { firstAttributes = attributes; if (configuration.writeHeader) for (auto attr : attributes) attribute(configuration.writeTypes ? attr.getAttributeName() + L"::" + attr.getTypeName() : attr.getAttributeName()); + } else if (matches(firstAttributes, attributes)) { + // do UNION ALL – just append the records } else { - // TODO: UNION ALL if data types and attribute count matches - throw RelpipeCSVWriterException(L"Only a single relation can be converted to the CSV format."); + throw RelpipeCSVWriterException(L"To the CSV format we can convert only one relation or multiple relations that have same number of attributes of same types (relation and attribute names may differ – result is named after the first one)."); } }