|
23 | 23 |
|
24 | 24 | #include "arrow/dataset/type_fwd.h" |
25 | 25 | #include "arrow/dataset/visibility.h" |
| 26 | +#include "arrow/util/iterator.h" |
26 | 27 |
|
27 | 28 | namespace arrow { |
28 | 29 | namespace dataset { |
29 | 30 |
|
30 | 31 | /// \brief A granular piece of a Dataset, such as an individual file, |
31 | | -/// which can be read/scanned separately from other fragments |
| 32 | +/// which can be read/scanned separately from other fragments. |
| 33 | +/// |
| 34 | +/// A DataFragment yields a collection of RecordBatch, encapsulated in one or |
| 35 | +/// more ScanTasks. |
32 | 36 | class ARROW_DS_EXPORT DataFragment { |
33 | 37 | public: |
34 | | - virtual ~DataFragment() = default; |
| 38 | + /// \brief Scan returns an iterator of ScanTasks, each of which yields |
| 39 | + /// RecordBatches from this DataFragment. |
| 40 | + virtual Status Scan(std::shared_ptr<ScanContext> scan_context, |
| 41 | + std::unique_ptr<ScanTaskIterator>* out) = 0; |
35 | 42 |
|
36 | 43 | /// \brief Return true if the fragment can benefit from parallel |
37 | 44 | /// scanning |
38 | 45 | virtual bool splittable() const = 0; |
39 | 46 |
|
40 | | - /// \brief Partition options to use when scanning this fragment. May be |
41 | | - /// nullptr |
| 47 | + /// \brief Filtering, schema reconciliation, and partition options to use when |
| 48 | + /// scanning this fragment. May be nullptr, which indicates that no filtering |
| 49 | + /// or schema reconciliation will be performed and all partitions will be |
| 50 | + /// scanned. |
42 | 51 | virtual std::shared_ptr<ScanOptions> scan_options() const = 0; |
43 | | -}; |
44 | | - |
45 | | -/// \brief Conditions to apply to a dataset when reading to include or |
46 | | -/// exclude fragments, filter out rows, etc. |
47 | | -struct DataSelector { |
48 | | - std::vector<std::shared_ptr<Filter>> filters; |
49 | 52 |
|
50 | | - // TODO(wesm): Select specific partition keys, file path globs, or |
51 | | - // other common desirable selections |
| 53 | + virtual ~DataFragment() = default; |
52 | 54 | }; |
53 | 55 |
|
54 | 56 | /// \brief A basic component of a Dataset which yields zero or more |
55 | | -/// DataFragments |
| 57 | +/// DataFragments. A DataSource acts as a discovery mechanism of DataFragments |
| 58 | +/// and partitions, e.g. files deeply nested in a directory. |
56 | 59 | class ARROW_DS_EXPORT DataSource { |
57 | 60 | public: |
58 | | - virtual ~DataSource() = default; |
| 61 | + /// \brief GetFragments returns an iterator of DataFragments. The ScanOptions |
| 62 | + /// controls filtering and schema inference. |
| 63 | + virtual std::unique_ptr<DataFragmentIterator> GetFragments( |
| 64 | + std::shared_ptr<ScanOptions> options) = 0; |
59 | 65 |
|
60 | 66 | virtual std::string type() const = 0; |
61 | 67 |
|
62 | | - virtual std::unique_ptr<DataFragmentIterator> GetFragments( |
63 | | - const DataSelector& selector) = 0; |
| 68 | + virtual ~DataSource() = default; |
64 | 69 | }; |
65 | 70 |
|
66 | 71 | /// \brief A DataSource consisting of a flat sequence of DataFragments |
67 | 72 | class ARROW_DS_EXPORT SimpleDataSource : public DataSource { |
68 | 73 | public: |
69 | 74 | std::unique_ptr<DataFragmentIterator> GetFragments( |
70 | | - const DataSelector& selector) override; |
| 75 | + std::shared_ptr<ScanOptions> options) override { |
| 76 | + return MakeIterator(fragments_); |
| 77 | + } |
71 | 78 |
|
72 | 79 | private: |
73 | 80 | DataFragmentVector fragments_; |
74 | 81 | }; |
75 | 82 |
|
76 | 83 | /// \brief Top-level interface for a Dataset with fragments coming |
77 | | -/// from possibly multiple sources |
| 84 | +/// from possibly multiple sources. |
78 | 85 | class ARROW_DS_EXPORT Dataset : public std::enable_shared_from_this<Dataset> { |
79 | 86 | public: |
80 | 87 | /// \param[in] source a single input data source |
@@ -110,5 +117,14 @@ class ARROW_DS_EXPORT Dataset : public std::enable_shared_from_this<Dataset> { |
110 | 117 | std::vector<std::shared_ptr<DataSource>> sources_; |
111 | 118 | }; |
112 | 119 |
|
| 120 | +/// \brief Conditions to apply to a dataset when reading to include or |
| 121 | +/// exclude fragments, filter out rows, etc. |
| 122 | +struct DataSelector { |
| 123 | + std::vector<std::shared_ptr<Filter>> filters; |
| 124 | + |
| 125 | + // TODO(wesm): Select specific partition keys, file path globs, or |
| 126 | + // other common desirable selections |
| 127 | +}; |
| 128 | + |
113 | 129 | } // namespace dataset |
114 | 130 | } // namespace arrow |
0 commit comments