souffle
2.0.2-371-g6315b36
|
Go to the documentation of this file.
40 class WriteStreamCSV :
public WriteStream {
52 for (
size_t col = 1; col <
arity; ++col) {
62 case 's': destination <<
symbolTable.unsafeResolve(value);
break;
63 case 'i': destination << value;
break;
64 case 'u': destination << ramBitCast<RamUnsigned>(value);
break;
65 case 'f': destination << ramBitCast<RamFloat>(value);
break;
68 default:
fatal(
"unsupported type attribute: `%c`",
type[0]);
73 class WriteFileCSV :
public WriteStreamCSV {
79 if (
getOr(rwOperation,
"headers",
"false") ==
"true") {
80 file << rwOperation.at(
"attributeNames") << std::endl;
82 file << std::setprecision(std::numeric_limits<RamFloat>::max_digits10);
105 static std::string
getFileName(
const std::map<std::string, std::string>& rwOperation) {
106 auto name =
getOr(rwOperation,
"filename", rwOperation.at(
"name") +
".csv");
107 if (name.front() !=
'/') {
108 name =
getOr(rwOperation,
"output-dir",
".") +
"/" + name;
115 class WriteGZipFileCSV :
public WriteStreamCSV {
117 WriteGZipFileCSV(
const std::map<std::string, std::string>& rwOperation,
const SymbolTable& symbolTable,
118 const RecordTable& recordTable)
119 : WriteStreamCSV(rwOperation, symbolTable, recordTable),
120 file(getFileName(rwOperation), std::ios::out | std::ios::binary) {
121 if (
getOr(rwOperation,
"headers",
"false") ==
"true") {
122 file << rwOperation.at(
"attributeNames") << std::endl;
124 file << std::setprecision(std::numeric_limits<RamFloat>::max_digits10);
127 ~WriteGZipFileCSV()
override =
default;
130 void writeNullary()
override {
134 void writeNextTuple(
const RamDomain* tuple)
override {
135 writeNextTupleCSV(file, tuple);
145 static std::string getFileName(
const std::map<std::string, std::string>& rwOperation) {
146 auto name =
getOr(rwOperation,
"filename", rwOperation.at(
"name") +
".csv.gz");
147 if (name.front() !=
'/') {
148 name =
getOr(rwOperation,
"output-dir",
".") +
"/" + name;
153 gzfstream::ogzfstream file;
157 class WriteCoutCSV :
public WriteStreamCSV {
162 std::cout <<
"---------------\n" << rwOperation.at(
"name");
163 if (
getOr(rwOperation,
"headers",
"false") ==
"true") {
164 std::cout <<
"\n" << rwOperation.at(
"attributeNames");
166 std::cout <<
"\n===============\n";
167 std::cout << std::setprecision(std::numeric_limits<RamFloat>::max_digits10);
171 std::cout <<
"===============\n";
188 std::cout << rwOperation.at(
"name") <<
"\t";
195 fatal(
"attempting to iterate over a print size operation");
199 fatal(
"attempting to iterate over a print size operation");
203 std::cout <<
size <<
"\n";
214 if (
contains(rwOperation,
"compress")) {
215 return mk<WriteGZipFileCSV>(rwOperation, symbolTable, recordTable);
218 return mk<WriteFileCSV>(rwOperation, symbolTable, recordTable);
220 const std::string&
getName()
const override {
221 static const std::string name =
"file";
231 return mk<WriteCoutCSV>(rwOperation, symbolTable, recordTable);
234 const std::string&
getName()
const override {
235 static const std::string name =
"stdout";
245 return mk<WriteCoutPrintSize>(rwOperation);
248 static const std::string name =
"stdoutprintsize";
WriteStreamCSV(const std::map< std::string, std::string > &rwOperation, const SymbolTable &symbolTable, const RecordTable &recordTable)
constexpr auto size(const C &c) -> decltype(c.size())
RO< RecordTable > & recordTable
void writeNextTuple(const RamDomain *tuple) override
const std::string & getName() const override
void writeNextTuple(const RamDomain *tuple) override
Own< WriteStream > getWriter(const std::map< std::string, std::string > &rwOperation, const SymbolTable &, const RecordTable &) override
~WriteFileCSVFactory() override=default
bool contains(const C &container, const typename C::value_type &element)
A utility to check generically whether a given element is contained in a given container.
~WriteFileCSV() override=default
void outputADT(std::ostream &destination, const RamDomain value, const std::string &name)
WriteStream(const std::map< std::string, std::string > &rwOperation, const SymbolTable &symbolTable, const RecordTable &recordTable)
void writeNullary() override
RO< SymbolTable > & symbolTable
std::vector< std::string > typeAttributes
void writeNextTupleCSV(std::ostream &destination, const RamDomain *tuple)
WriteCoutPrintSize(const std::map< std::string, std::string > &rwOperation)
C::mapped_type const & getOr(const C &container, typename C::key_type key, const typename C::mapped_type &defaultValue)
Get value for a given key; if not found, return default value.
WriteCoutCSV(const std::map< std::string, std::string > &rwOperation, const SymbolTable &symbolTable, const RecordTable &recordTable)
void outputRecord(std::ostream &destination, const RamDomain value, const std::string &name)
void writeNullary() override
Own< WriteStream > getWriter(const std::map< std::string, std::string > &rwOperation, const SymbolTable &symbolTable, const RecordTable &recordTable) override
static std::string getFileName(const std::map< std::string, std::string > &rwOperation)
Return given filename or construct from relation name.
const std::string & getName() const override
~WriteCoutPrintSizeFactory() override=default
void writeNullary() override
void writeNextTuple(const RamDomain *) override
void fatal(const char *format, const Args &... args)
~WriteCoutPrintSize() override=default
Lock & getOutputLock()
Obtains a reference to the lock synchronizing output operations.
const std::string & getName() const override
void writeSize(std::size_t size) override
const std::string delimiter
Own< WriteStream > getWriter(const std::map< std::string, std::string > &rwOperation, const SymbolTable &symbolTable, const RecordTable &recordTable) override
Defines a tuple for the OO interface such that relations with varying columns can be accessed.
~WriteCoutCSVFactory() override=default
void writeNextTupleElement(std::ostream &destination, const std::string &type, RamDomain value)
WriteFileCSV(const std::map< std::string, std::string > &rwOperation, const SymbolTable &symbolTable, const RecordTable &recordTable)