# HG changeset patch # User František Kučera # Date 1549321604 -3600 # Node ID 7977c1bdba1f473c626aa6f23aeac86319e9b2f2 # Parent 9603e64324bc4a2bd9780d9e7b0237f75365c0bf add --output-attribute so output relation can have different attributes than the input relation diff -r 9603e64324bc -r 7977c1bdba1f src/CLIParser.h --- a/src/CLIParser.h Sun Feb 03 21:53:10 2019 +0100 +++ b/src/CLIParser.h Tue Feb 05 00:06:44 2019 +0100 @@ -32,7 +32,7 @@ class CLIParser { private: - // TODO: move common methods/classes to relpipe-lib-cli + // FIXME: move common methods/classes to relpipe-lib-cli or relpipe-lib-helper string_t readNext(std::vector arguments, int& i) { if (i < arguments.size()) return arguments[i++]; @@ -52,9 +52,18 @@ else throw relpipe::cli::RelpipeCLIException(L"Unable to parse boolean value of option: " + optionName + L" (expecting true or false)", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); } + relpipe::writer::TypeId parseTypeId(const string_t& value) { + using t = relpipe::writer::TypeId; + if (value == L"string") return t::STRING; + else if (value == L"integer") return t::INTEGER; + else if (value == L"boolean") return t::BOOLEAN; + else throw relpipe::cli::RelpipeCLIException(L"Unable to parse TypeId: " + value, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); + } + public: static const string_t OPTION_RELATION; + static const string_t OPTION_OUTPUT_ATTRIBUTE; static const string_t OPTION_BEFORE_RECORDS; static const string_t OPTION_AFTER_RECORDS; static const string_t OPTION_FOR_EACH; @@ -78,6 +87,11 @@ else if (option == OPTION_RELATION) { addRelation(c, currentRelation); // previous relation currentRelation.relation = readNext(arguments, i); + } else if (option == OPTION_OUTPUT_ATTRIBUTE) { + relpipe::writer::AttributeMetadata attribute; + attribute.attributeName = readNext(arguments, i); + attribute.typeId = parseTypeId(readNext(arguments, i)); + currentRelation.writerMetadata.push_back(attribute); } else if (option == OPTION_DEFINE) { DefinitionRecipe definition; definition.name = readNext(arguments, i); @@ -99,6 +113,7 @@ }; const string_t CLIParser::OPTION_RELATION = L"--relation"; +const string_t CLIParser::OPTION_OUTPUT_ATTRIBUTE = L"--output-attribute"; const string_t CLIParser::OPTION_BEFORE_RECORDS = L"--before-records"; const string_t CLIParser::OPTION_AFTER_RECORDS = L"--after-records"; const string_t CLIParser::OPTION_FOR_EACH = L"--for-each"; diff -r 9603e64324bc -r 7977c1bdba1f src/Configuration.h --- a/src/Configuration.h Sun Feb 03 21:53:10 2019 +0100 +++ b/src/Configuration.h Tue Feb 05 00:06:44 2019 +0100 @@ -70,7 +70,6 @@ // TODO: --define – global definitions (for all relations)? // TODO: --relation … --drop – will execute --for-each, but no output will be generated for this relation - // TODO: --relation … --output-attribute 'name' 'type' – output relation will have different attributes than the input relation // TODO: --create t2 3 a integer b boolean '…guile…' – allow creating new relations? Or allow calling startRelation() and attribute() from Guile? virtual ~Configuration() { diff -r 9603e64324bc -r 7977c1bdba1f src/GuileHandler.h --- a/src/GuileHandler.h Sun Feb 03 21:53:10 2019 +0100 +++ b/src/GuileHandler.h Tue Feb 05 00:06:44 2019 +0100 @@ -190,13 +190,6 @@ for (DefinitionRecipe definition : currentRelationConfiguration->definitions) undefineGuileVariable(definition.name); } for (auto attribute : currentReaderMetadata) undefineGuileVariable(attribute.getAttributeName()); - currentReaderMetadata = attributes; - // TODO: move to a reusable method (or use same metadata on both reader and writer side?) - // TODO: allow structural changes during transformation - currentWriterMetadata.clear(); - for (AttributeMetadata readerMetadata : attributes) { - currentWriterMetadata.push_back({readerMetadata.getAttributeName(), relationalWriter->toTypeId(readerMetadata.getTypeName())}); - } currentRelationConfiguration = nullptr; for (int i = 0; i < configuration.relationConfigurations.size(); i++) { @@ -207,6 +200,15 @@ } } + currentReaderMetadata = attributes; + // TODO: move to a reusable method (or use same metadata on both reader and writer side?) + currentWriterMetadata.clear(); + if (currentRelationConfiguration && currentRelationConfiguration->writerMetadata.size()) { + currentWriterMetadata = currentRelationConfiguration->writerMetadata; + } else { + for (AttributeMetadata readerMetadata : attributes) currentWriterMetadata.push_back({readerMetadata.getAttributeName(), relationalWriter->toTypeId(readerMetadata.getTypeName())}); + } + relationalWriter->startRelation(name, currentWriterMetadata, true); if (currentRelationConfiguration) {