OmniSciDB  b24e664e58
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ArrowResultSet Class Reference

#include <ArrowResultSet.h>

Public Member Functions

 ArrowResultSet (const std::shared_ptr< ResultSet > &rows, const std::vector< TargetMetaInfo > &targets_meta)
 
 ArrowResultSet (const std::shared_ptr< ResultSet > &rows)
 
std::vector< TargetValuegetNextRow (const bool translate_strings, const bool decimal_to_double) const
 
size_t colCount () const
 
SQLTypeInfo getColType (const size_t col_idx) const
 
bool definitelyHasNoRows () const
 
size_t rowCount () const
 

Static Public Member Functions

static void deallocateArrowResultBuffer (const ArrowResult &result, const ExecutorDeviceType device_type, const size_t device_id, std::shared_ptr< Data_Namespace::DataMgr > &data_mgr)
 

Private Member Functions

void resultSetArrowLoopback ()
 
template<typename Type , typename ArrayType >
void appendValue (std::vector< TargetValue > &row, const arrow::Array &column, const Type null_val, const size_t idx) const
 

Private Attributes

std::shared_ptr< ResultSetrows_
 
std::vector< TargetMetaInfotargets_meta_
 
std::shared_ptr
< arrow::RecordBatch > 
record_batch_
 
std::vector< std::shared_ptr
< arrow::Array > > 
columns_
 
size_t crt_row_idx_
 
std::vector< TargetMetaInfocolumn_metainfo_
 

Detailed Description

Definition at line 89 of file ArrowResultSet.h.

Constructor & Destructor Documentation

ArrowResultSet::ArrowResultSet ( const std::shared_ptr< ResultSet > &  rows,
const std::vector< TargetMetaInfo > &  targets_meta 
)

Definition at line 71 of file ArrowResultSet.cpp.

References column_metainfo_, columns_, field(), record_batch_, resultSetArrowLoopback(), and anonymous_namespace{ArrowResultSet.cpp}::type_from_arrow_field().

73  : rows_(rows), targets_meta_(targets_meta), crt_row_idx_(0) {
75  auto schema = record_batch_->schema();
76  for (int i = 0; i < schema->num_fields(); ++i) {
77  std::shared_ptr<arrow::Field> field = schema->field(i);
78  SQLTypeInfo type_info = type_from_arrow_field(*schema->field(i));
79  column_metainfo_.emplace_back(field->name(), type_info);
80  columns_.emplace_back(record_batch_->column(i));
81  }
82 }
std::shared_ptr< ResultSet > rows_
SQLTypeInfo type_from_arrow_field(const arrow::Field &field)
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
std::vector< TargetMetaInfo > column_metainfo_
void resultSetArrowLoopback()
std::shared_ptr< arrow::RecordBatch > record_batch_
std::vector< TargetMetaInfo > targets_meta_
std::vector< std::shared_ptr< arrow::Array > > columns_

+ Here is the call graph for this function:

ArrowResultSet::ArrowResultSet ( const std::shared_ptr< ResultSet > &  rows)
inline

Definition at line 93 of file ArrowResultSet.h.

93 : ArrowResultSet(rows, {}) {}
ArrowResultSet(const std::shared_ptr< ResultSet > &rows, const std::vector< TargetMetaInfo > &targets_meta)

Member Function Documentation

template<typename Type , typename ArrayType >
void ArrowResultSet::appendValue ( std::vector< TargetValue > &  row,
const arrow::Array &  column,
const Type  null_val,
const size_t  idx 
) const
private

Definition at line 85 of file ArrowResultSet.cpp.

88  {
89  const auto& col = static_cast<const ArrayType&>(column);
90  row.emplace_back(col.IsNull(idx) ? null_val : static_cast<Type>(col.Value(idx)));
91 }
size_t ArrowResultSet::colCount ( ) const

Definition at line 190 of file ArrowResultSet.cpp.

References column_metainfo_.

190  {
191  return column_metainfo_.size();
192 }
std::vector< TargetMetaInfo > column_metainfo_
void ArrowResultSet::deallocateArrowResultBuffer ( const ArrowResult result,
const ExecutorDeviceType  device_type,
const size_t  device_id,
std::shared_ptr< Data_Namespace::DataMgr > &  data_mgr 
)
static

Definition at line 550 of file ArrowResultSetConverter.cpp.

References CHECK(), CHECK_EQ, CPU, ArrowResult::df_dev_ptr, ArrowResult::df_handle, ArrowResult::df_size, GPU, ArrowResult::sm_handle, ArrowResult::sm_size, and to_string().

Referenced by MapDHandler::deallocate_df().

