Apache GraphAr C++ Library
The C++ Library for Apache GraphAr
Public Member Functions | List of all members
graphar::FileSystem Class Reference

#include <filesystem.h>

Public Member Functions

 FileSystem (std::shared_ptr< arrow::fs::FileSystem > arrow_fs)
 Create a FileSystem instance. More...
 
Result< std::shared_ptr< arrow::Table > > ReadFileToTable (const std::string &path, FileType file_type, const util::FilterOptions &options={}) const noexcept
 Read and filter a file as an arrow::Table. More...
 
template<typename T >
Result< T > ReadFileToValue (const std::string &path) const noexcept
 Read a file and convert its bytes to a value of type T. More...
 
template<typename T >
Status WriteValueToFile (const T &value, const std::string &path) const noexcept
 Write a value of type T to a file. More...
 
Status WriteTableToFile (const std::shared_ptr< arrow::Table > &table, FileType file_type, const std::string &path) const noexcept
 Write a table to a file with a specific type. More...
 
Status CopyFile (const std::string &src_path, const std::string &dst_path) const noexcept
 
Result< IdType > GetFileNumOfDir (const std::string &dir_path, bool recursive=false) const noexcept
 
template<>
Result< std::string > ReadFileToValue (const std::string &path) const noexcept
 
template<>
Status WriteValueToFile (const std::string &value, const std::string &path) const noexcept
 

Detailed Description

This class wraps an arrow::fs::FileSystem and provides methods for reading and writing arrow::Table objects from and to files, as well as performing other file system operations such as copying and counting files.

Definition at line 59 of file filesystem.h.

Constructor & Destructor Documentation

◆ FileSystem()

graphar::FileSystem::FileSystem ( std::shared_ptr< arrow::fs::FileSystem >  arrow_fs)
inlineexplicit

Create a FileSystem instance.

Parameters
arrow_fsThe arrow::fs::FileSystem to wrap.

Definition at line 65 of file filesystem.h.

Member Function Documentation

◆ CopyFile()

Status graphar::FileSystem::CopyFile ( const std::string &  src_path,
const std::string &  dst_path 
) const
noexcept

Copy a file.

If the destination exists and is a directory, an Status::ArrowError is returned. Otherwise, it is replaced.

Definition at line 259 of file filesystem.cc.

◆ GetFileNumOfDir()

Result< IdType > graphar::FileSystem::GetFileNumOfDir ( const std::string &  dir_path,
bool  recursive = false 
) const
noexcept

Get the number of file of a directory.

the file is not pure file, it can be a directory or other type of file.

Definition at line 268 of file filesystem.cc.

◆ ReadFileToTable()

Result< std::shared_ptr< arrow::Table > > graphar::FileSystem::ReadFileToTable ( const std::string &  path,
FileType  file_type,
const util::FilterOptions options = {} 
) const
noexcept

Read and filter a file as an arrow::Table.

Parameters
pathThe path of the file to read.
file_typeThe type of the file to read.
optionsRow filter and columns to be selected
Returns
A Result containing a std::shared_ptr to an arrow::Table if successful, or an error Status if unsuccessful.

Definition at line 105 of file filesystem.cc.

◆ ReadFileToValue()

template<typename T >
Result< T > graphar::FileSystem::ReadFileToValue ( const std::string &  path) const
noexcept

Read a file and convert its bytes to a value of type T.

Template Parameters
TThe type to convert the file bytes to.
Parameters
pathThe path of the file to read.
Returns
A Result containing the value if successful, or an error Status if unsuccessful.

Definition at line 168 of file filesystem.cc.

◆ WriteTableToFile()

Status graphar::FileSystem::WriteTableToFile ( const std::shared_ptr< arrow::Table > &  table,
FileType  file_type,
const std::string &  path 
) const
noexcept

Write a table to a file with a specific type.

Parameters
input_tableThe table to write.
file_typeThe type of the output file.
pathThe path of the output file.
Returns
A Status indicating OK if successful, or an error if unsuccessful.

Definition at line 213 of file filesystem.cc.

◆ WriteValueToFile()

template<typename T >
Status graphar::FileSystem::WriteValueToFile ( const T &  value,
const std::string &  path 
) const
noexcept

Write a value of type T to a file.

Template Parameters
TThe type of the value to be written.
Parameters
valueThe value to be written.
pathThe path of the file to be written
Returns
A Status indicating OK if successful, or an error if unsuccessful.

Definition at line 190 of file filesystem.cc.


The documentation for this class was generated from the following files: