Skip to content

Commit b555f9b

Browse files
merge trino query code changes to main (#923)
if all env vars specific to Trino are set - P_TRINO_ENDPOINT P_TRINO_CATALOG_NAME P_TRINO_SCHEMA P_TRINO_USER_NAME About API Response sample - ` { "version": "v1.5.0", "uiVersion": "development", "commit": "cc8cf38", "deploymentId": "01J649HC5HPRNVD0VNK7Q6JMFY", "updateAvailable": false, "latestVersion": "v1.5.0", "llmActive": false, "llmProvider": null, "oidcActive": false, "license": "AGPL-3.0-only", "mode": "Distributed (Query)", "staging": "", "hotTier": "Disabled", "grpcPort": 8001, "store": { "type": "S3 bucket", "path": "https://s3.us-east-2.amazonaws.com/clickbenchtest" }, "analytics": { "clarityTag": null }, "queryEngine": "Trino" } ` if any of the above env var is missing, server will return About API response as - ` { "version": "v1.5.0", "uiVersion": "development", "commit": "cc8cf38", "deploymentId": "01J649HC5HPRNVD0VNK7Q6JMFY", "updateAvailable": false, "latestVersion": "v1.5.0", "llmActive": false, "llmProvider": null, "oidcActive": false, "license": "AGPL-3.0-only", "mode": "Distributed (Query)", "staging": "", "hotTier": "Disabled", "grpcPort": 8001, "store": { "type": "S3 bucket", "path": "https://s3.us-east-2.amazonaws.com/clickbenchtest" }, "analytics": { "clarityTag": null }, "queryEngine": "Parseable" } ` based on the field `queryEngine` a client can decide whether to user /query or /trinoquery endpoint
1 parent c916f1f commit b555f9b

File tree

9 files changed

+672
-303
lines changed

9 files changed

+672
-303
lines changed

server/src/cli.rs

Lines changed: 331 additions & 277 deletions
Large diffs are not rendered by default.

server/src/handlers.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ const COOKIE_AGE_DAYS: usize = 7;
4040
const SESSION_COOKIE_NAME: &str = "session";
4141
const USER_COOKIE_NAME: &str = "username";
4242

43+
//constants for trino
44+
const TRINO_SCHEMA: &str = "x-trino-schema";
45+
const TRINO_CATALOG: &str = "x-trino-catalog";
46+
const TRINO_USER: &str = "x-trino-user";
47+
4348
// constants for log Source values for known sources and formats
4449
const LOG_SOURCE_KINESIS: &str = "kinesis";
4550

server/src/handlers/http.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ mod otel;
4040
pub(crate) mod query;
4141
pub(crate) mod rbac;
4242
pub(crate) mod role;
43+
pub(crate) mod trino;
4344
pub mod users;
4445
pub const MAX_EVENT_PAYLOAD_SIZE: usize = 10485760;
4546
pub const API_BASE_PATH: &str = "api";

server/src/handlers/http/about.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818

1919
use actix_web::web::Json;
20-
use human_size::SpecificSize;
2120
use serde_json::json;
2221

2322
use crate::{
@@ -79,21 +78,6 @@ pub async fn about() -> Json<serde_json::Value> {
7978
let is_oidc_active = CONFIG.parseable.openid.is_some();
8079
let ui_version = option_env!("UI_VERSION").unwrap_or("development");
8180

82-
let cache_details: String = if CONFIG.cache_dir().is_none() {
83-
"Disabled".to_string()
84-
} else {
85-
let cache_dir: &Option<PathBuf> = CONFIG.cache_dir();
86-
let cache_size: SpecificSize<human_size::Gigibyte> =
87-
SpecificSize::new(CONFIG.cache_size() as f64, human_size::Byte)
88-
.unwrap()
89-
.into();
90-
format!(
91-
"Enabled, Path: {} (Size: {})",
92-
cache_dir.as_ref().unwrap().display(),
93-
cache_size
94-
)
95-
};
96-
9781
let hot_tier_details: String = if CONFIG.hot_tier_dir().is_none() {
9882
"Disabled".to_string()
9983
} else {
@@ -105,6 +89,16 @@ pub async fn about() -> Json<serde_json::Value> {
10589
};
10690

10791
let ms_clarity_tag = &CONFIG.parseable.ms_clarity_tag;
92+
let mut query_engine = "Parseable".to_string();
93+
if let (Some(_), Some(_), Some(_), Some(_)) = (
94+
CONFIG.parseable.trino_endpoint.as_ref(),
95+
CONFIG.parseable.trino_catalog.as_ref(),
96+
CONFIG.parseable.trino_schema.as_ref(),
97+
CONFIG.parseable.trino_username.as_ref(),
98+
) {
99+
// Trino is enabled
100+
query_engine = "Trino".to_string();
101+
}
108102

109103
Json(json!({
110104
"version": current_version,
@@ -119,7 +113,6 @@ pub async fn about() -> Json<serde_json::Value> {
119113
"license": "AGPL-3.0-only",
120114
"mode": mode,
121115
"staging": staging,
122-
"cache": cache_details,
123116
"hotTier": hot_tier_details,
124117
"grpcPort": grpc_port,
125118
"store": {
@@ -128,7 +121,8 @@ pub async fn about() -> Json<serde_json::Value> {
128121
},
129122
"analytics": {
130123
"clarityTag": ms_clarity_tag
131-
}
124+
},
125+
"queryEngine": query_engine
132126

133127
}))
134128
}

server/src/handlers/http/modal/query_server.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ impl QueryServer {
154154
web::scope(&base_path())
155155
// POST "/query" ==> Get results of the SQL query passed in request body
156156
.service(Server::get_query_factory())
157+
.service(Server::get_trino_factory())
157158
.service(Server::get_cache_webscope())
158159
.service(Server::get_liveness_factory())
159160
.service(Server::get_readiness_factory())

server/src/handlers/http/modal/server.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use crate::handlers::http::base_path;
2424
use crate::handlers::http::cache;
2525
use crate::handlers::http::health_check;
2626
use crate::handlers::http::query;
27+
use crate::handlers::http::trino;
2728
use crate::handlers::http::users::dashboards;
2829
use crate::handlers::http::users::filters;
2930
use crate::handlers::http::API_BASE_PATH;
@@ -169,6 +170,7 @@ impl Server {
169170
web::scope(&base_path())
170171
// POST "/query" ==> Get results of the SQL query passed in request body
171172
.service(Self::get_query_factory())
173+
.service(Self::get_trino_factory())
172174
.service(Self::get_cache_webscope())
173175
.service(Self::get_ingest_factory())
174176
.service(Self::get_liveness_factory())
@@ -187,6 +189,12 @@ impl Server {
187189
.service(Self::get_generated());
188190
}
189191

192+
// get the trino factory
193+
pub fn get_trino_factory() -> Resource {
194+
web::resource("/trinoquery")
195+
.route(web::post().to(trino::trino_query).authorize(Action::Query))
196+
}
197+
190198
pub fn get_metrics_webscope() -> Scope {
191199
web::scope("/metrics").service(
192200
web::resource("").route(web::get().to(metrics::get).authorize(Action::Metrics)),

server/src/handlers/http/query.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,3 +511,9 @@ impl actix_web::ResponseError for QueryError {
511511
.body(self.to_string())
512512
}
513513
}
514+
515+
impl From<reqwest::Error> for QueryError {
516+
fn from(value: reqwest::Error) -> Self {
517+
QueryError::Anyhow(anyhow::Error::msg(value.to_string()))
518+
}
519+
}

0 commit comments

Comments
 (0)