# HG changeset patch # User František Kučera # Date 1557257639 -7200 # Node ID e4558df9ba2d6aa2d46c09518b4d4a0d9d1d3bbd # Parent 2ac59242d0cb6daf5ff76cb8a4bb4fb5d63f2ce0 drop – run AWK code but generate no output for given relation diff -r 2ac59242d0cb -r e4558df9ba2d src/AwkHandler.h --- a/src/AwkHandler.h Tue May 07 21:25:45 2019 +0200 +++ b/src/AwkHandler.h Tue May 07 21:33:59 2019 +0200 @@ -141,6 +141,7 @@ currentAttributeIndex = 0; currentReaderMetadata.clear(); currentWriterMetadata.clear(); + currentRelationConfiguration = nullptr; } string_t a2v(const string_t& attributeName) { @@ -174,7 +175,6 @@ currentReaderMetadata = attributes; - currentRelationConfiguration = nullptr; for (int i = 0; i < configuration.relationConfigurations.size(); i++) { if (regex_match(name, wregex(configuration.relationConfigurations[i].relation))) { currentRelationConfiguration = &configuration.relationConfigurations[i]; @@ -262,13 +262,21 @@ __gnu_cxx::stdio_filebuf awkOutputReaderBuffer(awkOutputReaderFD, std::ios::in); std::wistream awkOutputReader(&awkOutputReaderBuffer); - // FIXME: currentWriterMetadata - relationalWriter->startRelation(name,{ - {L"message", writer::TypeId::STRING}, - }, true); + if (currentRelationConfiguration->drop) { + // TODO: omit whole this process and pipe AWK output to /dev/null? + } else { + // FIXME: currentWriterMetadata + relationalWriter->startRelation(name,{ + {L"message", writer::TypeId::STRING}, + }, true); + } for (string_t line; getline(awkOutputReader, line).good();) { - relationalWriter->writeAttribute(line); + if (currentRelationConfiguration->drop) { + // just eat the lines from the AWK + } else { + relationalWriter->writeAttribute(line); + } } closeOrThrow(awkOutputReaderFD); diff -r 2ac59242d0cb -r e4558df9ba2d src/CLIParser.h --- a/src/CLIParser.h Tue May 07 21:25:45 2019 +0200 +++ b/src/CLIParser.h Tue May 07 21:33:59 2019 +0200 @@ -67,6 +67,7 @@ static const string_t OPTION_BEFORE_RECORDS; static const string_t OPTION_AFTER_RECORDS; static const string_t OPTION_FOR_EACH; + static const string_t OPTION_DROP; static const string_t OPTION_DEFINE; Configuration parse(const std::vector& arguments) { @@ -79,6 +80,7 @@ if (option == OPTION_BEFORE_RECORDS) currentRelation.awkBeforeRecords = readNext(arguments, i); else if (option == OPTION_AFTER_RECORDS) currentRelation.awkAfterRecords = readNext(arguments, i); else if (option == OPTION_FOR_EACH) currentRelation.awkForEach = readNext(arguments, i); + else if (option == OPTION_DROP) currentRelation.drop = true; else if (option == OPTION_INPUT_ATTRIBUTES_APPEND) currentRelation.inputAttributesAppend = true; else if (option == OPTION_INPUT_ATTRIBUTES_PREPEND) currentRelation.inputAttributesPrepend = true; else if (option == OPTION_RELATION) { @@ -114,6 +116,7 @@ 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"; +const string_t CLIParser::OPTION_DROP = L"--drop"; const string_t CLIParser::OPTION_DEFINE = L"--define"; } diff -r 2ac59242d0cb -r e4558df9ba2d src/Configuration.h --- a/src/Configuration.h Tue May 07 21:25:45 2019 +0200 +++ b/src/Configuration.h Tue May 07 21:33:59 2019 +0200 @@ -47,6 +47,11 @@ relpipe::writer::string_t awkForEach; /** + * If true, AWK code will be executed, but no output will be generated. + */ + bool drop = false; + + /** * Variable definitions for this relation. * Can be used as a safe way for passing parameters from the outside environment. * See also Configuration::definitions (can be overridden by relation's definitions)