forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 3
/
column.h
103 lines (83 loc) · 2.72 KB
/
column.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
#ifndef ARROW_TABLE_COLUMN_H
#define ARROW_TABLE_COLUMN_H
#include <memory>
#include <string>
#include <vector>
#include "arrow/array.h"
#include "arrow/field.h"
namespace arrow {
typedef std::vector<std::shared_ptr<Array> > ArrayVector;
// A data structure managing a list of primitive Arrow arrays logically as one
// large array
class ChunkedArray {
public:
explicit ChunkedArray(const ArrayVector& chunks);
// @returns: the total length of the chunked array; computed on construction
int64_t length() const {
return length_;
}
int64_t null_count() const {
return null_count_;
}
int num_chunks() const {
return chunks_.size();
}
const std::shared_ptr<Array>& chunk(int i) const {
return chunks_[i];
}
protected:
ArrayVector chunks_;
int64_t length_;
int64_t null_count_;
};
// An immutable column data structure consisting of a field (type metadata) and
// a logical chunked data array (which can be validated as all being the same
// type).
class Column {
public:
Column(const std::shared_ptr<Field>& field, const ArrayVector& chunks);
Column(const std::shared_ptr<Field>& field,
const std::shared_ptr<ChunkedArray>& data);
int64_t length() const {
return data_->length();
}
int64_t null_count() const {
return data_->null_count();
}
// @returns: the column's name in the passed metadata
const std::string& name() const {
return field_->name;
}
// @returns: the column's type according to the metadata
const std::shared_ptr<DataType>& type() const {
return field_->type;
}
// @returns: the column's data as a chunked logical array
const std::shared_ptr<ChunkedArray>& data() const {
return data_;
}
// Verify that the column's array data is consistent with the passed field's
// metadata
Status ValidateData();
protected:
std::shared_ptr<Field> field_;
std::shared_ptr<ChunkedArray> data_;
};
} // namespace arrow
#endif // ARROW_TABLE_COLUMN_H