Create table partial implementation

This commit is contained in:
Yuriy Dupyn 2024-02-05 19:27:46 +01:00
parent f973df2ca2
commit 2dd0555174
5 changed files with 98 additions and 32 deletions

View file

@ -364,7 +364,7 @@ impl <'cursor, T> WriteCursor<'cursor, T>
async fn spawn_cursor_to_intermediate_file(&self) -> Result<AppendOnlyCursor<T>>
where T: Send
{
let table_folder = self.header.table_folder.to_string();
let table_folder = self.header.table_folder.clone();
let path_to_table = Path::new(&table_folder);
let path_to_rows = path_to_table.join(GARBAGE_COLLECTION_INTERMEDIATE_ROWS_FILE_NAME);

View file

@ -2,10 +2,11 @@ use crate::binary_coding::{encode, encode_sequence, decode, decode_sequence};
use crate::store::{Result, Column};
use crate::error::{Error, DecodeErrorKind};
use std::mem::size_of;
use std::path::PathBuf;
#[derive(Debug, Clone)]
pub struct StoreHeader {
pub table_folder: String, // This one is not encoded into the file
pub table_folder: PathBuf, // This one is not encoded into the file
pub number_of_columns: usize,
pub deleted_count: usize,
@ -93,7 +94,7 @@ impl StoreHeader {
.map_err(|e| Error::DecodeError(DecodeErrorKind::StoreHeaderIndexedColumns, e))?;
Ok(StoreHeader {
table_folder: header.table_folder,
table_folder: header.table_folder.into(),
number_of_columns: header.number_of_columns,
deleted_count: header.deleted_count,
total_count: header.total_count,

View file

@ -36,10 +36,9 @@ pub const GARBAGE_COLLECTION_INTERMEDIATE_ROWS_FILE_NAME: &'static str = "rows_i
impl <T>Store<T> {
// ===Creation===
pub async fn new(table_folder: &str, number_of_columns: usize, primary_column: Column) -> Result<Self>
pub async fn new(path_to_table: &Path, number_of_columns: usize, primary_column: Column) -> Result<Self>
where T: Encode + Decode + Ord
{
let path_to_table = Path::new(table_folder);
let path_to_rows = path_to_table.join(ROWS_FILE_NAME);
DirBuilder::new()
.create(path_to_table).await?;
@ -48,7 +47,7 @@ impl <T>Store<T> {
let mut indexed_columns = vec![false; number_of_columns];
indexed_columns[primary_column as usize] = true;
StoreHeader {
table_folder: table_folder.to_string(),
table_folder: path_to_table.to_path_buf(),
number_of_columns,
deleted_count: 0,
total_count: 0,
@ -225,7 +224,7 @@ mod tests {
async fn test_create() {
type Data = u32;
let table_path = "test_table_0";
let table_path = Path::new("test_table_0");
let number_of_columns = 5;
let primary_column = 0;
let store: Store<Data> = Store::new(table_path, number_of_columns, primary_column).await.unwrap();
@ -240,7 +239,7 @@ mod tests {
async fn test_insert() {
type Data = u32;
let table_path = "test_table_1";
let table_path = Path::new("test_table_1");
let number_of_columns = 5;
let primary_column = 0;
let mut store: Store<Data> = Store::new(table_path, number_of_columns, primary_column).await.unwrap();
@ -262,7 +261,7 @@ mod tests {
async fn test_select_next() {
type Data = u32;
let table_path = "test_table_2";
let table_path = Path::new("test_table_2");
let number_of_columns = 5;
let primary_column = 0;
let mut store: Store<Data> = Store::new(table_path, number_of_columns, primary_column).await.unwrap();
@ -294,7 +293,7 @@ mod tests {
async fn test_select_all() {
type Data = u32;
let table_path = "test_table_3";
let table_path = Path::new("test_table_3");
let number_of_columns = 5;
let primary_column = 0;
let mut store: Store<Data> = Store::new(table_path, number_of_columns, primary_column).await.unwrap();
@ -329,7 +328,7 @@ mod tests {
async fn test_select_eq() {
type Data = u32;
let table_path = "test_table_4";
let table_path = Path::new("test_table_4");
let number_of_columns = 5;
let primary_column = 0;
let mut store: Store<Data> = Store::new(table_path, number_of_columns, primary_column).await.unwrap();
@ -369,7 +368,7 @@ mod tests {
async fn test_select_eq_indexed() {
type Data = u32;
let table_path = "test_table_5";
let table_path = Path::new("test_table_5");
let number_of_columns = 5;
let primary_column = 0;
let mut store: Store<Data> = Store::new(table_path, number_of_columns, primary_column).await.unwrap();
@ -415,7 +414,7 @@ mod tests {
async fn test_delete_entry() {
type Data = u32;
let table_path = "test_table_6";
let table_path = Path::new("test_table_6");
let number_of_columns = 5;
let primary_column = 0;
let mut store: Store<Data> = Store::new(table_path, number_of_columns, primary_column).await.unwrap();
@ -452,7 +451,7 @@ mod tests {
async fn test_delete_where_eq() {
type Data = u32;
let table_path = "test_table_7";
let table_path = Path::new("test_table_7");
let number_of_columns = 5;
let primary_column = 0;
let mut store: Store<Data> = Store::new(table_path, number_of_columns, primary_column).await.unwrap();
@ -496,7 +495,7 @@ mod tests {
async fn test_garbage_collection() {
type Data = u32;
let table_path = "test_table_8";
let table_path = Path::new("test_table_8");
let number_of_columns = 5;
let primary_column = 0;
let mut store: Store<Data> = Store::new(table_path, number_of_columns, primary_column).await.unwrap();