optionally write data types into the CSV header: --write-types v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 18 Apr 2021 10:42:54 +0200
branchv_0
changeset 17 ea36eed9683f
parent 16 d2e0654803c1
child 18 4a0e3b828858
optionally write data types into the CSV header: --write-types
bash-completion.sh
src/CLIParser.h
src/CSVHandler.h
src/Configuration.h
--- a/bash-completion.sh	Sat Oct 24 00:08:18 2020 +0200
+++ b/bash-completion.sh	Sun Apr 18 10:42:54 2021 +0200
@@ -27,10 +27,12 @@
 		"false"
 	)
 
-	if [[ "$w1" == "--write-header"                                    ]];    then COMPREPLY=($(compgen -W "${WRITE_HEADER[*]}" -- "$w0"))
+	  if [[ "$w1" == "--write-header"                                   ]];    then COMPREPLY=($(compgen -W "${WRITE_HEADER[*]}" -- "$w0"))
+	elif [[ "$w1" == "--write-types"                                    ]];    then COMPREPLY=($(compgen -W "${WRITE_HEADER[*]}" -- "$w0"))
 	else
 		OPTIONS=(
 			"--write-header"
+			"--write-types"
 		)
 		COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0"))
 	fi
--- a/src/CLIParser.h	Sat Oct 24 00:08:18 2020 +0200
+++ b/src/CLIParser.h	Sun Apr 18 10:42:54 2021 +0200
@@ -49,6 +49,7 @@
 public:
 
 	static const relpipe::reader::string_t OPTION_WRITE_HEADER;
+	static const relpipe::reader::string_t OPTION_WRITE_TYPES;
 
 	Configuration parse(const std::vector<relpipe::reader::string_t>& arguments) {
 		Configuration c;
@@ -58,6 +59,8 @@
 
 			if (option == OPTION_WRITE_HEADER) {
 				c.writeHeader = parseBoolean(readNext(arguments, i));
+			} else if (option == OPTION_WRITE_TYPES) {
+				c.writeTypes = parseBoolean(readNext(arguments, i));
 			} else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
 		}
 
@@ -69,6 +72,7 @@
 };
 
 const relpipe::reader::string_t CLIParser::OPTION_WRITE_HEADER = L"--write-header";
+const relpipe::reader::string_t CLIParser::OPTION_WRITE_TYPES = L"--write-types";
 
 }
 }
--- a/src/CSVHandler.h	Sat Oct 24 00:08:18 2020 +0200
+++ b/src/CSVHandler.h	Sun Apr 18 10:42:54 2021 +0200
@@ -56,7 +56,7 @@
 	void startRelation(string_t name, std::vector<AttributeMetadata> attributes) override {
 		if (firstAttributes.empty()) {
 			firstAttributes = attributes;
-			if (configuration.writeHeader) for (auto attr : attributes) attribute(attr.getAttributeName());
+			if (configuration.writeHeader) for (auto attr : attributes) attribute(configuration.writeTypes ? attr.getAttributeName() + L"::" + attr.getTypeName() : attr.getAttributeName());
 		} else {
 			// TODO: UNION ALL if data types and attribute count matches
 			throw RelpipeCSVWriterException(L"Only a single relation can be converted to the CSV format.");
--- a/src/Configuration.h	Sat Oct 24 00:08:18 2020 +0200
+++ b/src/Configuration.h	Sun Apr 18 10:42:54 2021 +0200
@@ -29,6 +29,7 @@
 class Configuration {
 public:
 	relpipe::reader::boolean_t writeHeader = true;
+	relpipe::reader::boolean_t writeTypes = false;
 
 	virtual ~Configuration() {
 	}