# HG changeset patch # User František Kučera # Date 1618735374 -7200 # Node ID ea36eed9683fc1a5b19bd07b6853fbfccca65a5c # Parent d2e0654803c199a3310205cfd092908cca36e4e0 optionally write data types into the CSV header: --write-types diff -r d2e0654803c1 -r ea36eed9683f bash-completion.sh --- 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 diff -r d2e0654803c1 -r ea36eed9683f src/CLIParser.h --- 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& 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"; } } diff -r d2e0654803c1 -r ea36eed9683f src/CSVHandler.h --- 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 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."); diff -r d2e0654803c1 -r ea36eed9683f src/Configuration.h --- 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() { }