From bce92b196161e7d615ca418493e50bc198013bf7 Mon Sep 17 00:00:00 2001 From: EmirVildanov <reddog201030@gmail.com> Date: Wed, 21 Aug 2024 14:58:06 +0300 Subject: [PATCH] feat: update Types casting error, remove useless function --- .../src/cartridge/config/tests.rs | 5 ++++- sbroad-core/src/ir/relation.rs | 21 ++----------------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/sbroad-cartridge/src/cartridge/config/tests.rs b/sbroad-cartridge/src/cartridge/config/tests.rs index 661ae9ed46..dbd844010e 100644 --- a/sbroad-cartridge/src/cartridge/config/tests.rs +++ b/sbroad-cartridge/src/cartridge/config/tests.rs @@ -216,6 +216,9 @@ fn test_invalid_schema() { assert_eq!( s.load_schema(test_schema).unwrap_err(), - SbroadError::NotImplemented(Entity::Type, "invalid_type".into()) + SbroadError::Invalid( + Entity::Type, + Some("Unable to transform invalid_type to Type.".into()) + ) ); } diff --git a/sbroad-core/src/ir/relation.rs b/sbroad-core/src/ir/relation.rs index 6cac0316d1..88573b81c7 100644 --- a/sbroad-core/src/ir/relation.rs +++ b/sbroad-core/src/ir/relation.rs @@ -148,7 +148,7 @@ impl Type { "decimal" => Ok(Type::Decimal), "double" => Ok(Type::Double), "integer" => Ok(Type::Integer), - "number" => Ok(Type::Number), + "number" | "numeric" => Ok(Type::Number), "scalar" => Ok(Type::Scalar), "string" | "text" => Ok(Type::String), "uuid" => Ok(Type::Uuid), @@ -156,26 +156,9 @@ impl Type { "array" => Ok(Type::Array), "any" => Ok(Type::Any), "map" => Ok(Type::Map), - v => Err(SbroadError::NotImplemented(Entity::Type, v.to_smolstr())), - } - } - - /// Type constructor (in a case of the possibly incorrect input - - /// VALUES with the first NULL row can return incorrect type in the metadata). - /// - /// # Errors - /// - Invalid type name. - pub fn new_from_possibly_incorrect(s: &str) -> Result<Self, SbroadError> { - match s.to_string().to_lowercase().as_str() { - "boolean" | "decimal" | "double" | "integer" | "number" | "numeric" | "scalar" - | "string" | "uuid" | "text" | "unsigned" => Ok(Type::Scalar), - "array" => Ok(Type::Array), - "map" => Ok(Type::Map), - "datetime" => Ok(Type::Datetime), - "any" => Ok(Type::Any), v => Err(SbroadError::Invalid( Entity::Type, - Some(format_smolstr!("Unexpected type {v} met during ")), + Some(format_smolstr!("Unable to transform {v} to Type.")), )), } } -- GitLab