Clippy
This commit is contained in:
parent
8eec9c6759
commit
2ba158a0d4
7 changed files with 41 additions and 18 deletions
|
|
@ -7,6 +7,13 @@ pub struct ColumnIndex {
|
||||||
index: BTreeMap<IndexableValue, HashSet<Uuid>>,
|
index: BTreeMap<IndexableValue, HashSet<Uuid>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// To satisfy clippy.
|
||||||
|
impl Default for ColumnIndex {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ColumnIndex {
|
impl ColumnIndex {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let index = BTreeMap::new();
|
let index = BTreeMap::new();
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,13 @@ impl FromIterator<Value> for Row {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// To satisfy clippy.
|
||||||
|
impl Default for Row {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Row {
|
impl Row {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self(vec![])
|
Self(vec![])
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,13 @@ impl std::fmt::Debug for Response<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// To satisfy clippy.
|
||||||
|
impl Default for State {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ pub enum Error {
|
||||||
ValidationError(#[from] ValidationError)
|
ValidationError(#[from] ValidationError)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_statement<'a>(input: &'a str) -> IResult<&str, RawQuerySyntax> {
|
fn parse_statement(input: &str) -> IResult<&str, RawQuerySyntax> {
|
||||||
alt((
|
alt((
|
||||||
parse_insert,
|
parse_insert,
|
||||||
parse_create,
|
parse_create,
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,10 @@ pub fn parse_number(input: &str) -> IResult<&str, Value> {
|
||||||
Some((_fsign, fdigits)) => {
|
Some((_fsign, fdigits)) => {
|
||||||
// Combine integer and fractional parts
|
// Combine integer and fractional parts
|
||||||
let combined_parts = format!(
|
let combined_parts = format!(
|
||||||
"{}{}",
|
"{}{}.{}",
|
||||||
format!("{}{}", sign.unwrap_or('+'), digits),
|
sign.unwrap_or('+'),
|
||||||
format!(".{}", fdigits)
|
digits,
|
||||||
|
fdigits
|
||||||
);
|
);
|
||||||
// Parse the combined parts as a floating-point number
|
// Parse the combined parts as a floating-point number
|
||||||
let value = combined_parts.parse::<f64>()
|
let value = combined_parts.parse::<f64>()
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ pub fn try_parse_column_selection(input: &str) -> IResult<&str, ColumnSelection>
|
||||||
});
|
});
|
||||||
let columns_parser = map(
|
let columns_parser = map(
|
||||||
separated_list0(terminated(char(','), multispace0), parse_column_name),
|
separated_list0(terminated(char(','), multispace0), parse_column_name),
|
||||||
|names| ColumnSelection::Columns(names),
|
ColumnSelection::Columns,
|
||||||
);
|
);
|
||||||
alt((all_parser, columns_parser))(input)
|
alt((all_parser, columns_parser))(input)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ fn validate_table_exists<'a>(db_schema: &DbSchema<'a>, table_name: &'a TableName
|
||||||
|
|
||||||
fn validate_create_table(raw_table_schema: RawTableSchema, db_schema: &DbSchema) -> Result<Operation, ValidationError> {
|
fn validate_create_table(raw_table_schema: RawTableSchema, db_schema: &DbSchema) -> Result<Operation, ValidationError> {
|
||||||
let table_name: &TableName = &raw_table_schema.table_name;
|
let table_name: &TableName = &raw_table_schema.table_name;
|
||||||
if let Some(_) = get_table_schema(db_schema, &table_name) {
|
if get_table_schema(db_schema, table_name).is_some() {
|
||||||
return Err(ValidationError::TableAlreadyExists(table_name.to_string()));
|
return Err(ValidationError::TableAlreadyExists(table_name.to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,10 +89,11 @@ fn validate_table_schema(raw_table_schema: RawTableSchema) -> Result<TableSchema
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure it has exactly one primary key that has correct type.
|
// Ensure it has exactly one primary key that has correct type.
|
||||||
if primary_keys.len() == 0 {
|
let number_of_primary_keys = primary_keys.len();
|
||||||
return Err(ValidationError::PrimaryKeyMissing(raw_table_schema.table_name.clone()))
|
if number_of_primary_keys == 0 {
|
||||||
} else if primary_keys.len() > 1 {
|
Err(ValidationError::PrimaryKeyMissing(raw_table_schema.table_name.clone()))
|
||||||
return Err(ValidationError::MultiplePrimaryKeysFound(raw_table_schema.table_name.clone()))
|
} else if number_of_primary_keys > 1 {
|
||||||
|
Err(ValidationError::MultiplePrimaryKeysFound(raw_table_schema.table_name.clone()))
|
||||||
} else {
|
} else {
|
||||||
let (primary_column_name, primary_key_type) = primary_keys[0].clone();
|
let (primary_column_name, primary_key_type) = primary_keys[0].clone();
|
||||||
if primary_key_type == DbType::Uuid {
|
if primary_key_type == DbType::Uuid {
|
||||||
|
|
@ -113,18 +114,18 @@ fn validate_select(table_name: TableName, column_selection: syntax::ColumnSelect
|
||||||
syntax::ColumnSelection::Columns(columns) => {
|
syntax::ColumnSelection::Columns(columns) => {
|
||||||
let non_existant_columns: Vec<ColumnName> =
|
let non_existant_columns: Vec<ColumnName> =
|
||||||
columns.iter().filter_map(|column|
|
columns.iter().filter_map(|column|
|
||||||
if schema.does_column_exist(&column) {
|
if schema.does_column_exist(column) {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(column.clone())
|
Some(column.clone())
|
||||||
}).collect();
|
}).collect();
|
||||||
if non_existant_columns.len() > 0 {
|
if non_existant_columns.is_empty() {
|
||||||
Err(ValidationError::ColumnsDoNotExist(non_existant_columns))
|
|
||||||
} else {
|
|
||||||
let selection: operation::ColumnSelection =
|
let selection: operation::ColumnSelection =
|
||||||
columns.iter().filter_map(|column_name| schema.get_column(column_name)).collect();
|
columns.iter().filter_map(|column_name| schema.get_column(column_name)).collect();
|
||||||
let validated_condition = validate_condition(condition, schema)?;
|
let validated_condition = validate_condition(condition, schema)?;
|
||||||
Ok(Operation::Select(table_position, selection, validated_condition))
|
Ok(Operation::Select(table_position, selection, validated_condition))
|
||||||
|
} else {
|
||||||
|
Err(ValidationError::ColumnsDoNotExist(non_existant_columns))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
syntax::ColumnSelection::All => {
|
syntax::ColumnSelection::All => {
|
||||||
|
|
@ -149,11 +150,11 @@ fn validate_insert(table_name: TableName, insertion_values: syntax::InsertionVal
|
||||||
let columns_in_query: HashSet<&ColumnName> = HashSet::from_iter(columns_in_query_vec);
|
let columns_in_query: HashSet<&ColumnName> = HashSet::from_iter(columns_in_query_vec);
|
||||||
let columns_in_schema: HashSet<&ColumnName> = HashSet::from_iter(schema.get_columns());
|
let columns_in_schema: HashSet<&ColumnName> = HashSet::from_iter(schema.get_columns());
|
||||||
let non_existant_columns = Vec::from_iter(columns_in_query.difference(&columns_in_schema));
|
let non_existant_columns = Vec::from_iter(columns_in_query.difference(&columns_in_schema));
|
||||||
if non_existant_columns.len() > 0 {
|
if !non_existant_columns.is_empty() {
|
||||||
return Err(ValidationError::ColumnsDoNotExist(non_existant_columns.iter().map(|column_name| column_name.to_string()).collect()));
|
return Err(ValidationError::ColumnsDoNotExist(non_existant_columns.iter().map(|column_name| column_name.to_string()).collect()));
|
||||||
}
|
}
|
||||||
let missing_required_columns = Vec::from_iter(columns_in_schema.difference(&columns_in_query));
|
let missing_required_columns = Vec::from_iter(columns_in_schema.difference(&columns_in_query));
|
||||||
if missing_required_columns.len() > 0 {
|
if !missing_required_columns.is_empty() {
|
||||||
return Err(ValidationError::RequiredColumnsAreMissing(missing_required_columns.iter().map(|str| str.to_string()).collect()));
|
return Err(ValidationError::RequiredColumnsAreMissing(missing_required_columns.iter().map(|str| str.to_string()).collect()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -194,7 +195,7 @@ fn validate_condition(condition: Option<syntax::Condition>, schema: &TableSchema
|
||||||
if expected_type.eq(&value_type) {
|
if expected_type.eq(&value_type) {
|
||||||
Ok(Some(operation::Condition::Eq(column, value)))
|
Ok(Some(operation::Condition::Eq(column, value)))
|
||||||
} else {
|
} else {
|
||||||
return Err(ValidationError::TypeMismatch { column_name: column_name.to_string(), received_type: value_type, expected_type });
|
Err(ValidationError::TypeMismatch { column_name: column_name.to_string(), received_type: value_type, expected_type })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -228,7 +229,7 @@ where T: Eq + std::hash::Hash
|
||||||
if already_seen_elements.contains(t) {
|
if already_seen_elements.contains(t) {
|
||||||
return Some(t);
|
return Some(t);
|
||||||
} else {
|
} else {
|
||||||
already_seen_elements.insert(&t);
|
already_seen_elements.insert(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue