Skip to content

Commit

Permalink
Add union
Browse files Browse the repository at this point in the history
  • Loading branch information
tontinton committed Dec 6, 2024
1 parent a4b6e32 commit b6f7da0
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 119 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ inherits = "release"
lto = "thin"

[dependencies]
async-recursion = "1.1.1"
async-stream = "0.3.6"
axum = { version = "0.7.7", features = ["macros"] }
clap = { version = "4.5.20", features = ["derive"] }
Expand Down
10 changes: 9 additions & 1 deletion src/http_server.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{collections::HashMap, sync::Arc};

use async_recursion::async_recursion;
use axum::{
http::StatusCode,
response::{IntoResponse, Response},
Expand Down Expand Up @@ -30,6 +31,7 @@ struct State {

type SharedState = Arc<RwLock<State>>;

#[async_recursion]
async fn to_workflow(
state: SharedState,
query_steps: Vec<QueryStep>,
Expand Down Expand Up @@ -102,6 +104,11 @@ async fn to_workflow(
QueryStep::Summarize(config) => {
steps.push(WorkflowStep::Summarize(config));
}
QueryStep::Union(inner_steps) => {
steps.push(WorkflowStep::Union(
to_workflow(state.clone(), inner_steps).await?,
));
}
QueryStep::Count => {
if i != num_steps - 1 {
return Err(HttpError::new(
Expand All @@ -128,6 +135,7 @@ enum QueryStep {
Sort(Vec<Sort>),
Top(Vec<Sort>, u32),
Summarize(Summarize),
Union(Vec<QueryStep>),
Count,
}

Expand Down Expand Up @@ -184,7 +192,7 @@ async fn post_query_handler(
let workflow = to_workflow(state, req.query).await?;

debug!(?workflow, "Executing workflow");
if let Err(err) = workflow.execute().await {
if let Err(err) = workflow.execute_and_print().await {
return Err(HttpError::new(
StatusCode::INTERNAL_SERVER_ERROR,
format!("failed to execute workflow: {:?}", err),
Expand Down
Loading

0 comments on commit b6f7da0

Please sign in to comment.