diff -r 000000000000 -r 5d1c556ff7db src/InferTypesHandler.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/InferTypesHandler.h Fri May 21 20:16:03 2021 +0200 @@ -0,0 +1,85 @@ +/** + * Relational pipes + * Copyright © 2021 František Kučera (Frantovo.cz, GlobalCode.info) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +#include + +#include "Configuration.h" + +namespace relpipe { +namespace tr { +namespace infertypes { + +using namespace std; +using namespace relpipe; +using namespace relpipe::reader; +using namespace relpipe::reader::handlers; + +class InferTypesHandler : public RelationalReaderStringHandler { +private: + shared_ptr relationalWriter; + Configuration configuration; + + integer_t currentAttributeIndex = 0; + +public: + + InferTypesHandler(shared_ptr relationalWriter, Configuration configuration) : relationalWriter(relationalWriter), configuration(configuration) { + } + + void startRelation(string_t name, vector attributes) override { + // TODO: move to a reusable method (or use same metadata on both reader and writer side?) + vector writerMetadata; + for (AttributeMetadata readerMetadata : attributes) { + writerMetadata.push_back({readerMetadata.getAttributeName(), relationalWriter->toTypeId(readerMetadata.getTypeName())}); + } + + relationalWriter->startRelation(name, writerMetadata, true); + } + + void attribute(const string_t& value) override { + relationalWriter->writeAttribute(value); + + currentAttributeIndex++; + //currentAttributeIndex = currentAttributeIndex % currentRules.size(); + } + + void endOfPipe() { + + } + +}; + +} +} +}