Apache Arrow (C++)
A columnar in-memory analytics layer designed to accelerate big data.
table_builder.h
Go to the documentation of this file.
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_TABLE_BUILDER_H
19 #define ARROW_TABLE_BUILDER_H
20 
21 #include <cstdint>
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 #include "arrow/status.h"
27 #include "arrow/type.h"
29 #include "arrow/util/visibility.h"
30 
31 namespace arrow {
32 
33 class ArrayBuilder;
34 class MemoryPool;
35 class RecordBatch;
36 class Schema;
37 
42  public:
47  static Status Make(const std::shared_ptr<Schema>& schema, MemoryPool* pool,
48  std::unique_ptr<RecordBatchBuilder>* builder);
49 
55  static Status Make(const std::shared_ptr<Schema>& schema, MemoryPool* pool,
56  int64_t initial_capacity,
57  std::unique_ptr<RecordBatchBuilder>* builder);
58 
62  ArrayBuilder* GetField(int i) { return raw_field_builders_[i]; }
63 
67  template <typename T>
68  T* GetFieldAs(int i) {
69  return checked_cast<T*>(raw_field_builders_[i]);
70  }
71 
76  Status Flush(bool reset_builders, std::shared_ptr<RecordBatch>* batch);
77 
81  Status Flush(std::shared_ptr<RecordBatch>* batch);
82 
84  void SetInitialCapacity(int64_t capacity);
85 
87  int64_t initial_capacity() const { return initial_capacity_; }
88 
90  int num_fields() const { return schema_->num_fields(); }
91 
93  std::shared_ptr<Schema> schema() const { return schema_; }
94 
95  private:
96  RecordBatchBuilder(const std::shared_ptr<Schema>& schema, MemoryPool* pool,
97  int64_t initial_capacity);
98 
99  Status CreateBuilders();
100  Status InitBuilders();
101 
102  std::shared_ptr<Schema> schema_;
103  int64_t initial_capacity_;
104  MemoryPool* pool_;
105 
106  std::vector<std::unique_ptr<ArrayBuilder>> field_builders_;
107  std::vector<ArrayBuilder*> raw_field_builders_;
108 };
109 
110 } // namespace arrow
111 
112 #endif // ARROW_TABLE_BUILDER_H
T * GetFieldAs(int i)
Return field builder casted to indicated specific builder type.
Definition: table_builder.h:68
int64_t initial_capacity() const
The initial capacity for builders.
Definition: table_builder.h:87
Base class for all data array builders.
Definition: builder.h:60
Definition: status.h:93
ArrayBuilder * GetField(int i)
Get base pointer to field builder.
Definition: table_builder.h:62
Status Flush(bool reset_builders, std::shared_ptr< RecordBatch > *batch)
Finish current batch and optionally reset.
Helper class for creating record batches iteratively given a known schema.
Definition: table_builder.h:41
Top-level namespace for Apache Arrow C++ API.
Definition: adapter.h:32
static Status Make(const std::shared_ptr< Schema > &schema, MemoryPool *pool, std::unique_ptr< RecordBatchBuilder > *builder)
Create an initialize a RecordBatchBuilder.
std::shared_ptr< Schema > schema() const
The number of fields in the schema.
Definition: table_builder.h:93
OutputType checked_cast(InputType &&value)
Definition: checked_cast.h:26
Base class for memory allocation.
Definition: memory_pool.h:34
int num_fields() const
The number of fields in the schema.
Definition: table_builder.h:90
void SetInitialCapacity(int64_t capacity)
Set the initial capacity for new builders.