Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suggestions #8

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 4 additions & 7 deletions src/handlers/airplane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,10 @@ impl FlightService for AirServiceImpl {
})?;
let time = Instant::now();

let stream_name_clone = stream_name.clone();
let (records, _) =
match tokio::task::spawn_blocking(move || query.execute(stream_name_clone)).await {
Ok(Ok((records, fields))) => (records, fields),
Ok(Err(e)) => return Err(Status::internal(e.to_string())),
Err(err) => return Err(Status::internal(err.to_string())),
};
let (records, _) = query
.execute(&stream_name)
.await
.map_err(|err| Status::internal(err.to_string()))?;

/*
* INFO: No returning the schema with the data.
Expand Down
14 changes: 1 addition & 13 deletions src/handlers/http/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use actix_web::http::header::ContentType;
use actix_web::web::{self, Json};
use actix_web::{FromRequest, HttpRequest, HttpResponse, Responder};
use arrow_array::RecordBatch;
use chrono::{DateTime, Utc};
use datafusion::common::tree_node::TreeNode;
use datafusion::error::DataFusionError;
Expand Down Expand Up @@ -131,7 +130,7 @@ pub async fn query(req: HttpRequest, query_request: Query) -> Result<HttpRespons

return Ok(HttpResponse::Ok().json(response));
}
let (records, fields) = execute_query(query, table_name.clone()).await?;
let (records, fields) = query.execute(&table_name).await?;

let response = QueryResponse {
records,
Expand All @@ -150,17 +149,6 @@ pub async fn query(req: HttpRequest, query_request: Query) -> Result<HttpRespons
Ok(response)
}

async fn execute_query(
query: LogicalQuery,
stream_name: String,
) -> Result<(Vec<RecordBatch>, Vec<String>), QueryError> {
match tokio::task::spawn_blocking(move || query.execute(stream_name)).await {
Ok(Ok(result)) => Ok(result),
Ok(Err(e)) => Err(QueryError::Execute(e)),
Err(e) => Err(QueryError::Anyhow(anyhow::Error::msg(e.to_string()))),
}
}

pub async fn get_counts(
req: HttpRequest,
counts_request: Json<CountsRequest>,
Expand Down
5 changes: 2 additions & 3 deletions src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,11 @@ impl Query {
SessionContext::new_with_state(state)
}

#[tokio::main(flavor = "multi_thread")]
pub async fn execute(
&self,
stream_name: String,
stream_name: &str,
) -> Result<(Vec<RecordBatch>, Vec<String>), ExecuteError> {
let time_partition = PARSEABLE.get_stream(&stream_name)?.get_time_partition();
let time_partition = PARSEABLE.get_stream(stream_name)?.get_time_partition();

let df = QUERY_SESSION
.execute_logical_plan(self.final_logical_plan(&time_partition))
Expand Down
Loading