cmu-db / noisepage

Self-Driving Database Management System from Carnegie Mellon University
https://noise.page
MIT License
1.75k stars 502 forks source link

JSON (de)serialization for plan nodes #359

Closed GustavoAngulo closed 5 years ago

GustavoAngulo commented 5 years ago

We want to add JSON serialization for the plan nodes. Currently, the plan node PR is in the process of being reviewed, but we can still make progress on the serialization while thats happening. If you are able to help out, it should take you less than 30min to add support for a plan node.

Instructions

Some notes

Coding Best Practices

// BAD json["field"].get();

* Serializers and deserializers have already been written for oid types. You can easily serialize them as follows:

nlohmann::json j; catalog::col_oid_t oid(0); j["oid"]= oid; auto deserialized_oid = j.at("oid").get()

* Use `parser::DeserializeExpression` to deserialize any `std::shared_ptr<AbstractExpression>` object. Also, when deserializing anything that is a pointer, you need to check that what was serialized was not a `nullptr`. You should do that using `json::is_null()` as follows:

auto expr = std::make_shared(); nlohmann::json j; j["expr"] = expr;

std::shared_ptr deserialized_expr; if (!j.at("expr").is_null()) deserialized_expr = parser::DeserializeExpression(j.at("expr")); }

* The JSON library knows how to (de)serialize STL containers like `std::vectors` (given that what they hold is also (de)serializable). For example:

std::vector column_oids = {1,2,3}; j["column_oids"] = column_oids; auto col_ids = j.at("column_oids").get<std::vector>();

apavlo commented 5 years ago

This was merged in #366