2016-12-14 17:27:41 +08:00
|
|
|
#pragma once
|
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
#include <iostream>
|
|
|
|
#include <map>
|
2016-12-14 17:27:41 +08:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2017-03-01 02:38:57 +08:00
|
|
|
#include "query/backend/cpp/typed_value.hpp"
|
2017-02-23 21:19:52 +08:00
|
|
|
#include "storage/edge_accessor.hpp"
|
|
|
|
#include "storage/vertex_accessor.hpp"
|
|
|
|
|
|
|
|
void write_properties(std::ostream &os, const GraphDbAccessor &access,
|
2017-03-01 02:38:57 +08:00
|
|
|
const PropertyValueStore<GraphDb::Property> &properties) {
|
2017-02-23 21:19:52 +08:00
|
|
|
if (properties.size() > 0) {
|
|
|
|
os << "{";
|
|
|
|
for (auto x : properties) {
|
|
|
|
os << access.property_name(x.first) << ": " << x.second << ",";
|
|
|
|
}
|
|
|
|
os << "}\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream &operator<<(std::ostream &os, const VertexAccessor &vertex) {
|
|
|
|
if (vertex.labels().size() > 0) {
|
|
|
|
for (GraphDb::Label label : vertex.labels()) {
|
|
|
|
os << vertex.db_accessor().property_name(label) << ", ";
|
|
|
|
}
|
|
|
|
os << "\n";
|
|
|
|
}
|
|
|
|
write_properties(os, vertex.db_accessor(), vertex.Properties());
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream &operator<<(std::ostream &os, const EdgeAccessor &edge) {
|
|
|
|
os << "Edge: " << edge.db_accessor().edge_type_name(edge.edge_type()) << "\n";
|
|
|
|
write_properties(os, edge.db_accessor(), edge.Properties());
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2017-02-15 21:10:16 +08:00
|
|
|
class PrintRecordStream {
|
2017-02-18 18:54:37 +08:00
|
|
|
private:
|
2017-02-15 21:10:16 +08:00
|
|
|
std::ostream &stream;
|
2016-12-14 17:27:41 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
public:
|
2017-02-15 21:10:16 +08:00
|
|
|
PrintRecordStream(std::ostream &stream) : stream(stream) {}
|
2016-12-14 17:27:41 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
void write_success() { stream << "SUCCESS\n"; }
|
2016-12-14 17:27:41 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
void write_success_empty() { stream << "SUCCESS EMPTY\n"; }
|
2016-12-14 17:27:41 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
void write_ignored() { stream << "IGNORED\n"; }
|
2016-12-14 17:27:41 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
void write_empty_fields() { stream << "EMPTY FIELDS\n"; }
|
2016-12-14 17:27:41 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
void write_fields(const std::vector<std::string> &fields) {
|
2017-02-15 21:10:16 +08:00
|
|
|
stream << "FIELDS:";
|
|
|
|
for (auto &field : fields) {
|
|
|
|
stream << " " << field;
|
2016-12-14 17:27:41 +08:00
|
|
|
}
|
2017-02-15 21:10:16 +08:00
|
|
|
stream << '\n';
|
|
|
|
}
|
2016-12-14 17:27:41 +08:00
|
|
|
|
2017-02-15 21:10:16 +08:00
|
|
|
void write_field(const std::string &field) {
|
|
|
|
stream << "Field: " << field << '\n';
|
|
|
|
}
|
2016-12-14 17:27:41 +08:00
|
|
|
|
2017-02-28 19:14:49 +08:00
|
|
|
void write(const TypedValue &value) { stream << value << " "; }
|
2017-02-18 18:54:37 +08:00
|
|
|
void write_list_header(size_t size) { stream << "List: " << size << '\n'; }
|
2016-12-14 17:27:41 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
void write_record() { stream << "Record\n"; }
|
2016-12-14 17:27:41 +08:00
|
|
|
|
2017-02-23 21:19:52 +08:00
|
|
|
void write_vertex_record(const VertexAccessor &vertex) { stream << vertex; }
|
|
|
|
void write_edge_record(const EdgeAccessor &edge) { stream << edge; }
|
|
|
|
|
2017-02-15 21:10:16 +08:00
|
|
|
void write_meta(const std::string &type) {
|
|
|
|
stream << "Meta: " << type << std::endl;
|
|
|
|
}
|
2016-12-14 17:27:41 +08:00
|
|
|
|
2017-02-23 21:19:52 +08:00
|
|
|
void write_failure(const std::map<std::string, std::string> &data) {}
|
2016-12-14 17:27:41 +08:00
|
|
|
|
2017-02-23 21:19:52 +08:00
|
|
|
void write_count(const size_t count) {}
|
|
|
|
void chunk() { stream << "CHUNK\n"; }
|
2016-12-14 17:27:41 +08:00
|
|
|
};
|