drop – run AWK code but generate no output for given relation v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Tue, 07 May 2019 21:33:59 +0200
branchv_0
changeset 19 e4558df9ba2d
parent 18 2ac59242d0cb
child 20 f937ad57351f
drop – run AWK code but generate no output for given relation
src/AwkHandler.h
src/CLIParser.h
src/Configuration.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<wchar_t> 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);
--- 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<string_t>& 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";
 
 }
--- 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)