Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions crates/core/src/common/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ use pest::iterators::Pairs;
#[derive(Debug, PartialEq)]
pub enum Expression {
Get(GetExpression),
Sum(SumExpression),
}


#[derive(Debug, PartialEq)]
pub struct SumExpression {
pub query: GetExpression,
}

impl SumExpression {
fn new(query: GetExpression) -> Self {
Self {
query
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Make constructor public and add input validation.

The constructor should be public to allow creating instances from other modules.

 impl SumExpression {
-    fn new(query: GetExpression) -> Self {
+    pub fn new(query: GetExpression) -> Result<Self, GetExpressionError> {
+        // Validate that the query returns numeric fields that can be summed
         Self {
             query
         }
     }
+
+    pub fn query(&self) -> &GetExpression {
+        &self.query
+    }
 }

Committable suggestion skipped: line range outside the PR's diff.


#[derive(Debug, PartialEq)]
Expand Down
15 changes: 14 additions & 1 deletion crates/core/src/interpreter/backend/execution_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::{
resolve_transaction::resolve_transaction_query,
};
use crate::common::{
entity::Entity, query_result::{ExpressionResult, QueryResult}, serializer::dump_results, types::{Expression, GetExpression}
entity::Entity, query_result::{ExpressionResult, QueryResult}, serializer::dump_results, types::{Expression, GetExpression, SumExpression}
};
use anyhow::Result;

Expand Down Expand Up @@ -36,6 +36,10 @@ impl ExecutionEngine {
let result = self.run_get_expr(&get_expr).await?;
query_results.push(QueryResult::new(result));
}
Expression::Sum(sum_expr) => {
let result = self.run_sum_expr(&sum_expr).await?;
query_results.push(QueryResult::new(result));
}
}
}

Expand All @@ -59,6 +63,15 @@ impl ExecutionEngine {

Ok(result)
}

async fn run_sum_expr(
&self,
expr: &SumExpression,
) -> Result<ExpressionResult> {
let query_result = self.run_get_expr(&expr.query).await?;

Ok(query_result)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Implement summation logic.

The method currently just returns the query result without performing any summation.

 async fn run_sum_expr(
     &self,
     expr: &SumExpression,
 ) -> Result<ExpressionResult> {
     let query_result = self.run_get_expr(&expr.query).await?;
-    
-    Ok(query_result)
+    match query_result {
+        ExpressionResult::Account(accounts) => {
+            // Sum numeric fields from accounts
+        }
+        ExpressionResult::Block(blocks) => {
+            // Sum numeric fields from blocks
+        }
+        // Handle other variants
+        _ => Err(anyhow::anyhow!("Cannot sum non-numeric fields")),
+    }
 }

Committable suggestion skipped: line range outside the PR's diff.

}

#[cfg(test)]
Expand Down