首页 > 解决方案 > 在 C++ 中使用 Apache Arrow 打开 CSV 文件

问题描述

我正在尝试使用 Apache Arrow 读取 csv 文件,但我无法理解 InputStream ......看来他们文档中的示例已经过时了。

我对示例进行了一些调整,但出现“访问冲突读取位置”异常。知道我在做什么错吗?

谢谢

我的代码:

    arrow::MemoryPool* pool = arrow::default_memory_pool();

    std::shared_ptr<arrow::io::ReadableFile> infile;
    infile->Open("test.csv", pool);     

    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
    std::shared_ptr<arrow::csv::StreamingReader> reader;
    auto res1 = reader->Make(pool, infile, read_options, parse_options, convert_options);
    if (!res1.ok()) {
        // Handle TableReader instantiation error...
    }

    std::shared_ptr<arrow::Table> table;
    // Read table from CSV file
    
    auto res2 = reader->ReadAll(&table);
    if (!res2.ok()) {
        // Handle CSV read error
        // (for example a CSV syntax error or failed type conversion)
    }

标签: c++csvapache-arrow

解决方案


推荐阅读