11 #include <rapidjson/document.h> 12 #include <rapidjson/stringbuffer.h> 14 #include "base/type_traits.h" 15 #include "mr/do_context.h" 16 #include "mr/impl/table_impl.h" 17 #include "mr/mr_types.h" 18 #include "mr/output.h" 26 template <
typename MapperType,
typename =
void>
struct MapperTraits {
27 static_assert(
sizeof(MapperType) == 0,
28 "Must have member function Do(InputType inp, DoContext<OutputType>* context)");
31 template <
typename MapperType>
32 struct MapperTraits<MapperType, ::base::void_t<decltype(&MapperType::Do)>>
33 :
public EmitFuncTraits<decltype(&MapperType::Do)> {};
42 InputBase(
const std::string& name, pb::WireFormat::Type type,
43 const pb::Output* linked_outp =
nullptr)
44 : linked_outp_(linked_outp) {
45 input_.set_name(name);
46 input_.mutable_format()->set_type(type);
49 void operator=(
const InputBase&) =
delete;
51 pb::Input* mutable_msg() {
return &input_; }
52 const pb::Input& msg()
const {
return input_; }
54 const pb::Output* linked_outp()
const {
return linked_outp_; }
57 const pb::Output* linked_outp_;
61 template <
typename OutT>
class PTable {
65 template <
typename T>
friend class PTable;
71 Output<OutT>& Write(
const std::string& name, pb::WireFormat::Type type) {
72 return impl_->Write(name, type);
75 template <
typename MapType,
typename... Args>
77 Args&&... args)
const;
79 template <
typename Handler,
typename ToType,
typename U>
80 detail::HandlerBinding<Handler, ToType> BindWith(EmitMemberFn<U, Handler, ToType> ptr)
const {
81 return impl_->BindWith(ptr);
84 template <
typename U>
PTable<U> As()
const {
return PTable<U>{impl_->template Rebind<U>()}; }
89 using TableImpl = detail::TableImplT<OutT>;
91 explicit PTable(std::shared_ptr<TableImpl> impl) : impl_(std::move(impl)) {}
93 std::shared_ptr<TableImpl> impl_;
98 template <
typename OutT>
99 template <
typename MapType,
typename... Args>
101 const std::string& name, Args&&... args)
const {
102 using mapper_traits_t = detail::MapperTraits<MapType>;
103 using NewOutType =
typename mapper_traits_t::OutputType;
105 static_assert(std::is_constructible<typename mapper_traits_t::first_arg_t, OutT&&>::value,
106 "MapperType::Do() first argument " 107 "should be constructed from PTable element type");
109 auto res = detail::TableImplT<NewOutType>::template AsMapFrom<MapType>(
110 name, impl_.get(), std::forward<Args>(args)...);
116 rapidjson::StringBuffer sb_;
122 std::string Serialize(
bool is_binary,
const rapidjson::Document& doc);
123 bool Parse(
bool is_binary, std::string&& tmp, rapidjson::Document* res);
Serves as the main entry point for setting up and configuring the mapreduce pipeline.