Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update nlohmann/json to 3.6.1 and improve JSON encoding of RuntimeInformation #213

Merged
merged 4 commits into from
Apr 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 24 additions & 11 deletions src/engine/RuntimeInformation.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#pragma once

#include <iostream>
#include <nlohmann/fifo_map.hpp>
#include <nlohmann/json.hpp>
#include <string>
#include <vector>
Expand All @@ -15,7 +16,18 @@

class RuntimeInformation {
public:
friend void to_json(nlohmann::json& j, const RuntimeInformation& rti);
// The following declarations introduce an ordered_json type
// that functions exactly like nlohmann::json but keeps
// object keys in insertion order.
// This helps to make the JSON more readable as it forces children to be
// printed after their parents. See also
// https://github.com/nlohmann/json/issues/485#issuecomment-333652309
template <class K, class V, class dummy_compare, class A>
using fifo_map = nlohmann::fifo_map<K, V, nlohmann::fifo_map_compare<K>, A>;
using ordered_json = nlohmann::basic_json<fifo_map>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to work, but just out of curiosity: how is ordered_json a complete type here?
As I understand it fifo_map is still templated on <K, V, A> and I don't see an instantiation,
but later on we can write void foo(RuntimeInformation::ordered_json&j) without running into trouble.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think while fifo_map is indeed still templated and couldn't be used without template arguments, ordered_json is nlohmann::basic_json<fifo_map> which determines the K and V arguments.


friend inline void to_json(RuntimeInformation::ordered_json& j,
const RuntimeInformation& rti);

RuntimeInformation()
: _time(0),
Expand Down Expand Up @@ -131,14 +143,15 @@ class RuntimeInformation {
std::vector<RuntimeInformation> _children;
};

inline void to_json(nlohmann::json& j, const RuntimeInformation& rti) {
using nlohmann::json;
j = json{{"description", rti._descriptor},
{"result_rows", rti._rows},
{"result_cols", rti._cols},
{"total_time", rti._time},
{"operation_time", rti.getOperationTime()},
{"was_cached", rti._wasCached},
{"details", rti._details},
{"children", rti._children}};
inline void to_json(RuntimeInformation::ordered_json& j,
const RuntimeInformation& rti) {
j = RuntimeInformation::ordered_json{
{"description", rti._descriptor},
{"result_rows", rti._rows},
{"result_cols", rti._cols},
{"total_time", rti._time},
{"operation_time", rti.getOperationTime()},
{"was_cached", rti._wasCached},
{"details", rti._details},
{"children", rti._children}};
}
3 changes: 2 additions & 1 deletion src/engine/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ string Server::composeResponseJson(const ParsedQuery& query,
}

os << "\"runtimeInformation\" : ";
os << nlohmann::json(qet.getRootOperation()->getRuntimeInfo());
os << RuntimeInformation::ordered_json(
qet.getRootOperation()->getRuntimeInfo());
os << ", \n";

os << "\"res\": ";
Expand Down
49 changes: 0 additions & 49 deletions third_party/json/nlohmann/adl_serializer.hpp

This file was deleted.