1

I am trying to readapt this piece of code of the parquet C++ documentation to open a parquet file with a FileReader to get the minimum value of a column.

arrow::MemoryPool* pool = arrow::default_memory_pool();
std::shared_ptr<arrow::io::RandomAccessFile> input;
ARROW_ASSIGN_OR_RAISE(input, arrow::io::ReadableFile::Open(path_to_file));

// Open Parquet file reader
std::unique_ptr<parquet::arrow::FileReader> arrow_reader;
ARROW_RETURN_NOT_OK(parquet::arrow::OpenFile(input, pool, &arrow_reader));

// Read entire file as a single Arrow table
std::shared_ptr<arrow::Table> table;
ARROW_RETURN_NOT_OK(arrow_reader->ReadTable(&table));

However, the macro ARROW_ASSIGN_OR_RAISE_ERROR is causing the error:

error: cannot convert 'const arrow::Status' to 'int' in return

   27 |    ARROW_ASSIGN_OR_RAISE(input, arrow::io::ReadableFile::Open(parquet_path.c_str()));
      |    ^
      |    |
      |    const arrow::Status

The macro documentation says:

Execute an expression that returns a Result, extracting its value into the variable defined by lhs (or returning a Status on error).

So I tried to do the passages explicitly separating the initialisation from the declaration, something like:

std::shared_ptr<arrow::io::RandomAccessFile> input(nullptr);
input = std::make_shared<arrow::io::RandomAccessFile>(arrow::io::ReadableFile::Open(parquet_path.c_str()));
   

but I am getting the error

error: invalid new-expression of abstract class type 'arrow::io::RandomAccessFile'
  146 |  { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }

How can I initialize the shared pointer of arrow::io::RandomAccessFile after the declaration?

roschach
  • 8,390
  • 14
  • 74
  • 124

1 Answers1

2

You don't need std::make_shared, arrow::io::ReadableFile::Open() returns a shared pointer.

std::shared_ptr<arrow::io::RandomAccessFile> input =
    arrow::io::ReadableFile::Open(parquet_path.c_str()).ValueOrDie();
273K
  • 29,503
  • 10
  • 41
  • 64
  • In this case I am getting `error: conversion from 'arrow::Result >' to non-scalar type 'std::shared_ptr' requested 19 | arrow::io::ReadableFile::Open(parquet_path.c_str())` – roschach Feb 19 '23 at 17:16
  • Oh I need `*.ValueOrDie()` right? – roschach Feb 19 '23 at 17:19
  • I likely used an obsolete manual. Yes, as for the actual [manual](https://arrow.apache.org/docs/cpp/api/io.html#_CPPv4N5arrow2io12ReadableFile4OpenERKNSt6stringEP10MemoryPool), it returns a tuple `Result`. – 273K Feb 19 '23 at 17:20
  • Can you please paste the reference to the manual? I am having some difficulties finding C++ documentation on arrow – roschach Feb 19 '23 at 17:24