![](/img/trans.png)
[英]Simplest way to read binary data from a std::vector<unsigned char>?
[英]Read CSV from std::vector<unsigned char> using Apache Arrow
我正在尝试使用 Apache 箭头读取 csv 输入格式。 这里的示例提到输入应该是InputStream ,但是在我的情况下,我只有一个 std::vector 的无符号字符。 是否可以使用 apache 箭头来解析它? 我检查了I/O 接口,看看是否有一个“内存中”数据结构没有运气。 为了方便起见,我在这里复制粘贴示例代码以及我的输入数据:
#include "arrow/csv/api.h"
{
// ...
std::vector<unsigned char> data;
arrow::io::IOContext io_context = arrow::io::default_io_context();
// how can I fit the std::vector to the input stream?
std::shared_ptr<arrow::io::InputStream> input = ...;
auto read_options = arrow::csv::ReadOptions::Defaults();
auto parse_options = arrow::csv::ParseOptions::Defaults();
auto convert_options = arrow::csv::ConvertOptions::Defaults();
// Instantiate TableReader from input stream and options
auto maybe_reader =
arrow::csv::TableReader::Make(io_context,
input,
read_options,
parse_options,
convert_options);
if (!maybe_reader.ok()) {
// Handle TableReader instantiation error...
}
std::shared_ptr<arrow::csv::TableReader> reader = *maybe_reader;
// Read table from CSV file
auto maybe_table = reader->Read();
if (!maybe_table.ok()) {
// Handle CSV read error
// (for example a CSV syntax error or failed type conversion)
}
std::shared_ptr<arrow::Table> table = *maybe_table;
}
任何帮助,将不胜感激!
I/O 接口文档列出了 BufferReader ,它用作内存输入 stream。 虽然未在文档中列出,但它可以由一个指针和一个大小构成,应该让你使用你的vector<char>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.