--- a/src/MetadataMode.h Sun May 23 13:59:09 2021 +0200
+++ b/src/MetadataMode.h Sun May 23 15:46:54 2021 +0200
@@ -18,8 +18,10 @@
#include <regex>
#include <locale>
+#include <stdexcept>
#include <relpipe/common/type/typedefs.h>
+#include <relpipe/writer/RelpipeWriterException.h>
#include "Mode.h"
@@ -41,7 +43,16 @@
}
void startRelation(relpipe::common::type::StringX name, std::vector<relpipe::reader::handlers::AttributeMetadata> attributes) override {
- // TODO: share this code through relpipe-lib-infertypes (when available)
+ // TODO: this logic should be same as in relpipe-in-csv and should be shared through relpipe-lib-infertypes later
+ vector<writer::AttributeMetadata> writerMetadata;
+ std::wsmatch match;
+ for (relpipe::reader::handlers::AttributeMetadata& am : attributes) {
+ relpipe::common::type::StringX nameAndType = am.getAttributeName();
+ if (std::regex_match(nameAndType, match, pattern)) writerMetadata.push_back({match[1], relationalWriter->toTypeId(match[2])});
+ else throw relpipe::writer::RelpipeWriterException(L"Unable to find type in the attribute name: " + am.getAttributeName());
+ }
+
+ relationalWriter->startRelation(name, writerMetadata, true);
}
void attribute(const relpipe::common::type::StringX& value) override {
@@ -49,7 +60,7 @@
}
};
-std::wregex MetadataMode::pattern = std::wregex(L"(.*)::(.*)");
+std::wregex MetadataMode::pattern = std::wregex(L"(.*)::(.*)"); // name::type
}
}