#pragma once
#include <mutex>
#include <vector>
#include "catalog/catalog_entry/node_table_catalog_entry.h"
#include "common/exception/runtime.h"
#include "common/mask.h"
#include "common/types/internal_id_util.h"
#include "storage/table/node_table.h"
namespace lbug {
namespace storage {
struct ColumnarNodeTableScanState : NodeTableScanState {
bool initialized = false; size_t totalRows = 0;
bool scanCompleted = false;
ColumnarNodeTableScanState([[maybe_unused]] MemoryManager& mm,
common::ValueVector* nodeIDVector, std::vector<common::ValueVector*> outputVectors,
std::shared_ptr<common::DataChunkState> outChunkState)
: NodeTableScanState{nodeIDVector, std::move(outputVectors), std::move(outChunkState)} {}
};
struct ColumnarNodeTableScanSharedState {
virtual ~ColumnarNodeTableScanSharedState() = default;
virtual bool getNextMorsel(ColumnarNodeTableScanState* scanState) = 0;
};
class ColumnarNodeTableBase : public NodeTable {
public:
ColumnarNodeTableBase(const StorageManager* storageManager,
const catalog::NodeTableCatalogEntry* nodeTableEntry, MemoryManager* memoryManager,
std::unique_ptr<ColumnarNodeTableScanSharedState> tableScanSharedState)
: NodeTable{storageManager, nodeTableEntry, memoryManager},
nodeTableCatalogEntry{nodeTableEntry},
tableScanSharedState{std::move(tableScanSharedState)} {}
virtual ~ColumnarNodeTableBase() = default;
void insert([[maybe_unused]] transaction::Transaction* transaction,
[[maybe_unused]] TableInsertState& insertState) final {
throw common::RuntimeException(
"Cannot insert into " + getColumnarFormatName() + "-backed node table");
}
void update([[maybe_unused]] transaction::Transaction* transaction,
[[maybe_unused]] TableUpdateState& updateState) final {
throw common::RuntimeException(
"Cannot update " + getColumnarFormatName() + "-backed node table");
}
bool delete_([[maybe_unused]] transaction::Transaction* transaction,
[[maybe_unused]] TableDeleteState& deleteState) final {
throw common::RuntimeException(
"Cannot delete from " + getColumnarFormatName() + "-backed node table");
return false;
}
common::row_idx_t getNumTotalRows(const transaction::Transaction* transaction) override;
protected:
const catalog::NodeTableCatalogEntry* nodeTableCatalogEntry;
mutable std::unique_ptr<ColumnarNodeTableScanSharedState> tableScanSharedState;
virtual std::string getColumnarFormatName() const = 0;
virtual common::node_group_idx_t getNumBatches(
const transaction::Transaction* transaction) const = 0;
virtual common::row_idx_t getTotalRowCount(
const transaction::Transaction* transaction) const = 0;
std::string constructStoragePath(const std::string& prefix, const std::string& suffix) const {
std::string tableName = nodeTableCatalogEntry->getName();
return prefix + "_nodes_" + tableName + suffix;
}
public:
ColumnarNodeTableScanSharedState* getTableScanSharedState() const {
return tableScanSharedState.get();
}
};
} }