~ubuntu-branches/debian/sid/python-feather-format/sid

« back to all changes in this revision

Viewing changes to src/feather/writer.h

  • Committer: Package Import Robot
  • Author(s): ChangZhuo Chen (陳昌倬)
  • Date: 2016-03-30 19:01:30 UTC
  • Revision ID: package-import@ubuntu.com-20160330190130-b7o770i7o2drepi1
Tags: upstream-0.1.0
Import upstream version 0.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2016 Feather Developers
 
2
//
 
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
 
6
//
 
7
// http://www.apache.org/licenses/LICENSE-2.0
 
8
//
 
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.
 
14
 
 
15
#ifndef FEATHER_WRITER_H
 
16
#define FEATHER_WRITER_H
 
17
 
 
18
#include <memory>
 
19
#include <string>
 
20
 
 
21
#include "feather/io.h"
 
22
#include "feather/metadata.h"
 
23
#include "feather/types.h"
 
24
 
 
25
namespace feather {
 
26
 
 
27
class TableWriter {
 
28
 public:
 
29
  TableWriter();
 
30
 
 
31
  Status Open(const std::shared_ptr<OutputStream>& stream);
 
32
  static Status OpenFile(const std::string& abspath,
 
33
      std::unique_ptr<TableWriter>* out);
 
34
 
 
35
  void SetDescription(const std::string& desc);
 
36
  void SetNumRows(int64_t num_rows);
 
37
 
 
38
  // Plain-encoded data
 
39
  Status AppendPlain(const std::string& name, const PrimitiveArray& values);
 
40
 
 
41
  // Dictionary-encoded primitive data. Especially useful for strings and
 
42
  // binary data
 
43
  void AppendDictEncoded(const std::string& name, const DictEncodedArray& data);
 
44
 
 
45
  // Category type data
 
46
  Status AppendCategory(const std::string& name, const PrimitiveArray& values,
 
47
      const PrimitiveArray& levels, bool ordered = false);
 
48
 
 
49
  // Other primitive data types
 
50
  Status AppendTimestamp(const std::string& name, const PrimitiveArray& values,
 
51
      const TimestampMetadata& meta);
 
52
 
 
53
  Status AppendDate(const std::string& name, const PrimitiveArray& values);
 
54
 
 
55
  Status AppendTime(const std::string& name, const PrimitiveArray& values,
 
56
      const TimeMetadata& meta);
 
57
 
 
58
  // We are done, write the file metadata and footer
 
59
  Status Finalize();
 
60
 
 
61
 private:
 
62
  Status Init();
 
63
 
 
64
  std::shared_ptr<OutputStream> stream_;
 
65
 
 
66
  bool initialized_stream_;
 
67
  metadata::TableBuilder metadata_;
 
68
 
 
69
  Status AppendPrimitive(const PrimitiveArray& values, ArrayMetadata* out);
 
70
};
 
71
 
 
72
} // namespace feather
 
73
 
 
74
#endif // FEATHER_WRITER_H