554  {
555  // Remove shared memory on sysmem
556  CHECK_EQ(sizeof(key_t), result.sm_handle.size());
557  const key_t& schema_key = *(key_t*)(&result.sm_handle[0]);
558  auto shm_id = shmget(schema_key, result.sm_size, 0666);
559  if (shm_id < 0) {
560  throw std::runtime_error(
561  "failed to get an valid shm ID w/ given shm key of the schema");
562  }
563  if (-1 == shmctl(shm_id, IPC_RMID, 0)) {
564  throw std::runtime_error("failed to deallocate Arrow schema on errorno(" +
565  std::to_string(errno) + ")");
566  }
567 
568  if (device_type == ExecutorDeviceType::CPU) {
569  CHECK_EQ(sizeof(key_t), result.df_handle.size());
570  const key_t& df_key = *(key_t*)(&result.df_handle[0]);
571  auto shm_id = shmget(df_key, result.df_size, 0666);
572  if (shm_id < 0) {
573  throw std::runtime_error(
574  "failed to get an valid shm ID w/ given shm key of the data");
575  }
576  if (-1 == shmctl(shm_id, IPC_RMID, 0)) {
577  throw std::runtime_error("failed to deallocate Arrow data frame");
578  }
579  return;
580  }
581 
582  CHECK(device_type == ExecutorDeviceType::GPU);
583  if (!result.df_dev_ptr) {
584  throw std::runtime_error("null pointer to data frame on device");
585  }
586 
587  data_mgr->getCudaMgr()->freeDeviceMem(result.df_dev_ptr);
588 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
std::vector< char > sm_handle
std::string to_string(char const *&&v)
CHECK(cgen_state)
int8_t * df_dev_ptr
std::vector< char > df_handle
int64_t sm_size
int64_t df_size

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ArrowResultSet::definitelyHasNoRows ( ) const

Definition at line 199 of file ArrowResultSet.cpp.

References rowCount().

199  {
200  return !rowCount();
201 }
size_t rowCount() const

+ Here is the call graph for this function:

SQLTypeInfo ArrowResultSet::getColType ( const size_t  col_idx) const

Definition at line 194 of file ArrowResultSet.cpp.

References CHECK_LT, and column_metainfo_.

194  {
195  CHECK_LT(col_idx, column_metainfo_.size());
196  return column_metainfo_[col_idx].get_type_info();
197 }
#define CHECK_LT(x, y)
Definition: Logger.h:200
std::vector< TargetMetaInfo > column_metainfo_
std::vector< TargetValue > ArrowResultSet::getNextRow ( const bool  translate_strings,
const bool  decimal_to_double 
) const

Definition at line 179 of file ArrowResultSet.cpp.

References CHECK_LT, crt_row_idx_, and rowCount().

180  {
181  if (crt_row_idx_ == rowCount()) {
182  return {};
183  }
185  auto row = getRowAt(crt_row_idx_);
186  ++crt_row_idx_;
187  return row;
188 }
size_t rowCount() const
#define CHECK_LT(x, y)
Definition: Logger.h:200

+ Here is the call graph for this function:

void ArrowResultSet::resultSetArrowLoopback ( )
private

Definition at line 207 of file ArrowResultSet.cpp.

References ARROW_THROW_NOT_OK, CHECK_EQ, record_batch_, rows_, targets_meta_, and to_string().

Referenced by ArrowResultSet().

207  {
208  std::vector<std::string> col_names;
209 
210  if (!targets_meta_.empty()) {
211  for (auto& meta : targets_meta_) {
212  col_names.push_back(meta.get_resname());
213  }
214  } else {
215  for (unsigned int i = 0; i < rows_->colCount(); i++) {
216  col_names.push_back("col_" + std::to_string(i));
217  }
218  }
219  const auto converter = ArrowResultSetConverter(rows_, col_names, -1);
220  const auto serialized_arrow_output = converter.getSerializedArrowOutput();
221 
222  arrow::io::BufferReader schema_reader(serialized_arrow_output.schema);
223 
224  std::shared_ptr<arrow::Schema> schema;
225  ARROW_THROW_NOT_OK(arrow::ipc::ReadSchema(&schema_reader, &schema));
226 
227  arrow::io::BufferReader records_reader(serialized_arrow_output.records);
229  arrow::ipc::ReadRecordBatch(schema, &records_reader, &record_batch_));
230 
231  CHECK_EQ(schema->num_fields(), record_batch_->num_columns());
232 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
#define ARROW_THROW_NOT_OK(s)
Definition: ArrowUtil.h:28
std::shared_ptr< ResultSet > rows_
std::string to_string(char const *&&v)
std::shared_ptr< arrow::RecordBatch > record_batch_
std::vector< TargetMetaInfo > targets_meta_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t ArrowResultSet::rowCount ( ) const

Definition at line 203 of file ArrowResultSet.cpp.

References record_batch_.

Referenced by definitelyHasNoRows(), and getNextRow().

203  {
204  return record_batch_->num_rows();
205 }
std::shared_ptr< arrow::RecordBatch > record_batch_

+ Here is the caller graph for this function:

Member Data Documentation

std::vector<TargetMetaInfo> ArrowResultSet::column_metainfo_
private

Definition at line 146 of file ArrowResultSet.h.

Referenced by ArrowResultSet(), colCount(), and getColType().

std::vector<std::shared_ptr<arrow::Array> > ArrowResultSet::columns_
private

Definition at line 144 of file ArrowResultSet.h.

Referenced by ArrowResultSet().

size_t ArrowResultSet::crt_row_idx_
mutableprivate

Definition at line 145 of file ArrowResultSet.h.

Referenced by getNextRow().

std::shared_ptr<arrow::RecordBatch> ArrowResultSet::record_batch_
private

Definition at line 140 of file ArrowResultSet.h.

Referenced by ArrowResultSet(), resultSetArrowLoopback(), and rowCount().

std::shared_ptr<ResultSet> ArrowResultSet::rows_
private

Definition at line 138 of file ArrowResultSet.h.

Referenced by resultSetArrowLoopback().

std::vector<TargetMetaInfo> ArrowResultSet::targets_meta_
private

Definition at line 139 of file ArrowResultSet.h.

Referenced by resultSetArrowLoopback().


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