-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpyarrow_bind.cpp
More file actions
27 lines (20 loc) · 946 Bytes
/
pyarrow_bind.cpp
File metadata and controls
27 lines (20 loc) · 946 Bytes
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
#include "pyarrow/pyarrow_bind.h"
#include "cached_import/py_cached_import.h"
#include "common/arrow/arrow.h"
#include "common/arrow/arrow_converter.h"
namespace lbug {
std::shared_ptr<ArrowSchemaWrapper> Pyarrow::bind(py::handle tableToBind,
std::vector<common::LogicalType>& returnTypes, std::vector<std::string>& names) {
std::shared_ptr<ArrowSchemaWrapper> schema = std::make_shared<ArrowSchemaWrapper>();
auto pyschema = tableToBind.attr("schema");
auto exportSchemaToC = pyschema.attr("_export_to_c");
exportSchemaToC(reinterpret_cast<uint64_t>(schema.get()));
for (int64_t i = 0; i < schema->n_children; i++) {
ArrowSchema* child = schema->children[i];
names.emplace_back(child->name);
returnTypes.push_back(common::LogicalTypeUtils::purgeAny(
common::ArrowConverter::fromArrowSchema(child), common::LogicalType::STRING()));
}
return schema;
}
} // namespace lbug