# HG changeset patch # User František Kučera # Date 1549366914 -3600 # Node ID 82bd0f57a88993ab250028d2c9b5891cf37b7ebb # Parent c9fece435aa2c36a0039d5c916b94c3d7ef9ed97 add --drop option: all Guile code will be executed but not relational output for given relation will be generated diff -r c9fece435aa2 -r 82bd0f57a889 src/CLIParser.h --- a/src/CLIParser.h Tue Feb 05 12:14:58 2019 +0100 +++ b/src/CLIParser.h Tue Feb 05 12:41:54 2019 +0100 @@ -46,12 +46,6 @@ } } - bool parseBoolean(const string_t& value, const string_t& optionName) { - if (value == L"true") return true; - else if (value == L"false") return false; - 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; @@ -83,7 +77,7 @@ else if (option == OPTION_AFTER_RECORDS) currentRelation.guileAfterRecords = readNext(arguments, i); else if (option == OPTION_FOR_EACH) currentRelation.guileForEach = readNext(arguments, i); else if (option == OPTION_WHERE) currentRelation.guileWhere = readNext(arguments, i); - else if (option == OPTION_DROP) currentRelation.drop = parseBoolean(readNext(arguments, i), option); + else if (option == OPTION_DROP) currentRelation.drop = true; else if (option == OPTION_RELATION) { addRelation(c, currentRelation); // previous relation currentRelation.relation = readNext(arguments, i); diff -r c9fece435aa2 -r 82bd0f57a889 src/Configuration.h --- a/src/Configuration.h Tue Feb 05 12:14:58 2019 +0100 +++ b/src/Configuration.h Tue Feb 05 12:41:54 2019 +0100 @@ -75,7 +75,6 @@ */ std::vector definitions; - // TODO: --relation … --drop – will execute --for-each, but no output will be generated for this 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 c9fece435aa2 -r 82bd0f57a889 src/GuileHandler.h --- a/src/GuileHandler.h Tue Feb 05 12:14:58 2019 +0100 +++ b/src/GuileHandler.h Tue Feb 05 12:41:54 2019 +0100 @@ -190,7 +190,7 @@ for (DefinitionRecipe definition : currentRelationConfiguration->definitions) undefineGuileVariable(definition.name); } for (auto attribute : currentReaderMetadata) undefineGuileVariable(attribute.getAttributeName()); - + for (DefinitionRecipe definition : configuration.definitions) defineGuileVariable(definition); currentRelationConfiguration = nullptr; @@ -211,7 +211,7 @@ for (AttributeMetadata readerMetadata : attributes) currentWriterMetadata.push_back({readerMetadata.getAttributeName(), relationalWriter->toTypeId(readerMetadata.getTypeName())}); } - relationalWriter->startRelation(name, currentWriterMetadata, true); + if (!currentRelationConfiguration || !currentRelationConfiguration->drop) relationalWriter->startRelation(name, currentWriterMetadata, true); if (currentRelationConfiguration) { // TODO: better variable name, object, function? @@ -230,7 +230,7 @@ if (currentAttributeIndex > 0 && currentAttributeIndex % currentReaderMetadata.size() == 0) { evalGuileCode(currentRelationConfiguration->guileForEach); includeCurrentRecord = scm_to_bool(evalGuileCode(currentRelationConfiguration->guileWhere, SCM_BOOL_T)); - if (includeCurrentRecord) for (auto attribute : currentWriterMetadata) writeGuileValueToAttribute(attribute); + if (includeCurrentRecord && !currentRelationConfiguration->drop) for (auto attribute : currentWriterMetadata) writeGuileValueToAttribute(attribute); includeCurrentRecord = false; }