File: make_arrow_builders.hpp

package info (click to toggle)
reflect-cpp 0.21.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,128 kB
  • sloc: cpp: 50,336; python: 139; makefile: 30; sh: 3
file content (59 lines) | stat: -rw-r--r-- 1,732 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef RFL_PARSING_TABULAR_MAKEARROWBUILDERS_HPP_
#define RFL_PARSING_TABULAR_MAKEARROWBUILDERS_HPP_

#include <arrow/api.h>

#include <array>
#include <cinttypes>
#include <memory>
#include <optional>
#include <stdexcept>
#include <string>
#include <type_traits>

#include "../../named_tuple_t.hpp"
#include "ArrowTypes.hpp"

namespace rfl::parsing::tabular {

template <class T, SerializationType _s>
using arrow_builder_t =
    typename ArrowTypes<std::remove_cvref_t<std::remove_pointer_t<T>>,
                        _s>::BuilderType;

template <class T, SerializationType _s>
struct ArrowBuildersType;

template <SerializationType _s, class... FieldTypes>
struct ArrowBuildersType<NamedTuple<FieldTypes...>, _s> {
  using Type = Tuple<arrow_builder_t<typename FieldTypes::Type, _s>...>;

  static auto data_types() {
    return [&]<size_t... _is>(std::integer_sequence<size_t, _is...>) {
      return std::array<std::shared_ptr<arrow::DataType>,
                        sizeof...(FieldTypes)>(
          {ArrowTypes<typename FieldTypes::Type, _s>::data_type()...});
    }(std::make_integer_sequence<size_t, sizeof...(FieldTypes)>());
  }

  static Type make_builders() {
    return Type(ArrowTypes<typename FieldTypes::Type, _s>::make_builder()...);
  }

  static auto schema() {
    const auto fields =
        std::vector<std::shared_ptr<arrow::Field>>({arrow::field(
            typename FieldTypes::Name().str(),
            ArrowTypes<typename FieldTypes::Type, _s>::data_type())...});
    return arrow::schema(fields);
  }
};

template <class T, SerializationType _s>
auto make_arrow_builders() {
  return ArrowBuildersType<std::remove_cvref_t<T>, _s>::make_builders();
}

}  // namespace rfl::parsing::tabular

#endif