add --drop option: all Guile code will be executed but not relational output for given relation will be generated
--- 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);
--- 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<DefinitionRecipe> 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() {
--- 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;
}