#pragma once
#include <cudf/table/table.hpp>
#include <cudf/table/table_view.hpp>
#include <cudf/copying.hpp>
#include <cudf/io/types.hpp>
#include <memory>
#include <string>
#include <vector>
#include "rust/cxx.h"
#include "column_shim.h"
namespace cudf_shims {
struct OwnedTable {
std::unique_ptr<cudf::table> inner;
std::vector<std::unique_ptr<cudf::column>> released_columns;
bool released = false;
explicit OwnedTable(std::unique_ptr<cudf::table> tbl)
: inner(std::move(tbl)) {}
int32_t num_columns() const {
if (released) return static_cast<int32_t>(released_columns.size());
return inner->num_columns();
}
int32_t num_rows() const {
if (released) return 0;
return inner->view().num_rows();
}
cudf::table_view view() const {
if (released) throw std::runtime_error("table already released");
return inner->view();
}
void ensure_released() {
if (!released) {
released_columns = inner->release();
released = true;
}
}
};
struct OwnedTableWithMetadata {
std::unique_ptr<cudf::table> table;
std::vector<std::string> column_names;
OwnedTableWithMetadata(std::unique_ptr<cudf::table> tbl,
std::vector<std::string> names)
: table(std::move(tbl)), column_names(std::move(names)) {}
int32_t num_columns() const {
return static_cast<int32_t>(column_names.size());
}
};
struct TableBuilder {
std::vector<std::unique_ptr<cudf::column>> columns;
void add_column(std::unique_ptr<OwnedColumn> col) {
if (!col) {
throw std::runtime_error("Null column pointer in TableBuilder::add_column");
}
columns.push_back(std::move(col->inner));
}
std::unique_ptr<OwnedTable> build() {
auto table = std::make_unique<cudf::table>(std::move(columns));
columns.clear();
return std::make_unique<OwnedTable>(std::move(table));
}
};
std::unique_ptr<TableBuilder> table_builder_new();
std::unique_ptr<OwnedColumn> table_get_column(
const OwnedTable& table, int32_t index);
std::unique_ptr<OwnedColumn> table_release_column(
OwnedTable& table, int32_t index);
int32_t table_meta_num_columns(const OwnedTableWithMetadata& meta);
rust::String table_meta_column_name(const OwnedTableWithMetadata& meta, int32_t index);
std::unique_ptr<OwnedTable> table_meta_into_table(std::unique_ptr<OwnedTableWithMetadata> meta);
}