Skip to content

Commit

Permalink
chore: run cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mehulmathur16 authored and JayWhite2357 committed Oct 3, 2024
1 parent 743a3cf commit 9cbe4d0
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 53 deletions.
24 changes: 16 additions & 8 deletions crates/proof-of-sql-parser/src/intermediate_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -186,46 +188,52 @@ pub enum Expression {

impl Expression {
/// Create a new `SUM()`
#[must_use] pub fn sum(self) -> Box<Self> {
#[must_use]
pub fn sum(self) -> Box<Self> {
Box::new(Expression::Aggregation {
op: AggregationOperator::Sum,
expr: Box::new(self),
})
}

/// Create a new `MAX()`
#[must_use] pub fn max(self) -> Box<Self> {
#[must_use]
pub fn max(self) -> Box<Self> {
Box::new(Expression::Aggregation {
op: AggregationOperator::Max,
expr: Box::new(self),
})
}

/// Create a new `MIN()`
#[must_use] pub fn min(self) -> Box<Self> {
#[must_use]
pub fn min(self) -> Box<Self> {
Box::new(Expression::Aggregation {
op: AggregationOperator::Min,
expr: Box::new(self),
})
}

/// Create a new `COUNT()`
#[must_use] pub fn count(self) -> Box<Self> {
#[must_use]
pub fn count(self) -> Box<Self> {
Box::new(Expression::Aggregation {
op: AggregationOperator::Count,
expr: Box::new(self),
})
}

/// Create a new `FIRST()`
#[must_use] pub fn first(self) -> Box<Self> {
#[must_use]
pub fn first(self) -> Box<Self> {
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(),
Expand Down
4 changes: 2 additions & 2 deletions crates/proof-of-sql-parser/src/intermediate_decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion crates/proof-of-sql-parser/src/posql_time/timezone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 8 additions & 4 deletions crates/proof-of-sql-parser/src/resource_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}

Expand All @@ -63,7 +66,8 @@ impl ResourceId {
/// This method performs that transformation as well.
/// For more information, see
/// <https://space-and-time.atlassian.net/wiki/spaces/SE/pages/4947974/Gateway+Storage+Overview#Database-Resources>.
#[must_use] pub fn storage_format(&self) -> String {
#[must_use]
pub fn storage_format(&self) -> String {
let ResourceId {
schema,
object_name,
Expand Down
9 changes: 6 additions & 3 deletions crates/proof-of-sql-parser/src/select_statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ResourceId> {
#[must_use]
pub fn get_table_references(&self, default_schema: Identifier) -> Vec<ResourceId> {
let set_expression: &SetExpression = &(self.expr);

match set_expression {
Expand Down Expand Up @@ -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());
}
Expand Down
Loading

0 comments on commit 9cbe4d0

Please sign in to comment.