1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements. See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership. The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18#ifndef ARROW_CSV_COLUMN_BUILDER_H
19#define ARROW_CSV_COLUMN_BUILDER_H
20
21#include <cstdint>
22#include <memory>
23
24#include "arrow/array.h"
25#include "arrow/status.h"
26#include "arrow/util/visibility.h"
27
28namespace arrow {
29
30class ChunkedArray;
31class DataType;
32
33namespace internal {
34
35class TaskGroup;
36
37} // namespace internal
38
39namespace csv {
40
41class BlockParser;
42struct ConvertOptions;
43
44class ARROW_EXPORT ColumnBuilder {
45 public:
46 virtual ~ColumnBuilder() = default;
47
48 /// Spawn a task that will try to convert and append the given CSV block.
49 /// All calls to Append() should happen on the same thread, otherwise
50 /// call Insert() instead.
51 virtual void Append(const std::shared_ptr<BlockParser>& parser);
52
53 /// Spawn a task that will try to convert and insert the given CSV block
54 virtual void Insert(int64_t block_index,
55 const std::shared_ptr<BlockParser>& parser) = 0;
56
57 /// Return the final chunked array. The TaskGroup _must_ have finished!
58 virtual Status Finish(std::shared_ptr<ChunkedArray>* out) = 0;
59
60 /// Change the task group. The previous TaskGroup _must_ have finished!
61 void SetTaskGroup(const std::shared_ptr<internal::TaskGroup>& task_group);
62
63 std::shared_ptr<internal::TaskGroup> task_group() { return task_group_; }
64
65 /// Construct a strictly-typed ColumnBuilder.
66 static Status Make(const std::shared_ptr<DataType>& type, int32_t col_index,
67 const ConvertOptions& options,
68 const std::shared_ptr<internal::TaskGroup>& task_group,
69 std::shared_ptr<ColumnBuilder>* out);
70
71 /// Construct a type-inferring ColumnBuilder.
72 static Status Make(int32_t col_index, const ConvertOptions& options,
73 const std::shared_ptr<internal::TaskGroup>& task_group,
74 std::shared_ptr<ColumnBuilder>* out);
75
76 protected:
77 explicit ColumnBuilder(const std::shared_ptr<internal::TaskGroup>& task_group)
78 : task_group_(task_group) {}
79
80 std::shared_ptr<internal::TaskGroup> task_group_;
81 ArrayVector chunks_;
82};
83
84} // namespace csv
85} // namespace arrow
86
87#endif // ARROW_CSV_COLUMN_BUILDER_H
88