Petastorm C++ API
I wasn't able to find any past issues relating to this. Has there been any discussion on adding a C++ API to Petastorm? Obviously a significant undertaking, but I can't be the only one who'd like to be able to write Unischema parquet tables directly in C++.
"Yes, we'd love this, please implement it!" is a valid response :) Was curious and couldn't find any info, so figured I'd at least start a thread.
Can you elaborate, how would you use a c++ interface? The most common usage of petastorm is using it to read data from parquet into a deep learning framework (pytorch/tensorflow). These both are python frameworks that require a python API to read data. I wonder if there is another scenario that you had in mind for a c++ API?
If I understand correctly, Petastorm's Unischema can be used to write, for example, numpy tensors to parquet tables with a defined encoding, forming a dataset. I'm thinking of writing this dataset in C++ but reading it in python for training.
#include <petastorm/unischema.h>
// Just as an example, could use e.g. Eigen::Tensor or xtensor, etc.
#include <torch/torch.h>
void write_dataset(const std::vector<torch::Tensor>& xs, const std::string& path) {
// let's assume: assume: xs[0].dim() == 4, shape == (2,3,4,5), dtype == float
const Petastorm::Unischema my_schema("MySchema",
{Petastorm::UnischemaField("array_4d", float, xs[0].size(), Petastorm::Unischema::NdarrayCodec, False});
const Petastorm::DatasetWriter writer(path, my_schema);
for (const auto& x : xs) {
writer.write("array_4d", x);
}
writer.write();
}
On the python side I see Petastorm uses PySpark to do the dataset writing, so maybe the library isn't in the dataset creation business, just in the Parquet schema definition business. At any rate, I'm essentially just looking for a way to create Unischema parquet tables in C++. If there's a better/easier way, I'm all ears.
Forgive any ignorance, fairly new to Big Data.
Frankly, I am not sure how much of the Unischema and ndarrays features of petastorm are used by the community. I feel that just reading existing parquet files written by non-petastorm writers have more value, but I don't have a solid gauge on the number of folks that actually writing datasets with petastorm.
If that's the case, then native parquet types (including lists of values (i.e. 1D vectors)) are sufficient. Using standard arrow C++ API for writing these parquet files should suffice.
So long story short, what you are proposing is possible, not trivial to implement and not sure if has much benefit to commuity over standard arrow parquet writing C++ API.
Sounds good, I will close the ticket then.
After some further research, I did notice that Arrow has a tensor representation. The documentation isn't that detailed and unfortunately provides no examples, and I haven't dived into the source, but it might provide the tensor-to-parquet serialization I'm looking for since Arrow has to-parquet tools for other types.
Thanks for the reply and explanation!