From 01b1c2b1a93a20fd645125340384f0016024fe03 Mon Sep 17 00:00:00 2001 From: Mehul Mathur Date: Tue, 1 Oct 2024 18:46:00 +0000 Subject: [PATCH 01/17] chore: allow pedantic for lalrpop generated code --- crates/proof-of-sql-parser/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/proof-of-sql-parser/src/lib.rs b/crates/proof-of-sql-parser/src/lib.rs index 6702f5479..e020fa9c4 100644 --- a/crates/proof-of-sql-parser/src/lib.rs +++ b/crates/proof-of-sql-parser/src/lib.rs @@ -34,7 +34,7 @@ pub mod resource_id; pub use resource_id::ResourceId; // lalrpop-generated code is not clippy-compliant -lalrpop_mod!(#[allow(clippy::all, missing_docs, clippy::missing_docs_in_private_items)] pub sql); +lalrpop_mod!(#[allow(clippy::all, missing_docs, clippy::missing_docs_in_private_items, clippy::pedantic)] pub sql); /// Implement Deserialize through FromStr to avoid invalid identifiers. #[macro_export] From 81349d9eac7524f738aec3c4d5ba4b4cd09c4852 Mon Sep 17 00:00:00 2001 From: Mehul Mathur Date: Tue, 1 Oct 2024 18:47:19 +0000 Subject: [PATCH 02/17] chore: autofix clippy::doc_markdown --- crates/proof-of-sql-parser/src/error.rs | 4 ++-- crates/proof-of-sql-parser/src/identifier.rs | 8 ++++---- .../src/intermediate_ast.rs | 18 +++++++++--------- crates/proof-of-sql-parser/src/lib.rs | 2 +- .../src/posql_time/error.rs | 2 +- .../src/posql_time/timestamp.rs | 6 +++--- .../src/posql_time/timezone.rs | 2 +- crates/proof-of-sql-parser/src/resource_id.rs | 16 ++++++++-------- .../src/select_statement.rs | 4 ++-- 9 files changed, 31 insertions(+), 31 deletions(-) diff --git a/crates/proof-of-sql-parser/src/error.rs b/crates/proof-of-sql-parser/src/error.rs index e412df51a..702c686bc 100644 --- a/crates/proof-of-sql-parser/src/error.rs +++ b/crates/proof-of-sql-parser/src/error.rs @@ -17,13 +17,13 @@ pub enum ParseError { error: String, }, #[snafu(display("Unable to parse resource_id"))] - /// Can not parse the resource_id + /// Can not parse the `resource_id` ResourceIdParseError { /// The underlying error error: String, }, } -/// General parsing error that may occur, for example if the provided schema/object_name strings +/// General parsing error that may occur, for example if the provided `schema/object_name` strings /// aren't valid postgres-style identifiers (excluding dollar signs). pub type ParseResult = Result; diff --git a/crates/proof-of-sql-parser/src/identifier.rs b/crates/proof-of-sql-parser/src/identifier.rs index a5069aa28..7852703a1 100644 --- a/crates/proof-of-sql-parser/src/identifier.rs +++ b/crates/proof-of-sql-parser/src/identifier.rs @@ -12,9 +12,9 @@ pub struct Identifier { impl Identifier { /// Constructor for [Identifier] /// - /// Note: this constructor should be private within the proof_of_sql_parser crate. + /// Note: this constructor should be private within the `proof_of_sql_parser` crate. /// This is necessary to guarantee that no one outside the crate - /// can create Names, thus securing that ResourceIds and Identifiers + /// can create Names, thus securing that `ResourceIds` and Identifiers /// are always valid postgresql identifiers. pub(crate) fn new>(string: S) -> Self { Self { @@ -22,7 +22,7 @@ impl Identifier { } } - /// An alias for [Identifier::from_str], provided for convenience. + /// An alias for [`Identifier::from_str`], provided for convenience. pub fn try_new>(string: S) -> ParseResult { Self::from_str(string.as_ref()) } @@ -33,7 +33,7 @@ impl Identifier { self.name.as_str() } - /// An alias for [Identifier::name], provided for convenience. + /// An alias for [`Identifier::name`], provided for convenience. pub fn as_str(&self) -> &str { self.name() } diff --git a/crates/proof-of-sql-parser/src/intermediate_ast.rs b/crates/proof-of-sql-parser/src/intermediate_ast.rs index 2095301a5..edb9457ff 100644 --- a/crates/proof-of-sql-parser/src/intermediate_ast.rs +++ b/crates/proof-of-sql-parser/src/intermediate_ast.rs @@ -13,7 +13,7 @@ use core::{ }; use serde::{Deserialize, Serialize}; -/// Representation of a SetExpression, a collection of rows, each having one or more columns. +/// Representation of a `SetExpression`, a collection of rows, each having one or more columns. #[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] pub enum SetExpression { /// Query result as `SetExpression` @@ -185,7 +185,7 @@ pub enum Expression { } impl Expression { - /// Create a new SUM() + /// Create a new `SUM()` pub fn sum(self) -> Box { Box::new(Expression::Aggregation { op: AggregationOperator::Sum, @@ -193,7 +193,7 @@ impl Expression { }) } - /// Create a new MAX() + /// Create a new `MAX()` pub fn max(self) -> Box { Box::new(Expression::Aggregation { op: AggregationOperator::Max, @@ -201,7 +201,7 @@ impl Expression { }) } - /// Create a new MIN() + /// Create a new `MIN()` pub fn min(self) -> Box { Box::new(Expression::Aggregation { op: AggregationOperator::Min, @@ -209,7 +209,7 @@ impl Expression { }) } - /// Create a new COUNT() + /// Create a new `COUNT()` pub fn count(self) -> Box { Box::new(Expression::Aggregation { op: AggregationOperator::Count, @@ -217,7 +217,7 @@ impl Expression { }) } - /// Create a new FIRST() + /// Create a new `FIRST()` pub fn first(self) -> Box { Box::new(Expression::Aggregation { op: AggregationOperator::First, @@ -277,7 +277,7 @@ impl core::ops::Sub> for Box { } } -/// OrderBy +/// `OrderBy` #[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] pub struct OrderBy { /// which column to order by @@ -286,7 +286,7 @@ pub struct OrderBy { pub direction: OrderByDirection, } -/// OrderByDirection values +/// `OrderByDirection` values #[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone, Copy)] pub enum OrderByDirection { /// Ascending @@ -310,7 +310,7 @@ impl Display for OrderByDirection { pub struct Slice { /// number of rows to return /// - /// if u64::MAX, specify all rows + /// if `u64::MAX`, specify all rows pub number_rows: u64, /// number of rows to skip diff --git a/crates/proof-of-sql-parser/src/lib.rs b/crates/proof-of-sql-parser/src/lib.rs index e020fa9c4..fd4b38131 100644 --- a/crates/proof-of-sql-parser/src/lib.rs +++ b/crates/proof-of-sql-parser/src/lib.rs @@ -36,7 +36,7 @@ pub use resource_id::ResourceId; // lalrpop-generated code is not clippy-compliant lalrpop_mod!(#[allow(clippy::all, missing_docs, clippy::missing_docs_in_private_items, clippy::pedantic)] pub sql); -/// Implement Deserialize through FromStr to avoid invalid identifiers. +/// Implement Deserialize through `FromStr` to avoid invalid identifiers. #[macro_export] macro_rules! impl_serde_from_str { ($type:ty) => { diff --git a/crates/proof-of-sql-parser/src/posql_time/error.rs b/crates/proof-of-sql-parser/src/posql_time/error.rs index 9e23cd019..1a016555f 100644 --- a/crates/proof-of-sql-parser/src/posql_time/error.rs +++ b/crates/proof-of-sql-parser/src/posql_time/error.rs @@ -44,7 +44,7 @@ pub enum PoSQLTimestampError { error: String, }, - /// Represents a failure to parse a provided time unit precision value, PoSQL supports + /// Represents a failure to parse a provided time unit precision value, `PoSQL` supports /// Seconds, Milliseconds, Microseconds, and Nanoseconds #[snafu(display("Timestamp parsing error: {error}"))] UnsupportedPrecision { diff --git a/crates/proof-of-sql-parser/src/posql_time/timestamp.rs b/crates/proof-of-sql-parser/src/posql_time/timestamp.rs index 87e7b59da..e17627b9a 100644 --- a/crates/proof-of-sql-parser/src/posql_time/timestamp.rs +++ b/crates/proof-of-sql-parser/src/posql_time/timestamp.rs @@ -23,17 +23,17 @@ impl PoSQLTimestamp { self.timestamp } - /// Returns the [PoSQLTimeUnit] for this timestamp + /// Returns the [`PoSQLTimeUnit`] for this timestamp pub fn timeunit(&self) -> PoSQLTimeUnit { self.timeunit } - /// Returns the [PoSQLTimeZone] for this timestamp + /// Returns the [`PoSQLTimeZone`] for this timestamp pub fn timezone(&self) -> PoSQLTimeZone { self.timezone } - /// Attempts to parse a timestamp string into an [PoSQLTimestamp] structure. + /// Attempts to parse a timestamp string into an [`PoSQLTimestamp`] structure. /// This function supports two primary formats: /// /// 1. **RFC 3339 Parsing**: diff --git a/crates/proof-of-sql-parser/src/posql_time/timezone.rs b/crates/proof-of-sql-parser/src/posql_time/timezone.rs index b7b9cee20..cc86ca0ed 100644 --- a/crates/proof-of-sql-parser/src/posql_time/timezone.rs +++ b/crates/proof-of-sql-parser/src/posql_time/timezone.rs @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; pub enum PoSQLTimeZone { /// Default variant for UTC timezone Utc, - /// TImezone offset in seconds + /// `TImezone` offset in seconds FixedOffset(i32), } diff --git a/crates/proof-of-sql-parser/src/resource_id.rs b/crates/proof-of-sql-parser/src/resource_id.rs index 3c4348cc2..723abe9e2 100644 --- a/crates/proof-of-sql-parser/src/resource_id.rs +++ b/crates/proof-of-sql-parser/src/resource_id.rs @@ -17,7 +17,7 @@ pub struct ResourceId { } impl ResourceId { - /// Constructor for [ResourceId]s. + /// Constructor for [`ResourceId`]s. pub fn new(schema: Identifier, object_name: Identifier) -> Self { Self { schema, @@ -25,10 +25,10 @@ impl ResourceId { } } - /// Constructor for [ResourceId]s. + /// Constructor for [`ResourceId`]s. /// /// # Errors - /// Fails if the provided schema/object_name strings aren't valid postgres-style + /// Fails if the provided `schema/object_name` strings aren't valid postgres-style /// identifiers (excluding dollar signs). /// These identifiers are defined here: /// . @@ -42,21 +42,21 @@ impl ResourceId { }) } - /// The schema identifier of this [ResourceId]. + /// The schema identifier of this [`ResourceId`]. pub fn schema(&self) -> Identifier { self.schema } - /// The object_name identifier of this [ResourceId]. + /// The `object_name` identifier of this [`ResourceId`]. pub fn object_name(&self) -> Identifier { self.object_name } - /// Conversion to string in the format used in KeyDB. + /// Conversion to string in the format used in `KeyDB`. /// /// Space and time APIs accept a `.` separator in resource ids. - /// However, when a resource id is stored in KeyDB, or used as a key, a `:` separator is used. - /// This method differs from [ResourceId::to_string] by using the latter format. + /// However, when a resource id is stored in `KeyDB`, or used as a key, a `:` separator is used. + /// This method differs from [`ResourceId::to_string`] by using the latter format. /// /// Furthermore, while space and time APIs accept lowercase resource identifiers, /// all resource identifiers are stored internally in uppercase. diff --git a/crates/proof-of-sql-parser/src/select_statement.rs b/crates/proof-of-sql-parser/src/select_statement.rs index 283e0820f..77ef25619 100644 --- a/crates/proof-of-sql-parser/src/select_statement.rs +++ b/crates/proof-of-sql-parser/src/select_statement.rs @@ -29,11 +29,11 @@ impl fmt::Debug for SelectStatement { } impl SelectStatement { - /// This function returns the referenced tables in the provided intermediate_ast + /// This function returns the referenced tables in the provided `intermediate_ast` /// /// Note that we provide a `default_schema` in case the table expression /// does not have any associated schema. This `default_schema` is - /// used to construct the resource_id, as we cannot have this field empty. + /// used to construct the `resource_id`, as we cannot have this field empty. /// In case the table expression already has an associated schema, /// then it's used instead of `default_schema`. Although the DQL endpoint /// would require both to be equal, we have chosen to not fail here From 5743371d18af594968530b1ce08011bfdb9a7cd6 Mon Sep 17 00:00:00 2001 From: Mehul Mathur Date: Wed, 2 Oct 2024 08:15:01 +0000 Subject: [PATCH 03/17] chore: manually fix clippy::doc_markdown --- crates/proof-of-sql-parser/src/error.rs | 2 +- crates/proof-of-sql-parser/src/identifier.rs | 2 +- crates/proof-of-sql-parser/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/proof-of-sql-parser/src/error.rs b/crates/proof-of-sql-parser/src/error.rs index 702c686bc..c50d21eed 100644 --- a/crates/proof-of-sql-parser/src/error.rs +++ b/crates/proof-of-sql-parser/src/error.rs @@ -24,6 +24,6 @@ pub enum ParseError { }, } -/// General parsing error that may occur, for example if the provided `schema/object_name` strings +/// General parsing error that may occur, for example if the provided `schema`/`object_name` strings /// aren't valid postgres-style identifiers (excluding dollar signs). pub type ParseResult = Result; diff --git a/crates/proof-of-sql-parser/src/identifier.rs b/crates/proof-of-sql-parser/src/identifier.rs index 7852703a1..b95d7aab0 100644 --- a/crates/proof-of-sql-parser/src/identifier.rs +++ b/crates/proof-of-sql-parser/src/identifier.rs @@ -14,7 +14,7 @@ impl Identifier { /// /// Note: this constructor should be private within the `proof_of_sql_parser` crate. /// This is necessary to guarantee that no one outside the crate - /// can create Names, thus securing that `ResourceIds` and Identifiers + /// can create Names, thus securing that [`ResourceId`]s and [`Identifier`]s /// are always valid postgresql identifiers. pub(crate) fn new>(string: S) -> Self { Self { diff --git a/crates/proof-of-sql-parser/src/lib.rs b/crates/proof-of-sql-parser/src/lib.rs index fd4b38131..c9dab68e8 100644 --- a/crates/proof-of-sql-parser/src/lib.rs +++ b/crates/proof-of-sql-parser/src/lib.rs @@ -36,7 +36,7 @@ pub use resource_id::ResourceId; // lalrpop-generated code is not clippy-compliant lalrpop_mod!(#[allow(clippy::all, missing_docs, clippy::missing_docs_in_private_items, clippy::pedantic)] pub sql); -/// Implement Deserialize through `FromStr` to avoid invalid identifiers. +/// Implement [`Deserialize`] through [`FromStr`] to avoid invalid identifiers. #[macro_export] macro_rules! impl_serde_from_str { ($type:ty) => { From b3db268a0133d974fba0a973ff0792293043ee83 Mon Sep 17 00:00:00 2001 From: Mehul Mathur Date: Tue, 1 Oct 2024 18:48:49 +0000 Subject: [PATCH 04/17] chore: autofix clippy::uninlined_format_args --- crates/proof-of-sql-parser/src/identifier.rs | 2 +- crates/proof-of-sql-parser/src/posql_time/timestamp.rs | 2 +- crates/proof-of-sql-parser/src/posql_time/timezone.rs | 2 +- crates/proof-of-sql-parser/src/resource_id.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/proof-of-sql-parser/src/identifier.rs b/crates/proof-of-sql-parser/src/identifier.rs index b95d7aab0..8a6bb0eb3 100644 --- a/crates/proof-of-sql-parser/src/identifier.rs +++ b/crates/proof-of-sql-parser/src/identifier.rs @@ -46,7 +46,7 @@ impl FromStr for Identifier { let name = IdentifierParser::new() .parse(string) .map_err(|e| ParseError::IdentifierParseError{ error: - format!("failed to parse identifier, (you may have used a reserved keyword as an ID, i.e. 'timestamp') {:?}", e)})?; + format!("failed to parse identifier, (you may have used a reserved keyword as an ID, i.e. 'timestamp') {e:?}")})?; Ok(Identifier::new(name)) } diff --git a/crates/proof-of-sql-parser/src/posql_time/timestamp.rs b/crates/proof-of-sql-parser/src/posql_time/timestamp.rs index e17627b9a..7932000be 100644 --- a/crates/proof-of-sql-parser/src/posql_time/timestamp.rs +++ b/crates/proof-of-sql-parser/src/posql_time/timestamp.rs @@ -112,7 +112,7 @@ impl PoSQLTimestamp { timezone: PoSQLTimeZone::Utc, }), LocalResult::Ambiguous(earliest, latest) => Err(PoSQLTimestampError::Ambiguous{ error: - format!("The local time is ambiguous because there is a fold in the local time: earliest: {} latest: {} ", earliest, latest), + format!("The local time is ambiguous because there is a fold in the local time: earliest: {earliest} latest: {latest} "), }), LocalResult::None => Err(PoSQLTimestampError::LocalTimeDoesNotExist), } diff --git a/crates/proof-of-sql-parser/src/posql_time/timezone.rs b/crates/proof-of-sql-parser/src/posql_time/timezone.rs index cc86ca0ed..1404e2aaf 100644 --- a/crates/proof-of-sql-parser/src/posql_time/timezone.rs +++ b/crates/proof-of-sql-parser/src/posql_time/timezone.rs @@ -67,7 +67,7 @@ impl fmt::Display for PoSQLTimeZone { if seconds < 0 { write!(f, "-{:02}:{:02}", hours.abs(), minutes) } else { - write!(f, "+{:02}:{:02}", hours, minutes) + write!(f, "+{hours:02}:{minutes:02}") } } } diff --git a/crates/proof-of-sql-parser/src/resource_id.rs b/crates/proof-of-sql-parser/src/resource_id.rs index 723abe9e2..58efc7d47 100644 --- a/crates/proof-of-sql-parser/src/resource_id.rs +++ b/crates/proof-of-sql-parser/src/resource_id.rs @@ -93,7 +93,7 @@ impl FromStr for ResourceId { fn from_str(string: &str) -> ParseResult { let (schema, object_name) = ResourceIdParser::new().parse(string).map_err(|e| { ParseError::ResourceIdParseError { - error: format!("{:?}", e), + error: format!("{e:?}"), } })?; From 43e637effdc7d87e7a4e1a3d2a1c242c8f65a63f Mon Sep 17 00:00:00 2001 From: Mehul Mathur Date: Tue, 1 Oct 2024 18:49:47 +0000 Subject: [PATCH 05/17] chore: autofix clippy::must_use_candidate --- crates/proof-of-sql-parser/src/identifier.rs | 4 +- .../src/intermediate_ast.rs | 16 ++--- .../src/intermediate_decimal.rs | 6 +- .../src/posql_time/timestamp.rs | 6 +- .../src/posql_time/timezone.rs | 2 +- crates/proof-of-sql-parser/src/resource_id.rs | 8 +-- .../src/select_statement.rs | 2 +- crates/proof-of-sql-parser/src/utility.rs | 68 +++++++++---------- 8 files changed, 56 insertions(+), 56 deletions(-) diff --git a/crates/proof-of-sql-parser/src/identifier.rs b/crates/proof-of-sql-parser/src/identifier.rs index 8a6bb0eb3..2a0285c22 100644 --- a/crates/proof-of-sql-parser/src/identifier.rs +++ b/crates/proof-of-sql-parser/src/identifier.rs @@ -29,12 +29,12 @@ impl Identifier { /// The name of this [Identifier] /// It already implements [Deref] to [str], so this method is not necessary for most use cases. - pub fn name(&self) -> &str { + #[must_use] pub fn name(&self) -> &str { self.name.as_str() } /// An alias for [`Identifier::name`], provided for convenience. - pub fn as_str(&self) -> &str { + #[must_use] pub fn as_str(&self) -> &str { self.name() } } diff --git a/crates/proof-of-sql-parser/src/intermediate_ast.rs b/crates/proof-of-sql-parser/src/intermediate_ast.rs index edb9457ff..f1d99e2ef 100644 --- a/crates/proof-of-sql-parser/src/intermediate_ast.rs +++ b/crates/proof-of-sql-parser/src/intermediate_ast.rs @@ -50,7 +50,7 @@ pub struct AliasedResultExpr { impl AliasedResultExpr { /// Create a new `AliasedResultExpr` - pub fn new(expr: Expression, alias: Identifier) -> Self { + #[must_use] pub fn new(expr: Expression, alias: Identifier) -> Self { Self { expr: Box::new(expr), alias, @@ -59,7 +59,7 @@ impl AliasedResultExpr { /// Try to get the identifier of the expression if it is a column /// Otherwise return None - pub fn try_as_identifier(&self) -> Option<&Identifier> { + #[must_use] pub fn try_as_identifier(&self) -> Option<&Identifier> { match self.expr.as_ref() { Expression::Column(column) => Some(column), _ => None, @@ -186,7 +186,7 @@ pub enum Expression { impl Expression { /// Create a new `SUM()` - pub fn sum(self) -> Box { + #[must_use] pub fn sum(self) -> Box { Box::new(Expression::Aggregation { op: AggregationOperator::Sum, expr: Box::new(self), @@ -194,7 +194,7 @@ impl Expression { } /// Create a new `MAX()` - pub fn max(self) -> Box { + #[must_use] pub fn max(self) -> Box { Box::new(Expression::Aggregation { op: AggregationOperator::Max, expr: Box::new(self), @@ -202,7 +202,7 @@ impl Expression { } /// Create a new `MIN()` - pub fn min(self) -> Box { + #[must_use] pub fn min(self) -> Box { Box::new(Expression::Aggregation { op: AggregationOperator::Min, expr: Box::new(self), @@ -210,7 +210,7 @@ impl Expression { } /// Create a new `COUNT()` - pub fn count(self) -> Box { + #[must_use] pub fn count(self) -> Box { Box::new(Expression::Aggregation { op: AggregationOperator::Count, expr: Box::new(self), @@ -218,14 +218,14 @@ impl Expression { } /// Create a new `FIRST()` - pub fn first(self) -> Box { + #[must_use] pub fn first(self) -> Box { Box::new(Expression::Aggregation { op: AggregationOperator::First, expr: Box::new(self), }) } /// Create an `AliasedResultExpr` from an `Expression` using the provided alias. - pub fn alias(self, alias: &str) -> AliasedResultExpr { + #[must_use] pub fn alias(self, alias: &str) -> AliasedResultExpr { AliasedResultExpr { expr: Box::new(self), alias: alias.parse().unwrap(), diff --git a/crates/proof-of-sql-parser/src/intermediate_decimal.rs b/crates/proof-of-sql-parser/src/intermediate_decimal.rs index 9ebaeb04e..ccecad6b3 100644 --- a/crates/proof-of-sql-parser/src/intermediate_decimal.rs +++ b/crates/proof-of-sql-parser/src/intermediate_decimal.rs @@ -47,17 +47,17 @@ pub struct IntermediateDecimal { impl IntermediateDecimal { /// Get the integer part of the fixed-point representation of this intermediate decimal. - pub fn value(&self) -> BigDecimal { + #[must_use] pub fn value(&self) -> BigDecimal { self.value.clone() } /// Get the precision of the fixed-point representation of this intermediate decimal. - pub fn precision(&self) -> u8 { + #[must_use] pub fn precision(&self) -> u8 { self.value.digits() as u8 } /// Get the scale of the fixed-point representation of this intermediate decimal. - pub fn scale(&self) -> i8 { + #[must_use] pub fn scale(&self) -> i8 { self.value.fractional_digit_count() as i8 } diff --git a/crates/proof-of-sql-parser/src/posql_time/timestamp.rs b/crates/proof-of-sql-parser/src/posql_time/timestamp.rs index 7932000be..0070fcf4f 100644 --- a/crates/proof-of-sql-parser/src/posql_time/timestamp.rs +++ b/crates/proof-of-sql-parser/src/posql_time/timestamp.rs @@ -19,17 +19,17 @@ pub struct PoSQLTimestamp { impl PoSQLTimestamp { /// Returns the combined date and time with time zone. - pub fn timestamp(&self) -> DateTime { + #[must_use] pub fn timestamp(&self) -> DateTime { self.timestamp } /// Returns the [`PoSQLTimeUnit`] for this timestamp - pub fn timeunit(&self) -> PoSQLTimeUnit { + #[must_use] pub fn timeunit(&self) -> PoSQLTimeUnit { self.timeunit } /// Returns the [`PoSQLTimeZone`] for this timestamp - pub fn timezone(&self) -> PoSQLTimeZone { + #[must_use] pub fn timezone(&self) -> PoSQLTimeZone { self.timezone } diff --git a/crates/proof-of-sql-parser/src/posql_time/timezone.rs b/crates/proof-of-sql-parser/src/posql_time/timezone.rs index 1404e2aaf..597ee6b6c 100644 --- a/crates/proof-of-sql-parser/src/posql_time/timezone.rs +++ b/crates/proof-of-sql-parser/src/posql_time/timezone.rs @@ -14,7 +14,7 @@ pub enum PoSQLTimeZone { impl PoSQLTimeZone { /// Parse a timezone from a count of seconds - pub fn from_offset(offset: i32) -> Self { + #[must_use] pub fn from_offset(offset: i32) -> Self { if offset == 0 { PoSQLTimeZone::Utc } else { diff --git a/crates/proof-of-sql-parser/src/resource_id.rs b/crates/proof-of-sql-parser/src/resource_id.rs index 58efc7d47..8f568eb59 100644 --- a/crates/proof-of-sql-parser/src/resource_id.rs +++ b/crates/proof-of-sql-parser/src/resource_id.rs @@ -18,7 +18,7 @@ pub struct ResourceId { impl ResourceId { /// Constructor for [`ResourceId`]s. - pub fn new(schema: Identifier, object_name: Identifier) -> Self { + #[must_use] pub fn new(schema: Identifier, object_name: Identifier) -> Self { Self { schema, object_name, @@ -43,12 +43,12 @@ impl ResourceId { } /// The schema identifier of this [`ResourceId`]. - pub fn schema(&self) -> Identifier { + #[must_use] pub fn schema(&self) -> Identifier { self.schema } /// The `object_name` identifier of this [`ResourceId`]. - pub fn object_name(&self) -> Identifier { + #[must_use] pub fn object_name(&self) -> Identifier { self.object_name } @@ -63,7 +63,7 @@ impl ResourceId { /// This method performs that transformation as well. /// For more information, see /// . - pub fn storage_format(&self) -> String { + #[must_use] pub fn storage_format(&self) -> String { let ResourceId { schema, object_name, diff --git a/crates/proof-of-sql-parser/src/select_statement.rs b/crates/proof-of-sql-parser/src/select_statement.rs index 77ef25619..d43c078aa 100644 --- a/crates/proof-of-sql-parser/src/select_statement.rs +++ b/crates/proof-of-sql-parser/src/select_statement.rs @@ -42,7 +42,7 @@ impl SelectStatement { /// /// Return: /// - The vector with all tables referenced by the intermediate ast, encoded as resource ids. - pub fn get_table_references(&self, default_schema: Identifier) -> Vec { + #[must_use] pub fn get_table_references(&self, default_schema: Identifier) -> Vec { let set_expression: &SetExpression = &(self.expr); match set_expression { diff --git a/crates/proof-of-sql-parser/src/utility.rs b/crates/proof-of-sql-parser/src/utility.rs index 87d3d99ba..61fc10001 100644 --- a/crates/proof-of-sql-parser/src/utility.rs +++ b/crates/proof-of-sql-parser/src/utility.rs @@ -2,12 +2,12 @@ use crate::{intermediate_ast::*, Identifier, SelectStatement}; use alloc::{boxed::Box, vec, vec::Vec}; /// Construct an identifier from a str -pub fn ident(name: &str) -> Identifier { +#[must_use] pub fn ident(name: &str) -> Identifier { name.parse().unwrap() } /// Construct a new boxed `Expression` A == B -pub fn equal(left: Box, right: Box) -> Box { +#[must_use] pub fn equal(left: Box, right: Box) -> Box { Box::new(Expression::Binary { op: BinaryOperator::Equal, left, @@ -16,7 +16,7 @@ pub fn equal(left: Box, right: Box) -> Box { } /// Construct a new boxed `Expression` A >= B -pub fn ge(left: Box, right: Box) -> Box { +#[must_use] pub fn ge(left: Box, right: Box) -> Box { Box::new(Expression::Binary { op: BinaryOperator::GreaterThanOrEqual, left, @@ -25,7 +25,7 @@ pub fn ge(left: Box, right: Box) -> Box { } /// Construct a new boxed `Expression` A <= B -pub fn le(left: Box, right: Box) -> Box { +#[must_use] pub fn le(left: Box, right: Box) -> Box { Box::new(Expression::Binary { op: BinaryOperator::LessThanOrEqual, left, @@ -34,7 +34,7 @@ pub fn le(left: Box, right: Box) -> Box { } /// Construct a new boxed `Expression` NOT P -pub fn not(expr: Box) -> Box { +#[must_use] pub fn not(expr: Box) -> Box { Box::new(Expression::Unary { op: UnaryOperator::Not, expr, @@ -42,7 +42,7 @@ pub fn not(expr: Box) -> Box { } /// Construct a new boxed `Expression` P AND Q -pub fn and(left: Box, right: Box) -> Box { +#[must_use] pub fn and(left: Box, right: Box) -> Box { Box::new(Expression::Binary { op: BinaryOperator::And, left, @@ -51,7 +51,7 @@ pub fn and(left: Box, right: Box) -> Box { } /// Construct a new boxed `Expression` P OR Q -pub fn or(left: Box, right: Box) -> Box { +#[must_use] pub fn or(left: Box, right: Box) -> Box { Box::new(Expression::Binary { op: BinaryOperator::Or, left, @@ -60,7 +60,7 @@ pub fn or(left: Box, right: Box) -> Box { } /// Construct a new boxed `Expression` A + B -pub fn add(left: Box, right: Box) -> Box { +#[must_use] pub fn add(left: Box, right: Box) -> Box { Box::new(Expression::Binary { op: BinaryOperator::Add, left, @@ -69,7 +69,7 @@ pub fn add(left: Box, right: Box) -> Box { } /// Construct a new boxed `Expression` A - B -pub fn sub(left: Box, right: Box) -> Box { +#[must_use] pub fn sub(left: Box, right: Box) -> Box { Box::new(Expression::Binary { op: BinaryOperator::Subtract, left, @@ -78,7 +78,7 @@ pub fn sub(left: Box, right: Box) -> Box { } /// Construct a new boxed `Expression` A * B -pub fn mul(left: Box, right: Box) -> Box { +#[must_use] pub fn mul(left: Box, right: Box) -> Box { Box::new(Expression::Binary { op: BinaryOperator::Multiply, left, @@ -87,7 +87,7 @@ pub fn mul(left: Box, right: Box) -> Box { } /// Construct a new boxed `Expression` A / B -pub fn div(left: Box, right: Box) -> Box { +#[must_use] pub fn div(left: Box, right: Box) -> Box { Box::new(Expression::Binary { op: BinaryOperator::Division, left, @@ -98,7 +98,7 @@ pub fn div(left: Box, right: Box) -> Box { /// Get table from schema and name. /// /// If the schema is `None`, the table is assumed to be in the default schema. -pub fn tab(schema: Option<&str>, name: &str) -> Box { +#[must_use] pub fn tab(schema: Option<&str>, name: &str) -> Box { Box::new(TableExpression::Named { table: name.parse().unwrap(), schema: schema.map(|schema| schema.parse().unwrap()), @@ -106,7 +106,7 @@ pub fn tab(schema: Option<&str>, name: &str) -> Box { } /// Get column from name -pub fn col(name: &str) -> Box { +#[must_use] pub fn col(name: &str) -> Box { Box::new(Expression::Column(name.parse().unwrap())) } @@ -116,7 +116,7 @@ pub fn lit>(literal: L) -> Box { } /// Compute the sum of an expression -pub fn sum(expr: Box) -> Box { +#[must_use] pub fn sum(expr: Box) -> Box { Box::new(Expression::Aggregation { op: AggregationOperator::Sum, expr, @@ -124,7 +124,7 @@ pub fn sum(expr: Box) -> Box { } /// Compute the minimum of an expression -pub fn min(expr: Box) -> Box { +#[must_use] pub fn min(expr: Box) -> Box { Box::new(Expression::Aggregation { op: AggregationOperator::Min, expr, @@ -132,7 +132,7 @@ pub fn min(expr: Box) -> Box { } /// Compute the maximum of an expression -pub fn max(expr: Box) -> Box { +#[must_use] pub fn max(expr: Box) -> Box { Box::new(Expression::Aggregation { op: AggregationOperator::Max, expr, @@ -140,7 +140,7 @@ pub fn max(expr: Box) -> Box { } /// Count the amount of non-null entries of expression -pub fn count(expr: Box) -> Box { +#[must_use] pub fn count(expr: Box) -> Box { Box::new(Expression::Aggregation { op: AggregationOperator::Count, expr, @@ -148,12 +148,12 @@ pub fn count(expr: Box) -> Box { } /// Count the rows -pub fn count_all() -> Box { +#[must_use] pub fn count_all() -> Box { count(Box::new(Expression::Wildcard)) } /// An expression with an alias i.e. EXPR AS ALIAS -pub fn aliased_expr(expr: Box, alias: &str) -> AliasedResultExpr { +#[must_use] pub fn aliased_expr(expr: Box, alias: &str) -> AliasedResultExpr { AliasedResultExpr { expr, alias: alias.parse().unwrap(), @@ -161,12 +161,12 @@ pub fn aliased_expr(expr: Box, alias: &str) -> AliasedResultExpr { } /// Select all columns from a table i.e. SELECT * -pub fn col_res_all() -> SelectResultExpr { +#[must_use] pub fn col_res_all() -> SelectResultExpr { SelectResultExpr::ALL } /// Select one column from a table and give it an alias i.e. SELECT COL AS ALIAS -pub fn col_res(col_val: Box, alias: &str) -> SelectResultExpr { +#[must_use] pub fn col_res(col_val: Box, alias: &str) -> SelectResultExpr { SelectResultExpr::AliasedResultExpr(AliasedResultExpr { expr: col_val, alias: alias.parse().unwrap(), @@ -174,12 +174,12 @@ pub fn col_res(col_val: Box, alias: &str) -> SelectResultExpr { } /// Select multiple columns from a table i.e. SELECT COL1, COL2, ... -pub fn cols_res(names: &[&str]) -> Vec { +#[must_use] pub fn cols_res(names: &[&str]) -> Vec { names.iter().map(|name| col_res(col(name), name)).collect() } /// Compute the minimum of an expression and give it an alias i.e. SELECT MIN(EXPR) AS ALIAS -pub fn min_res(expr: Box, alias: &str) -> SelectResultExpr { +#[must_use] pub fn min_res(expr: Box, alias: &str) -> SelectResultExpr { SelectResultExpr::AliasedResultExpr(AliasedResultExpr { expr: min(expr), alias: alias.parse().unwrap(), @@ -187,7 +187,7 @@ pub fn min_res(expr: Box, alias: &str) -> SelectResultExpr { } /// Compute the maximum of an expression and give it an alias i.e. SELECT MAX(EXPR) AS ALIAS -pub fn max_res(expr: Box, alias: &str) -> SelectResultExpr { +#[must_use] pub fn max_res(expr: Box, alias: &str) -> SelectResultExpr { SelectResultExpr::AliasedResultExpr(AliasedResultExpr { expr: max(expr), alias: alias.parse().unwrap(), @@ -195,7 +195,7 @@ pub fn max_res(expr: Box, alias: &str) -> SelectResultExpr { } /// Compute the sum of an expression and give it an alias i.e. SELECT SUM(EXPR) AS ALIAS -pub fn sum_res(expr: Box, alias: &str) -> SelectResultExpr { +#[must_use] pub fn sum_res(expr: Box, alias: &str) -> SelectResultExpr { SelectResultExpr::AliasedResultExpr(AliasedResultExpr { expr: sum(expr), alias: alias.parse().unwrap(), @@ -203,7 +203,7 @@ pub fn sum_res(expr: Box, alias: &str) -> SelectResultExpr { } /// Count the amount of non-null entries of expression and give it an alias i.e. SELECT COUNT(EXPR) AS ALIAS -pub fn count_res(expr: Box, alias: &str) -> SelectResultExpr { +#[must_use] pub fn count_res(expr: Box, alias: &str) -> SelectResultExpr { SelectResultExpr::AliasedResultExpr(AliasedResultExpr { expr: count(expr), alias: alias.parse().unwrap(), @@ -211,7 +211,7 @@ pub fn count_res(expr: Box, alias: &str) -> SelectResultExpr { } /// Count rows and give the result an alias i.e. SELECT COUNT(*) AS ALIAS -pub fn count_all_res(alias: &str) -> SelectResultExpr { +#[must_use] pub fn count_all_res(alias: &str) -> SelectResultExpr { SelectResultExpr::AliasedResultExpr(AliasedResultExpr { expr: Expression::Aggregation { op: AggregationOperator::Count, @@ -223,7 +223,7 @@ pub fn count_all_res(alias: &str) -> SelectResultExpr { } /// Generate a `SetExpression` of the kind SELECT COL1, COL2, ... FROM TAB WHERE EXPR GROUP BY ... -pub fn query( +#[must_use] pub fn query( result_exprs: Vec, tab: Box, where_expr: Box, @@ -240,7 +240,7 @@ pub fn query( /// Generate a `SetExpression` of the kind SELECT COL1, COL2, ... FROM TAB GROUP BY ... /// /// Note that there is no WHERE clause. -pub fn query_all( +#[must_use] pub fn query_all( result_exprs: Vec, tab: Box, group_by: Vec, @@ -256,7 +256,7 @@ pub fn query_all( /// Generate a query of the kind SELECT ... ORDER BY ... [LIMIT ... OFFSET ...] /// /// Note that `expr` is a boxed `SetExpression` -pub fn select( +#[must_use] pub fn select( expr: Box, order_by: Vec, slice: Option, @@ -269,7 +269,7 @@ pub fn select( } /// Order by one column i.e. ORDER BY ID [ASC|DESC] -pub fn order(id: &str, direction: OrderByDirection) -> Vec { +#[must_use] pub fn order(id: &str, direction: OrderByDirection) -> Vec { vec![OrderBy { expr: id.parse().unwrap(), direction, @@ -277,7 +277,7 @@ pub fn order(id: &str, direction: OrderByDirection) -> Vec { } /// Order by multiple columns i.e. ORDER BY ID0 [ASC|DESC], ID1 [ASC|DESC], ... -pub fn orders(ids: &[&str], directions: &[OrderByDirection]) -> Vec { +#[must_use] pub fn orders(ids: &[&str], directions: &[OrderByDirection]) -> Vec { ids.iter() .zip(directions.iter()) .map(|(id, dir)| OrderBy { @@ -288,7 +288,7 @@ pub fn orders(ids: &[&str], directions: &[OrderByDirection]) -> Vec { } /// Slice a query result using `LIMIT` and `OFFSET` clauses i.e. LIMIT N OFFSET M -pub fn slice(number_rows: u64, offset_value: i64) -> Option { +#[must_use] pub fn slice(number_rows: u64, offset_value: i64) -> Option { Some(Slice { number_rows, offset_value, @@ -296,6 +296,6 @@ pub fn slice(number_rows: u64, offset_value: i64) -> Option { } /// Group by clause with multiple columns i.e. GROUP BY ID0, ID1, ... -pub fn group_by(ids: &[&str]) -> Vec { +#[must_use] pub fn group_by(ids: &[&str]) -> Vec { ids.iter().map(|id| id.parse().unwrap()).collect() } From 016268abc9949eaef8cd2573ba1397ac0667e951 Mon Sep 17 00:00:00 2001 From: Mehul Mathur Date: Tue, 1 Oct 2024 18:53:35 +0000 Subject: [PATCH 06/17] chore: allow clippy::missing_panics_docs to be fixed in a later PR --- crates/proof-of-sql-parser/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/proof-of-sql-parser/src/lib.rs b/crates/proof-of-sql-parser/src/lib.rs index c9dab68e8..461eed134 100644 --- a/crates/proof-of-sql-parser/src/lib.rs +++ b/crates/proof-of-sql-parser/src/lib.rs @@ -1,5 +1,6 @@ #![doc = include_str!("../README.md")] #![no_std] +#![allow(clippy::missing_panics_doc)] // Fixed in Issue #163 extern crate alloc; /// Module for handling an intermediate decimal type received from the lexer. From 374410a7a7aca4e74e68879520847dc46882bf54 Mon Sep 17 00:00:00 2001 From: Mehul Mathur Date: Tue, 1 Oct 2024 19:00:25 +0000 Subject: [PATCH 07/17] chore: manually fix clippy::missing_errors_doc --- crates/proof-of-sql-parser/src/identifier.rs | 11 ++++++-- .../src/intermediate_decimal.rs | 12 ++++++--- .../src/posql_time/timestamp.rs | 27 ++++++++++++++++--- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/crates/proof-of-sql-parser/src/identifier.rs b/crates/proof-of-sql-parser/src/identifier.rs index 2a0285c22..3248bcd14 100644 --- a/crates/proof-of-sql-parser/src/identifier.rs +++ b/crates/proof-of-sql-parser/src/identifier.rs @@ -23,18 +23,25 @@ impl Identifier { } /// An alias for [`Identifier::from_str`], provided for convenience. + /// + /// # Errors + /// Returns a `ParseResult::Err` if the input string does not meet the requirements for a valid identifier. + /// This may include errors such as invalid characters or incorrect formatting based on the specific rules + /// that `Identifier::from_str` enforces. pub fn try_new>(string: S) -> ParseResult { Self::from_str(string.as_ref()) } /// The name of this [Identifier] /// It already implements [Deref] to [str], so this method is not necessary for most use cases. - #[must_use] pub fn name(&self) -> &str { + #[must_use] + pub fn name(&self) -> &str { self.name.as_str() } /// An alias for [`Identifier::name`], provided for convenience. - #[must_use] pub fn as_str(&self) -> &str { + #[must_use] + pub fn as_str(&self) -> &str { self.name() } } diff --git a/crates/proof-of-sql-parser/src/intermediate_decimal.rs b/crates/proof-of-sql-parser/src/intermediate_decimal.rs index ccecad6b3..4303e0cde 100644 --- a/crates/proof-of-sql-parser/src/intermediate_decimal.rs +++ b/crates/proof-of-sql-parser/src/intermediate_decimal.rs @@ -47,22 +47,28 @@ pub struct IntermediateDecimal { impl IntermediateDecimal { /// Get the integer part of the fixed-point representation of this intermediate decimal. - #[must_use] pub fn value(&self) -> BigDecimal { + #[must_use] + pub fn value(&self) -> BigDecimal { self.value.clone() } /// Get the precision of the fixed-point representation of this intermediate decimal. - #[must_use] pub fn precision(&self) -> u8 { + #[must_use] + pub fn precision(&self) -> u8 { self.value.digits() as u8 } /// Get the scale of the fixed-point representation of this intermediate decimal. - #[must_use] pub fn scale(&self) -> i8 { + #[must_use] + pub fn scale(&self) -> i8 { self.value.fractional_digit_count() as i8 } /// Attempts to convert the decimal to `BigInt` while adjusting it to the specified precision and scale. /// Returns an error if the conversion cannot be performed due to precision or scale constraints. + /// + /// # Errors + /// Returns an `IntermediateDecimalError::LossyCast` error if the number of digits in the scaled decimal exceeds the specified precision. pub fn try_into_bigint_with_precision_and_scale( &self, precision: u8, diff --git a/crates/proof-of-sql-parser/src/posql_time/timestamp.rs b/crates/proof-of-sql-parser/src/posql_time/timestamp.rs index 0070fcf4f..9465b674c 100644 --- a/crates/proof-of-sql-parser/src/posql_time/timestamp.rs +++ b/crates/proof-of-sql-parser/src/posql_time/timestamp.rs @@ -19,17 +19,20 @@ pub struct PoSQLTimestamp { impl PoSQLTimestamp { /// Returns the combined date and time with time zone. - #[must_use] pub fn timestamp(&self) -> DateTime { + #[must_use] + pub fn timestamp(&self) -> DateTime { self.timestamp } /// Returns the [`PoSQLTimeUnit`] for this timestamp - #[must_use] pub fn timeunit(&self) -> PoSQLTimeUnit { + #[must_use] + pub fn timeunit(&self) -> PoSQLTimeUnit { self.timeunit } /// Returns the [`PoSQLTimeZone`] for this timestamp - #[must_use] pub fn timezone(&self) -> PoSQLTimeZone { + #[must_use] + pub fn timezone(&self) -> PoSQLTimeZone { self.timezone } @@ -45,6 +48,13 @@ impl PoSQLTimestamp { /// - The `from_offset` method is used to determine whether the timezone should be represented /// as `Utc` or `FixedOffset`. This function simplifies the decision based on the offset value. /// + /// # Errors + /// This function returns a `PoSQLTimestampError` in the following cases: + /// + /// - **Parsing Error**: Returns `PoSQLTimestampError::ParsingError` if the input string does not conform + /// to the RFC 3339 format or if the timestamp cannot be parsed due to invalid formatting. + /// This error includes the original parsing error message for further details. + /// /// # Examples /// ``` /// use chrono::{DateTime, Utc}; @@ -94,6 +104,17 @@ impl PoSQLTimestamp { /// - Since Unix epoch timestamps don't inherently carry timezone information, /// any Unix time parsed directly from an integer is assumed to be in UTC. /// + /// # Errors + /// This function returns a `PoSQLTimestampError` in the following cases: + /// + /// - **Ambiguous Time**: Returns `PoSQLTimestampError::Ambiguous` if the provided epoch time + /// corresponds to a time that is ambiguous (e.g., during a daylight saving time change where + /// the local time could correspond to two different UTC times). + /// + /// - **Non-Existent Local Time**: Returns `PoSQLTimestampError::LocalTimeDoesNotExist` if the + /// provided epoch time corresponds to a time that does not exist in the local time zone (e.g., + /// during a daylight saving time change where a certain local time is skipped). + /// /// # Examples /// ``` /// use chrono::{DateTime, Utc}; From f035fd83e5b7d00a1fc5a0e05b3e06ce96e64dc2 Mon Sep 17 00:00:00 2001 From: Mehul Mathur Date: Tue, 1 Oct 2024 19:02:03 +0000 Subject: [PATCH 08/17] chore: autofix clippy::wildcard_imports --- crates/proof-of-sql-parser/src/utility.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/proof-of-sql-parser/src/utility.rs b/crates/proof-of-sql-parser/src/utility.rs index 61fc10001..fb7ba2251 100644 --- a/crates/proof-of-sql-parser/src/utility.rs +++ b/crates/proof-of-sql-parser/src/utility.rs @@ -1,4 +1,4 @@ -use crate::{intermediate_ast::*, Identifier, SelectStatement}; +use crate::{intermediate_ast::{AggregationOperator, AliasedResultExpr, BinaryOperator, Expression, Literal, OrderBy, OrderByDirection, SelectResultExpr, SetExpression, Slice, TableExpression, UnaryOperator}, Identifier, SelectStatement}; use alloc::{boxed::Box, vec, vec::Vec}; /// Construct an identifier from a str From 1483a9d570673948b4ec44b40c4478dda6b51c20 Mon Sep 17 00:00:00 2001 From: Mehul Mathur Date: Tue, 1 Oct 2024 19:05:19 +0000 Subject: [PATCH 09/17] chore: manually fix clippy::cast_lossless --- crates/proof-of-sql-parser/src/intermediate_ast.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/proof-of-sql-parser/src/intermediate_ast.rs b/crates/proof-of-sql-parser/src/intermediate_ast.rs index f1d99e2ef..8e5c796e1 100644 --- a/crates/proof-of-sql-parser/src/intermediate_ast.rs +++ b/crates/proof-of-sql-parser/src/intermediate_ast.rs @@ -349,7 +349,7 @@ macro_rules! impl_int_to_literal { ($tt:ty) => { impl From<$tt> for Literal { fn from(val: $tt) -> Self { - Literal::BigInt(val as i64) + Literal::BigInt(i64::from(val)) } } }; From f5858c6743473b24bcc6fa1828b3a3f6de6da7a4 Mon Sep 17 00:00:00 2001 From: Mehul Mathur Date: Tue, 1 Oct 2024 19:06:28 +0000 Subject: [PATCH 10/17] chore: autofix clippy::redundant_closure_for_method_calls --- crates/proof-of-sql-parser/src/select_statement.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/proof-of-sql-parser/src/select_statement.rs b/crates/proof-of-sql-parser/src/select_statement.rs index d43c078aa..32e9d0d1b 100644 --- a/crates/proof-of-sql-parser/src/select_statement.rs +++ b/crates/proof-of-sql-parser/src/select_statement.rs @@ -81,7 +81,7 @@ fn convert_table_expr_to_resource_id_vector( TableExpression::Named { table, schema } => { let schema = schema .as_ref() - .map(|schema| schema.as_str()) + .map(super::identifier::Identifier::as_str) .unwrap_or_else(|| default_schema.name()); tables.push(ResourceId::try_new(schema, table.as_str()).unwrap()); From e653076ebe97b24623f4ecc00e790357b34eed3e Mon Sep 17 00:00:00 2001 From: Mehul Mathur Date: Tue, 1 Oct 2024 19:07:21 +0000 Subject: [PATCH 11/17] chore: autofix clippy::map_unwrap_or --- crates/proof-of-sql-parser/src/select_statement.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/proof-of-sql-parser/src/select_statement.rs b/crates/proof-of-sql-parser/src/select_statement.rs index 32e9d0d1b..6a773a415 100644 --- a/crates/proof-of-sql-parser/src/select_statement.rs +++ b/crates/proof-of-sql-parser/src/select_statement.rs @@ -80,9 +80,7 @@ fn convert_table_expr_to_resource_id_vector( match table_ref { TableExpression::Named { table, schema } => { let schema = schema - .as_ref() - .map(super::identifier::Identifier::as_str) - .unwrap_or_else(|| default_schema.name()); + .as_ref().map_or_else(|| default_schema.name(), super::identifier::Identifier::as_str); tables.push(ResourceId::try_new(schema, table.as_str()).unwrap()); } From 119438965daf18c34e2f5725ded69b0ed8c87c9e Mon Sep 17 00:00:00 2001 From: Mehul Mathur Date: Tue, 1 Oct 2024 19:11:38 +0000 Subject: [PATCH 12/17] chore: manually allow: clippy::module_name_repetitions --- crates/proof-of-sql-parser/src/error.rs | 1 + crates/proof-of-sql-parser/src/intermediate_decimal.rs | 1 + crates/proof-of-sql-parser/src/posql_time/error.rs | 1 + crates/proof-of-sql-parser/src/posql_time/timestamp.rs | 1 + crates/proof-of-sql-parser/src/posql_time/unit.rs | 1 + 5 files changed, 5 insertions(+) diff --git a/crates/proof-of-sql-parser/src/error.rs b/crates/proof-of-sql-parser/src/error.rs index c50d21eed..32f2e3017 100644 --- a/crates/proof-of-sql-parser/src/error.rs +++ b/crates/proof-of-sql-parser/src/error.rs @@ -2,6 +2,7 @@ use alloc::string::String; use snafu::Snafu; /// Errors encountered during the parsing process +#[allow(clippy::module_name_repetitions)] #[derive(Debug, Snafu, Eq, PartialEq)] pub enum ParseError { #[snafu(display("Unable to parse query"))] diff --git a/crates/proof-of-sql-parser/src/intermediate_decimal.rs b/crates/proof-of-sql-parser/src/intermediate_decimal.rs index 4303e0cde..33356681e 100644 --- a/crates/proof-of-sql-parser/src/intermediate_decimal.rs +++ b/crates/proof-of-sql-parser/src/intermediate_decimal.rs @@ -13,6 +13,7 @@ use serde::{Deserialize, Serialize}; use snafu::Snafu; /// Errors related to the processing of decimal values in proof-of-sql +#[allow(clippy::module_name_repetitions)] #[derive(Snafu, Debug, PartialEq)] pub enum IntermediateDecimalError { /// Represents an error encountered during the parsing of a decimal string. diff --git a/crates/proof-of-sql-parser/src/posql_time/error.rs b/crates/proof-of-sql-parser/src/posql_time/error.rs index 1a016555f..6897b3e1d 100644 --- a/crates/proof-of-sql-parser/src/posql_time/error.rs +++ b/crates/proof-of-sql-parser/src/posql_time/error.rs @@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize}; use snafu::Snafu; /// Errors related to time operations, including timezone and timestamp conversions.s +#[allow(clippy::module_name_repetitions)] #[derive(Snafu, Debug, Eq, PartialEq, Serialize, Deserialize)] pub enum PoSQLTimestampError { /// Error when the timezone string provided cannot be parsed into a valid timezone. diff --git a/crates/proof-of-sql-parser/src/posql_time/timestamp.rs b/crates/proof-of-sql-parser/src/posql_time/timestamp.rs index 9465b674c..f036bac14 100644 --- a/crates/proof-of-sql-parser/src/posql_time/timestamp.rs +++ b/crates/proof-of-sql-parser/src/posql_time/timestamp.rs @@ -5,6 +5,7 @@ use core::hash::Hash; use serde::{Deserialize, Serialize}; /// Represents a fully parsed timestamp with detailed time unit and timezone information +#[allow(clippy::module_name_repetitions)] #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)] pub struct PoSQLTimestamp { /// The datetime representation in UTC. diff --git a/crates/proof-of-sql-parser/src/posql_time/unit.rs b/crates/proof-of-sql-parser/src/posql_time/unit.rs index 97b1d87e1..480080b76 100644 --- a/crates/proof-of-sql-parser/src/posql_time/unit.rs +++ b/crates/proof-of-sql-parser/src/posql_time/unit.rs @@ -3,6 +3,7 @@ use core::fmt; use serde::{Deserialize, Serialize}; /// An intermediate type representing the time units from a parsed query +#[allow(clippy::module_name_repetitions)] #[derive(Debug, Clone, Copy, Hash, Serialize, Deserialize, PartialEq, Eq)] pub enum PoSQLTimeUnit { /// Represents seconds with precision 0: ex "2024-06-20 12:34:56" From 62ef9880077a576c48141ad8b672bc03850bc2db Mon Sep 17 00:00:00 2001 From: Mehul Mathur Date: Tue, 1 Oct 2024 19:13:11 +0000 Subject: [PATCH 13/17] chore: autofix clippy::explicit_iter_loop --- crates/proof-of-sql-parser/src/select_statement.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/proof-of-sql-parser/src/select_statement.rs b/crates/proof-of-sql-parser/src/select_statement.rs index 6a773a415..da92b263f 100644 --- a/crates/proof-of-sql-parser/src/select_statement.rs +++ b/crates/proof-of-sql-parser/src/select_statement.rs @@ -74,7 +74,7 @@ fn convert_table_expr_to_resource_id_vector( ) -> Vec { let mut tables = Vec::new(); - for table_expression in table_expressions.iter() { + for table_expression in table_expressions { let table_ref: &TableExpression = table_expression.deref(); match table_ref { From 88b6728bfd6fe7431c3515e8952a85fd519327bd Mon Sep 17 00:00:00 2001 From: Mehul Mathur Date: Tue, 1 Oct 2024 19:13:53 +0000 Subject: [PATCH 14/17] chore: autofix clippy::explicit_deref_methods --- crates/proof-of-sql-parser/src/select_statement.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/proof-of-sql-parser/src/select_statement.rs b/crates/proof-of-sql-parser/src/select_statement.rs index da92b263f..11434f22e 100644 --- a/crates/proof-of-sql-parser/src/select_statement.rs +++ b/crates/proof-of-sql-parser/src/select_statement.rs @@ -75,7 +75,7 @@ fn convert_table_expr_to_resource_id_vector( let mut tables = Vec::new(); for table_expression in table_expressions { - let table_ref: &TableExpression = table_expression.deref(); + let table_ref: &TableExpression = &**table_expression; match table_ref { TableExpression::Named { table, schema } => { From 67102cf310878edd900d5465fdb184e0ceae890b Mon Sep 17 00:00:00 2001 From: Mehul Mathur Date: Tue, 1 Oct 2024 19:14:50 +0000 Subject: [PATCH 15/17] chore: autofix clippy::explicit_auto_deref --- crates/proof-of-sql-parser/src/select_statement.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/proof-of-sql-parser/src/select_statement.rs b/crates/proof-of-sql-parser/src/select_statement.rs index 11434f22e..246d6d77c 100644 --- a/crates/proof-of-sql-parser/src/select_statement.rs +++ b/crates/proof-of-sql-parser/src/select_statement.rs @@ -1,7 +1,7 @@ use super::intermediate_ast::{OrderBy, SetExpression, Slice, TableExpression}; use crate::{sql::SelectStatementParser, Identifier, ParseError, ParseResult, ResourceId}; use alloc::{boxed::Box, string::ToString, vec::Vec}; -use core::{fmt, ops::Deref, str::FromStr}; +use core::{fmt, str::FromStr}; use serde::{Deserialize, Serialize}; /// Representation of a select statement, that is, the only type of queries allowed. @@ -75,7 +75,7 @@ fn convert_table_expr_to_resource_id_vector( let mut tables = Vec::new(); for table_expression in table_expressions { - let table_ref: &TableExpression = &**table_expression; + let table_ref: &TableExpression = table_expression; match table_ref { TableExpression::Named { table, schema } => { From 743a3cf7523af277c019d143016e9f55868cd8b1 Mon Sep 17 00:00:00 2001 From: Mehul Mathur Date: Tue, 1 Oct 2024 19:26:19 +0000 Subject: [PATCH 16/17] chore: manually fix clippy::cast_possible_truncation --- crates/proof-of-sql-parser/src/intermediate_decimal.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/proof-of-sql-parser/src/intermediate_decimal.rs b/crates/proof-of-sql-parser/src/intermediate_decimal.rs index 33356681e..f80a84ba3 100644 --- a/crates/proof-of-sql-parser/src/intermediate_decimal.rs +++ b/crates/proof-of-sql-parser/src/intermediate_decimal.rs @@ -56,13 +56,19 @@ impl IntermediateDecimal { /// Get the precision of the fixed-point representation of this intermediate decimal. #[must_use] pub fn precision(&self) -> u8 { - self.value.digits() as u8 + match u8::try_from(self.value.digits()) { + Ok(v) => v, + Err(_) => u8::MAX, // Returning u8::MAX on truncation + } } /// Get the scale of the fixed-point representation of this intermediate decimal. #[must_use] pub fn scale(&self) -> i8 { - self.value.fractional_digit_count() as i8 + match i8::try_from(self.value.fractional_digit_count()) { + Ok(v) => v, + Err(_) => i8::MAX, // Returning i8::MAX on truncation + } } /// Attempts to convert the decimal to `BigInt` while adjusting it to the specified precision and scale. From 9cbe4d0f50551fcb798fad4046d7a632cb86f0a8 Mon Sep 17 00:00:00 2001 From: Mehul Mathur Date: Tue, 1 Oct 2024 19:37:04 +0000 Subject: [PATCH 17/17] chore: run cargo fmt --- .../src/intermediate_ast.rs | 24 ++-- .../src/intermediate_decimal.rs | 4 +- .../src/posql_time/timezone.rs | 3 +- crates/proof-of-sql-parser/src/resource_id.rs | 12 +- .../src/select_statement.rs | 9 +- crates/proof-of-sql-parser/src/utility.rs | 110 ++++++++++++------ 6 files changed, 109 insertions(+), 53 deletions(-) diff --git a/crates/proof-of-sql-parser/src/intermediate_ast.rs b/crates/proof-of-sql-parser/src/intermediate_ast.rs index 8e5c796e1..70bec1122 100644 --- a/crates/proof-of-sql-parser/src/intermediate_ast.rs +++ b/crates/proof-of-sql-parser/src/intermediate_ast.rs @@ -50,7 +50,8 @@ pub struct AliasedResultExpr { impl AliasedResultExpr { /// Create a new `AliasedResultExpr` - #[must_use] pub fn new(expr: Expression, alias: Identifier) -> Self { + #[must_use] + pub fn new(expr: Expression, alias: Identifier) -> Self { Self { expr: Box::new(expr), alias, @@ -59,7 +60,8 @@ impl AliasedResultExpr { /// Try to get the identifier of the expression if it is a column /// Otherwise return None - #[must_use] pub fn try_as_identifier(&self) -> Option<&Identifier> { + #[must_use] + pub fn try_as_identifier(&self) -> Option<&Identifier> { match self.expr.as_ref() { Expression::Column(column) => Some(column), _ => None, @@ -186,7 +188,8 @@ pub enum Expression { impl Expression { /// Create a new `SUM()` - #[must_use] pub fn sum(self) -> Box { + #[must_use] + pub fn sum(self) -> Box { Box::new(Expression::Aggregation { op: AggregationOperator::Sum, expr: Box::new(self), @@ -194,7 +197,8 @@ impl Expression { } /// Create a new `MAX()` - #[must_use] pub fn max(self) -> Box { + #[must_use] + pub fn max(self) -> Box { Box::new(Expression::Aggregation { op: AggregationOperator::Max, expr: Box::new(self), @@ -202,7 +206,8 @@ impl Expression { } /// Create a new `MIN()` - #[must_use] pub fn min(self) -> Box { + #[must_use] + pub fn min(self) -> Box { Box::new(Expression::Aggregation { op: AggregationOperator::Min, expr: Box::new(self), @@ -210,7 +215,8 @@ impl Expression { } /// Create a new `COUNT()` - #[must_use] pub fn count(self) -> Box { + #[must_use] + pub fn count(self) -> Box { Box::new(Expression::Aggregation { op: AggregationOperator::Count, expr: Box::new(self), @@ -218,14 +224,16 @@ impl Expression { } /// Create a new `FIRST()` - #[must_use] pub fn first(self) -> Box { + #[must_use] + pub fn first(self) -> Box { Box::new(Expression::Aggregation { op: AggregationOperator::First, expr: Box::new(self), }) } /// Create an `AliasedResultExpr` from an `Expression` using the provided alias. - #[must_use] pub fn alias(self, alias: &str) -> AliasedResultExpr { + #[must_use] + pub fn alias(self, alias: &str) -> AliasedResultExpr { AliasedResultExpr { expr: Box::new(self), alias: alias.parse().unwrap(), diff --git a/crates/proof-of-sql-parser/src/intermediate_decimal.rs b/crates/proof-of-sql-parser/src/intermediate_decimal.rs index f80a84ba3..1cfa7e1c9 100644 --- a/crates/proof-of-sql-parser/src/intermediate_decimal.rs +++ b/crates/proof-of-sql-parser/src/intermediate_decimal.rs @@ -59,7 +59,7 @@ impl IntermediateDecimal { match u8::try_from(self.value.digits()) { Ok(v) => v, Err(_) => u8::MAX, // Returning u8::MAX on truncation - } + } } /// Get the scale of the fixed-point representation of this intermediate decimal. @@ -68,7 +68,7 @@ impl IntermediateDecimal { match i8::try_from(self.value.fractional_digit_count()) { Ok(v) => v, Err(_) => i8::MAX, // Returning i8::MAX on truncation - } + } } /// Attempts to convert the decimal to `BigInt` while adjusting it to the specified precision and scale. diff --git a/crates/proof-of-sql-parser/src/posql_time/timezone.rs b/crates/proof-of-sql-parser/src/posql_time/timezone.rs index 597ee6b6c..c4f775afd 100644 --- a/crates/proof-of-sql-parser/src/posql_time/timezone.rs +++ b/crates/proof-of-sql-parser/src/posql_time/timezone.rs @@ -14,7 +14,8 @@ pub enum PoSQLTimeZone { impl PoSQLTimeZone { /// Parse a timezone from a count of seconds - #[must_use] pub fn from_offset(offset: i32) -> Self { + #[must_use] + pub fn from_offset(offset: i32) -> Self { if offset == 0 { PoSQLTimeZone::Utc } else { diff --git a/crates/proof-of-sql-parser/src/resource_id.rs b/crates/proof-of-sql-parser/src/resource_id.rs index 8f568eb59..fa1e453ca 100644 --- a/crates/proof-of-sql-parser/src/resource_id.rs +++ b/crates/proof-of-sql-parser/src/resource_id.rs @@ -18,7 +18,8 @@ pub struct ResourceId { impl ResourceId { /// Constructor for [`ResourceId`]s. - #[must_use] pub fn new(schema: Identifier, object_name: Identifier) -> Self { + #[must_use] + pub fn new(schema: Identifier, object_name: Identifier) -> Self { Self { schema, object_name, @@ -43,12 +44,14 @@ impl ResourceId { } /// The schema identifier of this [`ResourceId`]. - #[must_use] pub fn schema(&self) -> Identifier { + #[must_use] + pub fn schema(&self) -> Identifier { self.schema } /// The `object_name` identifier of this [`ResourceId`]. - #[must_use] pub fn object_name(&self) -> Identifier { + #[must_use] + pub fn object_name(&self) -> Identifier { self.object_name } @@ -63,7 +66,8 @@ impl ResourceId { /// This method performs that transformation as well. /// For more information, see /// . - #[must_use] pub fn storage_format(&self) -> String { + #[must_use] + pub fn storage_format(&self) -> String { let ResourceId { schema, object_name, diff --git a/crates/proof-of-sql-parser/src/select_statement.rs b/crates/proof-of-sql-parser/src/select_statement.rs index 246d6d77c..cd97c4ce8 100644 --- a/crates/proof-of-sql-parser/src/select_statement.rs +++ b/crates/proof-of-sql-parser/src/select_statement.rs @@ -42,7 +42,8 @@ impl SelectStatement { /// /// Return: /// - The vector with all tables referenced by the intermediate ast, encoded as resource ids. - #[must_use] pub fn get_table_references(&self, default_schema: Identifier) -> Vec { + #[must_use] + pub fn get_table_references(&self, default_schema: Identifier) -> Vec { let set_expression: &SetExpression = &(self.expr); match set_expression { @@ -79,8 +80,10 @@ fn convert_table_expr_to_resource_id_vector( match table_ref { TableExpression::Named { table, schema } => { - let schema = schema - .as_ref().map_or_else(|| default_schema.name(), super::identifier::Identifier::as_str); + let schema = schema.as_ref().map_or_else( + || default_schema.name(), + super::identifier::Identifier::as_str, + ); tables.push(ResourceId::try_new(schema, table.as_str()).unwrap()); } diff --git a/crates/proof-of-sql-parser/src/utility.rs b/crates/proof-of-sql-parser/src/utility.rs index fb7ba2251..d6b0d8957 100644 --- a/crates/proof-of-sql-parser/src/utility.rs +++ b/crates/proof-of-sql-parser/src/utility.rs @@ -1,13 +1,21 @@ -use crate::{intermediate_ast::{AggregationOperator, AliasedResultExpr, BinaryOperator, Expression, Literal, OrderBy, OrderByDirection, SelectResultExpr, SetExpression, Slice, TableExpression, UnaryOperator}, Identifier, SelectStatement}; +use crate::{ + intermediate_ast::{ + AggregationOperator, AliasedResultExpr, BinaryOperator, Expression, Literal, OrderBy, + OrderByDirection, SelectResultExpr, SetExpression, Slice, TableExpression, UnaryOperator, + }, + Identifier, SelectStatement, +}; use alloc::{boxed::Box, vec, vec::Vec}; /// Construct an identifier from a str -#[must_use] pub fn ident(name: &str) -> Identifier { +#[must_use] +pub fn ident(name: &str) -> Identifier { name.parse().unwrap() } /// Construct a new boxed `Expression` A == B -#[must_use] pub fn equal(left: Box, right: Box) -> Box { +#[must_use] +pub fn equal(left: Box, right: Box) -> Box { Box::new(Expression::Binary { op: BinaryOperator::Equal, left, @@ -16,7 +24,8 @@ use alloc::{boxed::Box, vec, vec::Vec}; } /// Construct a new boxed `Expression` A >= B -#[must_use] pub fn ge(left: Box, right: Box) -> Box { +#[must_use] +pub fn ge(left: Box, right: Box) -> Box { Box::new(Expression::Binary { op: BinaryOperator::GreaterThanOrEqual, left, @@ -25,7 +34,8 @@ use alloc::{boxed::Box, vec, vec::Vec}; } /// Construct a new boxed `Expression` A <= B -#[must_use] pub fn le(left: Box, right: Box) -> Box { +#[must_use] +pub fn le(left: Box, right: Box) -> Box { Box::new(Expression::Binary { op: BinaryOperator::LessThanOrEqual, left, @@ -34,7 +44,8 @@ use alloc::{boxed::Box, vec, vec::Vec}; } /// Construct a new boxed `Expression` NOT P -#[must_use] pub fn not(expr: Box) -> Box { +#[must_use] +pub fn not(expr: Box) -> Box { Box::new(Expression::Unary { op: UnaryOperator::Not, expr, @@ -42,7 +53,8 @@ use alloc::{boxed::Box, vec, vec::Vec}; } /// Construct a new boxed `Expression` P AND Q -#[must_use] pub fn and(left: Box, right: Box) -> Box { +#[must_use] +pub fn and(left: Box, right: Box) -> Box { Box::new(Expression::Binary { op: BinaryOperator::And, left, @@ -51,7 +63,8 @@ use alloc::{boxed::Box, vec, vec::Vec}; } /// Construct a new boxed `Expression` P OR Q -#[must_use] pub fn or(left: Box, right: Box) -> Box { +#[must_use] +pub fn or(left: Box, right: Box) -> Box { Box::new(Expression::Binary { op: BinaryOperator::Or, left, @@ -60,7 +73,8 @@ use alloc::{boxed::Box, vec, vec::Vec}; } /// Construct a new boxed `Expression` A + B -#[must_use] pub fn add(left: Box, right: Box) -> Box { +#[must_use] +pub fn add(left: Box, right: Box) -> Box { Box::new(Expression::Binary { op: BinaryOperator::Add, left, @@ -69,7 +83,8 @@ use alloc::{boxed::Box, vec, vec::Vec}; } /// Construct a new boxed `Expression` A - B -#[must_use] pub fn sub(left: Box, right: Box) -> Box { +#[must_use] +pub fn sub(left: Box, right: Box) -> Box { Box::new(Expression::Binary { op: BinaryOperator::Subtract, left, @@ -78,7 +93,8 @@ use alloc::{boxed::Box, vec, vec::Vec}; } /// Construct a new boxed `Expression` A * B -#[must_use] pub fn mul(left: Box, right: Box) -> Box { +#[must_use] +pub fn mul(left: Box, right: Box) -> Box { Box::new(Expression::Binary { op: BinaryOperator::Multiply, left, @@ -87,7 +103,8 @@ use alloc::{boxed::Box, vec, vec::Vec}; } /// Construct a new boxed `Expression` A / B -#[must_use] pub fn div(left: Box, right: Box) -> Box { +#[must_use] +pub fn div(left: Box, right: Box) -> Box { Box::new(Expression::Binary { op: BinaryOperator::Division, left, @@ -98,7 +115,8 @@ use alloc::{boxed::Box, vec, vec::Vec}; /// Get table from schema and name. /// /// If the schema is `None`, the table is assumed to be in the default schema. -#[must_use] pub fn tab(schema: Option<&str>, name: &str) -> Box { +#[must_use] +pub fn tab(schema: Option<&str>, name: &str) -> Box { Box::new(TableExpression::Named { table: name.parse().unwrap(), schema: schema.map(|schema| schema.parse().unwrap()), @@ -106,7 +124,8 @@ use alloc::{boxed::Box, vec, vec::Vec}; } /// Get column from name -#[must_use] pub fn col(name: &str) -> Box { +#[must_use] +pub fn col(name: &str) -> Box { Box::new(Expression::Column(name.parse().unwrap())) } @@ -116,7 +135,8 @@ pub fn lit>(literal: L) -> Box { } /// Compute the sum of an expression -#[must_use] pub fn sum(expr: Box) -> Box { +#[must_use] +pub fn sum(expr: Box) -> Box { Box::new(Expression::Aggregation { op: AggregationOperator::Sum, expr, @@ -124,7 +144,8 @@ pub fn lit>(literal: L) -> Box { } /// Compute the minimum of an expression -#[must_use] pub fn min(expr: Box) -> Box { +#[must_use] +pub fn min(expr: Box) -> Box { Box::new(Expression::Aggregation { op: AggregationOperator::Min, expr, @@ -132,7 +153,8 @@ pub fn lit>(literal: L) -> Box { } /// Compute the maximum of an expression -#[must_use] pub fn max(expr: Box) -> Box { +#[must_use] +pub fn max(expr: Box) -> Box { Box::new(Expression::Aggregation { op: AggregationOperator::Max, expr, @@ -140,7 +162,8 @@ pub fn lit>(literal: L) -> Box { } /// Count the amount of non-null entries of expression -#[must_use] pub fn count(expr: Box) -> Box { +#[must_use] +pub fn count(expr: Box) -> Box { Box::new(Expression::Aggregation { op: AggregationOperator::Count, expr, @@ -148,12 +171,14 @@ pub fn lit>(literal: L) -> Box { } /// Count the rows -#[must_use] pub fn count_all() -> Box { +#[must_use] +pub fn count_all() -> Box { count(Box::new(Expression::Wildcard)) } /// An expression with an alias i.e. EXPR AS ALIAS -#[must_use] pub fn aliased_expr(expr: Box, alias: &str) -> AliasedResultExpr { +#[must_use] +pub fn aliased_expr(expr: Box, alias: &str) -> AliasedResultExpr { AliasedResultExpr { expr, alias: alias.parse().unwrap(), @@ -161,12 +186,14 @@ pub fn lit>(literal: L) -> Box { } /// Select all columns from a table i.e. SELECT * -#[must_use] pub fn col_res_all() -> SelectResultExpr { +#[must_use] +pub fn col_res_all() -> SelectResultExpr { SelectResultExpr::ALL } /// Select one column from a table and give it an alias i.e. SELECT COL AS ALIAS -#[must_use] pub fn col_res(col_val: Box, alias: &str) -> SelectResultExpr { +#[must_use] +pub fn col_res(col_val: Box, alias: &str) -> SelectResultExpr { SelectResultExpr::AliasedResultExpr(AliasedResultExpr { expr: col_val, alias: alias.parse().unwrap(), @@ -174,12 +201,14 @@ pub fn lit>(literal: L) -> Box { } /// Select multiple columns from a table i.e. SELECT COL1, COL2, ... -#[must_use] pub fn cols_res(names: &[&str]) -> Vec { +#[must_use] +pub fn cols_res(names: &[&str]) -> Vec { names.iter().map(|name| col_res(col(name), name)).collect() } /// Compute the minimum of an expression and give it an alias i.e. SELECT MIN(EXPR) AS ALIAS -#[must_use] pub fn min_res(expr: Box, alias: &str) -> SelectResultExpr { +#[must_use] +pub fn min_res(expr: Box, alias: &str) -> SelectResultExpr { SelectResultExpr::AliasedResultExpr(AliasedResultExpr { expr: min(expr), alias: alias.parse().unwrap(), @@ -187,7 +216,8 @@ pub fn lit>(literal: L) -> Box { } /// Compute the maximum of an expression and give it an alias i.e. SELECT MAX(EXPR) AS ALIAS -#[must_use] pub fn max_res(expr: Box, alias: &str) -> SelectResultExpr { +#[must_use] +pub fn max_res(expr: Box, alias: &str) -> SelectResultExpr { SelectResultExpr::AliasedResultExpr(AliasedResultExpr { expr: max(expr), alias: alias.parse().unwrap(), @@ -195,7 +225,8 @@ pub fn lit>(literal: L) -> Box { } /// Compute the sum of an expression and give it an alias i.e. SELECT SUM(EXPR) AS ALIAS -#[must_use] pub fn sum_res(expr: Box, alias: &str) -> SelectResultExpr { +#[must_use] +pub fn sum_res(expr: Box, alias: &str) -> SelectResultExpr { SelectResultExpr::AliasedResultExpr(AliasedResultExpr { expr: sum(expr), alias: alias.parse().unwrap(), @@ -203,7 +234,8 @@ pub fn lit>(literal: L) -> Box { } /// Count the amount of non-null entries of expression and give it an alias i.e. SELECT COUNT(EXPR) AS ALIAS -#[must_use] pub fn count_res(expr: Box, alias: &str) -> SelectResultExpr { +#[must_use] +pub fn count_res(expr: Box, alias: &str) -> SelectResultExpr { SelectResultExpr::AliasedResultExpr(AliasedResultExpr { expr: count(expr), alias: alias.parse().unwrap(), @@ -211,7 +243,8 @@ pub fn lit>(literal: L) -> Box { } /// Count rows and give the result an alias i.e. SELECT COUNT(*) AS ALIAS -#[must_use] pub fn count_all_res(alias: &str) -> SelectResultExpr { +#[must_use] +pub fn count_all_res(alias: &str) -> SelectResultExpr { SelectResultExpr::AliasedResultExpr(AliasedResultExpr { expr: Expression::Aggregation { op: AggregationOperator::Count, @@ -223,7 +256,8 @@ pub fn lit>(literal: L) -> Box { } /// Generate a `SetExpression` of the kind SELECT COL1, COL2, ... FROM TAB WHERE EXPR GROUP BY ... -#[must_use] pub fn query( +#[must_use] +pub fn query( result_exprs: Vec, tab: Box, where_expr: Box, @@ -240,7 +274,8 @@ pub fn lit>(literal: L) -> Box { /// Generate a `SetExpression` of the kind SELECT COL1, COL2, ... FROM TAB GROUP BY ... /// /// Note that there is no WHERE clause. -#[must_use] pub fn query_all( +#[must_use] +pub fn query_all( result_exprs: Vec, tab: Box, group_by: Vec, @@ -256,7 +291,8 @@ pub fn lit>(literal: L) -> Box { /// Generate a query of the kind SELECT ... ORDER BY ... [LIMIT ... OFFSET ...] /// /// Note that `expr` is a boxed `SetExpression` -#[must_use] pub fn select( +#[must_use] +pub fn select( expr: Box, order_by: Vec, slice: Option, @@ -269,7 +305,8 @@ pub fn lit>(literal: L) -> Box { } /// Order by one column i.e. ORDER BY ID [ASC|DESC] -#[must_use] pub fn order(id: &str, direction: OrderByDirection) -> Vec { +#[must_use] +pub fn order(id: &str, direction: OrderByDirection) -> Vec { vec![OrderBy { expr: id.parse().unwrap(), direction, @@ -277,7 +314,8 @@ pub fn lit>(literal: L) -> Box { } /// Order by multiple columns i.e. ORDER BY ID0 [ASC|DESC], ID1 [ASC|DESC], ... -#[must_use] pub fn orders(ids: &[&str], directions: &[OrderByDirection]) -> Vec { +#[must_use] +pub fn orders(ids: &[&str], directions: &[OrderByDirection]) -> Vec { ids.iter() .zip(directions.iter()) .map(|(id, dir)| OrderBy { @@ -288,7 +326,8 @@ pub fn lit>(literal: L) -> Box { } /// Slice a query result using `LIMIT` and `OFFSET` clauses i.e. LIMIT N OFFSET M -#[must_use] pub fn slice(number_rows: u64, offset_value: i64) -> Option { +#[must_use] +pub fn slice(number_rows: u64, offset_value: i64) -> Option { Some(Slice { number_rows, offset_value, @@ -296,6 +335,7 @@ pub fn lit>(literal: L) -> Box { } /// Group by clause with multiple columns i.e. GROUP BY ID0, ID1, ... -#[must_use] pub fn group_by(ids: &[&str]) -> Vec { +#[must_use] +pub fn group_by(ids: &[&str]) -> Vec { ids.iter().map(|id| id.parse().unwrap()).collect() }