Esempio n. 1
0
/**
 * garrow_writeable_flush:
 * @writeable: A #GArrowWriteable.
 * @error: (nullable): Return location for a #GError or %NULL.
 *
 * It ensures writing all data on memory to storage.
 *
 * Returns: %TRUE on success, %FALSE if there was an error.
 */
gboolean
garrow_writeable_flush(GArrowWriteable *writeable,
                          GError **error)
{
  const auto arrow_writeable = garrow_writeable_get_raw(writeable);

  auto status = arrow_writeable->Flush();
  return garrow_error_check(error, status, "[io][writeable][flush]");
}
Esempio n. 2
0
/**
 * garrow_writeable_write:
 * @writeable: A #GArrowWriteable.
 * @data: (array length=n_bytes): The data to be written.
 * @n_bytes: The number of bytes to be written.
 * @error: (nullable): Return location for a #GError or %NULL.
 *
 * Returns: %TRUE on success, %FALSE if there was an error.
 */
gboolean
garrow_writeable_write(GArrowWriteable *writeable,
                          const guint8 *data,
                          gint64 n_bytes,
                          GError **error)
{
  const auto arrow_writeable = garrow_writeable_get_raw(writeable);

  auto status = arrow_writeable->Write(data, n_bytes);
  return garrow_error_check(error, status, "[io][writeable][write]");
}
Esempio n. 3
0
/**
 * garrow_gpu_cuda_device_manager_new:
 * @error: (nullable): Return location for a #GError or %NULL.
 *
 * Returns: A newly created #GArrowGPUCUDADeviceManager on success,
 *   %NULL on error.
 *
 * Since: 0.8.0
 */
GArrowGPUCUDADeviceManager *
garrow_gpu_cuda_device_manager_new(GError **error)
{
  arrow::gpu::CudaDeviceManager *manager;
  auto status = arrow::gpu::CudaDeviceManager::GetInstance(&manager);
  if (garrow_error_check(error, status, "[gpu][cuda][device-manager][new]")) {
    auto manager = g_object_new(GARROW_GPU_TYPE_CUDA_DEVICE_MANAGER,
                                NULL);
    return GARROW_GPU_CUDA_DEVICE_MANAGER(manager);
  } else {
    return NULL;
  }
}
Esempio n. 4
0
/**
 * garrow_readable_read:
 * @readable: A #GArrowReadable.
 * @n_bytes: The number of bytes to be read.
 * @error: (nullable): Return location for a #GError or %NULL.
 *
 * Returns: (transfer full) (nullable): #GArrowBuffer that has read
 *   data on success, %NULL if there was an error.
 */
GArrowBuffer *
garrow_readable_read(GArrowReadable *readable,
                     gint64 n_bytes,
                     GError **error)
{
  const auto arrow_readable = garrow_readable_get_raw(readable);

  std::shared_ptr<arrow::Buffer> arrow_buffer;
  auto status = arrow_readable->Read(n_bytes, &arrow_buffer);
  if (garrow_error_check(error, status, "[io][readable][read]")) {
    return garrow_buffer_new_raw(&arrow_buffer);
  } else {
    return NULL;
  }
}
Esempio n. 5
0
/**
 * garrow_gpu_cuda_device_manager_get_context:
 * @manager: A #GArrowGPUCUDADeviceManager.
 * @gpu_number: A GPU device number for the target context.
 * @error: (nullable): Return location for a #GError or %NULL.
 *
 * Returns: (transfer full): A newly created #GArrowGPUCUDAContext on
 *   success, %NULL on error. Contexts for the same GPU device number
 *   share the same data internally.
 *
 * Since: 0.8.0
 */
GArrowGPUCUDAContext *
garrow_gpu_cuda_device_manager_get_context(GArrowGPUCUDADeviceManager *manager,
                                           gint gpu_number,
                                           GError **error)
{
  arrow::gpu::CudaDeviceManager *arrow_manager;
  arrow::gpu::CudaDeviceManager::GetInstance(&arrow_manager);
  std::shared_ptr<arrow::gpu::CudaContext> context;
  auto status = arrow_manager->GetContext(gpu_number, &context);
  if (garrow_error_check(error, status,
                         "[gpu][cuda][device-manager][get-context]]")) {
    return garrow_gpu_cuda_context_new_raw(&context);
  } else {
    return NULL;
  }
}
Esempio n. 6
0
/**
 * garrow_output_stream_write_tensor:
 * @stream: A #GArrowWriteable.
 * @tensor: A #GArrowTensor to be written.
 * @error: (nullable): Return location for a #GError or %NULL.
 *
 * Returns: The number of written bytes on success, -1 on error.
 *
 * Since: 0.4.0
 */
gint64
garrow_output_stream_write_tensor(GArrowOutputStream *stream,
                                  GArrowTensor *tensor,
                                  GError **error)
{
  auto arrow_tensor = garrow_tensor_get_raw(tensor);
  auto arrow_stream = garrow_output_stream_get_raw(stream);
  int32_t metadata_length;
  int64_t body_length;
  auto status = arrow::ipc::WriteTensor(*arrow_tensor,
                                        arrow_stream.get(),
                                        &metadata_length,
                                        &body_length);
  if (garrow_error_check(error, status, "[output-stream][write-tensor]")) {
    return metadata_length + body_length;
  } else {
    return -1;
  }
}
Esempio n. 7
0
/**
 * garrow_file_output_stream_new:
 * @path: The path of the file output stream.
 * @append: Whether the path is opened as append mode or recreate mode.
 * @error: (nullable): Return location for a #GError or %NULL.
 *
 * Returns: (nullable): A newly opened #GArrowFileOutputStream or
 *   %NULL on error.
 */
GArrowFileOutputStream *
garrow_file_output_stream_new(const gchar *path,
                              gboolean append,
                              GError **error)
{
  std::shared_ptr<arrow::io::FileOutputStream> arrow_file_output_stream;
  auto status =
    arrow::io::FileOutputStream::Open(std::string(path),
                                      append,
                                      &arrow_file_output_stream);
  if (status.ok()) {
    return garrow_file_output_stream_new_raw(&arrow_file_output_stream);
  } else {
    std::string context("[io][file-output-stream][open]: <");
    context += path;
    context += ">";
    garrow_error_check(error, status, context.c_str());
    return NULL;
  }
}