Scanner C++ API
column_sink.h
1 /* Copyright 2018 Carnegie Mellon University
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "scanner/api/sink.h"
17 
18 #include "storehouse/storage_backend.h"
19 #include "scanner/engine/video_index_entry.h"
20 #include "scanner/engine/table_meta_cache.h"
21 #include "scanner/util/thread_pool.h"
22 
23 #include <glog/logging.h>
24 #include <vector>
25 
26 namespace scanner {
27 namespace internal {
28 
29 class ColumnSink : public Sink {
30  public:
31  ColumnSink(const SinkConfig& config);
32 
33  ~ColumnSink();
34 
35  void new_stream(const std::vector<u8>& args) override;
36 
37  void write(const BatchedElements& input_columns) override;
38 
39  void new_task(i32 table_id, i32 task_id,
40  std::vector<ColumnType> column_types);
41 
42  void finished();
43 
44  void provide_column_info(
45  const std::vector<bool>& compressed,
46  const std::vector<FrameInfo>& frame_info);
47 
48  private:
49  Result valid_;
50  ThreadPool thread_pool_;
51  // Setup a distinct storage backend for each IO thread
52  std::unique_ptr<storehouse::StorageBackend> storage_;
53  // Files to write io packets to
54  std::vector<std::unique_ptr<storehouse::WriteFile>> output_;
55  std::vector<std::unique_ptr<storehouse::WriteFile>> output_metadata_;
56  std::vector<VideoMetadata> video_metadata_;
57 
58  std::vector<ColumnType> column_types_;
59  std::vector<bool> compressed_;
60  std::vector<FrameInfo> frame_info_;
61 
62  // Continuation state
63  bool first_item_;
64  bool needs_configure_;
65  bool needs_reset_;
66 
67  i64 current_work_item_;
68  i64 current_row_;
69  i64 total_work_items_;
70 };
71 
72 }
73 } // namespace scanner
void write(const BatchedElements &input_columns) override
Runs the Sink to write elements.
Definition: column_sink.cpp:71
Interface for reading data in a computation graph.
Definition: sink.h:42
Definition: column_sink.h:29
void new_stream(const std::vector< u8 > &args) override
Called when the Sink is about to process a new stream.
Definition: column_sink.cpp:67
Definition: database.cpp:36
void finished()
When this function returns, the data for all previous &#39;write&#39; calls MUST BE durably written...
Definition: column_sink.cpp:239
Parameters provided at instantiation of Sink node.
Definition: sink.h:28