-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
118 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ version = "0.1.0" | |
edition = "2021" | ||
|
||
[dependencies] | ||
types = { workspace = true } | ||
anyhow = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use types::datalake::base::DataPoint; | ||
|
||
// TODO: Implement the avg function | ||
pub fn avg(values: &Vec<DataPoint>) -> usize { | ||
let mut sum = 0; | ||
for value in values { | ||
match value { | ||
DataPoint::Str(_) => panic!("String value found"), | ||
DataPoint::Int(int) => sum += int, | ||
} | ||
} | ||
sum / values.len() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use types::datalake::base::DataPoint; | ||
|
||
pub mod avg; | ||
|
||
/// Get [`AggregationFunction`] from function id | ||
pub fn get_aggregation_function_type(function_id: String) -> AggregationFunction { | ||
match function_id.as_str() { | ||
"AVG" => AggregationFunction::Avg, | ||
_ => panic!("Unknown aggregation function"), | ||
} | ||
} | ||
|
||
/// Aggregation function types | ||
pub enum AggregationFunction { | ||
Avg, | ||
} | ||
|
||
impl AggregationFunction { | ||
pub fn get_index(&self) -> usize { | ||
match self { | ||
AggregationFunction::Avg => 0, | ||
} | ||
} | ||
|
||
pub fn operation(&self, values: &Vec<DataPoint>) -> usize { | ||
match self { | ||
AggregationFunction::Avg => avg::avg(values), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,60 @@ | ||
use aggregation_functions::get_aggregation_function_type; | ||
use anyhow::{bail, Result}; | ||
use std::collections::HashMap; | ||
|
||
pub mod aggregation_functions; | ||
|
||
use types::{datalake::base::Derivable, task::ComputationalTask, Datalake}; | ||
|
||
pub struct EvaluationResult { | ||
pub result: HashMap<String, usize>, | ||
} | ||
|
||
impl EvaluationResult { | ||
pub fn new() -> Self { | ||
EvaluationResult { | ||
result: HashMap::new(), | ||
} | ||
} | ||
pub fn merkle_commit(&self) -> String { | ||
"merkle_commit".to_string() | ||
} | ||
} | ||
|
||
impl Default for EvaluationResult { | ||
fn default() -> Self { | ||
EvaluationResult::new() | ||
} | ||
} | ||
|
||
pub fn evaluator( | ||
mut compute_expressions: Vec<ComputationalTask>, | ||
datalake_for_tasks: Option<Vec<Datalake>>, | ||
) -> Result<EvaluationResult> { | ||
let mut results = EvaluationResult::new(); | ||
// If optional datalake_for_tasks is provided, need to assign the datalake to the corresponding task | ||
if let Some(datalake) = datalake_for_tasks { | ||
for (datalake_idx, datalake) in datalake.iter().enumerate() { | ||
let task = &mut compute_expressions[datalake_idx]; | ||
|
||
task.datalake = match datalake { | ||
Datalake::BlockSampled(block_datalake) => Some(block_datalake.derive()), | ||
Datalake::DynamicLayout(dynamic_layout_datalake) => { | ||
Some(dynamic_layout_datalake.derive()) | ||
} | ||
_ => bail!("Unknown datalake type"), | ||
}; | ||
} | ||
} | ||
|
||
// Evaulate the compute expressions | ||
for compute_expression in compute_expressions { | ||
let computation_task_id = compute_expression.to_string(); | ||
let datapoints = compute_expression.datalake.unwrap().compile(); | ||
let aggregation_fn = get_aggregation_function_type(compute_expression.aggregate_fn_id); | ||
let result = aggregation_fn.operation(&datapoints); | ||
results.result.insert(computation_task_id, result); | ||
} | ||
|
||
Ok(results) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters