From 6707ffb92c665c910582096764887897ad946371 Mon Sep 17 00:00:00 2001 From: SIMRAN MAKHIJA Date: Thu, 2 May 2024 00:18:53 -0400 Subject: [PATCH] fmt --- src/dto/errors.rs | 24 +++++------ src/dto/rename_request.rs | 3 +- src/dto/table_data.rs | 10 ++--- src/handlers/namespace_handler.rs | 11 ++--- src/handlers/table_handler.rs | 14 ++++--- src/repository/mod.rs | 1 - src/repository/namespace.rs | 1 - src/repository/table.rs | 68 +++++++++++++++++++++---------- src/structs/mod.rs | 2 +- 9 files changed, 78 insertions(+), 56 deletions(-) diff --git a/src/dto/errors.rs b/src/dto/errors.rs index a8349b8..2619ba2 100644 --- a/src/dto/errors.rs +++ b/src/dto/errors.rs @@ -3,24 +3,22 @@ use std::fmt::Debug; #[derive(Debug, Deserialize, Serialize)] pub struct NamespaceNotFoundError { - pub message: String, + pub message: String, } - impl From for IcebergErrorResponse { - fn from(err: NamespaceNotFoundError) -> Self { - IcebergErrorResponse { - error: ErrorModel { - message: err.message, - r#type: "NamespaceNotFound".to_string(), - code: 404, - stack: None, - }, + fn from(err: NamespaceNotFoundError) -> Self { + IcebergErrorResponse { + error: ErrorModel { + message: err.message, + r#type: "NamespaceNotFound".to_string(), + code: 404, + stack: None, + }, + } } - } } - #[derive(Debug, Deserialize, Serialize)] pub struct ErrorModel { pub message: String, @@ -58,7 +56,7 @@ pub enum ErrorTypes { Unauthorized(String), ServiceUnavailable(String), ServerError(String), - NamespaceNotFound(String) + NamespaceNotFound(String), } impl std::fmt::Display for ErrorTypes { diff --git a/src/dto/rename_request.rs b/src/dto/rename_request.rs index 42ef009..0f082c9 100644 --- a/src/dto/rename_request.rs +++ b/src/dto/rename_request.rs @@ -1,9 +1,8 @@ -use serde::{Deserialize, Serialize}; use crate::dto::table_data::TableIdent; +use serde::{Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize)] pub struct TableRenameRequest { pub source: TableIdent, pub destination: TableIdent, } - diff --git a/src/dto/table_data.rs b/src/dto/table_data.rs index 6dabf1e..4935b54 100644 --- a/src/dto/table_data.rs +++ b/src/dto/table_data.rs @@ -4,7 +4,6 @@ use serde::{Deserialize, Serialize}; use typed_builder::TypedBuilder; // use std::collections::HashMap; - #[derive(Debug, Serialize, Deserialize, Clone)] pub struct Table { pub id: TableIdent, @@ -27,7 +26,6 @@ impl TableIdent { } } - #[derive(Serialize, Deserialize, Debug, TypedBuilder)] pub struct TableCreation { /// The name of the table. @@ -39,8 +37,8 @@ pub struct TableCreation { #[derive(Debug, Serialize, Deserialize, Clone)] pub struct TableMetadata { - pub table_uuid: String, -// pub file_urls: Option>, -// pub columns: Option>, -// pub properties: Option>, + pub table_uuid: String, + // pub file_urls: Option>, + // pub columns: Option>, + // pub properties: Option>, } diff --git a/src/handlers/namespace_handler.rs b/src/handlers/namespace_handler.rs index d6a8ba0..f182cbf 100644 --- a/src/handlers/namespace_handler.rs +++ b/src/handlers/namespace_handler.rs @@ -24,8 +24,11 @@ pub async fn list_namespaces( "namespaces": namespaces }); Ok(Json(json_object)) - }, - Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, format!("Internal server error: {}", e))) + } + Err(e) => Err(( + StatusCode::INTERNAL_SERVER_ERROR, + format!("Internal server error: {}", e), + )), } } @@ -33,7 +36,6 @@ pub async fn create_namespace( State(repo): State>, new_namespace: Json, ) -> Result, (StatusCode, String)> { - if repo.namespace_exists(new_namespace.get_name()).unwrap() { return Err((StatusCode::CONFLICT, format!("namespace already exists"))); } @@ -123,8 +125,7 @@ pub async fn set_namespace_properties( } // Check if a property key was included in both `removals` and `updates` - - + repo.set_namespace_properties( id, request_body.removals.clone(), diff --git a/src/handlers/table_handler.rs b/src/handlers/table_handler.rs index e42b0b6..37162b2 100644 --- a/src/handlers/table_handler.rs +++ b/src/handlers/table_handler.rs @@ -1,12 +1,12 @@ +use crate::dto::namespace_data::NamespaceIdent; use crate::dto::rename_request::TableRenameRequest; -use crate::dto::table_data::{TableIdent, TableCreation, Table}; +use crate::dto::table_data::{Table, TableCreation, TableIdent}; use crate::repository::table::TableRepository; -use crate::dto::namespace_data::{NamespaceIdent}; use axum::{ extract::{Json, Path, State}, http::StatusCode, }; -use std::io::{ ErrorKind}; +use std::io::ErrorKind; use std::sync::Arc; pub async fn list_tables( @@ -62,7 +62,10 @@ pub async fn load_table( match repo.load_table(&id, table.clone()) { Ok(Some(table_data)) => Ok(Json(table_data)), - Ok(None) => Err((StatusCode::NOT_FOUND, format!("Table {} not found", table.clone()))), + Ok(None) => Err(( + StatusCode::NOT_FOUND, + format!("Table {} not found", table.clone()), + )), Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, format!("Error: {}", e))), } } @@ -82,7 +85,7 @@ pub async fn delete_table( Err(e) => match e.kind() { ErrorKind::NotFound => Err((StatusCode::NOT_FOUND, format!("Error: {}", e))), _ => Err((StatusCode::INTERNAL_SERVER_ERROR, format!("Error: {}", e))), - } + }, } } @@ -117,4 +120,3 @@ pub async fn rename_table( }, } } - diff --git a/src/repository/mod.rs b/src/repository/mod.rs index bcc19b5..a65bd7d 100644 --- a/src/repository/mod.rs +++ b/src/repository/mod.rs @@ -1,3 +1,2 @@ pub mod namespace; pub mod table; - diff --git a/src/repository/namespace.rs b/src/repository/namespace.rs index bc1d1f6..2ceb9b8 100644 --- a/src/repository/namespace.rs +++ b/src/repository/namespace.rs @@ -100,4 +100,3 @@ impl NamespaceRepository { fn current_time() -> String { "current_time".to_string() } - diff --git a/src/repository/table.rs b/src/repository/table.rs index 083dc2b..d55f2ad 100644 --- a/src/repository/table.rs +++ b/src/repository/table.rs @@ -1,7 +1,7 @@ use crate::database::database::Database; +use crate::dto::namespace_data::{NamespaceData, NamespaceIdent}; use crate::dto::rename_request::TableRenameRequest; -use crate::dto::table_data::{TableIdent, TableCreation, Table, TableMetadata}; -use crate::dto::namespace_data::{NamespaceIdent, NamespaceData}; +use crate::dto::table_data::{Table, TableCreation, TableIdent, TableMetadata}; use std::io::{Error, ErrorKind}; use std::sync::{Arc, Mutex}; use uuid::Uuid; @@ -15,9 +15,12 @@ impl TableRepository { Self { database } } - pub fn list_all_tables(&self, namespace: &NamespaceIdent) -> Result>, Error> { + pub fn list_all_tables( + &self, + namespace: &NamespaceIdent, + ) -> Result>, Error> { let db = self.database.lock().unwrap(); - let _ : NamespaceData = match db.get("NamespaceData", namespace)? { + let _: NamespaceData = match db.get("NamespaceData", namespace)? { Some(data) => data, None => { return Err(std::io::Error::new( @@ -29,9 +32,13 @@ impl TableRepository { db.get::>("TableNamespaceMap", namespace) } - pub fn create_table(&self, namespace: &NamespaceIdent, table_creation: &TableCreation) -> Result<(), Error> { + pub fn create_table( + &self, + namespace: &NamespaceIdent, + table_creation: &TableCreation, + ) -> Result<(), Error> { let db = self.database.lock().unwrap(); - let _ : NamespaceData = match db.get("NamespaceData", namespace)? { + let _: NamespaceData = match db.get("NamespaceData", namespace)? { Some(data) => data, None => { return Err(std::io::Error::new( @@ -42,12 +49,10 @@ impl TableRepository { }; let table_id = TableIdent::new(namespace.clone(), table_creation.name.clone()); - let table_uuid = Uuid::new_v4().to_string(); - - let table_metadata = TableMetadata{ - table_uuid - }; - + let table_uuid = Uuid::new_v4().to_string(); + + let table_metadata = TableMetadata { table_uuid }; + let mut tables = db .get::>("TableNamespaceMap", namespace) .unwrap() @@ -56,17 +61,27 @@ impl TableRepository { if tables.contains(&table_id) { return Err(std::io::Error::new( ErrorKind::AlreadyExists, - format!("Table {} already exists in namespace {}", table_creation.name, namespace.clone().0.join("\u{1F}")), - )) + format!( + "Table {} already exists in namespace {}", + table_creation.name, + namespace.clone().0.join("\u{1F}") + ), + )); } - db.insert("TableData", &table_id, &Table{id: table_id.clone(), metadata: table_metadata})?; + db.insert( + "TableData", + &table_id, + &Table { + id: table_id.clone(), + metadata: table_metadata, + }, + )?; tables.push(table_id.clone()); let r_val = db.insert("TableNamespaceMap", namespace, &tables); r_val } - pub fn load_table( &self, namespace: &NamespaceIdent, @@ -82,7 +97,7 @@ impl TableRepository { let db = self.database.lock().unwrap(); let table_id = TableIdent::new(namespace.clone(), table_name.clone()); - let _ : Table = match db.get::("TableData", &table_id)? { + let _: Table = match db.get::("TableData", &table_id)? { Some(data) => data, None => { return Err(std::io::Error::new( @@ -101,7 +116,11 @@ impl TableRepository { db.insert("TableNamespaceMap", namespace, &tables) } - pub fn table_exists(&self, namespace: &NamespaceIdent, table_name: String) -> Result { + pub fn table_exists( + &self, + namespace: &NamespaceIdent, + table_name: String, + ) -> Result { let table = self.load_table(namespace, table_name)?; Ok(table.is_some()) } @@ -116,14 +135,21 @@ impl TableRepository { .ok_or_else(|| Error::new(ErrorKind::NotFound, "Source table not found"))?; if self.table_exists(&destination.namespace, destination.name.clone())? { - return Err(Error::new(ErrorKind::AlreadyExists, "Destination table already exists")); + return Err(Error::new( + ErrorKind::AlreadyExists, + "Destination table already exists", + )); } let mut new_table = table.clone(); new_table.id = destination.clone(); - self.create_table(&destination.namespace.clone(), &TableCreation{name: destination.name.clone()})?; + self.create_table( + &destination.namespace.clone(), + &TableCreation { + name: destination.name.clone(), + }, + )?; self.drop_table(&namespace, source.name.clone()) } } - diff --git a/src/structs/mod.rs b/src/structs/mod.rs index a281f3e..a91e735 100644 --- a/src/structs/mod.rs +++ b/src/structs/mod.rs @@ -1 +1 @@ -pub mod error; \ No newline at end of file +pub mod error;