1
// Copyright 2016 Feather Developers
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
7
// http://www.apache.org/licenses/LICENSE-2.0
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.
15
#ifndef FEATHER_READER_H
16
#define FEATHER_READER_H
20
#include "feather/io.h"
21
#include "feather/metadata.h"
22
#include "feather/types.h"
30
Column(ColumnType::type type,
31
const std::shared_ptr<metadata::Column>& metadata,
32
const PrimitiveArray& values) :
37
const PrimitiveArray& values() const {
41
ColumnType::type type() const {
45
const std::shared_ptr<metadata::Column>& metadata() const {
49
std::string name() const {
50
return metadata_->name();
54
ColumnType::type type_;
55
std::shared_ptr<metadata::Column> metadata_;
56
PrimitiveArray values_;
59
class CategoryColumn : public Column {
61
CategoryColumn(const std::shared_ptr<metadata::Column>& metadata,
62
const PrimitiveArray& values,
63
const PrimitiveArray& levels,
64
bool ordered = false) :
65
Column(ColumnType::CATEGORY, metadata, values),
68
category_meta_ = static_cast<const metadata::CategoryColumn*>(metadata.get());
71
const PrimitiveArray& levels() const {
75
bool ordered() const {
80
const metadata::CategoryColumn* category_meta_;
81
PrimitiveArray levels_;
85
class TimestampColumn : public Column {
87
TimestampColumn(const std::shared_ptr<metadata::Column>& metadata,
88
const PrimitiveArray& values) :
89
Column(ColumnType::TIMESTAMP, metadata, values) {
90
timestamp_meta_ = static_cast<const metadata::TimestampColumn*>(metadata.get());
93
TimeUnit::type unit() const {
94
return timestamp_meta_->unit();
97
std::string timezone() const {
98
return timestamp_meta_->timezone();
102
const metadata::TimestampColumn* timestamp_meta_;
105
class DateColumn : public Column {
107
DateColumn(const std::shared_ptr<metadata::Column>& metadata,
108
const PrimitiveArray& values) :
109
Column(ColumnType::DATE, metadata, values) {
110
date_meta_ = static_cast<const metadata::DateColumn*>(metadata.get());
114
const metadata::DateColumn* date_meta_;
117
class TimeColumn : public Column {
119
TimeColumn(const std::shared_ptr<metadata::Column>& metadata,
120
const PrimitiveArray& values) :
121
Column(ColumnType::TIME, metadata, values) {
122
time_meta_ = static_cast<const metadata::TimeColumn*>(metadata.get());
125
TimeUnit::type unit() const {
126
return time_meta_->unit();
130
const metadata::TimeColumn* time_meta_;
137
Status Open(const std::shared_ptr<RandomAccessReader>& source);
139
static Status OpenFile(const std::string& abspath, std::unique_ptr<TableReader>* out);
141
// Optional table description
143
// This does not return a const std::string& because a string has to be
144
// copied from the flatbuffer to be able to return a non-flatbuffer type
145
std::string GetDescription() const;
146
bool HasDescription() const;
148
int64_t num_rows() const;
149
int64_t num_columns() const;
151
Status GetColumn(int i, std::shared_ptr<Column>* out);
154
Status GetPrimitive(std::shared_ptr<metadata::Column> col_meta,
155
std::shared_ptr<Column>* out);
156
Status GetCategory(std::shared_ptr<metadata::Column> col_meta,
157
std::shared_ptr<Column>* out);
159
Status GetTimestamp(std::shared_ptr<metadata::Column> col_meta,
160
std::shared_ptr<Column>* out);
162
Status GetTime(std::shared_ptr<metadata::Column> col_meta,
163
std::shared_ptr<Column>* out);
165
Status GetDate(std::shared_ptr<metadata::Column> col_meta,
166
std::shared_ptr<Column>* out);
168
// Retrieve a primitive array from the data source
170
// @returns: a Buffer instance, the precise type will depend on the kind of
171
// input data source (which may or may not have memory-map like semantics)
172
Status GetPrimitiveArray(const ArrayMetadata& meta, PrimitiveArray* out);
174
std::shared_ptr<RandomAccessReader> source_;
175
metadata::Table metadata_;
178
} // namespace feather
180
#endif // FEATHER_WRITER_H