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 #pragma once
19 
20 #include <memory>
21 #include <vector>
22 
23 #include "arrow/status.h"
24 #include "arrow/type_fwd.h"
25 #include "arrow/util/type_fwd.h"
26 #include "arrow/util/visibility.h"
27 
28 namespace arrow {
29 namespace json {
30 
31 class PromotionGraph;
32 
33 class ARROW_EXPORT ChunkedArrayBuilder {
34  public:
35   virtual ~ChunkedArrayBuilder() = default;
36 
37   /// Spawn a task that will try to convert and insert the given JSON block
38   virtual void Insert(int64_t block_index,
39                       const std::shared_ptr<Field>& unconverted_field,
40                       const std::shared_ptr<Array>& unconverted) = 0;
41 
42   /// Return the final chunked array.
43   /// Every chunk must be inserted before this is called!
44   virtual Status Finish(std::shared_ptr<ChunkedArray>* out) = 0;
45 
46   /// Finish current task group and substitute a new one
47   virtual Status ReplaceTaskGroup(
48       const std::shared_ptr<arrow::internal::TaskGroup>& task_group) = 0;
49 
50  protected:
ChunkedArrayBuilder(const std::shared_ptr<arrow::internal::TaskGroup> & task_group)51   explicit ChunkedArrayBuilder(
52       const std::shared_ptr<arrow::internal::TaskGroup>& task_group)
53       : task_group_(task_group) {}
54 
55   std::shared_ptr<arrow::internal::TaskGroup> task_group_;
56 };
57 
58 /// create a chunked builder
59 ///
60 /// if unexpected fields and promotion need to be handled, promotion_graph must be
61 /// non-null
62 ARROW_EXPORT Status MakeChunkedArrayBuilder(
63     const std::shared_ptr<arrow::internal::TaskGroup>& task_group, MemoryPool* pool,
64     const PromotionGraph* promotion_graph, const std::shared_ptr<DataType>& type,
65     std::shared_ptr<ChunkedArrayBuilder>* out);
66 
67 }  // namespace json
68 }  // namespace arrow
69