CPARK 1.0
A light-weighted, distributed computing framework for C++ that offers a fast and general-purpose large data processing solution.
Loading...
Searching...
No Matches
transformed_rdd.h
1#ifndef CPARK_TRANSFORMED_RDD_H
2#define CPARK_TRANSFORMED_RDD_H
3
4#include <vector>
5
6#include "base_rdd.h"
7#include "utils.h"
8
9namespace cpark {
10
29template <concepts::Rdd R, typename Func,
30 typename T = std::invoke_result_t<Func, utils::RddElementType<R>>>
31requires std::invocable<Func, utils::RddElementType<R>>&& std::convertible_to<
32 std::invoke_result_t<Func, utils::RddElementType<R>>, T> class TransformedRdd
33 : public BaseRdd<TransformedRdd<R, Func, T>> {
34public:
36 friend Base;
37
38 constexpr TransformedRdd(const R& prev, Func func) : Base{prev, false} {
40 "Instance of TransformedRdd does not satisfy Rdd concept.");
41 // Create the transformed splits.
42 for (const concepts::Split auto& prev_split : prev) {
43 splits_.emplace_back(prev_split | std::views::transform(func), prev_split);
44 splits_.back().addDependency(prev_split);
45 }
46 }
47
48 // Explicitly define default copy constrictor and assignment operator,
49 // because some linters or compilers can not define implicit copy constructors for this class,
50 // though they are supposed to do so.
51 // TODO: find out why.
52 constexpr TransformedRdd(const TransformedRdd&) = default;
53 TransformedRdd& operator=(const TransformedRdd&) = default;
54
55private:
56 constexpr auto beginImpl() const { return std::ranges::begin(splits_); }
57
58 constexpr auto endImpl() const { return std::ranges::end(splits_); }
59
60private:
61 using TransformedViewype =
62 decltype(std::declval<R>().front() | std::views::transform(std::declval<Func>()));
63 // A vector holding the splits for this rdd.
64 std::vector<ViewSplit<TransformedViewype>> splits_{};
65};
66
70template <typename Func>
71class Transform {
72public:
73 explicit Transform(Func func) : func_{std::move(func)} {}
74
75 template <concepts::Rdd R, typename T = utils::RddElementType<R>,
76 typename U = std::invoke_result_t<Func, T>>
77 requires std::invocable<Func, T>&& std::convertible_to<std::invoke_result_t<Func, T>, U> auto
78 operator()(const R& r) const {
79 return TransformedRdd(r, func_);
80 }
81
82private:
83 Func func_;
84};
85
89template <typename Func, concepts::Rdd R>
90auto operator|(const R& r, const Transform<Func>& transform) {
91 return transform(r);
92}
93
// end of t_Transform
108
109} // namespace cpark
110
111#endif //CPARK_TRANSFORMED_RDD_H
Definition base_rdd.h:522
Definition base_rdd.h:94
Definition transformed_rdd.h:71
Definition transformed_rdd.h:33
Definition base_rdd.h:53
Definition base_rdd.h:44
auto operator|(const R &r, const Collect &collect)
Definition collect.h:48