Skip to content

Commit

Permalink
remove sample
Browse files Browse the repository at this point in the history
  • Loading branch information
WillAyd committed Jan 18, 2024
1 parent 12eb2f4 commit 39653d8
Showing 1 changed file with 1 addition and 48 deletions.
49 changes: 1 addition & 48 deletions pantab/src/pantab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,57 +748,10 @@ auto read_from_hyper_query(const std::string &path, const std::string &query)
return result;
}

auto get_sample_capsule() -> nb::capsule {
auto schema = std::unique_ptr<struct ArrowSchema>{new (struct ArrowSchema)};

ArrowSchemaInit(schema.get());
if (ArrowSchemaSetTypeStruct(schema.get(), 1)) {
throw std::runtime_error("ArrowSchemaSetTypeStruct failed");
}
if (ArrowSchemaSetType(schema->children[0], NANOARROW_TYPE_INT32)) {
throw std::runtime_error("ArrowSchemaSetType failed");
}

if (ArrowSchemaSetName(schema->children[0], "int_column")) {
throw std::runtime_error("ArrowSchemaSetName failed");
}

auto array = std::unique_ptr<struct ArrowArray>{new (struct ArrowArray)};
if (ArrowArrayInitFromSchema(array.get(), schema.get(), nullptr)) {
throw std::runtime_error("ArrowSchemaInitFromSchema failed");
}
if (ArrowArrayStartAppending(array.get())) {
throw std::runtime_error("ArrowArrayStartAppending failed");
}
for (auto i : {1, 2, 4, 8}) {
if (ArrowArrayAppendInt(array->children[0], i)) {
throw std::runtime_error("ArrowArrayAppendInt failed");
}
if (ArrowArrayFinishElement(array.get())) {
throw std::runtime_error("ArrowArrayFinishElement failed");
}
}
if (ArrowArrayFinishBuildingDefault(array.get(), nullptr)) {
throw std::runtime_error("ArrowArrayFinishBuildingDefault failed");
}

auto stream =
(struct ArrowArrayStream *)malloc(sizeof(struct ArrowArrayStream));
if (ArrowBasicArrayStreamInit(stream, schema.get(), 1)) {
free(stream);
throw std::runtime_error("ArrowBasicArrayStreamInit failed");
}
ArrowBasicArrayStreamSetArray(stream, 0, array.get());

nb::capsule result{stream, "arrow_array_stream", &releaseArrowStream};
return result;
}

NB_MODULE(pantab, m) { // NOLINT
m.def("write_to_hyper", &write_to_hyper, nb::arg("dict_of_exportable"),
nb::arg("path"), nb::arg("table_mode"))
.def("read_from_hyper_query", &read_from_hyper_query, nb::arg("path"),
nb::arg("query"))
.def("get_sample_capsule", &get_sample_capsule);
nb::arg("query"));
PyDateTime_IMPORT;
}

0 comments on commit 39653d8

Please sign in to comment.