Skip to content
Snippets Groups Projects
Commit fc288c52 authored by Denis Smirnov's avatar Denis Smirnov
Browse files

refactoring: please linter

parent 3bf75270
No related branches found
No related tags found
1 merge request!1414sbroad import
......@@ -12,6 +12,10 @@ pub mod cartridge;
/// A metadata storage trait of the cluster.
pub trait Metadata {
/// Get a table by name.
///
/// # Errors
/// - Failed to get table by name from the metadata.
fn get_table_segment(
&self,
table_name: &str,
......@@ -19,6 +23,7 @@ pub trait Metadata {
fn get_exec_waiting_timeout(&self) -> u64;
#[must_use]
fn to_name(s: &str) -> String {
if let (Some('"'), Some('"')) = (s.chars().next(), s.chars().last()) {
s.to_string()
......@@ -46,6 +51,9 @@ pub trait Engine {
fn clear_metadata(&mut self);
/// Load metadate information to storage
///
/// # Errors
/// - Failed to load metadata.
fn load_metadata(&mut self) -> Result<(), QueryPlannerError>;
/// Materialize result motion node to virtual table
......
......@@ -162,6 +162,10 @@ impl Engine for Runtime {
}
impl Runtime {
/// Create new Tarantool cartridge runtime.
///
/// # Errors
/// - Failed to detect the correct amount of buckets.
pub fn new() -> Result<Self, QueryPlannerError> {
let mut result = Runtime {
metadata: ClusterAppConfig::new(),
......
......@@ -28,7 +28,14 @@ pub struct ClusterAppConfig {
tables: HashMap<String, Table>,
}
impl Default for ClusterAppConfig {
fn default() -> Self {
Self::new()
}
}
impl ClusterAppConfig {
#[must_use]
pub fn new() -> Self {
ClusterAppConfig {
schema: yaml::Yaml::Null,
......@@ -53,7 +60,12 @@ impl ClusterAppConfig {
Err(QueryPlannerError::InvalidClusterSchema)
}
/// Get table sharding key.
///
/// # Panics
/// - Invalid schema.
#[allow(dead_code)]
#[must_use]
pub fn get_sharding_key_by_space(self, space: &str) -> Vec<String> {
let mut result = Vec::new();
let spaces = self.schema["spaces"].as_hash().unwrap();
......
......@@ -75,6 +75,12 @@ pub struct BoxExecuteFormat {
pub rows: Vec<BoxExecuteTuple>,
}
impl Default for BoxExecuteFormat {
fn default() -> Self {
Self::new()
}
}
impl BoxExecuteFormat {
/// Create empty query result set
#[allow(dead_code)]
......
......@@ -24,6 +24,12 @@ pub struct VirtualTable {
hashing: HashMap<String, HashSet<usize>>,
}
impl Default for VirtualTable {
fn default() -> Self {
Self::new()
}
}
impl VirtualTable {
#[must_use]
pub fn new() -> Self {
......
......@@ -137,14 +137,26 @@ pub struct ParseNodes {
pub(crate) arena: Vec<ParseNode>,
}
impl Default for ParseNodes {
fn default() -> Self {
Self::new()
}
}
#[allow(dead_code)]
impl ParseNodes {
/// Get a node from arena
///
/// # Errors
/// - Failed to get a node from arena.
pub fn get_node(&self, node: usize) -> Result<&ParseNode, QueryPlannerError> {
self.arena.get(node).ok_or(QueryPlannerError::InvalidNode)
}
/// Get a mutable node from arena
///
/// # Errors
/// - Failed to get a node from arena.
pub fn get_mut_node(&mut self, node: usize) -> Result<&mut ParseNode, QueryPlannerError> {
self.arena
.get_mut(node)
......@@ -159,11 +171,13 @@ impl ParseNodes {
}
/// Get next node id
#[must_use]
pub fn next_id(&self) -> usize {
self.arena.len()
}
/// Constructor
#[must_use]
pub fn new() -> Self {
ParseNodes { arena: Vec::new() }
}
......@@ -171,6 +185,9 @@ impl ParseNodes {
/// Adds children to already existing node.
/// New elements are added to the beginning of the current list
/// as we use inverted node order.
///
/// # Errors
/// - Failed to retrieve node from arena.
pub fn add_child(
&mut self,
node: Option<usize>,
......@@ -188,6 +205,9 @@ impl ParseNodes {
}
/// Update node's value (string from pairs)
///
/// # Errors
/// - Target node is present in the arena.
pub fn update_value(
&mut self,
node: usize,
......@@ -226,6 +246,9 @@ pub struct AbstractSyntaxTree {
#[allow(dead_code)]
impl AbstractSyntaxTree {
/// Set the top of AST.
///
/// # Errors
/// - The new top is not in the arena.
pub fn set_top(&mut self, top: usize) -> Result<(), QueryPlannerError> {
self.nodes.get_node(top)?;
self.top = Some(top);
......@@ -233,12 +256,18 @@ impl AbstractSyntaxTree {
}
/// Get the top of AST.
///
/// # Errors
/// - AST tree doesn't have a top node.
pub fn get_top(&self) -> Result<usize, QueryPlannerError> {
self.top
.ok_or_else(|| QueryPlannerError::CustomError("No top node found in AST".to_string()))
}
/// Serialize AST from YAML.
///
/// # Errors
/// - Failed to parse YAML.
pub fn from_yaml(s: &str) -> Result<Self, QueryPlannerError> {
let ast: AbstractSyntaxTree = match serde_yaml::from_str(s) {
Ok(p) => p,
......@@ -249,6 +278,9 @@ impl AbstractSyntaxTree {
/// Constructor.
/// Builds a tree (nodes are in postorder reverse).
///
/// # Errors
/// - Failed to parse an SQL query.
pub fn new(query: &str) -> Result<Self, QueryPlannerError> {
let mut ast = AbstractSyntaxTree {
nodes: ParseNodes::new(),
......
......@@ -31,6 +31,7 @@ impl<'n> Iterator for AstIterator<'n> {
impl<'n> ParseNodes {
/// Returns an iterator over the children of the node.
#[allow(dead_code)]
#[must_use]
pub fn ast_iter(&'n self, current: &'n usize) -> AstIterator<'n> {
AstIterator {
current,
......
......@@ -49,7 +49,7 @@
//!
//! The corresponding tree:
//! ```text
//!
//!
//! ┌────┐
//! │ OR │
//! └┬──┬┘
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment