src/TabularPrefetchingHandler.h
branchv_0
changeset 30 3c6374467a82
parent 27 f03e1f9cfcb6
child 31 c22577615ce4
--- a/src/TabularPrefetchingHandler.h	Sat Jun 06 01:50:44 2020 +0200
+++ b/src/TabularPrefetchingHandler.h	Thu Sep 24 18:57:20 2020 +0200
@@ -29,6 +29,8 @@
 #include <relpipe/reader/handlers/RelationalReaderStringHandler.h>
 #include <relpipe/reader/handlers/AttributeMetadata.h>
 
+#include "Configuration.h"
+
 namespace relpipe {
 namespace out {
 namespace tabular {
@@ -52,7 +54,11 @@
 
 	const char* INDENT = " "; // table indent from the left
 
-	std::ostream &output;
+	std::ostream& output;
+	Configuration& configuration;
+	RelationConfiguration* currentRelationConfiguration;
+
+#define getConfiguration(option) (currentRelationConfiguration ? currentRelationConfiguration->option : configuration.option)
 
 	std::vector<TypeId> columnTypes;
 	std::vector<string_t> columnTypeCodes;
@@ -146,7 +152,7 @@
 		for (size_t i = 0; i < columnCount; i++) {
 			string_t typeCode = columnTypeCodes[i];
 			string_t columnName = columnNames[i];
-			integer_t minWidth = columnName.size() + typeCode.size() + 3; // 3 = " ()" in "columnName (typeCode)"
+			integer_t minWidth = columnName.size() + (getConfiguration(printTypes) ? typeCode.size() + 3 : 0); // 3 = " ()" in "columnName (typeCode)"
 			columnWidths[i] = max(columnWidths[i], minWidth);
 			paddings[i] = columnWidths[i] - minWidth;
 		}
@@ -160,7 +166,7 @@
 			for (integer_t p = 0; p < paddings[i]; p++) {
 				output << " ";
 			}
-			output << " (" << convertor.to_bytes(columnTypeCodes[i]) << ")";
+			if (getConfiguration(printTypes)) output << " (" << convertor.to_bytes(columnTypeCodes[i]) << ")";
 			output << ESC_BORDER << " │" << ESC_RESET;
 		}
 		output << std::endl;
@@ -182,21 +188,32 @@
 			if (columnIndex == (columnCount - 1)) output << std::endl;
 		}
 		printHorizontalLine(L"╰", L"┴", L"╯");
-		integer_t recordCount = values.size() / columnCount;
-		output << ESC_YELLOW << "Record count: " << ESC_RESET << recordCount << std::endl;
+
+		if (getConfiguration(printRecordCount)) {
+			integer_t recordCount = values.size() / columnCount;
+			output << ESC_YELLOW << "Record count: " << ESC_RESET << recordCount << std::endl;
+		}
 
 		values.clear();
 	}
 
 public:
 
-	TabularPrefetchingHandler(std::ostream& output) : output(output) {
+	TabularPrefetchingHandler(std::ostream& output, Configuration& configuration) : output(output), configuration(configuration) {
 	}
 
 	void startRelation(string_t name, std::vector<handlers::AttributeMetadata> attributes) override {
 		if (columnCount) printCachedData();
 
-		output << ESC_RED << convertor.to_bytes(name) << ":" << ESC_RESET << endl;
+		currentRelationConfiguration = nullptr;
+		for (int i = 0; i < configuration.relationConfigurations.size(); i++) {
+			if (std::regex_match(name, std::wregex(configuration.relationConfigurations[i].relation))) {
+				currentRelationConfiguration = &configuration.relationConfigurations[i];
+				break; // it there are multiple matches, only the first configuration is used
+			}
+		}
+
+		if (getConfiguration(printRelationName)) output << ESC_RED << convertor.to_bytes(name) << ":" << ESC_RESET << endl;
 		columnCount = attributes.size();
 		columnTypes.resize(columnCount);
 		columnTypeCodes.resize(columnCount);
@@ -222,6 +239,8 @@
 
 };
 
+#undef getConfiguration
+
 }
 }
 }