#pragma once #include "index.h" #include "parser.h" #include "row.h" #include #include namespace usql { struct Table { Table(const Table &other); Table(const std::string& name, const std::vector& columns); ColDefNode get_column_def(const std::string &col_name); ColDefNode get_column_def(int col_index); [[nodiscard]] int columns_count() const { return (int) m_col_defs.size(); }; [[nodiscard]] size_t rows_count() const { return m_rows.size(); }; [[nodiscard]] size_t get_rowid(const Row &row) const; Row &create_empty_row(); void commit_row(Row &row); void commit_copy_of_row(Row &row); static void validate_column(const ColDefNode *col_def, ValueNode *col_val); static void validate_column(const ColDefNode *col_def, ColValue &col_val); void validate_row(Row &row); std::string csv_string(); int load_csv_string(const std::string &content); int load_csv_file(const std::string &filename); void print(); std::string m_name; std::vector m_col_defs; std::vector m_rows; std::vector m_indexes; void create_row_from_vector(const std::vector &colDefs, const std::vector &csv_line); void create_index(const Index& index); bool drop_index(const std::string &index_name); static void index_row(Index &index, const ColDefNode &col_def, const Row &row, size_t rowid); static void unindex_row(Index &index, const ColDefNode &col_def, const Row &row, size_t rowid); static void reindex_row(Index &index, const ColDefNode &col_def, const Row &old_row, const Row &new_row, size_t rowid); void index_row(const Row &row); void unindex_row(const Row &row); void reindex_row(const Row &old_row, const Row &new_row); void index_rows(const std::string &index_name); Index * get_index(const std::string &index_name); Index * get_index_for_column(const std::string &col_name); bool empty(); struct rows_scanner { explicit rows_scanner(Table *tbl) : m_use_rowids(false), m_table(tbl), m_fscan_itr(tbl->m_rows.begin()) {} rows_scanner(Table *tbl, std::vector rowids) : m_use_rowids(true), m_table(tbl), m_rowids(std::move(rowids)), m_rowids_idx(0) {} Row *next(); private: bool m_use_rowids; Table * m_table; std::vector::iterator m_fscan_itr; std::vector m_rowids; size_t m_rowids_idx{}; }; }; } // namespace