#pragma once
#include <cstdint>
#include <memory>
#include <string>
#include <vector>
#include "common/api.h"
#include "common/arrow/arrow.h"
#include "main/connection.h"
namespace lbug {
enum class ArrowRelTableLayout : uint8_t { FLAT, CSR };
struct ArrowRelTableData {
ArrowRelTableLayout layout = ArrowRelTableLayout::FLAT;
ArrowSchemaWrapper schema;
std::vector<ArrowArrayWrapper> arrays;
ArrowSchemaWrapper indptrSchema;
std::vector<ArrowArrayWrapper> indptrArrays;
std::string dstColumnName = "to";
};
struct ArrowTableCreationResult {
std::unique_ptr<main::QueryResult> queryResult;
std::string arrowId;
};
class LBUG_API ArrowTableSupport {
public:
static std::string registerArrowData(ArrowSchemaWrapper schema,
std::vector<ArrowArrayWrapper> arrays);
static std::string registerArrowRelData(ArrowRelTableData data);
static bool getArrowData(const std::string& id, ArrowSchemaWrapper*& schema,
std::vector<ArrowArrayWrapper>*& arrays);
static bool getArrowRelData(const std::string& id, ArrowRelTableData*& data);
static void unregisterArrowData(const std::string& id);
static ArrowTableCreationResult createViewFromArrowTable(main::Connection& connection,
const std::string& viewName, ArrowSchemaWrapper schema,
std::vector<ArrowArrayWrapper> arrays);
static ArrowTableCreationResult createRelTableFromArrowTable(main::Connection& connection,
const std::string& tableName, const std::string& srcTableName,
const std::string& dstTableName, ArrowSchemaWrapper schema,
std::vector<ArrowArrayWrapper> arrays, const std::string& srcColumnName = "from",
const std::string& dstColumnName = "to");
static ArrowTableCreationResult createRelTableFromArrowCSR(main::Connection& connection,
const std::string& tableName, const std::string& srcTableName,
const std::string& dstTableName, ArrowSchemaWrapper indicesSchema,
std::vector<ArrowArrayWrapper> indicesArrays, ArrowSchemaWrapper indptrSchema,
std::vector<ArrowArrayWrapper> indptrArrays, const std::string& dstColumnName = "to");
static std::unique_ptr<main::QueryResult> unregisterArrowTable(main::Connection& connection,
const std::string& tableName);
};
}