src/RecfileHandler.h
author František Kučera <franta-hg@frantovo.cz>
Sun, 19 Feb 2023 00:36:47 +0100
branchv_0
changeset 17 f67047a1e19e
parent 16 1731e8dff446
child 18 002077ecb17a
permissions -rw-r--r--
attribute name escaping: also attributes in the relation header
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * Relational pipes
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
7
d59f31fa7009 fix license version: GNU GPLv3
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
     7
 * the Free Software Foundation, version 3 of the License.
0
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 *
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * GNU General Public License for more details.
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 *
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 */
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
#pragma once
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
#include <string>
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
#include <vector>
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
#include <iostream>
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
#include <sstream>
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
#include <locale>
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
#include <codecvt>
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
#include <regex>
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
#include <cassert>
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
#include <relpipe/reader/typedefs.h>
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
#include <relpipe/reader/TypeId.h>
1
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    30
#include <relpipe/reader/RelpipeReaderException.h>
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    31
#include <relpipe/reader/handlers/RelationalReaderStringHandler.h>
0
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
#include <relpipe/reader/handlers/AttributeMetadata.h>
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
namespace relpipe {
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
namespace out {
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
namespace recfile {
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
using namespace relpipe::reader;
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
2
db029ce62ec5 fix typo: Hadler → Handler
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    40
class RecfileHandler : public handlers::RelationalReaderStringHandler {
0
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
private:
1
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    42
	std::ostream& output;
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    43
	wstring_convert<codecvt_utf8<wchar_t>> convertor; // XML output will be always in UTF-8
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    44
	std::vector<TypeId> attributeTypes;
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    45
	std::vector<string_t> attributeTypeCodes;
17
f67047a1e19e attribute name escaping: also attributes in the relation header
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    46
	std::vector<string_t> attributeNamesIn;
f67047a1e19e attribute name escaping: also attributes in the relation header
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    47
	std::vector<string_t> attributeNamesOut;
0
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
	integer_t valueCount = 0;
1
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    49
	integer_t attributeCount = 0;
0
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
	integer_t relationCount = 0;
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
1
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    52
	void writeRelationName(const string_t& name) {
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    53
		// FIXME: escaping/filtering
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    54
		output << "%rec: " << convertor.to_bytes(name) << std::endl;
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    55
	}
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    56
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    57
	const std::string toRecfileType(const TypeId& type) {
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    58
		switch (type) {
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    59
			case TypeId::BOOLEAN: return "bool";
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    60
			case TypeId::INTEGER: return "int";
3
b0fe316e1201 string is the default type in recfile, so there is no need for %type metadata for string attributes
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    61
			case TypeId::STRING: return "";
1
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    62
			default: throw RelpipeReaderException(L"Unsupported type – unable to convert to a Recfile type");
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    63
		}
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    64
	}
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    65
17
f67047a1e19e attribute name escaping: also attributes in the relation header
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    66
	void writeAttributeMetadata(size_t i) {
f67047a1e19e attribute name escaping: also attributes in the relation header
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    67
		std::string recfileType = toRecfileType(attributeTypes[i]);
f67047a1e19e attribute name escaping: also attributes in the relation header
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    68
		if (recfileType.size()) output << "%type: " << convertor.to_bytes(attributeNamesOut[i]) << " " << recfileType << std::endl;
1
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    69
	}
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    70
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    71
	void writeSeparator() {
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    72
		output << std::endl;
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    73
	}
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    74
16
1731e8dff446 attribute name escaping: first version
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    75
	bool between(wchar_t ch, wchar_t start, wchar_t end) {
1731e8dff446 attribute name escaping: first version
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    76
		return ch >= start && ch <= end;
1731e8dff446 attribute name escaping: first version
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    77
	}
1731e8dff446 attribute name escaping: first version
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    78
1731e8dff446 attribute name escaping: first version
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    79
	bool isValidNameCharacter(wchar_t ch, bool first) {
1731e8dff446 attribute name escaping: first version
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    80
		if (first) {
1731e8dff446 attribute name escaping: first version
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    81
			// also '%' is technically valid here, but it is used for special
1731e8dff446 attribute name escaping: first version
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    82
			// purposes like the relation name or attribute types
1731e8dff446 attribute name escaping: first version
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    83
			return /**/between(ch, L'a', L'z')
1731e8dff446 attribute name escaping: first version
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    84
					|| between(ch, L'A', L'Z');
1731e8dff446 attribute name escaping: first version
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    85
		} else {
1731e8dff446 attribute name escaping: first version
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    86
			return ch == L'_'
1731e8dff446 attribute name escaping: first version
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    87
					|| between(ch, L'a', L'z')
1731e8dff446 attribute name escaping: first version
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    88
					|| between(ch, L'A', L'Z')
1731e8dff446 attribute name escaping: first version
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    89
					|| between(ch, L'0', L'9');
1731e8dff446 attribute name escaping: first version
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    90
		}
1731e8dff446 attribute name escaping: first version
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    91
	}
1731e8dff446 attribute name escaping: first version
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    92
17
f67047a1e19e attribute name escaping: also attributes in the relation header
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    93
	const string_t escapeAttributeName(const string_t& name) {
f67047a1e19e attribute name escaping: also attributes in the relation header
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    94
		std::wstringstream escaped;
f67047a1e19e attribute name escaping: also attributes in the relation header
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    95
16
1731e8dff446 attribute name escaping: first version
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    96
		// TODO: multiple escapting mode - including one that is not lossless
1731e8dff446 attribute name escaping: first version
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    97
		// but allows writing a single '_' inside the name
1731e8dff446 attribute name escaping: first version
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    98
		for (size_t i = 0, limit = name.size(); i < limit; i++) {
1731e8dff446 attribute name escaping: first version
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    99
			wchar_t ch = name[i];
1731e8dff446 attribute name escaping: first version
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
   100
			bool valid = isValidNameCharacter(ch, i == 0);
1731e8dff446 attribute name escaping: first version
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
   101
1731e8dff446 attribute name escaping: first version
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
   102
			// Not a lossless round-trip
1731e8dff446 attribute name escaping: first version
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
   103
			// (maybe we could sacrifice some reserved prefix):
17
f67047a1e19e attribute name escaping: also attributes in the relation header
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   104
			if (i == 0 && !valid) escaped << 'x';
16
1731e8dff446 attribute name escaping: first version
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
   105
17
f67047a1e19e attribute name escaping: also attributes in the relation header
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   106
			if (ch == '_') escaped << "__";
f67047a1e19e attribute name escaping: also attributes in the relation header
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   107
			else if (valid) escaped << ch;
f67047a1e19e attribute name escaping: also attributes in the relation header
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   108
			else escaped << '_' << ((uint32_t) ch) << '_';
16
1731e8dff446 attribute name escaping: first version
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
   109
		}
17
f67047a1e19e attribute name escaping: also attributes in the relation header
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   110
f67047a1e19e attribute name escaping: also attributes in the relation header
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   111
		return escaped.str();
f67047a1e19e attribute name escaping: also attributes in the relation header
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   112
	}
f67047a1e19e attribute name escaping: also attributes in the relation header
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   113
f67047a1e19e attribute name escaping: also attributes in the relation header
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   114
	void writeAttribute(const string_t& escapedName, const TypeId& type, const string_t& value) {
f67047a1e19e attribute name escaping: also attributes in the relation header
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   115
		output << convertor.to_bytes(escapedName) << ": ";
1
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   116
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   117
		for (char ch : convertor.to_bytes(value)) {
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   118
			output << ch;
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   119
			if (ch == '\n') output << "+ ";
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   120
		}
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   121
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   122
		output << std::endl;
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   123
	}
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   124
15
e5421eea0583 write record count (as a comment at the end of the relation)
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   125
	void writeRecordCount() {
e5421eea0583 write record count (as a comment at the end of the relation)
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   126
		if (attributeCount) {
e5421eea0583 write record count (as a comment at the end of the relation)
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   127
			output << std::endl << "# Record count: " << (valueCount / attributeCount) << std::endl;
e5421eea0583 write record count (as a comment at the end of the relation)
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   128
		}
e5421eea0583 write record count (as a comment at the end of the relation)
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   129
	}
e5421eea0583 write record count (as a comment at the end of the relation)
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   130
0
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   131
public:
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   132
1
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   133
	RecfileHandler(std::ostream& output) : output(output) {
0
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   134
	}
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   135
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   136
	void startRelation(string_t name, std::vector<handlers::AttributeMetadata> attributes) override {
15
e5421eea0583 write record count (as a comment at the end of the relation)
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   137
		writeRecordCount();
e5421eea0583 write record count (as a comment at the end of the relation)
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   138
0
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   139
		valueCount = 0;
1
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   140
		attributeCount = 0;
0
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   141
1
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   142
		if (relationCount) writeSeparator();
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   143
0
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   144
		relationCount++;
1
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   145
		writeRelationName(name);
0
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   146
1
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   147
		attributeCount = attributes.size();
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   148
		attributeTypes.resize(attributeCount);
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   149
		attributeTypeCodes.resize(attributeCount);
17
f67047a1e19e attribute name escaping: also attributes in the relation header
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   150
		attributeNamesIn.resize(attributeCount);
f67047a1e19e attribute name escaping: also attributes in the relation header
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   151
		attributeNamesOut.resize(attributeCount);
0
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   152
		for (int i = 0; i < attributes.size(); i++) {
17
f67047a1e19e attribute name escaping: also attributes in the relation header
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   153
			attributeNamesIn[i] = attributes[i].getAttributeName();
f67047a1e19e attribute name escaping: also attributes in the relation header
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   154
			attributeNamesOut[i] = escapeAttributeName(attributeNamesIn[i]);
1
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   155
			attributeTypes[i] = attributes[i].getTypeId();
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   156
			attributeTypeCodes[i] = attributes[i].getTypeName();
17
f67047a1e19e attribute name escaping: also attributes in the relation header
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   157
			writeAttributeMetadata(i);
0
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   158
		}
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   159
	}
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   160
1
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   161
	void attribute(const string_t& value) override {
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   162
		integer_t i = valueCount % attributeCount;
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   163
		if (i == 0) writeSeparator();
0
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   164
		valueCount++;
17
f67047a1e19e attribute name escaping: also attributes in the relation header
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   165
		writeAttribute(attributeNamesOut[i], attributeTypes[i], value);
0
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   166
	}
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   167
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   168
	void endOfPipe() {
15
e5421eea0583 write record count (as a comment at the end of the relation)
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
   169
		writeRecordCount();
1
1b4ca23e5d04 draft version
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
   170
		if (valueCount) writeSeparator();
0
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   171
	}
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   172
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   173
};
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   174
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   175
}
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   176
}
9005fdd81bca project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   177
}